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