For DH, use standard primes from RFCs
[exim.git] / src / src / exim.h
CommitLineData
059ec3d9
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
c4ceed07 5/* Copyright (c) University of Cambridge 1995 - 2012 */
059ec3d9
PH
6/* See the file NOTICE for conditions of use and distribution. */
7
8
9/* Source files for exim all #include this header, which drags in everything
10that is needed. They don't all need everything, of course, but it's far too
11messy to have each one importing its own list, and anyway, most of them need
12most of these includes. */
13
14/* Assume most systems have statfs() unless os.h undefines this macro */
15
16#define HAVE_STATFS
17
0eb8eedd
NM
18/* Similarly, assume most systems have srandom() unless os.h undefines it.
19This call dates back at least as far as SUSv2. */
20
21#define HAVE_SRANDOM
22
b87a6e0e 23/* This is primarily for the Gnu C library; we define it before os.h so that
57eb9e91
PP
24os.h has a chance to hurriedly undef it, Just In Case. We need C99 for some
2564-bit math support, and defining _ISOC99_SOURCE breaks <resolv.h> and friends.
26*/
b87a6e0e 27
57eb9e91 28#define _GNU_SOURCE 1
b87a6e0e 29
059ec3d9
PH
30/* First of all include the os-specific header, which might set things that
31are needed by any of the other headers, including system headers. */
32
33#include "os.h"
34
35/* If it didn't define os_find_running_interfaces, use the common function. */
36
37#ifndef os_find_running_interfaces
38#define os_find_running_interfaces os_common_find_running_interfaces
39#endif
40
41/* If it didn't define the base for "base 62" numbers, we really do use 62.
42This is the case for all real Unix and Unix-like OS. It's only Cygwin and
43Darwin, with their case-insensitive file systems, that can't use base 62 for
44making unique names. */
45
46#ifndef BASE_62
47#define BASE_62 62
48#endif
49
50/* The maximum value of localhost_number depends on the base being used */
51
52#if BASE_62 == 62
53#define LOCALHOST_MAX 16
54#else
55#define LOCALHOST_MAX 10
56#endif
57
e12f8c32
PP
58/* If not overriden by os.h, dynamic libraries have filenames ending .so */
59#ifndef DYNLIB_FN_EXT
60# define DYNLIB_FN_EXT "so"
61#endif
62
059ec3d9
PH
63/* ANSI C standard includes */
64
65#include <ctype.h>
66#include <locale.h>
870f6ba8 67#include <math.h>
059ec3d9
PH
68#include <signal.h>
69#include <stdarg.h>
70#include <stddef.h>
71#include <stdio.h>
72#include <stdlib.h>
73#include <string.h>
74#include <time.h>
75
76/* Unix includes */
77
78#include <errno.h>
1a46a8c5 79#if defined(__svr4__) && defined(__sparc) && ! defined(__EXTENSIONS__)
059ec3d9
PH
80#define __EXTENSIONS__ /* so that SunOS 5 gets NGROUPS_MAX */
81#include <limits.h>
82#undef __EXTENSIONS__
83#else
84#include <limits.h>
85#endif
86
17c76198
PP
87/* C99 integer types, figure out how to undo this if needed for older systems */
88
89#include <inttypes.h>
90
059ec3d9
PH
91/* Just in case some aged system doesn't define them... */
92
93#ifndef INT_MAX
94#define INT_MAX 2147483647
95#endif
96
4362ff0d
PH
97#ifndef INT_MIN
98#define INT_MIN (-INT_MAX - 1)
99#endif
100
101#ifndef SHRT_MAX
102#define SHRT_MAX 32767
103#endif
104
059ec3d9
PH
105#ifndef UCHAR_MAX
106#define UCHAR_MAX 255
107#endif
108
109/* Some systems have PATH_MAX and some have MAX_PATH_LEN. */
110
111#ifndef PATH_MAX
112#ifdef MAX_PATH_LEN
113#define PATH_MAX MAX_PATH_LEN
114#else
115#define PATH_MAX 1024
116#endif
117#endif
118
119#include <sys/types.h>
120#include <sys/file.h>
121#include <dirent.h>
122#include <netdb.h>
f452e07e 123#ifndef NO_POLL_H
cfe75fc3 124#include <poll.h>
f452e07e 125#endif
059ec3d9
PH
126#include <pwd.h>
127#include <grp.h>
128#include <syslog.h>
129
130/* Not all systems have flock() available. Those that do must define LOCK_SH
131in sys/file.h. */
132
133#ifndef LOCK_SH
134#define NO_FLOCK
135#endif
136
137#ifndef NO_SYSEXITS /* some OS don't have this */
138#include <sysexits.h>
139#endif
140
36a3b041
PH
141/* A few OS don't have socklen_t; their os.h files define EXIM_SOCKLEN_T to
142be size_t or whatever. We used to use SOCKLEN_T, but then it was discovered
143that this is used by the AIX include files. */
059ec3d9 144
36a3b041
PH
145#ifndef EXIM_SOCKLEN_T
146#define EXIM_SOCKLEN_T socklen_t
059ec3d9
PH
147#endif
148
149/* Ensure that the sysexits we reference are defined */
150
151#ifndef EX_UNAVAILABLE
152#define EX_UNAVAILABLE 69 /* service unavailable; used for execv fail */
153#endif
154#ifndef EX_CANTCREAT
155#define EX_CANTCREAT 73 /* can't create file: treat as temporary */
156#endif
157#ifndef EX_TEMPFAIL
158#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
159#endif
160#ifndef EX_CONFIG
161#define EX_CONFIG 78 /* configuration error */
162#endif
163
164/* This one is not in any sysexits file that I've come across */
165
166#define EX_EXECFAILED 127 /* execve() failed */
167
168
169#include <sys/time.h>
170#include <sys/param.h>
171
172#ifndef NO_SYS_RESOURCE_H /* QNX doesn't have this */
173#include <sys/resource.h>
174#endif
175
176#include <sys/socket.h>
177
178/* If we are on an IPv6 system, the macro AF_INET6 will have been defined in
179the sys/socket.h header. It is helpful to have this defined on an IPv4 system
180so that it can appear in the code, even if it is never actually used when
181the code is run. It saves some #ifdef occurrences. */
182
183#ifndef AF_INET6
184#define AF_INET6 24
185#endif
186
187#include <sys/ioctl.h>
188
189/* The new standard is statvfs; some OS have statfs. For statvfs the block
190counts must be multiplied by the "fragment size" f_frsize to get the actual
191size. In other cases the value seems to be f_bsize (which is sometimes the only
192block size), so we use a macro to get that instead.
193
194Also arrange to be able to cut it out altogether for way-out OS that don't have
195anything. I've indented a bit here to try to make the mess a bit more
196intelligible. Note that simply defining one name to be another when
197HAVE_SYS_STATVFS_H is not set will not work if the system has a statvfs macro
198or a macro with entries f_frsize and f_bsize. */
199
200#ifdef HAVE_STATFS
201 #ifdef HAVE_SYS_STATVFS_H
202 #include <sys/statvfs.h>
203 #define STATVFS statvfs
204 #define F_FRSIZE f_frsize
205 #else
206 #define STATVFS statfs
207 #define F_FRSIZE f_bsize
208 #ifdef HAVE_SYS_VFS_H
209 #include <sys/vfs.h>
210 #ifdef HAVE_SYS_STATFS_H
211 #include <sys/statfs.h>
212 #endif
213 #endif
214 #ifdef HAVE_SYS_MOUNT_H
215 #include <sys/mount.h>
216 #endif
217 #endif
218
219 /* Macros for the fields for the available space for non-superusers; define
220 these only if the OS header has not. Not all OS have f_favail; those that
221 are known to have it define F_FAVAIL as f_favail. The default is to use
222 f_free. */
223
224 #ifndef F_BAVAIL
225 #define F_BAVAIL f_bavail
226 #endif
227
228 #ifndef F_FAVAIL
229 #define F_FAVAIL f_ffree
230 #endif
231
232 /* All the systems I've been able to look at seem to have F_FILES */
233
234 #ifndef F_FILES
235 #define F_FILES f_files
236 #endif
237
238#endif
239
240
1a46a8c5 241#ifndef SIOCGIFCONF /* HACK for SunOS 5 */
059ec3d9
PH
242#include <sys/sockio.h>
243#endif
244
245#include <sys/stat.h>
246#include <sys/wait.h>
247#include <sys/utsname.h>
248#include <fcntl.h>
249
250/* There's a shambles in IRIX6 - it defines EX_OK in unistd.h which conflicts
415c8f3b
PH
251with the definition in sysexits.h. Exim does not actually use this macro, so we
252just undefine it. It would be nice to be able to re-instate the definition from
253sysexits.h if there is no definition in unistd.h, but I do not think there is a
254way to do this in C because macro definitions are not scanned for other macros
255at definition time. [The code here used to assume they were, until I was
256disabused of the notion. Luckily, since EX_OK is not used, it didn't matter.] */
059ec3d9
PH
257
258#ifdef EX_OK
059ec3d9
PH
259#undef EX_OK
260#endif
261
262#include <unistd.h>
263
059ec3d9
PH
264#include <utime.h>
265#ifndef NO_NET_IF_H
266#include <net/if.h>
267#endif
268#include <sys/un.h>
269#include <netinet/in.h>
270#include <netinet/tcp.h>
271#include <arpa/inet.h>
272#include <arpa/nameser.h>
273
274
275/* If arpa/nameser.h defines a maximum name server packet size, use it,
276provided it is greater than 2048. Otherwise go for a default. PACKETSZ was used
277for this, but it seems that NS_PACKETSZ is coming into use. */
278
279#if defined(NS_PACKETSZ) && NS_PACKETSZ >= 2048
280 #define MAXPACKET NS_PACKETSZ
281#elif defined(PACKETSZ) && PACKETSZ >= 2048
282 #define MAXPACKET PACKETSZ
283#else
284 #define MAXPACKET 2048
285#endif
286
287/* While IPv6 is still young the definitions of T_AAAA and T_A6 may not be
288included in arpa/nameser.h. Fudge them here. */
289
290#ifndef T_AAAA
291#define T_AAAA 28
292#endif
293
294#ifndef T_A6
295#define T_A6 38
296#endif
297
298/* Ancient systems (e.g. SunOS4) don't appear to have T_TXT defined in their
299header files. I don't suppose they have T_SRV either. */
300
301#ifndef T_TXT
302#define T_TXT 16
303#endif
304
305#ifndef T_SRV
306#define T_SRV 33
307#endif
308
eae0036b
PP
309/* Many systems do not have T_SPF. */
310
311#ifndef T_SPF
312#define T_SPF 99
313#endif
314
ade42478
PH
315/* It seems that some versions of arpa/nameser.h don't define *any* of the
316T_xxx macros, which seem to be non-standard nowadays. Just to be on the safe
317side, put in definitions for all the ones that Exim uses. */
318
319#ifndef T_A
320#define T_A 1
321#endif
322
323#ifndef T_CNAME
324#define T_CNAME 5
325#endif
326
885ccd3e
PH
327#ifndef T_SOA
328#define T_SOA 6
329#endif
330
ade42478
PH
331#ifndef T_MX
332#define T_MX 15
333#endif
334
335#ifndef T_NS
336#define T_NS 2
337#endif
338
339#ifndef T_PTR
340#define T_PTR 12
341#endif
342
343
e5a9dba6
PH
344/* We define a few private types for special DNS lookups:
345
346 . T_ZNS gets the nameservers of the enclosing zone of a domain
347
348 . T_MXH gets the MX hostnames only (without their priorities)
349
350 . T_CSA gets the domain's Client SMTP Authorization SRV record
351
352*/
33397d19
PH
353
354#define T_ZNS (-1)
ea3bc19b 355#define T_MXH (-2)
e5a9dba6 356#define T_CSA (-3)
33397d19 357
059ec3d9
PH
358/* The resolv.h header defines __P(x) on some Solaris 2.5.1 systems (without
359checking that it is already defined, in fact). This conflicts with other
360headers that behave likewise (see below), leading to compiler warnings. Arrange
361to undefine it if resolv.h defines it. */
362
363#if defined(__P)
364#define __P_WAS_DEFINED_BEFORE_RESOLV
365#endif
366
367#include <resolv.h>
368
369#if defined(__P) && ! defined (__P_WAS_DEFINED_BEFORE_RESOLV)
370#undef __P
371#endif
372
5bfb4cdf
PP
373/* If not defined by os.h, we do nothing special to push DNS resolver state
374back to be available by the classic resolver routines. Also, provide
375prototype for our get routine, unless defined away. */
376
377#ifndef os_put_dns_resolver_res
378# define os_put_dns_resolver_res(R) do {/**/} while(0)
379#endif
380#ifndef os_get_dns_resolver_res
381res_state os_get_dns_resolver_res(void);
382#endif
383
059ec3d9
PH
384/* These three are to support the IP option logging code. Linux is
385different to everyone else and there are also other systems which don't
386have netinet/ip_var.h, so there's a general macro to control its inclusion. */
387
388#include <netinet/in_systm.h>
389#include <netinet/ip.h>
390
391#ifndef NO_IP_VAR_H
392#include <netinet/ip_var.h>
393#endif
394
395/* Linux (and some others) uses a different type for the 2nd argument of
396iconv(). It's os.h file defines ICONV_ARG2_TYPE. For the rest, define a default
397here. */
398
399#ifndef ICONV_ARG2_TYPE
400#define ICONV_ARG2_TYPE const char **
401#endif
402
403/* One OS uses a different type for the 5th argument of getsockopt */
404
405#ifndef GETSOCKOPT_ARG5_TYPE
406#define GETSOCKOPT_ARG5_TYPE socklen_t *
407#endif
408
409/* One operating system uses a different type for the 2nd argument of select().
410Its os.h file defines SELECT_ARG2_TYPE. For the rest, define a default here. */
411
412#ifndef SELECT_ARG2_TYPE
413#define SELECT_ARG2_TYPE fd_set
414#endif
415
416/* One operating system uses a different type for the 4th argument of
417dn_expand(). Its os.h file defines DN_EXPAND_ARG4_TYPE. For the rest, define a
418default here. */
419
420#ifndef DN_EXPAND_ARG4_TYPE
421#define DN_EXPAND_ARG4_TYPE char *
422#endif
423
424/* One operating system defines a different type for the yield of inet_addr().
425In Exim code, its value is always assigned to the s_addr members of address
426structures. Casting the yield to the type of s_addr should fix the problem,
427since the size of the data is correct. Just in case this ever has to be
428changed, use a macro for the type, and define it here so that it is possible to
429use different values for specific OS if ever necessary. */
430
431#ifndef S_ADDR_TYPE
432#define S_ADDR_TYPE u_long
433#endif
434
435/* (At least) one operating system (Solaris) defines a different type for the
436second argument of pam_converse() - the difference is the absence of "const".
437Its os.h file defines PAM_CONVERSE_ARG2_TYPE. For the rest, define a default
438here. */
439
440#ifndef PAM_CONVERSE_ARG2_TYPE
441#define PAM_CONVERSE_ARG2_TYPE const struct pam_message
442#endif
443
444/* One operating system (SunOS4) defines getc, ungetc, feof, and ferror as
445macros and not as functions. Exim needs them to be assignable functions. This
446flag gets set to cause this to be sorted out here. */
447
448#ifdef FUDGE_GETC_AND_FRIENDS
449#undef getc
450extern int getc(FILE *);
451#undef ungetc
452extern int ungetc(int, FILE *);
453#undef feof
454extern int feof(FILE *);
455#undef ferror
456extern int ferror(FILE *);
457#endif
458
459/* The header from the PCRE regex package */
460
8eb9f5bd 461#include <pcre.h>
059ec3d9
PH
462
463/* Exim includes are in several files. Note that local_scan.h #includes
750af86e
PH
464config.h, mytypes.h, and store.h, so we don't need to mention them explicitly.
465*/
8523533c 466
059ec3d9
PH
467#include "local_scan.h"
468#include "macros.h"
059ec3d9
PH
469#include "dbstuff.h"
470#include "structs.h"
471#include "globals.h"
472#include "functions.h"
473#include "dbfunctions.h"
474#include "osfunctions.h"
475
8523533c
TK
476#ifdef EXPERIMENTAL_BRIGHTMAIL
477#include "bmi_spam.h"
478#endif
479#ifdef EXPERIMENTAL_SPF
480#include "spf.h"
481#endif
482#ifdef EXPERIMENTAL_SRS
483#include "srs.h"
484#endif
80a47a2c
TK
485#ifndef DISABLE_DKIM
486#include "dkim.h"
f7572e5a 487#endif
8523533c 488
059ec3d9
PH
489/* The following stuff must follow the inclusion of config.h because it
490requires various things that are set therein. */
491
492#if HAVE_ICONV /* Not all OS have this */
493#include <iconv.h>
494#endif
495
379120bf 496#if defined(USE_READLINE) || defined(EXPAND_DLFUNC) || defined (LOOKUP_MODULE_DIR)
059ec3d9
PH
497#include <dlfcn.h>
498#endif
499
54fc8428
PH
500#ifdef ENABLE_DISABLE_FSYNC
501#define EXIMfsync(f) (disable_fsync? 0 : fsync(f))
502#else
503#define EXIMfsync(f) fsync(f)
504#endif
505
059ec3d9
PH
506/* Backward compatibility; LOOKUP_LSEARCH now includes all three */
507
508#if (!defined LOOKUP_LSEARCH) && (defined LOOKUP_WILDLSEARCH || defined LOOKUP_NWILDLSEARCH)
509#define LOOKUP_LSEARCH yes
510#endif
511
512/* Define a union to hold either an IPv4 or an IPv6 sockaddr structure; this
52ba4661
PP
513simplifies some of the coding. We include the sockaddr to reduce type-punning
514issues in C99. */
059ec3d9
PH
515
516union sockaddr_46 {
517 struct sockaddr_in v4;
518 #if HAVE_IPV6
519 struct sockaddr_in6 v6;
520 #endif
52ba4661 521 struct sockaddr v0;
059ec3d9
PH
522};
523
524/* If SUPPORT_TLS is not defined, ensure that USE_GNUTLS is also not defined
525so that if USE_GNUTLS *is* set, we can assume SUPPORT_TLS is also set. */
526
527#ifndef SUPPORT_TLS
528#undef USE_GNUTLS
529#endif
530
531/* If SPOOL_DIRECTORY, LOG_FILE_PATH or PID_FILE_PATH have not been defined,
532set them to the null string. */
533
534#ifndef SPOOL_DIRECTORY
535 #define SPOOL_DIRECTORY ""
536#endif
537#ifndef LOG_FILE_PATH
538 #define LOG_FILE_PATH ""
539#endif
540#ifndef PID_FILE_PATH
541 #define PID_FILE_PATH ""
542#endif
543
544/* The EDQUOT error code isn't universally available, though it is widespread.
545There is a particular shambles in SunOS5, where it did not exist originally,
546but got installed with a particular patch for Solaris 2.4. There is a
547configuration variable for specifying what the system's "over quota" error is,
548which will end up in config.h if supplied in OS/Makefile-xxx. If it is not set,
549default to EDQUOT if it exists, otherwise ENOSPC. */
550
551#ifndef ERRNO_QUOTA
552#ifdef EDQUOT
553#define ERRNO_QUOTA EDQUOT
554#else
555#define ERRNO_QUOTA ENOSPC
556#endif
557#endif
558
559/* Ensure PATH_MAX is defined */
560
561#ifndef PATH_MAX
562 #ifdef MAXPATHLEN
563 #define PATH_MAX MAXPATHLEN
564 #else
565 #define PATH_MAX 1024
566 #endif
567#endif
568
059ec3d9 569/* End of exim.h */