1 /* Copyright 1993,1994 by Paul Vixie
2  * All rights reserved
3  */
4 
5 /*
6  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
7  * Copyright (c) 1997,2000 by Internet Software Consortium, Inc.
8  *
9  * Permission to use, copy, modify, and distribute this software for any
10  * purpose with or without fee is hereby granted, provided that the above
11  * copyright notice and this permission notice appear in all copies.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
16  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /* reorder these #include's at your peril */
23 
24 #include <sys/param.h>
25 #include <sys/types.h>
26 #include <sys/time.h>
27 #include <sys/wait.h>
28 #include <sys/fcntl.h>
29 #include <sys/file.h>
30 #include <sys/stat.h>
31 
32 #include <bitstring.h>
33 #include <ctype.h>
34 #ifndef isascii
35 #define isascii(c)      ((unsigned)(c)<=0177)
36 #endif
37 #include <dirent.h>
38 #include <errno.h>
39 #include <fcntl.h>
40 #include <grp.h>
41 #include <locale.h>
42 #include <pwd.h>
43 #include <signal.h>
44 #include <stdarg.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48 #include <time.h>
49 #include <unistd.h>
50 #include <utime.h>
51 
52 #if defined(SYSLOG)
53 # include <syslog.h>
54 #endif
55 
56 #if defined(LOGIN_CAP)
57 # include <login_cap.h>
58 #endif /*LOGIN_CAP*/
59 
60 #if defined(BSD_AUTH)
61 # include <bsd_auth.h>
62 #endif /*BSD_AUTH*/
63 
64 #define DIR_T	struct dirent
65 #define WAIT_T	int
66 #define SIG_T	sig_t
67 #define TIME_T	time_t
68 #define PID_T	pid_t
69 
70 #ifndef TZNAME_ALREADY_DEFINED
71 extern char *tzname[2];
72 #endif
73 #define TZONE(tm) tzname[(tm).tm_isdst]
74 
75 #if (defined(BSD)) && (BSD >= 198606) || defined(__linux)
76 # define HAVE_FCHOWN
77 # define HAVE_FCHMOD
78 #endif
79 
80 #if (defined(BSD)) && (BSD >= 199103) || defined(__linux)
81 # define HAVE_SAVED_UIDS
82 #endif
83 
84 #define MY_UID(pw) getuid()
85 #define MY_GID(pw) getgid()
86 
87 /* getopt() isn't part of POSIX.  some systems define it in <stdlib.h> anyway.
88  * of those that do, some complain that our definition is different and some
89  * do not.  to add to the misery and confusion, some systems define getopt()
90  * in ways that we cannot predict or comprehend, yet do not define the adjunct
91  * external variables needed for the interface.
92  */
93 #if (!defined(BSD) || (BSD < 198911))
94 int	getopt(int, char * const *, const char *);
95 #endif
96 
97 #if (!defined(BSD) || (BSD < 199103))
98 extern	char *optarg;
99 extern	int optind, opterr, optopt;
100 #endif
101 
102 /* digital unix needs this but does not give us a way to identify it.
103  */
104 extern	int		flock(int, int);
105 
106 /* not all systems who provide flock() provide these definitions.
107  */
108 #ifndef LOCK_SH
109 # define LOCK_SH 1
110 #endif
111 #ifndef LOCK_EX
112 # define LOCK_EX 2
113 #endif
114 #ifndef LOCK_NB
115 # define LOCK_NB 4
116 #endif
117 #ifndef LOCK_UN
118 # define LOCK_UN 8
119 #endif
120 
121 #ifndef WCOREDUMP
122 # define WCOREDUMP(st)          (((st) & 0200) != 0)
123 #endif
124