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