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