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

proftpd / proftpd / 30135626854

25 Jul 2026 12:15AM UTC coverage: 93.034% (+0.6%) from 92.428%
30135626854

push

github

51363 of 55209 relevant lines covered (93.03%)

219.82 hits per line

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

91.8
/tests/api/stubs.c
1
/*
2
 * ProFTPD - FTP server API testsuite
3
 * Copyright (c) 2008-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
#include "tests.h"
25

26
/* Stubs */
27

28
session_t session;
29

30
char ServerType = SERVER_STANDALONE;
31
int ServerUseReverseDNS = 1;
32
unsigned char is_master = FALSE;
33
server_rec *main_server = NULL;
34
pid_t mpid = 1;
35
module *static_modules[] = { NULL };
36
module *loaded_modules = NULL;
37
xaset_t *server_list = NULL;
38

39
static cmd_rec *next_cmd = NULL;
40
static const char *tests_proto = "ftp";
41

42
volatile unsigned int recvd_signal_flags = 0;
43

44
int tests_stubs_set_next_cmd(cmd_rec *cmd) {
45
  next_cmd = cmd;
7✔
46
  return 0;
7✔
47
}
7✔
48

49
int tests_stubs_set_main_server(server_rec *s) {
50
  main_server = s;
80✔
51
  return 0;
80✔
52
}
80✔
53

54
int tests_stubs_set_protocol(const char *proto) {
55
  tests_proto = proto;
12✔
56
  return 0;
12✔
57
}
12✔
58

59
const char *get_full_cmd(cmd_rec *cmd) {
60
  return "TEST";
6✔
61
}
6✔
62

63
void init_dirtree(void) {
64
  pool *main_pool;
22✔
65
  xaset_t *servers;
22✔
66

22✔
67
  main_pool = make_sub_pool(permanent_pool);
68
  pr_pool_tag(main_pool, "testsuite#main_server pool");
22✔
69

22✔
70
  servers = xaset_create(main_pool, NULL);
71

22✔
72
  main_server = (server_rec *) pcalloc(main_pool, sizeof(server_rec));
73
  xaset_insert(servers, (xasetmember_t *) main_server);
22✔
74

22✔
75
  main_server->pool = main_pool;
76
  main_server->set = servers;
22✔
77
  main_server->sid = 1;
22✔
78
  main_server->notes = pr_table_nalloc(main_pool, 0, 8);
22✔
79

22✔
80
  /* TCP KeepAlive is enabled by default, with the system defaults. */
81
  main_server->tcp_keepalive = palloc(main_server->pool,
82
    sizeof(struct tcp_keepalive));
22✔
83
  main_server->tcp_keepalive->keepalive_enabled = TRUE;
84
  main_server->tcp_keepalive->keepalive_idle = -1;
22✔
85
  main_server->tcp_keepalive->keepalive_count = -1;
22✔
86
  main_server->tcp_keepalive->keepalive_intvl = -1;
22✔
87

22✔
88
  main_server->ServerPort = 21;
89
}
22✔
90

22✔
91
int pr_cmd_dispatch(cmd_rec *cmd) {
92
  return 0;
3✔
93
}
3✔
94

95
int pr_cmd_read(cmd_rec **cmd) {
96
  if (next_cmd != NULL) {
14✔
97
    *cmd = next_cmd;
14✔
98
    next_cmd = NULL;
7✔
99

7✔
100
  } else {
101
    *cmd = NULL;
102
  }
7✔
103

104
  return 0;
105
}
14✔
106

107
int pr_config_get_server_xfer_bufsz(int direction) {
108
  int bufsz = -1;
91✔
109

91✔
110
  switch (direction) {
111
    case PR_NETIO_IO_RD:
91✔
112
      bufsz = PR_TUNABLE_DEFAULT_RCVBUFSZ;
113
      break;
114

115
    case PR_NETIO_IO_WR:
116
      bufsz = PR_TUNABLE_DEFAULT_SNDBUFSZ;
117
      break;
118

119
    default:
120
      errno = EINVAL;
1✔
121
      return -1;
1✔
122
  }
1✔
123

124
  return bufsz;
125
}
126

