1 /*
2  * ProFTPD - FTP server API testsuite
3  * Copyright (c) 2008-2017 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 
42 volatile unsigned int recvd_signal_flags = 0;
43 
tests_stubs_set_next_cmd(cmd_rec * cmd)44 int tests_stubs_set_next_cmd(cmd_rec *cmd) {
45   next_cmd = cmd;
46   return 0;
47 }
48 
tests_stubs_set_main_server(server_rec * s)49 int tests_stubs_set_main_server(server_rec *s) {
50   main_server = s;
51   return 0;
52 }
53 
get_full_cmd(cmd_rec * cmd)54 const char *get_full_cmd(cmd_rec *cmd) {
55   return "TEST";
56 }
57 
init_dirtree(void)58 void init_dirtree(void) {
59   pool *main_pool;
60   xaset_t *servers;
61 
62   main_pool = make_sub_pool(permanent_pool);
63   pr_pool_tag(main_pool, "testsuite#main_server pool");
64 
65   servers = xaset_create(main_pool, NULL);
66 
67   main_server = (server_rec *) pcalloc(main_pool, sizeof(server_rec));
68   xaset_insert(servers, (xasetmember_t *) main_server);
69 
70   main_server->pool = main_pool;
71   main_server->set = servers;
72   main_server->sid = 1;
73   main_server->notes = pr_table_nalloc(main_pool, 0, 8);
74 
75   /* TCP KeepAlive is enabled by default, with the system defaults. */
76   main_server->tcp_keepalive = palloc(main_server->pool,
77     sizeof(struct tcp_keepalive));
78   main_server->tcp_keepalive->keepalive_enabled = TRUE;
79   main_server->tcp_keepalive->keepalive_idle = -1;
80   main_server->tcp_keepalive->keepalive_count = -1;
81   main_server->tcp_keepalive->keepalive_intvl = -1;
82 
83   main_server->ServerPort = 21;
84 }
85 
pr_cmd_dispatch(cmd_rec * cmd)86 int pr_cmd_dispatch(cmd_rec *cmd) {
87   return 0;
88 }
89 
pr_cmd_read(cmd_rec ** cmd)90 int pr_cmd_read(cmd_rec **cmd) {
91   if (next_cmd != NULL) {
92     *cmd = next_cmd;
93     next_cmd = NULL;
94 
95   } else {
96     *cmd = NULL;
97   }
98 
99   return 0;
100 }
101 
pr_config_get_server_xfer_bufsz(int direction)102 int pr_config_get_server_xfer_bufsz(int direction) {
103   int bufsz = -1;
104 
105   switch (direction) {
106     case PR_NETIO_IO_RD:
107       bufsz = PR_TUNABLE_DEFAULT_RCVBUFSZ;
108       break;
109 
110     case PR_NETIO_IO_WR:
111       bufsz = PR_TUNABLE_DEFAULT_SNDBUFSZ;
112       break;
113 
114     default:
115       errno = EINVAL;
116       return -1;
117   }
118 
119   return bufsz;
120 }
121 
pr_ctrls_unregister(module * m,const char * action)122 int pr_ctrls_unregister(module *m, const char *action) {
123   return 0;
124 }
125 
pr_log_auth(int level,const char * fmt,...)126 void pr_log_auth(int level, const char *fmt, ...) {
127   if (getenv("TEST_VERBOSE") != NULL) {
128     va_list msg;
129 
130     fprintf(stderr, "AUTH%d: ", level);
131 
132     va_start(msg, fmt);
133     vfprintf(stderr, fmt, msg);
134     va_end(msg);
135 
136     fprintf(stderr, "\n");
137   }
138 }
139 
pr_log_debug(int level,const char * fmt,...)140 void pr_log_debug(int level, const char *fmt, ...) {
141   if (getenv("TEST_VERBOSE") != NULL) {
142     va_list msg;
143 
144     fprintf(stderr, "DEBUG%d: ", level);
145 
146     va_start(msg, fmt);
147     vfprintf(stderr, fmt, msg);
148     va_end(msg);
149 
150     fprintf(stderr, "\n");
151   }
152 }
153 
pr_log_event_generate(unsigned int log_type,int log_fd,int log_level,const char * log_msg,size_t log_msglen)154 int pr_log_event_generate(unsigned int log_type, int log_fd, int log_level,
155     const char *log_msg, size_t log_msglen) {
156   errno = ENOSYS;
157   return -1;
158 }
159 
pr_log_event_listening(unsigned int log_type)160 int pr_log_event_listening(unsigned int log_type) {
161   return FALSE;
162 }
163 
pr_log_pri(int prio,const char * fmt,...)164 void pr_log_pri(int prio, const char *fmt, ...) {
165   if (getenv("TEST_VERBOSE") != NULL) {
166     va_list msg;
167 
168     fprintf(stderr, "PRI%d: ", prio);
169 
170     va_start(msg, fmt);
171     vfprintf(stderr, fmt, msg);
172     va_end(msg);
173 
174     fprintf(stderr, "\n");
175   }
176 }
177 
pr_log_openfile(const char * log_file,int * log_fd,mode_t log_mode)178 int pr_log_openfile(const char *log_file, int *log_fd, mode_t log_mode) {
179   int res;
180   struct stat st;
181 
182   if (log_file == NULL ||
183       log_fd == NULL) {
184     errno = EINVAL;
185     return -1;
186   }
187 
188   res = stat(log_file, &st);
189   if (res < 0) {
190     if (errno != ENOENT) {
191       return -1;
192     }
193 
194   } else {
195     if (S_ISDIR(st.st_mode)) {
196       errno = EISDIR;
197       return -1;
198     }
199   }
200 
201   *log_fd = STDERR_FILENO;
202   return 0;
203 }
204 
pr_log_stacktrace(int fd,const char * name)205 void pr_log_stacktrace(int fd, const char *name) {
206 }
207 
pr_proctitle_get(char * buf,size_t buflen)208 int pr_proctitle_get(char *buf, size_t buflen) {
209   errno = ENOSYS;
210   return -1;
211 }
212 
pr_proctitle_set(const char * fmt,...)213 void pr_proctitle_set(const char *fmt, ...) {
214 }
215 
pr_proctitle_set_str(const char * str)216 void pr_proctitle_set_str(const char *str) {
217 }
218 
pr_session_disconnect(module * m,int reason_code,const char * details)219 void pr_session_disconnect(module *m, int reason_code, const char *details) {
220 }
221 
pr_session_get_disconnect_reason(const char ** details)222 const char *pr_session_get_disconnect_reason(const char **details) {
223   if (details != NULL) {
224     *details = "bebugging";
225   }
226 
227   return "testing";
228 }
229 
pr_session_get_protocol(int flags)230 const char *pr_session_get_protocol(int flags) {
231   return "ftp";
232 }
233 
pr_session_set_idle(void)234 int pr_session_set_idle(void) {
235   return 0;
236 }
237 
pr_signals_handle(void)238 void pr_signals_handle(void) {
239 }
240