blob: 23e00d1a779c49af894d70635e72ff1a199a9a6e [file] [log] [blame]
Damien Miller6b85a7f2000-01-02 11:45:33 +11001#ifndef _DEFINES_H
2#define _DEFINES_H
3
Damien Miller74d0d4a1999-12-29 02:24:35 +11004/* Necessary headers */
5
Damien Miller1c67c992000-03-14 10:16:34 +11006#include <sys/types.h> /* For [u]intxx_t */
Damien Miller5a3e6831999-12-27 09:48:56 +11007#include <sys/socket.h> /* For SHUT_XXXX */
Damien Millera66626b2000-06-13 18:57:53 +10008#include <sys/param.h> /* For MAXPATHLEN */
9#include <netinet/in_systm.h> /* For typedefs */
Damien Miller1c67c992000-03-14 10:16:34 +110010#include <netinet/in.h> /* For IPv6 macros */
Damien Millerbc7c7cc2000-04-08 17:48:56 +100011#include <netinet/ip.h> /* For IPTOS macros */
Damien Millerb29ea912000-01-15 14:12:03 +110012#ifdef HAVE_SYS_BITYPES_H
13# include <sys/bitypes.h> /* For u_intXX_t */
14#endif
Damien Miller5a3e6831999-12-27 09:48:56 +110015#ifdef HAVE_PATHS_H
16# include <paths.h> /* For _PATH_XXX */
17#endif
Damien Millera66626b2000-06-13 18:57:53 +100018#ifdef HAVE_LIMITS_H
19# include <limits.h> /* For PATH_MAX */
20#endif
Damien Miller5a3e6831999-12-27 09:48:56 +110021#ifdef HAVE_SYS_TIME_H
22# include <sys/time.h> /* For timersub */
23#endif
Damien Miller5a3e6831999-12-27 09:48:56 +110024#ifdef HAVE_MAILLOCK_H
Damien Millerbeb4ba51999-12-28 15:09:35 +110025# include <maillock.h> /* For _PATH_MAILDIR */
Damien Miller5a3e6831999-12-27 09:48:56 +110026#endif
Damien Millerbeb4ba51999-12-28 15:09:35 +110027#ifdef HAVE_SYS_CDEFS_H
28# include <sys/cdefs.h> /* For __P() */
29#endif
Damien Milleree1c0b32000-01-21 00:18:15 +110030#ifdef HAVE_SYS_SYSMACROS_H
31# include <sys/sysmacros.h> /* For MIN, MAX, etc */
32#endif
Damien Miller0f91b4e2000-06-18 15:43:25 +100033#ifdef HAVE_SYS_STAT_H
34# include <sys/stat.h> /* For S_* constants and macros */
35#endif
36
37#include <unistd.h> /* For STDIN_FILENO, etc */
Damien Milleree1c0b32000-01-21 00:18:15 +110038
Damien Miller74d0d4a1999-12-29 02:24:35 +110039/* Constants */
40
Damien Miller5a3e6831999-12-27 09:48:56 +110041#ifndef SHUT_RDWR
42enum
43{
44 SHUT_RD = 0, /* No more receptions. */
45 SHUT_WR, /* No more transmissions. */
46 SHUT_RDWR /* No more receptions or transmissions. */
47};
48# define SHUT_RD SHUT_RD
49# define SHUT_WR SHUT_WR
50# define SHUT_RDWR SHUT_RDWR
51#endif
52
Damien Millerbc7c7cc2000-04-08 17:48:56 +100053#ifndef IPTOS_LOWDELAY
54# define IPTOS_LOWDELAY 0x10
55# define IPTOS_THROUGHPUT 0x08
56# define IPTOS_RELIABILITY 0x04
57# define IPTOS_LOWCOST 0x02
58# define IPTOS_MINCOST IPTOS_LOWCOST
59#endif /* IPTOS_LOWDELAY */
60
Damien Millera66626b2000-06-13 18:57:53 +100061#ifndef MAXPATHLEN
62# ifdef PATH_MAX
63# define MAXPATHLEN PATH_MAX
64# else /* PATH_MAX */
65# define MAXPATHLEN 64 /* Should be safe */
66# endif /* PATH_MAX */
67#endif /* MAXPATHLEN */
68
Damien Miller0f91b4e2000-06-18 15:43:25 +100069#ifndef STDIN_FILENO
70# define STDIN_FILENO 0
71#endif
72#ifndef STDOUT_FILENO
73# define STDOUT_FILENO 1
74#endif
75#ifndef STDERR_FILENO
76# define STDERR_FILENO 2
77#endif
78
79#ifndef S_ISREG
80# define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
81# define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG))
82#endif /* S_ISREG */
83
84#ifndef S_IXUSR
85# define S_IXUSR 0000100 /* execute/search permission, */
86# define S_IXGRP 0000010 /* execute/search permission, */
87# define S_IXOTH 0000001 /* execute/search permission, */
88# define _S_IWUSR 0000200 /* write permission, */
89# define S_IWUSR _S_IWUSR /* write permission, owner */
90# define S_IWGRP 0000020 /* write permission, group */
91# define S_IWOTH 0000002 /* write permission, other */
92# define S_IRUSR 0000400 /* read permission, owner */
93# define S_IRGRP 0000040 /* read permission, group */
94# define S_IROTH 0000004 /* read permission, other */
95# define S_IRWXU 0000700 /* read, write, execute */
96# define S_IRWXG 0000070 /* read, write, execute */
97# define S_IRWXO 0000007 /* read, write, execute */
98#endif /* S_IXUSR */
99
Damien Miller74d0d4a1999-12-29 02:24:35 +1100100/* Types */
101
Damien Miller5a3e6831999-12-27 09:48:56 +1100102/* If sys/types.h does not supply intXX_t, supply them ourselves */
103/* (or die trying) */
104#ifndef HAVE_INTXX_T
Damien Millere0f45742000-01-18 09:12:06 +1100105# if (SIZEOF_CHAR == 1)
106typedef char int8_t;
107# else
108# error "8 bit int type not found."
109# endif
Damien Miller5a3e6831999-12-27 09:48:56 +1100110# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100111typedef short int int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100112# else
113# error "16 bit int type not found."
114# endif
115# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100116typedef int int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100117# else
118# error "32 bit int type not found."
119# endif
Damien Miller70494d12000-04-03 15:57:06 +1000120/*
Damien Miller5a3e6831999-12-27 09:48:56 +1100121# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100122typedef long int int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100123# else
124# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100125typedef long long int int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100126# define HAVE_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100127# else
128# error "64 bit int type not found."
129# endif
130# endif
Damien Miller70494d12000-04-03 15:57:06 +1000131*/
Damien Miller5a3e6831999-12-27 09:48:56 +1100132#endif
133
134/* If sys/types.h does not supply u_intXX_t, supply them ourselves */
135#ifndef HAVE_U_INTXX_T
136# ifdef HAVE_UINTXX_T
Damien Millere0f45742000-01-18 09:12:06 +1100137typedef uint8_t u_int8_t;
Damien Miller74d0d4a1999-12-29 02:24:35 +1100138typedef uint16_t u_int16_t;
139typedef uint32_t u_int32_t;
Damien Miller70494d12000-04-03 15:57:06 +1000140/*
Damien Miller74d0d4a1999-12-29 02:24:35 +1100141typedef uint64_t u_int64_t;
Damien Miller70494d12000-04-03 15:57:06 +1000142*/
Damien Miller6b85a7f2000-01-02 11:45:33 +1100143# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100144# else
Damien Millere0f45742000-01-18 09:12:06 +1100145# if (SIZEOF_CHAR == 1)
146typedef unsigned char u_int8_t;
147# else
148# error "8 bit int type not found."
149# endif
Damien Miller5a3e6831999-12-27 09:48:56 +1100150# if (SIZEOF_SHORT_INT == 2)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100151typedef unsigned short int u_int16_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100152# else
153# error "16 bit int type not found."
154# endif
155# if (SIZEOF_INT == 4)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100156typedef unsigned int u_int32_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100157# else
158# error "32 bit int type not found."
159# endif
Damien Miller70494d12000-04-03 15:57:06 +1000160/*
Damien Miller5a3e6831999-12-27 09:48:56 +1100161# if (SIZEOF_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100162typedef unsigned long int u_int64_t;
Damien Miller5a3e6831999-12-27 09:48:56 +1100163# else
164# if (SIZEOF_LONG_LONG_INT == 8)
Damien Miller74d0d4a1999-12-29 02:24:35 +1100165typedef unsigned long long int u_int64_t;
Damien Miller6b85a7f2000-01-02 11:45:33 +1100166# define HAVE_U_INTXX_T 1
Damien Miller5a3e6831999-12-27 09:48:56 +1100167# else
168# error "64 bit int type not found."
169# endif
170# endif
Damien Miller70494d12000-04-03 15:57:06 +1000171*/
Damien Miller5a3e6831999-12-27 09:48:56 +1100172# endif
173#endif
174
Damien Miller74d0d4a1999-12-29 02:24:35 +1100175#ifndef HAVE_SOCKLEN_T
176typedef unsigned int socklen_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100177# define HAVE_SOCKLEN_T
Damien Miller74d0d4a1999-12-29 02:24:35 +1100178#endif /* HAVE_SOCKLEN_T */
179
Damien Miller95058511999-12-29 10:36:45 +1100180#ifndef HAVE_SIZE_T
181typedef unsigned int size_t;
Damien Millerb2532b31999-12-31 09:18:12 +1100182# define HAVE_SIZE_T
Damien Miller95058511999-12-29 10:36:45 +1100183#endif /* HAVE_SIZE_T */
184
Damien Miller615f9392000-05-17 22:53:33 +1000185#ifndef HAVE_SSIZE_T
186typedef int ssize_t;
187# define HAVE_SSIZE_T
188#endif /* HAVE_SSIZE_T */
189
Damien Millerb54b40e2000-06-23 08:23:34 +1000190#ifndef HAVE_SA_FAMILY_T
191typedef int sa_family_t;
192# define HAVE_SA_FAMILY_T
193#endif /* HAVE_SA_FAMILY_T */
194
Damien Miller0f91b4e2000-06-18 15:43:25 +1000195#ifndef HAVE_PID_T
196typedef int pid_t;
197# define HAVE_PID_T
198#endif /* HAVE_PID_T */
199
200#ifndef HAVE_MODE_T
201typedef int mode_t;
202# define HAVE_MODE_T
203#endif /* HAVE_MODE_T */
204
Damien Miller34132e52000-01-14 15:45:46 +1100205#if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
206# define ss_family __ss_family
207#endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
208
Damien Miller74d0d4a1999-12-29 02:24:35 +1100209/* Paths */
210
Damien Miller5a3e6831999-12-27 09:48:56 +1100211#ifndef _PATH_BSHELL
212# define _PATH_BSHELL "/bin/sh"
213#endif
214
215#ifdef USER_PATH
216# ifdef _PATH_STDPATH
217# undef _PATH_STDPATH
218# endif
219# define _PATH_STDPATH USER_PATH
220#endif
221
222#ifndef _PATH_STDPATH
223# define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
224#endif
225
226#ifndef _PATH_DEVNULL
227# define _PATH_DEVNULL "/dev/null"
228#endif
229
Damien Miller615f9392000-05-17 22:53:33 +1000230#ifndef MAIL_DIRECTORY
231# define MAIL_DIRECTORY "/var/spool/mail"
232#endif
233
Damien Miller5a3e6831999-12-27 09:48:56 +1100234#ifndef MAILDIR
235# define MAILDIR MAIL_DIRECTORY
236#endif
237
238#if !defined(_PATH_MAILDIR) && defined(MAILDIR)
239# define _PATH_MAILDIR MAILDIR
240#endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */
241
Damien Miller74d0d4a1999-12-29 02:24:35 +1100242#ifndef _PATH_RSH
243# ifdef RSH_PATH
244# define _PATH_RSH RSH_PATH
245# endif /* RSH_PATH */
246#endif /* _PATH_RSH */
247
248/* Macros */
249
Damien Miller5a3e6831999-12-27 09:48:56 +1100250#ifndef MAX
251# define MAX(a,b) (((a)>(b))?(a):(b))
252# define MIN(a,b) (((a)<(b))?(a):(b))
253#endif
254
255#ifndef timersub
256#define timersub(a, b, result) \
257 do { \
258 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
259 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
260 if ((result)->tv_usec < 0) { \
261 --(result)->tv_sec; \
262 (result)->tv_usec += 1000000; \
263 } \
264 } while (0)
265#endif
266
Damien Miller5a3e6831999-12-27 09:48:56 +1100267#ifndef __P
268# define __P(x) x
269#endif
270
Damien Miller1c67c992000-03-14 10:16:34 +1100271#if !defined(IN6_IS_ADDR_V4MAPPED)
272# define IN6_IS_ADDR_V4MAPPED(a) \
Damien Millerdb819592000-03-14 13:44:01 +1100273 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
274 (((u_int32_t *) (a))[2] == htonl (0xffff)))
Damien Miller1c67c992000-03-14 10:16:34 +1100275#endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
276
Damien Miller5a3e6831999-12-27 09:48:56 +1100277#if !defined(__GNUC__) || (__GNUC__ < 2)
Damien Millere0f45742000-01-18 09:12:06 +1100278# define __attribute__(x)
Damien Miller5a3e6831999-12-27 09:48:56 +1100279#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
280
Damien Miller74d0d4a1999-12-29 02:24:35 +1100281#if defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM)
282# define USE_PAM
283#endif /* defined(HAVE_SECURITY_PAM_APPL_H) && !defined(DISABLE_PAM) */
284
285/* Function replacement / compatibility hacks */
286
287/* In older versions of libpam, pam_strerror takes a single argument */
288#ifdef HAVE_OLD_PAM
289# define PAM_STRERROR(a,b) pam_strerror((b))
290#else
291# define PAM_STRERROR(a,b) pam_strerror((a),(b))
292#endif
293
Damien Millereca71f82000-01-20 22:38:27 +1100294#if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
295# undef HAVE_GETADDRINFO
296#endif /* defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) */
297
Damien Miller615f9392000-05-17 22:53:33 +1000298#if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY)
299# define memmove(s1, s2, n) bcopy((s2), (s1), (n))
300#endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */
301
Damien Millerbe260a02000-05-30 12:57:46 +1000302#if !defined(HAVE_ATEXIT) && defined(HAVE_ON_EXIT)
303# define atexit(a) on_exit(a)
304#endif /* !defined(HAVE_ATEXIT) && defined(HAVE_ON_EXIT) */
305
andre2ff7b5d2000-06-03 14:57:40 +0000306/**
307 ** login recorder definitions
308 **/
309
310/* preprocess */
311
312#ifdef HAVE_UTMP_H
313# ifdef HAVE_TIME_IN_UTMP
314# include <time.h>
315# endif
316# include <utmp.h>
317#endif
318#ifdef HAVE_UTMPX_H
319# ifdef HAVE_TV_IN_UTMPX
320# include <sys/time.h>
321# endif
322# include <utmpx.h>
323#endif
324#ifdef HAVE_LASTLOG_H
325# include <lastlog.h>
326#endif
327#ifdef HAVE_PATHS_H
328# include <paths.h>
329#endif
330
331/* FIXME: put default paths back in */
332#if !defined(UTMP_FILE) && defined(_PATH_UTMP)
333# define UTMP_FILE _PATH_UTMP
334#endif
335#if !defined(WTMP_FILE) && defined(_PATH_WTMP)
336# define WTMP_FILE _PATH_WTMP
337#endif
338/* pick up the user's location for lastlog if given */
andre2ff7b5d2000-06-03 14:57:40 +0000339#if !defined(LASTLOG_FILE) && defined(_PATH_LASTLOG)
340# define LASTLOG_FILE _PATH_LASTLOG
341#endif
Damien Miller2994e082000-06-04 15:51:47 +1000342#if !defined(LASTLOG_FILE) && defined(CONF_LASTLOG_FILE)
343# define LASTLOG_FILE CONF_LASTLOG_FILE
344#endif
andre2ff7b5d2000-06-03 14:57:40 +0000345
346
347/* The login() library function in libutil is first choice */
348#if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN)
349# define USE_LOGIN
350
351#else
352/* Simply select your favourite login types. */
353/* Can't do if-else because some systems use several... <sigh> */
354# if defined(UTMPX_FILE) && !defined(DISABLE_UTMPX)
355# define USE_UTMPX
356# endif
357# if defined(UTMP_FILE) && !defined(DISABLE_UTMP)
358# define USE_UTMP
359# endif
360# if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX)
361# define USE_WTMPX
362# endif
363# if defined(WTMP_FILE) && !defined(DISABLE_WTMP)
364# define USE_WTMP
365# endif
366
367#endif
368
369/* I hope that the presence of LASTLOG_FILE is enough to detect this */
370#if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG)
371# define USE_LASTLOG
372#endif
373
374/* which type of time to use? (api.c) */
375#ifdef HAVE_SYS_TIME_H
376# define USE_TIMEVAL
377#endif
378
379/** end of login recorder definitions */
380
Damien Miller6b85a7f2000-01-02 11:45:33 +1100381#endif /* _DEFINES_H */