]> granicus.if.org Git - shadow/blob - lib/defines.h
* lib/defines.h: Include <config.h> since it uses the macro that
[shadow] / lib / defines.h
1 /* $Id$ */
2 /* some useful defines */
3
4 #ifndef _DEFINES_H_
5 #define _DEFINES_H_
6
7 #include <config.h>
8
9 #define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
10
11 /* Take care of NLS matters.  */
12
13 #ifdef HAVE_LOCALE_H
14 # include <locale.h>
15 #else
16 # undef setlocale
17 # define setlocale(category, locale)    (NULL)
18 # ifndef LC_ALL
19 #  define LC_ALL        6
20 # endif
21 #endif
22
23 #define gettext_noop(String) (String)
24 /* #define gettext_def(String) "#define String" */
25
26 #ifdef ENABLE_NLS
27 # include <libintl.h>
28 # define _(Text) gettext (Text)
29 #else
30 # undef bindtextdomain
31 # define bindtextdomain(Domain, Directory)      (NULL)
32 # undef textdomain
33 # define textdomain(Domain)     (NULL)
34 # define _(Text) Text
35 # define ngettext(Msgid1, Msgid2, N) \
36     ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
37 #endif
38
39 #if STDC_HEADERS
40 # include <stdlib.h>
41 # include <string.h>
42 #else                           /* not STDC_HEADERS */
43 # ifndef HAVE_STRCHR
44 #  define strchr index
45 #  define strrchr rindex
46 # endif
47 char *strchr (), *strrchr (), *strtok ();
48
49 # ifndef HAVE_MEMCPY
50 #  define memcpy(d, s, n) bcopy((s), (d), (n))
51 # endif
52 #endif                          /* not STDC_HEADERS */
53
54 #if HAVE_ERRNO_H
55 # include <errno.h>
56 #endif
57
58 #include <sys/stat.h>
59 #include <sys/types.h>
60 #if HAVE_SYS_WAIT_H
61 # include <sys/wait.h>
62 #endif
63 #ifndef WEXITSTATUS
64 # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
65 #endif
66 #ifndef WIFEXITED
67 # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
68 #endif
69
70 #if HAVE_UNISTD_H
71 # include <unistd.h>
72 #endif
73
74 #if TIME_WITH_SYS_TIME
75 # include <sys/time.h>
76 # include <time.h>
77 #else                           /* not TIME_WITH_SYS_TIME */
78 # if HAVE_SYS_TIME_H
79 #  include <sys/time.h>
80 # else
81 #  include <time.h>
82 # endif
83 #endif                          /* not TIME_WITH_SYS_TIME */
84
85 #ifdef HAVE_MEMSET
86 # define memzero(ptr, size) memset((void *)(ptr), 0, (size))
87 #else
88 # define memzero(ptr, size) bzero((char *)(ptr), (size))
89 #endif
90 #define strzero(s) memzero(s, strlen(s))        /* warning: evaluates twice */
91
92 #ifdef HAVE_DIRENT_H            /* DIR_SYSV */
93 # include <dirent.h>
94 # define DIRECT dirent
95 #else
96 # ifdef HAVE_SYS_NDIR_H         /* DIR_XENIX */
97 #  include <sys/ndir.h>
98 # endif
99 # ifdef HAVE_SYS_DIR_H          /* DIR_??? */
100 #  include <sys/dir.h>
101 # endif
102 # ifdef HAVE_NDIR_H             /* DIR_BSD */
103 #  include <ndir.h>
104 # endif
105 # define DIRECT direct
106 #endif
107
108 /*
109  * Possible cases:
110  * - /usr/include/shadow.h exists and includes the shadow group stuff.
111  * - /usr/include/shadow.h exists, but we use our own gshadow.h.
112  */
113 #include <shadow.h>
114 #if defined(SHADOWGRP) && !defined(GSHADOW)
115 #include "gshadow_.h"
116 #endif
117
118 #include <limits.h>
119
120 #ifndef NGROUPS_MAX
121 #ifdef  NGROUPS
122 #define NGROUPS_MAX     NGROUPS
123 #else
124 #define NGROUPS_MAX     64
125 #endif
126 #endif
127
128 #ifdef USE_SYSLOG
129 #include <syslog.h>
130
131 #ifndef LOG_WARN
132 #define LOG_WARN LOG_WARNING
133 #endif
134
135 /* LOG_NOWAIT is deprecated */
136 #ifndef LOG_NOWAIT
137 #define LOG_NOWAIT 0
138 #endif
139
140 /* LOG_AUTH is deprecated, use LOG_AUTHPRIV instead */
141 #ifndef LOG_AUTHPRIV
142 #define LOG_AUTHPRIV LOG_AUTH
143 #endif
144
145 /* cleaner than lots of #ifdefs everywhere - use this as follows:
146    SYSLOG((LOG_CRIT, "user %s cracked root", user)); */
147 #ifdef ENABLE_NLS
148 /* Temporarily set LC_TIME to "C" to avoid strange dates in syslog.
149    This is a workaround for a more general syslog(d) design problem -
150    syslogd should log the current system time for each event, and not
151    trust the formatted time received from the unix domain (or worse,
152    UDP) socket.  -MM */
153 /* Avoid translated PAM error messages: Set LC_ALL to "C".
154  * --Nekral */
155 #define SYSLOG(x)                                                       \
156         do {                                                            \
157                 char *saved_locale = setlocale(LC_ALL, NULL);           \
158                 if (saved_locale)                                       \
159                         saved_locale = strdup(saved_locale);            \
160                 if (saved_locale)                                       \
161                         setlocale(LC_ALL, "C");                 \
162                 syslog x ;                                              \
163                 if (saved_locale) {                                     \
164                         setlocale(LC_ALL, saved_locale);                \
165                         free(saved_locale);                             \
166                 }                                                       \
167         } while (0)
168 #else                           /* !ENABLE_NLS */
169 #define SYSLOG(x) syslog x
170 #endif                          /* !ENABLE_NLS */
171
172 #else                           /* !USE_SYSLOG */
173
174 #define SYSLOG(x)               /* empty */
175 #define openlog(a,b,c)          /* empty */
176 #define closelog()              /* empty */
177
178 #endif                          /* !USE_SYSLOG */
179
180 /* The default syslog settings can now be changed here,
181    in just one place.  */
182
183 #ifndef SYSLOG_OPTIONS
184 /* #define SYSLOG_OPTIONS (LOG_PID | LOG_CONS | LOG_NOWAIT) */
185 #define SYSLOG_OPTIONS (LOG_PID)
186 #endif
187
188 #ifndef SYSLOG_FACILITY
189 #define SYSLOG_FACILITY LOG_AUTHPRIV
190 #endif
191
192 #define OPENLOG(progname) openlog(progname, SYSLOG_OPTIONS, SYSLOG_FACILITY)
193
194 #ifndef F_OK
195 # define F_OK 0
196 # define X_OK 1
197 # define W_OK 2
198 # define R_OK 4
199 #endif
200
201 #ifndef SEEK_SET
202 # define SEEK_SET 0
203 # define SEEK_CUR 1
204 # define SEEK_END 2
205 #endif
206
207 #ifdef STAT_MACROS_BROKEN
208 # define S_ISDIR(x) ((x) & S_IFMT) == S_IFDIR)
209 # define S_ISREG(x) ((x) & S_IFMT) == S_IFREG)
210 # ifdef S_IFLNK
211 #  define S_ISLNK(x) ((x) & S_IFMT) == S_IFLNK)
212 # endif
213 #endif
214
215 #ifndef S_ISLNK
216 #define S_ISLNK(x) (0)
217 #endif
218
219 #if HAVE_LCHOWN
220 #define LCHOWN lchown
221 #else
222 #define LCHOWN chown
223 #endif
224
225 #if HAVE_LSTAT
226 #define LSTAT lstat
227 #else
228 #define LSTAT stat
229 #endif
230
231 #if HAVE_TERMIOS_H
232 # include <termios.h>
233 # define STTY(fd, termio) tcsetattr(fd, TCSANOW, termio)
234 # define GTTY(fd, termio) tcgetattr(fd, termio)
235 # define TERMIO struct termios
236 # define USE_TERMIOS
237 #else                           /* assumed HAVE_TERMIO_H */
238 # include <sys/ioctl.h>
239 # include <termio.h>
240 # define STTY(fd, termio) ioctl(fd, TCSETA, termio)
241 # define GTTY(fd, termio) ioctl(fd, TCGETA, termio)
242 # define TEMRIO struct termio
243 # define USE_TERMIO
244 #endif
245
246 /*
247  * Password aging constants
248  *
249  * DAY - seconds / day
250  * WEEK - seconds / week
251  * SCALE - seconds / aging unit
252  */
253
254 /* Solaris defines this in shadow.h */
255 #ifndef DAY
256 #define DAY (24L*3600L)
257 #endif
258
259 #define WEEK (7*DAY)
260
261 #ifdef ITI_AGING
262 #define SCALE 1
263 #else
264 #define SCALE DAY
265 #endif
266
267 /* Copy string pointed by B to array A with size checking.  It was originally
268    in lmain.c but is _very_ useful elsewhere.  Some setuid root programs with
269    very sloppy coding used to assume that BUFSIZ will always be enough...  */
270
271                                         /* danger - side effects */
272 #define STRFCPY(A,B) \
273         (strncpy((A), (B), sizeof(A) - 1), (A)[sizeof(A) - 1] = '\0')
274
275 #ifndef PASSWD_FILE
276 #define PASSWD_FILE "/etc/passwd"
277 #endif
278
279 #ifndef GROUP_FILE
280 #define GROUP_FILE "/etc/group"
281 #endif
282
283 #ifndef SHADOW_FILE
284 #define SHADOW_FILE "/etc/shadow"
285 #endif
286
287 #ifdef SHADOWGRP
288 #ifndef SGROUP_FILE
289 #define SGROUP_FILE "/etc/gshadow"
290 #endif
291 #endif
292
293 #ifndef NULL
294 #define NULL ((void *) 0)
295 #endif
296
297 #ifdef sun                      /* hacks for compiling on SunOS */
298 # ifndef SOLARIS
299 extern int fputs ();
300 extern char *strdup ();
301 extern char *strerror ();
302 # endif
303 #endif
304
305 /*
306  * string to use for the pw_passwd field in /etc/passwd when using
307  * shadow passwords - most systems use "x" but there are a few
308  * exceptions, so it can be changed here if necessary.  --marekm
309  */
310 #ifndef SHADOW_PASSWD_STRING
311 #define SHADOW_PASSWD_STRING "x"
312 #endif
313
314 #define SHADOW_SP_FLAG_UNSET ((unsigned long int)-1)
315
316 #ifdef WITH_AUDIT
317 #ifdef __u8                     /* in case we use pam < 0.80 */
318 #undef __u8
319 #endif
320 #ifdef __u32
321 #undef __u32
322 #endif
323
324 #include <libaudit.h>
325 #endif
326
327 /* To be used for verified unused parameters */
328 #if defined(__GNUC__) && !defined(__STRICT_ANSI__)
329 # define unused __attribute__((unused))
330 #else
331 # define unused
332 #endif
333
334 #if HAVE_STDBOOL_H
335 # include <stdbool.h>
336 #else
337 # if ! HAVE__BOOL
338 #  ifdef __cplusplus
339 typedef bool _Bool;
340 #  else
341 typedef unsigned char _Bool;
342 #  endif
343 # endif
344 # define bool _Bool
345 # define false (0)
346 # define true  (1)
347 # define __bool_true_false_are_defined 1
348 #endif
349
350 #endif                          /* _DEFINES_H_ */