• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proftpd / proftpd / 26127302554

19 May 2026 07:34PM UTC coverage: 92.635% (-0.4%) from 93.024%
26127302554

push

github

Castaglia
Make a flaky, racy mod_copy regression test more reliable.

47303 of 51064 relevant lines covered (92.63%)

241.07 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.83
/src/help.c
1
/*
2
 * ProFTPD - FTP server daemon
3
 * Copyright (c) 2004-2026 The ProFTPD Project team
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, see <https://www.gnu.org/licenses/>.
17
 *
18
 * As a special exemption, The ProFTPD Project team and other respective
19
 * copyright holders give permission to link this program with OpenSSL, and
20
 * distribute the resulting executable, without including the source code for
21
 * OpenSSL in the source distribution.
22
 */
23

24
/* HELP management code */
25

26
#include "conf.h"
27

28
struct help_rec {
29
  const char *cmd;
30
  const char *syntax;
31
  int impl;
32
};
33

34
static pool *help_pool = NULL;
35
static array_header *help_list = NULL;
36

37
void pr_help_add(const char *cmd, const char *syntax, int impl) {
7✔
38
  struct help_rec *help;
39

40
  if (cmd == NULL ||
14✔
41
      syntax == NULL) {
7✔
42
    return;
43
  }
44

45
  /* If no list has been allocated, create one. */
46
  if (help_pool == NULL) {
5✔
47
    help_pool = make_sub_pool(permanent_pool);
2✔
48
    pr_pool_tag(help_pool, "Help Pool");
2✔
49
    help_list = make_array(help_pool, 0, sizeof(struct help_rec));
2✔
50
  }
51

52
  /* Make sure that the command being added isn't already in the list.
53
   * However, if it _is_ already in the list, but it's marked as not
54
   * implemented, _and_ the given impl flag is TRUE, then handle it
55
   * accordingly.
56
   */
57
  if (help_list->nelts > 0) {
5✔
58
    register unsigned int i = 0;
3✔
59
    struct help_rec *helps = help_list->elts;
3✔
60

61
    for (i = 0; i < help_list->nelts; i++) {
5✔
62
      if (strcmp(helps[i].cmd, cmd) == 0) {
3✔
63
        if (helps[i].impl == FALSE &&
1✔
64
            impl == TRUE) {
65
          helps[i].impl = impl;
1✔
66
        }
67

68
        return;
69
      }
70
    }
71
  }
72

73
  help = push_array(help_list);
4✔
74
  help->cmd = pstrdup(help_pool, cmd);
4✔
75
  help->syntax = pstrdup(help_pool, syntax);
4✔
76
  help->impl = impl;
4✔
77
}
78

79
int pr_help_add_response(cmd_rec *cmd, const char *target) {
5✔
80
  if (cmd == NULL) {
5✔
81
    errno = EINVAL;
1✔
82
    return -1;
1✔
83
  }
84

85
  if (help_list) {
4✔
86
    register unsigned int i;
87
    struct help_rec *helps = help_list->elts;
3✔
88
    char *outa[8], *outstr;
89
    char buf[9] = {'\0'};
3✔
90

91
    if (target == NULL) {
3✔
92
      const char *server_admin = "ftp-admin";
1✔
93
      int col = 0;
1✔
94

95
      pr_response_add(R_214,
1✔
96
        _("The following commands are recognized (* =>'s unimplemented):"));
1✔
97

98
      memset(outa, '\0', sizeof(outa));
1✔
99

100
      for (i = 0; i < help_list->nelts; i++) {
3✔
101
        outstr = "";
1✔
102

103
        if (helps[i].impl) {
1✔
104
          outa[col++] = (char *) helps[i].cmd;
1✔
105

106
        } else {
107
          outa[col++] = pstrcat(cmd->tmp_pool, helps[i].cmd, "*", NULL);
×
108
        }
109

110
        /* 8 rows */
111
        if ((i + 1) % 8 == 0 ||
2✔
112
            (i+1 == help_list->nelts)) {
1✔
113
          register unsigned int j;
114

115
          for (j = 0; j < 8; j++) {
1✔
116
            if (outa[j]) {
2✔
117
              pr_snprintf(buf, sizeof(buf), "%-8s", outa[j]);
1✔
118
              buf[sizeof(buf)-1] = '\0';
1✔
119
              outstr = pstrcat(cmd->tmp_pool, outstr, buf, NULL);
1✔
120

121
            } else {
122
              break;
123
            }
124
          }
125

126
          if (*outstr) {
1✔
127
            pr_response_add(R_DUP, "%s", outstr);
1✔
128
          }
129

130
          memset(outa, '\0', sizeof(outa));
1✔
131
          col = 0;
1✔
132
        }
133
      }
134

135
      if (cmd->server != NULL &&
1✔
136
          cmd->server->ServerAdmin != NULL) {
×
137
        server_admin = cmd->server->ServerAdmin;
×
138
      }
139

140
      pr_response_add(R_DUP, _("Direct comments to %s"), server_admin);
1✔
141
      return 0;
1✔
142
    }
143

144
    /* List the syntax for the given target command. */
145
    for (i = 0; i < help_list->nelts; i++) {
1✔
146
      if (strcasecmp(helps[i].cmd, target) == 0) {
3✔
147
        pr_response_add(R_214, "Syntax: %s %s", helps[i].cmd,
2✔
148
          helps[i].syntax);
149
        return 0;
2✔
150
      }
151
    }
152
  }
153

154
  errno = ENOENT;
1✔
155
  return -1;
1✔
156
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc