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