lukemftpd.h revision 92282
1/* $Id: lukemftpd.h,v 1.18 2002/03/14 06:02:24 lukem Exp $ */ 2 3#define FTPD_VERSION "lukemftpd 1.2 beta 1" 4 5#include "config.h" 6 7#include <sys/types.h> 8#include <sys/param.h> 9#include <sys/ioctl.h> 10#include <sys/socket.h> 11#include <sys/stat.h> 12#include <sys/wait.h> 13#if HAVE_SYS_SYSMACROS_H 14# include <sys/sysmacros.h> 15#endif 16 17#include <netinet/in.h> 18#include <netinet/in_systm.h> 19#include <netinet/ip.h> 20 21#if HAVE_FTP_NAMES 22# include <arpa/ftp.h> 23#else 24# include "arpaftp.h" 25#endif 26#include <arpa/inet.h> 27 28#include <ctype.h> 29#include <errno.h> 30#include <fcntl.h> 31#include <fnmatch.h> 32#include <grp.h> 33#include <limits.h> 34#include <locale.h> 35#include <netdb.h> 36#include <pwd.h> 37#include <setjmp.h> 38#include <signal.h> 39#include <stdarg.h> 40#include <stddef.h> 41#include <stdio.h> 42#include <stdlib.h> 43#include <string.h> 44#include <syslog.h> 45#include <termios.h> 46#include <unistd.h> 47#include <utmp.h> 48 49#if HAVE_DIRENT_H 50# include <dirent.h> 51#else 52# define dirent direct 53# if HAVE_SYS_NDIR_H 54# include <sys/ndir.h> 55# endif 56# if HAVE_SYS_DIR_H 57# include <sys/dir.h> 58# endif 59# if HAVE_NDIR_H 60# include <ndir.h> 61# endif 62#endif 63 64#if TIME_WITH_SYS_TIME 65# include <sys/time.h> 66# include <time.h> 67#else 68# if HAVE_SYS_TIME_H 69# include <sys/time.h> 70# else 71# include <time.h> 72# endif 73#endif 74 75#if HAVE_ERR_H 76# include <err.h> 77#endif 78 79#if HAVE_WORKING_GLOB 80# include <glob.h> 81#else 82# include "ftpglob.h" 83#endif 84 85#if HAVE_PATHS_H 86# include <paths.h> 87#endif 88#ifndef _PATH_BSHELL 89#define _PATH_BSHELL "/bin/sh" 90#endif 91#ifndef _PATH_CSHELL 92#define _PATH_CSHELL "/bin/csh" 93#endif 94#ifndef _PATH_SHELLS 95#define _PATH_SHELLS "/etc/shells" 96#endif 97#ifndef _PATH_DEVNULL 98#define _PATH_DEVNULL "/dev/null" 99#endif 100#ifndef _PATH_NOLOGIN 101#define _PATH_NOLOGIN "/etc/nologin" 102#endif 103 104#ifndef FTPD_LOGTYPE 105# ifdef LOG_FTP 106# define FTPD_LOGTYPE LOG_FTP 107# else 108# define FTPD_LOGTYPE LOG_DAEMON 109# endif 110#endif 111 112#ifndef LOG_AUTHPRIV 113# ifdef LOG_AUTH 114# define LOG_AUTHPRIV LOG_AUTH 115# else 116# define LOG_AUTHPRIV LOG_DAEMON 117# endif 118#endif 119 120typedef struct _stringlist { 121 char **sl_str; 122 size_t sl_max; 123 size_t sl_cur; 124} StringList; 125 126StringList *sl_init(void); 127int sl_add(StringList *, char *); 128void sl_free(StringList *, int); 129char *sl_find(StringList *, char *); 130 131#if HAVE_FTS_H 132# include <fts.h> 133#else 134# include "ftpfts.h" 135#endif 136 137#if HAVE_UTIL_H 138# include <util.h> 139#endif 140 141#if HAVE_LIBUTIL_H 142# include <libutil.h> 143#endif 144 145#if ! HAVE_IN_PORT_T 146typedef unsigned short in_port_t; 147#endif 148 149#if ! HAVE_SOCKLEN_T 150typedef unsigned int socklen_t; 151#endif 152 153#if HAVE_AF_INET6 && HAVE_SOCKADDR_IN6 154# define INET6 155#endif 156 157 158#if ! HAVE_RFC2553_NETDB 159 160 /* RFC 2553 */ 161#undef EAI_ADDRFAMILY 162#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ 163#undef EAI_AGAIN 164#define EAI_AGAIN 2 /* temporary failure in name resolution */ 165#undef EAI_BADFLAGS 166#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ 167#undef EAI_FAIL 168#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ 169#undef EAI_FAMILY 170#define EAI_FAMILY 5 /* ai_family not supported */ 171#undef EAI_MEMORY 172#define EAI_MEMORY 6 /* memory allocation failure */ 173#undef EAI_NODATA 174#define EAI_NODATA 7 /* no address associated with hostname */ 175#undef EAI_NONAME 176#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ 177#undef EAI_SERVICE 178#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ 179#undef EAI_SOCKTYPE 180#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ 181#undef EAI_SYSTEM 182#define EAI_SYSTEM 11 /* system error returned in errno */ 183 184 /* KAME extensions? */ 185#undef EAI_BADHINTS 186#define EAI_BADHINTS 12 187#undef EAI_PROTOCOL 188#define EAI_PROTOCOL 13 189#undef EAI_MAX 190#define EAI_MAX 14 191 192 /* RFC 2553 */ 193#undef NI_MAXHOST 194#define NI_MAXHOST 1025 195#undef NI_MAXSERV 196#define NI_MAXSERV 32 197 198#undef NI_NOFQDN 199#define NI_NOFQDN 0x00000001 200#undef NI_NUMERICHOST 201#define NI_NUMERICHOST 0x00000002 202#undef NI_NAMEREQD 203#define NI_NAMEREQD 0x00000004 204#undef NI_NUMERICSERV 205#define NI_NUMERICSERV 0x00000008 206#undef NI_DGRAM 207#define NI_DGRAM 0x00000010 208 209 /* RFC 2553 */ 210#undef AI_PASSIVE 211#define AI_PASSIVE 0x00000001 /* get address to use bind() */ 212#undef AI_CANONNAME 213#define AI_CANONNAME 0x00000002 /* fill ai_canonname */ 214 215 /* KAME extensions ? */ 216#undef AI_NUMERICHOST 217#define AI_NUMERICHOST 0x00000004 /* prevent name resolution */ 218#undef AI_MASK 219#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST) 220 221 /* RFC 2553 */ 222#undef AI_ALL 223#define AI_ALL 0x00000100 /* IPv6 and IPv4-mapped (with AI_V4MAPPED) */ 224#undef AI_V4MAPPED_CFG 225#define AI_V4MAPPED_CFG 0x00000200 /* accept IPv4-mapped if kernel supports */ 226#undef AI_ADDRCONFIG 227#define AI_ADDRCONFIG 0x00000400 /* only if any address is assigned */ 228#undef AI_V4MAPPED 229#define AI_V4MAPPED 0x00000800 /* accept IPv4-mapped IPv6 address */ 230 231#endif /* ! HAVE_RFC2553_NETDB */ 232 233 234#if ! HAVE_RFC2553_NETDB && ! HAVE_ADDRINFO 235 236struct addrinfo { 237 int ai_flags; /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */ 238 int ai_family; /* PF_xxx */ 239 int ai_socktype; /* SOCK_xxx */ 240 int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 241 size_t ai_addrlen; /* length of ai_addr */ 242 char *ai_canonname; /* canonical name for hostname */ 243 struct sockaddr *ai_addr; /* binary address */ 244 struct addrinfo *ai_next; /* next structure in linked list */ 245}; 246 247int getaddrinfo(const char *, const char *, 248 const struct addrinfo *, struct addrinfo **); 249int getnameinfo(const struct sockaddr *, socklen_t, char *, 250 size_t, char *, size_t, int); 251void freeaddrinfo(struct addrinfo *); 252char *gai_strerror(int); 253 254#endif /* ! HAVE_RFC2553_NETDB && ! HAVE_ADDRINFO */ 255 256 257#if ! HAVE_D_NAMLEN 258# define DIRENT_MISSING_D_NAMLEN 259#endif 260 261#if ! HAVE_CRYPT_D 262char *crypt(const char *, const char *); 263#endif 264 265#if ! HAVE_FCLOSE_D 266int fclose(FILE *); 267#endif 268 269#if ! HAVE_OPTARG_D 270extern char *optarg; 271#endif 272 273#if ! HAVE_OPTIND_D 274extern int optind; 275#endif 276 277#if ! HAVE_PCLOSE_D 278int pclose(FILE *); 279#endif 280 281#if ! HAVE_ERR 282void err(int, const char *, ...); 283void errx(int, const char *, ...); 284void warn(const char *, ...); 285void warnx(const char *, ...); 286#endif 287 288#if ! HAVE_FGETLN 289char *fgetln(FILE *, size_t *); 290#endif 291 292#if ! HAVE_FPARSELN 293# define FPARSELN_UNESCESC 0x01 294# define FPARSELN_UNESCCONT 0x02 295# define FPARSELN_UNESCCOMM 0x04 296# define FPARSELN_UNESCREST 0x08 297# define FPARSELN_UNESCALL 0x0f 298char *fparseln(FILE *, size_t *, size_t *, const char[3], int); 299#endif 300 301#if ! HAVE_GETUSERSHELL || ! HAVE_GETUSERSHELL_D 302char *getusershell(void); 303void setusershell(void); 304void endusershell(void); 305#endif 306 307#if ! HAVE_INET_NTOP 308const char *inet_ntop(int, const void *, char *, size_t); 309#endif 310 311#if ! HAVE_INET_PTON 312int inet_pton(int, const char *, void *); 313#endif 314 315#if ! HAVE_MKSTEMP 316int mkstemp(const char *); 317#endif 318 319#if ! HAVE_SNPRINTF 320int snprintf(char *, size_t, const char *, ...); 321#endif 322 323#if ! HAVE_STRDUP 324char *strdup(const char *); 325#endif 326 327#if ! HAVE_STRERROR 328char *strerror(int); 329#endif 330 331#if HAVE_QUAD_SUPPORT 332# if ! HAVE_STRTOLL && HAVE_LONG_LONG 333long long strtoll(const char *, char **, int); 334# if ! defined(QUAD_MIN) 335# define QUAD_MIN (-0x7fffffffffffffffL-1) 336# endif 337# if ! defined(QUAD_MAX) 338# define QUAD_MAX (0x7fffffffffffffffL) 339# endif 340# endif 341#else /* ! HAVE_QUAD_SUPPORT */ 342# define NO_LONG_LONG 1 343#endif /* ! HAVE_QUAD_SUPPORT */ 344 345#if ! HAVE_STRLCAT 346size_t strlcat(char *, const char *, size_t); 347#endif 348 349#if ! HAVE_STRLCPY 350size_t strlcpy(char *, const char *, size_t); 351#endif 352 353#if ! HAVE_STRMODE 354void strmode(mode_t, char *); 355#endif 356 357#if ! HAVE_STRSEP 358char *strsep(char **, const char *); 359#endif 360 361#if ! HAVE_USER_FROM_UID 362const char *user_from_uid(uid_t, int); 363const char *group_from_gid(gid_t, int); 364#endif 365 366#if ! HAVE_VSYSLOG 367void vsyslog(int level, const char *, va_list); 368#endif 369 370 371#if ! defined(MIN) 372# define MIN(a, b) ((a) < (b) ? (a) : (b)) 373#endif 374#if ! defined(MAX) 375# define MAX(a, b) ((a) < (b) ? (b) : (a)) 376#endif 377 378#if ! defined(timersub) 379# define timersub(tvp, uvp, vvp) \ 380 do { \ 381 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ 382 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ 383 if ((vvp)->tv_usec < 0) { \ 384 (vvp)->tv_sec--; \ 385 (vvp)->tv_usec += 1000000; \ 386 } \ 387 } while (0) 388#endif 389 390#if ! defined(S_ISLNK) 391# define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK) 392#endif 393 394#define DAYSPERNYEAR 365 395#define SECSPERDAY 86400 396#define TM_YEAR_BASE 1900 397