127
void pr_log_auth(int level, const char *fmt, ...) {
128
  if (getenv("TEST_VERBOSE") != NULL) {
1✔
129
    va_list msg;
1✔
130

1✔
131
    fprintf(stderr, "AUTH%d: ", level);
132

1✔
133
    va_start(msg, fmt);
134
    vfprintf(stderr, fmt, msg);
1✔
135
    va_end(msg);
1✔
136

1✔
137
    fprintf(stderr, "\n");
138
  }
1✔
139
}
140

1✔
141
void pr_log_debug(int level, const char *fmt, ...) {
142
  if (getenv("TEST_VERBOSE") != NULL) {
149✔
143
    va_list msg;
149✔
144

149✔
145
    fprintf(stderr, "DEBUG%d: ", level);
146

149✔
147
    va_start(msg, fmt);
148
    vfprintf(stderr, fmt, msg);
149✔
149
    va_end(msg);
149✔
150

149✔
151
    fprintf(stderr, "\n");
152
  }
149✔
153
}
154

149✔
155
int pr_log_event_generate(unsigned int log_type, int log_fd, int log_level,
156
    const char *log_msg, size_t log_msglen) {
4,909✔
157
  errno = ENOSYS;
158
  return -1;
4,909✔
159
}
4,909✔
160

161
int pr_log_event_listening(unsigned int log_type) {
162
  return FALSE;
7,266✔
163
}
7,266✔
164

165
void pr_log_pri(int prio, const char *fmt, ...) {
166
  if (getenv("TEST_VERBOSE") != NULL) {
133✔
167
    va_list msg;
133✔
168

133✔
169
    fprintf(stderr, "PRI%d: ", prio);
170

133✔
171
    va_start(msg, fmt);
172
    vfprintf(stderr, fmt, msg);
133✔
173
    va_end(msg);
133✔
174

133✔
175
    fprintf(stderr, "\n");
176
  }
133✔
177
}
178

133✔
179
int pr_log_openfile(const char *log_file, int *log_fd, mode_t log_mode) {
180
  int res;
3✔
181
  struct stat st;
3✔
182

3✔
183
  if (log_file == NULL ||
184
      log_fd == NULL) {
3✔
185
    errno = EINVAL;
3✔
186
    return -1;
×
187
  }
×
188

189
  res = stat(log_file, &st);
190
  if (res < 0) {
3✔
191
    if (errno != ENOENT) {
3✔
192
      return -1;
1✔
193
    }
194

195
  } else {
196
    if (S_ISDIR(st.st_mode)) {
197
      errno = EISDIR;
2✔
198
      return -1;
2✔
199
    }
2✔
200
  }
201

202
  *log_fd = dup(STDERR_FILENO);
203
  return 0;
1✔
204
}
1✔
205

206
void pr_log_stacktrace(int fd, const char *name) {
207
}
7✔
208

7✔
209
int pr_log_vwritefile(int fd, const char *ident, const char *fmt, va_list msg) {
210
  (void) fd;
1✔
211

1✔
212
  if (ident == NULL) {
213
    errno = EINVAL;
1✔
214
    return -1;
×
215
  }
×
216

217
  if (getenv("TEST_VERBOSE") != NULL) {
218
    fprintf(stderr, "%s: ", ident);
1✔
219
    vfprintf(stderr, fmt, msg);
1✔
220
    fprintf(stderr, "\n");
1✔
221
  }
1✔
222

223
  return 0;
224
}
225

226
int pr_proctitle_get(char *buf, size_t buflen) {
227
  errno = ENOSYS;
3✔
228
  return -1;
3✔
229
}
3✔
230

231
void pr_proctitle_set(const char *fmt, ...) {
232
}
×
233

×
234
void pr_proctitle_set_str(const char *str) {
235
}
×
236

×
237
void pr_session_disconnect(module *m, int reason_code, const char *details) {
238
}
×
239

×
240
const char *pr_session_get_disconnect_reason(const char **details) {
241
  if (session.disconnect_reason < 0) {
2✔
242
    return NULL;
2✔
243
  }
244

245
  if (details != NULL) {
246
    *details = "bebugging";
1✔
247
  }
1✔
248

249
  return "testing";
250
}
251

252
const char *pr_session_get_protocol(int flags) {
253
  if (tests_proto == NULL) {
27✔
254
    return "ftp";
27✔
255
  }
9✔
256

257
  return tests_proto;
258
}
259

260
int pr_session_set_idle(void) {
261
  return 0;
23✔
262
}
23✔
263

264
void pr_signals_handle(void) {
265
}
212,040✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc