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