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