1161764Sobrien/* $NetBSD: extern.h,v 1.55 2006/02/01 14:20:12 christos Exp $ */ 279968Sobrien 379968Sobrien/*- 479968Sobrien * Copyright (c) 1992, 1993 579968Sobrien * The Regents of the University of California. All rights reserved. 679968Sobrien * 779968Sobrien * Redistribution and use in source and binary forms, with or without 879968Sobrien * modification, are permitted provided that the following conditions 979968Sobrien * are met: 1079968Sobrien * 1. Redistributions of source code must retain the above copyright 1179968Sobrien * notice, this list of conditions and the following disclaimer. 1279968Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1379968Sobrien * notice, this list of conditions and the following disclaimer in the 1479968Sobrien * documentation and/or other materials provided with the distribution. 15133936Sobrien * 3. Neither the name of the University nor the names of its contributors 1679968Sobrien * may be used to endorse or promote products derived from this software 1779968Sobrien * without specific prior written permission. 1879968Sobrien * 1979968Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2079968Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2179968Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2279968Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2379968Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2479968Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2579968Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2679968Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2779968Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2879968Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2979968Sobrien * SUCH DAMAGE. 3079968Sobrien * 3179968Sobrien * @(#)extern.h 8.2 (Berkeley) 4/4/94 3279968Sobrien */ 3379968Sobrien 3479968Sobrien/*- 35161764Sobrien * Copyright (c) 1997-2005 The NetBSD Foundation, Inc. 3679968Sobrien * All rights reserved. 3779968Sobrien * 3879968Sobrien * This code is derived from software contributed to The NetBSD Foundation 3979968Sobrien * by Luke Mewburn. 4079968Sobrien * 4179968Sobrien * Redistribution and use in source and binary forms, with or without 4279968Sobrien * modification, are permitted provided that the following conditions 4379968Sobrien * are met: 4479968Sobrien * 1. Redistributions of source code must retain the above copyright 4579968Sobrien * notice, this list of conditions and the following disclaimer. 4679968Sobrien * 2. Redistributions in binary form must reproduce the above copyright 4779968Sobrien * notice, this list of conditions and the following disclaimer in the 4879968Sobrien * documentation and/or other materials provided with the distribution. 4979968Sobrien * 3. All advertising materials mentioning features or use of this software 5079968Sobrien * must display the following acknowledgement: 5179968Sobrien * This product includes software developed by the NetBSD 5279968Sobrien * Foundation, Inc. and its contributors. 5379968Sobrien * 4. Neither the name of The NetBSD Foundation nor the names of its 5479968Sobrien * contributors may be used to endorse or promote products derived 5579968Sobrien * from this software without specific prior written permission. 5679968Sobrien * 5779968Sobrien * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 5879968Sobrien * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 5979968Sobrien * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 6079968Sobrien * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 6179968Sobrien * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 6279968Sobrien * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6379968Sobrien * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 6479968Sobrien * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 6579968Sobrien * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6679968Sobrien * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6779968Sobrien * POSSIBILITY OF SUCH DAMAGE. 6879968Sobrien */ 6979968Sobrien 7079968Sobrien/* 7179968Sobrien * Copyright (C) 1997 and 1998 WIDE Project. 7279968Sobrien * All rights reserved. 7379968Sobrien * 7479968Sobrien * Redistribution and use in source and binary forms, with or without 7579968Sobrien * modification, are permitted provided that the following conditions 7679968Sobrien * are met: 7779968Sobrien * 1. Redistributions of source code must retain the above copyright 7879968Sobrien * notice, this list of conditions and the following disclaimer. 7979968Sobrien * 2. Redistributions in binary form must reproduce the above copyright 8079968Sobrien * notice, this list of conditions and the following disclaimer in the 8179968Sobrien * documentation and/or other materials provided with the distribution. 8279968Sobrien * 3. Neither the name of the project nor the names of its contributors 8379968Sobrien * may be used to endorse or promote products derived from this software 8479968Sobrien * without specific prior written permission. 8579968Sobrien * 8679968Sobrien * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 8779968Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 8879968Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8979968Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 9079968Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 9179968Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 9279968Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 9379968Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 9479968Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 9579968Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 9679968Sobrien * SUCH DAMAGE. 9779968Sobrien */ 9879968Sobrien 9979968Sobrien#ifdef NO_LONG_LONG 10079968Sobrien# define LLF "%ld" 10179968Sobrien# define LLFP(x) "%" x "ld" 10279968Sobrien# define LLT long 10379968Sobrien# define ULLF "%lu" 10479968Sobrien# define ULLFP(x) "%" x "lu" 10579968Sobrien# define ULLT unsigned long 10679968Sobrien# define STRTOLL(x,y,z) strtol(x,y,z) 107108746Sobrien# define LLTMIN LONG_MIN 108108746Sobrien# define LLTMAX LONG_MAX 10979968Sobrien#else 11079968Sobrien# define LLF "%lld" 11179968Sobrien# define LLFP(x) "%" x "lld" 11279968Sobrien# define LLT long long 11379968Sobrien# define ULLF "%llu" 11479968Sobrien# define ULLFP(x) "%" x "llu" 11579968Sobrien# define ULLT unsigned long long 11679968Sobrien# define STRTOLL(x,y,z) strtoll(x,y,z) 117108746Sobrien# define LLTMIN LLONG_MIN 118108746Sobrien# define LLTMAX LLONG_MAX 11979968Sobrien#endif 12079968Sobrien 12179968Sobrien#define FTP_BUFLEN 512 12279968Sobrien 12379968Sobrienvoid abor(void); 12479968Sobrienvoid blkfree(char **); 12579968Sobrienvoid closedataconn(FILE *); 12679968Sobrienchar *conffilename(const char *); 12779968Sobrienchar **copyblk(char **); 12879968Sobrienvoid count_users(void); 12979968Sobrienvoid cprintf(FILE *, const char *, ...) 130108746Sobrien __attribute__((__format__(__printf__, 2, 3))); 13179968Sobrienvoid cwd(const char *); 13279968SobrienFILE *dataconn(const char *, off_t, const char *); 13379968Sobrienvoid delete(const char *); 13479968Sobrienint display_file(const char *, int); 13579968Sobrienchar **do_conversion(const char *); 13679968Sobrienvoid dologout(int); 13779968Sobrienvoid fatal(const char *); 13879968Sobrienvoid feat(void); 13979968Sobrienvoid format_path(char *, const char *); 14079968Sobrienint ftpd_pclose(FILE *); 14179968SobrienFILE *ftpd_popen(char *[], const char *, int); 142186872Ssimonint getline(char *, int, FILE *); 14379968Sobrienvoid init_curclass(void); 14479968Sobrienvoid logxfer(const char *, off_t, const char *, const char *, 14579968Sobrien const struct timeval *, const char *); 14679968Sobrienstruct tab *lookup(struct tab *, const char *); 14779968Sobrienvoid makedir(const char *); 14879968Sobrienvoid mlsd(const char *); 14979968Sobrienvoid mlst(const char *); 15079968Sobrienvoid opts(const char *); 15179968Sobrienvoid parse_conf(const char *); 15279968Sobrienvoid pass(const char *); 15379968Sobrienvoid passive(void); 15479968Sobrienint lpsvproto2af(int); 15579968Sobrienint af2lpsvproto(int); 15679968Sobrienint epsvproto2af(int); 15779968Sobrienint af2epsvproto(int); 15879968Sobrienvoid long_passive(char *, int); 15979968Sobrienint extended_port(const char *); 16079968Sobrienvoid epsv_protounsupp(const char *); 16179968Sobrienvoid perror_reply(int, const char *); 16279968Sobrienvoid pwd(void); 16379968Sobrienvoid removedir(const char *); 16479968Sobrienvoid renamecmd(const char *, const char *); 16579968Sobrienchar *renamefrom(const char *); 16679968Sobrienvoid reply(int, const char *, ...) 167108746Sobrien __attribute__((__format__(__printf__, 2, 3))); 16879968Sobrienvoid retrieve(char *[], const char *); 16979968Sobrienvoid send_file_list(const char *); 17079968Sobrienvoid show_chdir_messages(int); 17179968Sobrienvoid sizecmd(const char *); 17279968Sobrienvoid statcmd(void); 17379968Sobrienvoid statfilecmd(const char *); 17479968Sobrienvoid statxfer(void); 17579968Sobrienvoid store(const char *, const char *, int); 17679968Sobrienvoid user(const char *); 177161764Sobrienchar *ftpd_strdup(const char *); 17879968Sobrienvoid yyerror(char *); 17979968Sobrien 180133936Sobrien#ifdef SUPPORT_UTMP 181133936Sobrienstruct utmp; 182133936Sobrien 183161764Sobrienvoid ftpd_initwtmp(void); 184133936Sobrienvoid ftpd_logwtmp(const char *, const char *, const char *); 185161764Sobrienvoid ftpd_login(const struct utmp *); 186161764Sobrienint ftpd_logout(const char *); 187133936Sobrien#endif 188133936Sobrien 189133936Sobrien#ifdef SUPPORT_UTMPX 190133936Sobrienstruct utmpx; 191161764Sobrienstruct sockinet; 192133936Sobrien 193161764Sobrienvoid ftpd_initwtmpx(void); 194161764Sobrienvoid ftpd_logwtmpx(const char *, const char *, const char *, 195161764Sobrien struct sockinet *, int, int); 196133936Sobrienvoid ftpd_loginx(const struct utmpx *); 197161764Sobrienint ftpd_logoutx(const char *, int, int); 198133936Sobrien#endif 199133936Sobrien 20079968Sobrien#include <netinet/in.h> 20179968Sobrien 20292282Sobrien#if defined(__NetBSD__) 20379968Sobrien# define HAVE_SETPROCTITLE 1 20479968Sobrien# define HAVE_SOCKADDR_SA_LEN 1 20579968Sobrien#endif 20679968Sobrien 20779968Sobrienstruct sockinet { 20879968Sobrien union sockunion { 20979968Sobrien struct sockaddr_in su_sin; 21079968Sobrien#ifdef INET6 21179968Sobrien struct sockaddr_in6 su_sin6; 21279968Sobrien#endif 21379968Sobrien } si_su; 21479968Sobrien#if !HAVE_SOCKADDR_SA_LEN 21579968Sobrien int si_len; 21679968Sobrien#endif 21779968Sobrien}; 21879968Sobrien 21979968Sobrien#if !HAVE_SOCKADDR_SA_LEN 22079968Sobrien# define su_len si_len 22179968Sobrien#else 22279968Sobrien# define su_len si_su.su_sin.sin_len 22379968Sobrien#endif 22479968Sobrien#define su_addr si_su.su_sin.sin_addr 22579968Sobrien#define su_family si_su.su_sin.sin_family 22679968Sobrien#define su_port si_su.su_sin.sin_port 22779968Sobrien#ifdef INET6 22879968Sobrien# define su_6addr si_su.su_sin6.sin6_addr 22979968Sobrien# define su_scope_id si_su.su_sin6.sin6_scope_id 23079968Sobrien#endif 23179968Sobrien 23279968Sobrienstruct tab { 23379968Sobrien char *name; 23479968Sobrien short token; 23579968Sobrien short state; 23679968Sobrien short flags; /* 1 if command implemented, 2 if has options, 23779968Sobrien 4 if can occur OOB */ 23879968Sobrien char *help; 23979968Sobrien char *options; 24079968Sobrien}; 24179968Sobrien 24279968Sobrienstruct ftpconv { 24379968Sobrien struct ftpconv *next; 24479968Sobrien char *suffix; /* Suffix of requested name */ 24579968Sobrien char *types; /* Valid file types */ 24679968Sobrien char *disable; /* File to disable conversions */ 24779968Sobrien char *command; /* Command to do the conversion */ 24879968Sobrien}; 24979968Sobrien 25079968Sobrientypedef enum { 25179968Sobrien CLASS_GUEST, 25279968Sobrien CLASS_CHROOT, 25379968Sobrien CLASS_REAL 25479968Sobrien} class_ft; 25579968Sobrien 25679968Sobrientypedef enum { 25779968Sobrien FLAG_checkportcmd = 1<<0, /* Check port commands */ 25892282Sobrien FLAG_denyquick = 1<<1, /* Check ftpusers(5) before PASS */ 259161764Sobrien FLAG_hidesymlinks = 1<<2, /* For symbolic links, list the file 260161764Sobrien or directory the link references 261161764Sobrien rather than the link itself */ 262161764Sobrien FLAG_modify = 1<<3, /* Allow CHMOD, DELE, MKD, RMD, RNFR, 26379968Sobrien UMASK */ 264161764Sobrien FLAG_passive = 1<<4, /* Allow PASV mode */ 265161764Sobrien FLAG_private = 1<<5, /* Don't publish class info in STAT */ 266161764Sobrien FLAG_sanenames = 1<<6, /* Restrict names of uploaded files */ 267161764Sobrien FLAG_upload = 1<<7, /* As per modify, but also allow 26879968Sobrien APPE, STOR, STOU */ 26979968Sobrien} classflag_t; 27079968Sobrien 27179968Sobrien#define CURCLASS_FLAGS_SET(x) (curclass.flags |= (FLAG_ ## x)) 27279968Sobrien#define CURCLASS_FLAGS_CLR(x) (curclass.flags &= ~(FLAG_ ## x)) 27379968Sobrien#define CURCLASS_FLAGS_ISSET(x) (curclass.flags & (FLAG_ ## x)) 27479968Sobrien 27579968Sobrienstruct ftpclass { 27679968Sobrien struct sockinet advertise; /* PASV address to advertise as */ 27779968Sobrien char *chroot; /* Directory to chroot(2) to at login */ 27879968Sobrien char *classname; /* Current class */ 27979968Sobrien struct ftpconv *conversions; /* List of conversions */ 28079968Sobrien char *display; /* File to display upon chdir */ 28179968Sobrien char *homedir; /* Directory to chdir(2) to at login */ 28279968Sobrien classflag_t flags; /* Flags; see classflag_t above */ 283108746Sobrien LLT limit; /* Max connections (-1 = unlimited) */ 28479968Sobrien char *limitfile; /* File to display if limit reached */ 28579968Sobrien LLT maxfilesize; /* Maximum file size of uploads */ 28679968Sobrien LLT maxrateget; /* Maximum get transfer rate throttle */ 28779968Sobrien LLT maxrateput; /* Maximum put transfer rate throttle */ 288108746Sobrien LLT maxtimeout; /* Maximum permitted timeout */ 28979968Sobrien char *motd; /* MotD file to display after login */ 29079968Sobrien char *notify; /* Files to notify about upon chdir */ 291108746Sobrien LLT portmin; /* Minumum port for passive mode */ 292108746Sobrien LLT portmax; /* Maximum port for passive mode */ 29379968Sobrien LLT rateget; /* Get (RETR) transfer rate throttle */ 29479968Sobrien LLT rateput; /* Put (STOR) transfer rate throttle */ 295108746Sobrien LLT timeout; /* Default timeout */ 29679968Sobrien class_ft type; /* Class type */ 29779968Sobrien mode_t umask; /* Umask to use */ 298108746Sobrien LLT mmapsize; /* mmap window size */ 299108746Sobrien LLT readsize; /* data read size */ 300108746Sobrien LLT writesize; /* data write size */ 301161764Sobrien LLT recvbufsize; /* SO_RCVBUF size */ 302108746Sobrien LLT sendbufsize; /* SO_SNDBUF size */ 303108746Sobrien LLT sendlowat; /* SO_SNDLOWAT size */ 30479968Sobrien}; 30579968Sobrien 306108746Sobrienextern void ftp_loop(void) __attribute__ ((noreturn)); 30779968Sobrienextern void ftp_handle_line(char *); 30879968Sobrien 30979968Sobrien#ifndef GLOBAL 31079968Sobrien#define GLOBAL extern 31179968Sobrien#endif 31279968Sobrien 31379968Sobrien 31479968SobrienGLOBAL struct sockinet ctrl_addr; 31579968SobrienGLOBAL struct sockinet data_dest; 31679968SobrienGLOBAL struct sockinet data_source; 31779968SobrienGLOBAL struct sockinet his_addr; 31879968SobrienGLOBAL struct sockinet pasv_addr; 31979968SobrienGLOBAL int connections; 32079968SobrienGLOBAL struct ftpclass curclass; 321161764SobrienGLOBAL int ftpd_debug; 32279968SobrienGLOBAL char *emailaddr; 32379968SobrienGLOBAL int form; 32479968SobrienGLOBAL int gidcount; /* number of entries in gidlist[] */ 325133936SobrienGLOBAL gid_t *gidlist; 32679968SobrienGLOBAL int hasyyerrored; 32779968SobrienGLOBAL char hostname[MAXHOSTNAMELEN+1]; 32879968SobrienGLOBAL char homedir[MAXPATHLEN]; 32979968Sobrien#ifdef KERBEROS5 33079968SobrienGLOBAL krb5_context kcontext; 33179968Sobrien#endif 33279968SobrienGLOBAL int logged_in; 33379968SobrienGLOBAL int logging; 33479968SobrienGLOBAL int pdata; /* for passive mode */ 33579968Sobrien#if HAVE_SETPROCTITLE 33679968SobrienGLOBAL char proctitle[BUFSIZ]; /* initial part of title */ 33779968Sobrien#endif 33879968SobrienGLOBAL struct passwd *pw; 33979968SobrienGLOBAL int quietmessages; 34079968SobrienGLOBAL char remotehost[MAXHOSTNAMELEN+1]; 34179968SobrienGLOBAL off_t restart_point; 34279968SobrienGLOBAL char tmpline[FTP_BUFLEN]; 34379968SobrienGLOBAL int type; 34479968SobrienGLOBAL int usedefault; /* for data transfers */ 34579968SobrienGLOBAL const char *version; 34679968SobrienGLOBAL int is_oob; 34779968Sobrien 34879968Sobrien /* total file data bytes */ 34979968SobrienGLOBAL off_t total_data_in, total_data_out, total_data; 35079968Sobrien /* total number of data files */ 35179968SobrienGLOBAL off_t total_files_in, total_files_out, total_files; 35279968Sobrien /* total bytes */ 35379968SobrienGLOBAL off_t total_bytes_in, total_bytes_out, total_bytes; 35479968Sobrien /* total number of xfers */ 35579968SobrienGLOBAL off_t total_xfers_in, total_xfers_out, total_xfers; 35679968Sobrien 35779968Sobrienextern struct tab cmdtab[]; 35879968Sobrien 35979968Sobrien#define INTERNAL_LS "/bin/ls" 36079968Sobrien 36179968Sobrien 36279968Sobrien#define CMD_IMPLEMENTED(x) ((x)->flags != 0) 36379968Sobrien#define CMD_HAS_OPTIONS(x) ((x)->flags & 0x2) 36479968Sobrien#define CMD_OOB(x) ((x)->flags & 0x4) 36579968Sobrien 36679968Sobrien#define CPUTC(c, f) do { \ 36779968Sobrien putc(c, f); total_bytes++; total_bytes_out++; \ 36879968Sobrien } while (0); 36979968Sobrien 37079968Sobrien#define CURCLASSTYPE curclass.type == CLASS_GUEST ? "GUEST" : \ 371108746Sobrien curclass.type == CLASS_CHROOT ? "CHROOT" : \ 372108746Sobrien curclass.type == CLASS_REAL ? "REAL" : \ 37379968Sobrien "<unknown>" 37479968Sobrien 37579968Sobrien#define ISDOTDIR(x) (x[0] == '.' && x[1] == '\0') 37679968Sobrien#define ISDOTDOTDIR(x) (x[0] == '.' && x[1] == '.' && x[2] == '\0') 37779968Sobrien 37879968Sobrien#define EMPTYSTR(p) ((p) == NULL || *(p) == '\0') 37979968Sobrien#define NEXTWORD(P, W) do { \ 38079968Sobrien (W) = strsep(&(P), " \t"); \ 38179968Sobrien } while ((W) != NULL && *(W) == '\0') 38279968Sobrien#define PLURAL(s) ((s) == 1 ? "" : "s") 38379968Sobrien#define REASSIGN(X,Y) do { if (X) free(X); (X)=(Y); } while (/*CONSTCOND*/0) 38479968Sobrien 38579968Sobrien#ifndef IPPORT_ANONMAX 38679968Sobrien# define IPPORT_ANONMAX 65535 38779968Sobrien#endif 388