Debian Codegraph @

tests/api/stubs.c

raw symbols SCIP
1 /*
2 * ProFTPD - FTP server API testsuite
3 * Copyright (c) 2008-2020 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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, The ProFTPD Project team and other respective
20 * copyright holders give permission to link this program with OpenSSL, and
21 * distribute the resulting executable, without including the source code for
22 * OpenSSL in the source distribution.
23 */
24
25 #include "tests.h"
26
27 /* Stubs */
28
29 session_t session;
30
31 char ServerType = SERVER_STANDALONE;
32 int ServerUseReverseDNS = 1;
33 unsigned char is_master = FALSE;
34 server_rec *main_server = NULL;
35 pid_t mpid = 1;
36 module *static_modules[] = { NULL };
37 module *loaded_modules = NULL;
38 xaset_t *server_list = NULL;
39
40 static cmd_rec *next_cmd = NULL;
41 static const char *tests_proto = "ftp";
42
43 volatile unsigned int recvd_signal_flags = 0;
44
45 int tests_stubs_set_next_cmd(cmd_rec *cmd) {
46 next_cmd = cmd;
47 return 0;
48 }
49
50 int tests_stubs_set_main_server(server_rec *s) {
51 main_server = s;
52 return 0;
53 }
54
55 int tests_stubs_set_protocol(const char *proto) {
56 tests_proto = proto;
57 return 0;
58 }
59
60 const char *get_full_cmd(cmd_rec *cmd) {
61 return "TEST";
62 }
63
64 void init_dirtree(void) {
65 pool *main_pool;
66 xaset_t *servers;
67
68 main_pool = make_sub_pool(permanent_pool);
69 pr_pool_tag(main_pool, "testsuite#main_server pool");
70
71 servers = xaset_create(main_pool, NULL);
72
73 main_server = (server_rec *) pcalloc(main_pool, sizeof(server_rec));
74 xaset_insert(servers, (xasetmember_t *) main_server);
75
76 main_server->pool = main_pool;
77 main_server->set = servers;
78 main_server->sid = 1;
79 main_server->notes = pr_table_nalloc(main_pool, 0, 8);
80
81 /* TCP KeepAlive is enabled by default, with the system defaults. */
82 main_server->tcp_keepalive = palloc(main_server->pool,
83 sizeof(struct tcp_keepalive));
84 main_server->tcp_keepalive->keepalive_enabled = TRUE;
85 main_server->tcp_keepalive->keepalive_idle = -1;
86 main_server->tcp_keepalive->keepalive_count = -1;
87 main_server->tcp_keepalive->keepalive_intvl = -1;
88
89 main_server->ServerPort = 21;
90 }
91
92 int pr_cmd_dispatch(cmd_rec *cmd) {
93 return 0;
94 }
95
96 int pr_cmd_read(cmd_rec **cmd) {
97 if (next_cmd != NULL) {
98 *cmd = next_cmd;
99 next_cmd = NULL;
100
101 } else {
102 *cmd = NULL;
103 }
104
105 return 0;
106 }
107
108 int pr_config_get_server_xfer_bufsz(int direction) {
109 int bufsz = -1;
110
111 switch (direction) {
112 case PR_NETIO_IO_RD:
113 bufsz = PR_TUNABLE_DEFAULT_RCVBUFSZ;
114 break;
115
116 case PR_NETIO_IO_WR:
117 bufsz = PR_TUNABLE_DEFAULT_SNDBUFSZ;
118 break;
119
120 default:
121 errno = EINVAL;
122 return -1;
123 }
124
125 return bufsz;
126 }
127
128 void pr_log_auth(int level, const char *fmt, ...) {
129 if (getenv("TEST_VERBOSE") != NULL) {
130 va_list msg;
131
132 fprintf(stderr, "AUTH%d: ", level);
133
134 va_start(msg, fmt);
135 vfprintf(stderr, fmt, msg);
136 va_end(msg);
137
138 fprintf(stderr, "\n");
139 }
140 }
141
142 void pr_log_debug(int level, const char *fmt, ...) {
143 if (getenv("TEST_VERBOSE") != NULL) {
144 va_list msg;
145
146 fprintf(stderr, "DEBUG%d: ", level);
147
148 va_start(msg, fmt);
149 vfprintf(stderr, fmt, msg);
150 va_end(msg);
151
152 fprintf(stderr, "\n");
153 }
154 }
155
156 int pr_log_event_generate(unsigned int log_type, int log_fd, int log_level,
157 const char *log_msg, size_t log_msglen) {
158 errno = ENOSYS;
159 return -1;
160 }
161
162 int pr_log_event_listening(unsigned int log_type) {
163 return FALSE;
164 }
165
166 void pr_log_pri(int prio, const char *fmt, ...) {
167 if (getenv("TEST_VERBOSE") != NULL) {
168 va_list msg;
169
170 fprintf(stderr, "PRI%d: ", prio);
171
172 va_start(msg, fmt);
173 vfprintf(stderr, fmt, msg);
174 va_end(msg);
175
176 fprintf(stderr, "\n");
177 }
178 }
179
180 int pr_log_openfile(const char *log_file, int *log_fd, mode_t log_mode) {
181 int res;
182 struct stat st;
183
184 if (log_file == NULL ||
185 log_fd == NULL) {
186 errno = EINVAL;
187 return -1;
188 }
189
190 res = stat(log_file, &st);
191 if (res < 0) {
192 if (errno != ENOENT) {
193 return -1;
194 }
195
196 } else {
197 if (S_ISDIR(st.st_mode)) {
198 errno = EISDIR;
199 return -1;
200 }
201 }
202
203 *log_fd = dup(STDERR_FILENO);
204 return 0;
205 }
206
207 void pr_log_stacktrace(int fd, const char *name) {
208 }
209
210 int pr_log_vwritefile(int fd, const char *ident, const char *fmt, va_list msg) {
211 (void) fd;
212
213 if (ident == NULL) {
214 errno = EINVAL;
215 return -1;
216 }
217
218 if (getenv("TEST_VERBOSE") != NULL) {
219 fprintf(stderr, "%s: ", ident);
220 vfprintf(stderr, fmt, msg);
221 fprintf(stderr, "\n");
222 }
223
224 return 0;
225 }
226
227 int pr_proctitle_get(char *buf, size_t buflen) {
228 errno = ENOSYS;
229 return -1;
230 }
231
232 void pr_proctitle_set(const char *fmt, ...) {
233 }
234
235 void pr_proctitle_set_str(const char *str) {
236 }
237
238 void pr_session_disconnect(module *m, int reason_code, const char *details) {
239 }
240
241 const char *pr_session_get_disconnect_reason(const char **details) {
242 if (session.disconnect_reason < 0) {
243 return NULL;
244 }
245
246 if (details != NULL) {
247 *details = "bebugging";
248 }
249
250 return "testing";
251 }
252
253 const char *pr_session_get_protocol(int flags) {
254 if (tests_proto == NULL) {
255 return "ftp";
256 }
257
258 return tests_proto;
259 }
260
261 int pr_session_set_idle(void) {
262 return 0;
263 }
264
265 void pr_signals_handle(void) {
266 }