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

proftpd / proftpd / 26127302613

19 May 2026 09:51PM UTC coverage: 93.024% (+0.4%) from 92.635%
26127302613

push

github

51329 of 55178 relevant lines covered (93.02%)

215.14 hits per line

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

95.16
/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) {
38
  struct help_rec *help;
7✔
39

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

45
  /* If no list has been allocated, create one. */
46
  if (help_pool == NULL) {
47
    help_pool = make_sub_pool(permanent_pool);
5✔
48
    pr_pool_tag(help_pool, "Help Pool");
2✔
49
    help_list = make_array(help_pool, 0, sizeof(struct help_rec));
2✔
50
  }
2✔
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) {
58
    register unsigned int i = 0;
5✔
59
    struct help_rec *helps = help_list->elts;
3✔
60

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

68
        return;
69
      }
1✔
70
    }
71
  }
72

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

154
  errno = ENOENT;
155
  return -1;
1✔
156
}
1✔
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