extern.h revision 1.59 1 1.59 christos /* $NetBSD: extern.h,v 1.59 2009/01/08 18:47:49 christos Exp $ */
2 1.19 itojun
3 1.21 lukem /*-
4 1.21 lukem * Copyright (c) 1992, 1993
5 1.21 lukem * The Regents of the University of California. All rights reserved.
6 1.21 lukem *
7 1.19 itojun * Redistribution and use in source and binary forms, with or without
8 1.19 itojun * modification, are permitted provided that the following conditions
9 1.19 itojun * are met:
10 1.19 itojun * 1. Redistributions of source code must retain the above copyright
11 1.19 itojun * notice, this list of conditions and the following disclaimer.
12 1.19 itojun * 2. Redistributions in binary form must reproduce the above copyright
13 1.19 itojun * notice, this list of conditions and the following disclaimer in the
14 1.19 itojun * documentation and/or other materials provided with the distribution.
15 1.49 agc * 3. Neither the name of the University nor the names of its contributors
16 1.19 itojun * may be used to endorse or promote products derived from this software
17 1.19 itojun * without specific prior written permission.
18 1.21 lukem *
19 1.21 lukem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.19 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.19 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.21 lukem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.19 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.19 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.19 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.19 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.19 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.19 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.19 itojun * SUCH DAMAGE.
30 1.21 lukem *
31 1.21 lukem * @(#)extern.h 8.2 (Berkeley) 4/4/94
32 1.19 itojun */
33 1.2 cgd
34 1.1 deraadt /*-
35 1.58 lukem * Copyright (c) 1997-2008 The NetBSD Foundation, Inc.
36 1.21 lukem * All rights reserved.
37 1.21 lukem *
38 1.21 lukem * This code is derived from software contributed to The NetBSD Foundation
39 1.21 lukem * by Luke Mewburn.
40 1.1 deraadt *
41 1.1 deraadt * Redistribution and use in source and binary forms, with or without
42 1.1 deraadt * modification, are permitted provided that the following conditions
43 1.1 deraadt * are met:
44 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
45 1.1 deraadt * notice, this list of conditions and the following disclaimer.
46 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
47 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
48 1.1 deraadt * documentation and/or other materials provided with the distribution.
49 1.21 lukem *
50 1.21 lukem * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
51 1.21 lukem * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
52 1.21 lukem * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 1.21 lukem * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
54 1.21 lukem * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
55 1.21 lukem * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
56 1.21 lukem * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
57 1.21 lukem * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
58 1.21 lukem * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
59 1.21 lukem * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
60 1.21 lukem * POSSIBILITY OF SUCH DAMAGE.
61 1.21 lukem */
62 1.21 lukem
63 1.21 lukem /*
64 1.21 lukem * Copyright (C) 1997 and 1998 WIDE Project.
65 1.21 lukem * All rights reserved.
66 1.21 lukem *
67 1.21 lukem * Redistribution and use in source and binary forms, with or without
68 1.21 lukem * modification, are permitted provided that the following conditions
69 1.21 lukem * are met:
70 1.21 lukem * 1. Redistributions of source code must retain the above copyright
71 1.21 lukem * notice, this list of conditions and the following disclaimer.
72 1.21 lukem * 2. Redistributions in binary form must reproduce the above copyright
73 1.21 lukem * notice, this list of conditions and the following disclaimer in the
74 1.21 lukem * documentation and/or other materials provided with the distribution.
75 1.21 lukem * 3. Neither the name of the project nor the names of its contributors
76 1.1 deraadt * may be used to endorse or promote products derived from this software
77 1.1 deraadt * without specific prior written permission.
78 1.21 lukem *
79 1.21 lukem * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
80 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
81 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
82 1.21 lukem * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
83 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
84 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
85 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
86 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
87 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
88 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
89 1.1 deraadt * SUCH DAMAGE.
90 1.1 deraadt */
91 1.1 deraadt
92 1.35 lukem #ifdef NO_LONG_LONG
93 1.35 lukem # define LLF "%ld"
94 1.35 lukem # define LLFP(x) "%" x "ld"
95 1.35 lukem # define LLT long
96 1.35 lukem # define ULLF "%lu"
97 1.35 lukem # define ULLFP(x) "%" x "lu"
98 1.35 lukem # define ULLT unsigned long
99 1.35 lukem # define STRTOLL(x,y,z) strtol(x,y,z)
100 1.45 lukem # define LLTMIN LONG_MIN
101 1.45 lukem # define LLTMAX LONG_MAX
102 1.35 lukem #else
103 1.35 lukem # define LLF "%lld"
104 1.35 lukem # define LLFP(x) "%" x "lld"
105 1.35 lukem # define LLT long long
106 1.35 lukem # define ULLF "%llu"
107 1.35 lukem # define ULLFP(x) "%" x "llu"
108 1.35 lukem # define ULLT unsigned long long
109 1.35 lukem # define STRTOLL(x,y,z) strtoll(x,y,z)
110 1.45 lukem # define LLTMIN LLONG_MIN
111 1.45 lukem # define LLTMAX LLONG_MAX
112 1.35 lukem #endif
113 1.35 lukem
114 1.39 aidan #define FTP_BUFLEN 512
115 1.39 aidan
116 1.39 aidan void abor(void);
117 1.26 lukem void blkfree(char **);
118 1.28 lukem void closedataconn(FILE *);
119 1.26 lukem char *conffilename(const char *);
120 1.26 lukem char **copyblk(char **);
121 1.26 lukem void count_users(void);
122 1.29 sommerfe void cprintf(FILE *, const char *, ...)
123 1.29 sommerfe __attribute__((__format__(__printf__, 2, 3)));
124 1.26 lukem void cwd(const char *);
125 1.27 lukem FILE *dataconn(const char *, off_t, const char *);
126 1.26 lukem void delete(const char *);
127 1.30 lukem int display_file(const char *, int);
128 1.26 lukem char **do_conversion(const char *);
129 1.26 lukem void dologout(int);
130 1.26 lukem void fatal(const char *);
131 1.27 lukem void feat(void);
132 1.30 lukem void format_path(char *, const char *);
133 1.26 lukem int ftpd_pclose(FILE *);
134 1.26 lukem FILE *ftpd_popen(char *[], const char *, int);
135 1.58 lukem int getline(char *, int, FILE *);
136 1.26 lukem void init_curclass(void);
137 1.37 lukem void logxfer(const char *, off_t, const char *, const char *,
138 1.26 lukem const struct timeval *, const char *);
139 1.27 lukem struct tab *lookup(struct tab *, const char *);
140 1.26 lukem void makedir(const char *);
141 1.27 lukem void mlsd(const char *);
142 1.27 lukem void mlst(const char *);
143 1.27 lukem void opts(const char *);
144 1.26 lukem void parse_conf(const char *);
145 1.26 lukem void pass(const char *);
146 1.26 lukem void passive(void);
147 1.33 itojun int lpsvproto2af(int);
148 1.33 itojun int af2lpsvproto(int);
149 1.33 itojun int epsvproto2af(int);
150 1.33 itojun int af2epsvproto(int);
151 1.26 lukem void long_passive(char *, int);
152 1.33 itojun int extended_port(const char *);
153 1.33 itojun void epsv_protounsupp(const char *);
154 1.26 lukem void perror_reply(int, const char *);
155 1.26 lukem void pwd(void);
156 1.26 lukem void removedir(const char *);
157 1.26 lukem void renamecmd(const char *, const char *);
158 1.26 lukem char *renamefrom(const char *);
159 1.29 sommerfe void reply(int, const char *, ...)
160 1.29 sommerfe __attribute__((__format__(__printf__, 2, 3)));
161 1.26 lukem void retrieve(char *[], const char *);
162 1.26 lukem void send_file_list(const char *);
163 1.26 lukem void show_chdir_messages(int);
164 1.27 lukem void sizecmd(const char *);
165 1.26 lukem void statcmd(void);
166 1.26 lukem void statfilecmd(const char *);
167 1.39 aidan void statxfer(void);
168 1.26 lukem void store(const char *, const char *, int);
169 1.26 lukem void user(const char *);
170 1.55 christos char *ftpd_strdup(const char *);
171 1.26 lukem void yyerror(char *);
172 1.47 lukem
173 1.47 lukem #ifdef SUPPORT_UTMP
174 1.47 lukem struct utmp;
175 1.47 lukem
176 1.53 christos void ftpd_initwtmp(void);
177 1.47 lukem void ftpd_logwtmp(const char *, const char *, const char *);
178 1.53 christos void ftpd_login(const struct utmp *);
179 1.53 christos int ftpd_logout(const char *);
180 1.48 tacha #endif
181 1.48 tacha
182 1.48 tacha #ifdef SUPPORT_UTMPX
183 1.48 tacha struct utmpx;
184 1.51 christos struct sockinet;
185 1.53 christos
186 1.53 christos void ftpd_initwtmpx(void);
187 1.53 christos void ftpd_logwtmpx(const char *, const char *, const char *,
188 1.53 christos struct sockinet *, int, int);
189 1.48 tacha void ftpd_loginx(const struct utmpx *);
190 1.53 christos int ftpd_logoutx(const char *, int, int);
191 1.47 lukem #endif
192 1.18 ross
193 1.37 lukem #include <netinet/in.h>
194 1.37 lukem
195 1.42 lukem #if defined(__NetBSD__)
196 1.56 lukem # define HAVE_SETPROCTITLE 1
197 1.56 lukem # define HAVE_STRUCT_SOCKADDR_SA_LEN 1
198 1.59 christos # define HAVE_SOCKADDR_SNPRINTF 1
199 1.37 lukem #endif
200 1.37 lukem
201 1.37 lukem struct sockinet {
202 1.37 lukem union sockunion {
203 1.37 lukem struct sockaddr_in su_sin;
204 1.37 lukem #ifdef INET6
205 1.37 lukem struct sockaddr_in6 su_sin6;
206 1.37 lukem #endif
207 1.37 lukem } si_su;
208 1.56 lukem #if !defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
209 1.37 lukem int si_len;
210 1.37 lukem #endif
211 1.37 lukem };
212 1.37 lukem
213 1.56 lukem #if !defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
214 1.37 lukem # define su_len si_len
215 1.37 lukem #else
216 1.37 lukem # define su_len si_su.su_sin.sin_len
217 1.37 lukem #endif
218 1.37 lukem #define su_addr si_su.su_sin.sin_addr
219 1.37 lukem #define su_family si_su.su_sin.sin_family
220 1.37 lukem #define su_port si_su.su_sin.sin_port
221 1.37 lukem #ifdef INET6
222 1.37 lukem # define su_6addr si_su.su_sin6.sin6_addr
223 1.37 lukem # define su_scope_id si_su.su_sin6.sin6_scope_id
224 1.37 lukem #endif
225 1.37 lukem
226 1.27 lukem struct tab {
227 1.27 lukem char *name;
228 1.27 lukem short token;
229 1.27 lukem short state;
230 1.39 aidan short flags; /* 1 if command implemented, 2 if has options,
231 1.39 aidan 4 if can occur OOB */
232 1.27 lukem char *help;
233 1.27 lukem char *options;
234 1.27 lukem };
235 1.3 lukem
236 1.3 lukem struct ftpconv {
237 1.3 lukem struct ftpconv *next;
238 1.4 christos char *suffix; /* Suffix of requested name */
239 1.4 christos char *types; /* Valid file types */
240 1.4 christos char *disable; /* File to disable conversions */
241 1.4 christos char *command; /* Command to do the conversion */
242 1.3 lukem };
243 1.3 lukem
244 1.35 lukem typedef enum {
245 1.35 lukem CLASS_GUEST,
246 1.35 lukem CLASS_CHROOT,
247 1.35 lukem CLASS_REAL
248 1.35 lukem } class_ft;
249 1.35 lukem
250 1.35 lukem typedef enum {
251 1.35 lukem FLAG_checkportcmd = 1<<0, /* Check port commands */
252 1.43 lukem FLAG_denyquick = 1<<1, /* Check ftpusers(5) before PASS */
253 1.52 ginsbach FLAG_hidesymlinks = 1<<2, /* For symbolic links, list the file
254 1.52 ginsbach or directory the link references
255 1.52 ginsbach rather than the link itself */
256 1.52 ginsbach FLAG_modify = 1<<3, /* Allow CHMOD, DELE, MKD, RMD, RNFR,
257 1.35 lukem UMASK */
258 1.52 ginsbach FLAG_passive = 1<<4, /* Allow PASV mode */
259 1.52 ginsbach FLAG_private = 1<<5, /* Don't publish class info in STAT */
260 1.52 ginsbach FLAG_sanenames = 1<<6, /* Restrict names of uploaded files */
261 1.52 ginsbach FLAG_upload = 1<<7, /* As per modify, but also allow
262 1.35 lukem APPE, STOR, STOU */
263 1.35 lukem } classflag_t;
264 1.35 lukem
265 1.35 lukem #define CURCLASS_FLAGS_SET(x) (curclass.flags |= (FLAG_ ## x))
266 1.35 lukem #define CURCLASS_FLAGS_CLR(x) (curclass.flags &= ~(FLAG_ ## x))
267 1.35 lukem #define CURCLASS_FLAGS_ISSET(x) (curclass.flags & (FLAG_ ## x))
268 1.35 lukem
269 1.3 lukem struct ftpclass {
270 1.37 lukem struct sockinet advertise; /* PASV address to advertise as */
271 1.30 lukem char *chroot; /* Directory to chroot(2) to at login */
272 1.4 christos char *classname; /* Current class */
273 1.20 lukem struct ftpconv *conversions; /* List of conversions */
274 1.35 lukem char *display; /* File to display upon chdir */
275 1.30 lukem char *homedir; /* Directory to chdir(2) to at login */
276 1.35 lukem classflag_t flags; /* Flags; see classflag_t above */
277 1.45 lukem LLT limit; /* Max connections (-1 = unlimited) */
278 1.22 lukem char *limitfile; /* File to display if limit reached */
279 1.35 lukem LLT maxfilesize; /* Maximum file size of uploads */
280 1.35 lukem LLT maxrateget; /* Maximum get transfer rate throttle */
281 1.35 lukem LLT maxrateput; /* Maximum put transfer rate throttle */
282 1.45 lukem LLT maxtimeout; /* Maximum permitted timeout */
283 1.21 lukem char *motd; /* MotD file to display after login */
284 1.4 christos char *notify; /* Files to notify about upon chdir */
285 1.45 lukem LLT portmin; /* Minumum port for passive mode */
286 1.45 lukem LLT portmax; /* Maximum port for passive mode */
287 1.35 lukem LLT rateget; /* Get (RETR) transfer rate throttle */
288 1.35 lukem LLT rateput; /* Put (STOR) transfer rate throttle */
289 1.45 lukem LLT timeout; /* Default timeout */
290 1.27 lukem class_ft type; /* Class type */
291 1.3 lukem mode_t umask; /* Umask to use */
292 1.44 enami LLT mmapsize; /* mmap window size */
293 1.44 enami LLT readsize; /* data read size */
294 1.44 enami LLT writesize; /* data write size */
295 1.54 ginsbach LLT recvbufsize; /* SO_RCVBUF size */
296 1.44 enami LLT sendbufsize; /* SO_SNDBUF size */
297 1.44 enami LLT sendlowat; /* SO_SNDLOWAT size */
298 1.3 lukem };
299 1.19 itojun
300 1.40 aidan extern void ftp_loop(void) __attribute__ ((noreturn));
301 1.39 aidan extern void ftp_handle_line(char *);
302 1.11 lukem
303 1.23 lukem #ifndef GLOBAL
304 1.23 lukem #define GLOBAL extern
305 1.23 lukem #endif
306 1.23 lukem
307 1.25 lukem
308 1.34 lukem GLOBAL struct sockinet ctrl_addr;
309 1.34 lukem GLOBAL struct sockinet data_dest;
310 1.34 lukem GLOBAL struct sockinet data_source;
311 1.34 lukem GLOBAL struct sockinet his_addr;
312 1.34 lukem GLOBAL struct sockinet pasv_addr;
313 1.23 lukem GLOBAL int connections;
314 1.23 lukem GLOBAL struct ftpclass curclass;
315 1.55 christos GLOBAL int ftpd_debug;
316 1.35 lukem GLOBAL char *emailaddr;
317 1.23 lukem GLOBAL int form;
318 1.28 lukem GLOBAL int gidcount; /* number of entries in gidlist[] */
319 1.46 matt GLOBAL gid_t *gidlist;
320 1.23 lukem GLOBAL int hasyyerrored;
321 1.25 lukem GLOBAL char hostname[MAXHOSTNAMELEN+1];
322 1.30 lukem GLOBAL char homedir[MAXPATHLEN];
323 1.11 lukem #ifdef KERBEROS5
324 1.23 lukem GLOBAL krb5_context kcontext;
325 1.11 lukem #endif
326 1.23 lukem GLOBAL int logged_in;
327 1.23 lukem GLOBAL int logging;
328 1.25 lukem GLOBAL int pdata; /* for passive mode */
329 1.56 lukem #if defined(HAVE_SETPROCTITLE)
330 1.25 lukem GLOBAL char proctitle[BUFSIZ]; /* initial part of title */
331 1.25 lukem #endif
332 1.23 lukem GLOBAL struct passwd *pw;
333 1.24 lukem GLOBAL int quietmessages;
334 1.25 lukem GLOBAL char remotehost[MAXHOSTNAMELEN+1];
335 1.59 christos GLOBAL char remoteloghost[2 * MAXHOSTNAMELEN+1];
336 1.23 lukem GLOBAL off_t restart_point;
337 1.39 aidan GLOBAL char tmpline[FTP_BUFLEN];
338 1.23 lukem GLOBAL int type;
339 1.25 lukem GLOBAL int usedefault; /* for data transfers */
340 1.31 lukem GLOBAL const char *version;
341 1.39 aidan GLOBAL int is_oob;
342 1.23 lukem
343 1.25 lukem /* total file data bytes */
344 1.23 lukem GLOBAL off_t total_data_in, total_data_out, total_data;
345 1.25 lukem /* total number of data files */
346 1.23 lukem GLOBAL off_t total_files_in, total_files_out, total_files;
347 1.25 lukem /* total bytes */
348 1.23 lukem GLOBAL off_t total_bytes_in, total_bytes_out, total_bytes;
349 1.25 lukem /* total number of xfers */
350 1.23 lukem GLOBAL off_t total_xfers_in, total_xfers_out, total_xfers;
351 1.16 lukem
352 1.27 lukem extern struct tab cmdtab[];
353 1.27 lukem
354 1.27 lukem #define INTERNAL_LS "/bin/ls"
355 1.27 lukem
356 1.27 lukem
357 1.27 lukem #define CMD_IMPLEMENTED(x) ((x)->flags != 0)
358 1.39 aidan #define CMD_HAS_OPTIONS(x) ((x)->flags & 0x2)
359 1.39 aidan #define CMD_OOB(x) ((x)->flags & 0x4)
360 1.28 lukem
361 1.28 lukem #define CPUTC(c, f) do { \
362 1.28 lukem putc(c, f); total_bytes++; total_bytes_out++; \
363 1.28 lukem } while (0);
364 1.27 lukem
365 1.27 lukem #define CURCLASSTYPE curclass.type == CLASS_GUEST ? "GUEST" : \
366 1.45 lukem curclass.type == CLASS_CHROOT ? "CHROOT" : \
367 1.45 lukem curclass.type == CLASS_REAL ? "REAL" : \
368 1.27 lukem "<unknown>"
369 1.27 lukem
370 1.27 lukem #define ISDOTDIR(x) (x[0] == '.' && x[1] == '\0')
371 1.27 lukem #define ISDOTDOTDIR(x) (x[0] == '.' && x[1] == '.' && x[2] == '\0')
372 1.16 lukem
373 1.21 lukem #define EMPTYSTR(p) ((p) == NULL || *(p) == '\0')
374 1.21 lukem #define NEXTWORD(P, W) do { \
375 1.21 lukem (W) = strsep(&(P), " \t"); \
376 1.21 lukem } while ((W) != NULL && *(W) == '\0')
377 1.16 lukem #define PLURAL(s) ((s) == 1 ? "" : "s")
378 1.26 lukem #define REASSIGN(X,Y) do { if (X) free(X); (X)=(Y); } while (/*CONSTCOND*/0)
379 1.34 lukem
380 1.34 lukem #ifndef IPPORT_ANONMAX
381 1.34 lukem # define IPPORT_ANONMAX 65535
382 1.34 lukem #endif
383