-
Notifications
You must be signed in to change notification settings - Fork 175
/
exim.c
5725 lines (4790 loc) · 171 KB
/
exim.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
/* Copyright (c) University of Cambridge 1995 - 2015 */
/* See the file NOTICE for conditions of use and distribution. */
/* The main function: entry point, initialization, and high-level control.
Also a few functions that don't naturally fit elsewhere. */
#include "exim.h"
#ifdef USE_GNUTLS
# include <gnutls/gnutls.h>
# if GNUTLS_VERSION_NUMBER < 0x030103 && !defined(DISABLE_OCSP)
# define DISABLE_OCSP
# endif
#endif
extern void init_lookup_list(void);
/*************************************************
* Function interface to store functions *
*************************************************/
/* We need some real functions to pass to the PCRE regular expression library
for store allocation via Exim's store manager. The normal calls are actually
macros that pass over location information to make tracing easier. These
functions just interface to the standard macro calls. A good compiler will
optimize out the tail recursion and so not make them too expensive. There
are two sets of functions; one for use when we want to retain the compiled
regular expression for a long time; the other for short-term use. */
static void *
function_store_get(size_t size)
{
return store_get((int)size);
}
static void
function_dummy_free(void *block) { block = block; }
static void *
function_store_malloc(size_t size)
{
return store_malloc((int)size);
}
static void
function_store_free(void *block)
{
store_free(block);
}
/*************************************************
* Enums for cmdline interface *
*************************************************/
enum commandline_info { CMDINFO_NONE=0,
CMDINFO_HELP, CMDINFO_SIEVE, CMDINFO_DSCP };
/*************************************************
* Compile regular expression and panic on fail *
*************************************************/
/* This function is called when failure to compile a regular expression leads
to a panic exit. In other cases, pcre_compile() is called directly. In many
cases where this function is used, the results of the compilation are to be
placed in long-lived store, so we temporarily reset the store management
functions that PCRE uses if the use_malloc flag is set.
Argument:
pattern the pattern to compile
caseless TRUE if caseless matching is required
use_malloc TRUE if compile into malloc store
Returns: pointer to the compiled pattern
*/
const pcre *
regex_must_compile(const uschar *pattern, BOOL caseless, BOOL use_malloc)
{
int offset;
int options = PCRE_COPT;
const pcre *yield;
const uschar *error;
if (use_malloc)
{
pcre_malloc = function_store_malloc;
pcre_free = function_store_free;
}
if (caseless) options |= PCRE_CASELESS;
yield = pcre_compile(CCS pattern, options, (const char **)&error, &offset, NULL);
pcre_malloc = function_store_get;
pcre_free = function_dummy_free;
if (yield == NULL)
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "regular expression error: "
"%s at offset %d while compiling %s", error, offset, pattern);
return yield;
}
/*************************************************
* Execute regular expression and set strings *
*************************************************/
/* This function runs a regular expression match, and sets up the pointers to
the matched substrings.
Arguments:
re the compiled expression
subject the subject string
options additional PCRE options
setup if < 0 do full setup
if >= 0 setup from setup+1 onwards,
excluding the full matched string
Returns: TRUE or FALSE
*/
BOOL
regex_match_and_setup(const pcre *re, const uschar *subject, int options, int setup)
{
int ovector[3*(EXPAND_MAXN+1)];
uschar * s = string_copy(subject); /* de-constifying */
int n = pcre_exec(re, NULL, CS s, Ustrlen(s), 0,
PCRE_EOPT | options, ovector, sizeof(ovector)/sizeof(int));
BOOL yield = n >= 0;
if (n == 0) n = EXPAND_MAXN + 1;
if (yield)
{
int nn;
expand_nmax = (setup < 0)? 0 : setup + 1;
for (nn = (setup < 0)? 0 : 2; nn < n*2; nn += 2)
{
expand_nstring[expand_nmax] = s + ovector[nn];
expand_nlength[expand_nmax++] = ovector[nn+1] - ovector[nn];
}
expand_nmax--;
}
return yield;
}
/*************************************************
* Set up processing details *
*************************************************/
/* Save a text string for dumping when SIGUSR1 is received.
Do checks for overruns.
Arguments: format and arguments, as for printf()
Returns: nothing
*/
void
set_process_info(const char *format, ...)
{
int len;
va_list ap;
sprintf(CS process_info, "%5d ", (int)getpid());
len = Ustrlen(process_info);
va_start(ap, format);
if (!string_vformat(process_info + len, PROCESS_INFO_SIZE - len - 2, format, ap))
Ustrcpy(process_info + len, "**** string overflowed buffer ****");
len = Ustrlen(process_info);
process_info[len+0] = '\n';
process_info[len+1] = '\0';
process_info_len = len + 1;
DEBUG(D_process_info) debug_printf("set_process_info: %s", process_info);
va_end(ap);
}
/*************************************************
* Handler for SIGUSR1 *
*************************************************/
/* SIGUSR1 causes any exim process to write to the process log details of
what it is currently doing. It will only be used if the OS is capable of
setting up a handler that causes automatic restarting of any system call
that is in progress at the time.
This function takes care to be signal-safe.
Argument: the signal number (SIGUSR1)
Returns: nothing
*/
static void
usr1_handler(int sig)
{
int fd;
os_restarting_signal(sig, usr1_handler);
fd = Uopen(process_log_path, O_APPEND|O_WRONLY, LOG_MODE);
if (fd < 0)
{
/* If we are already running as the Exim user, try to create it in the
current process (assuming spool_directory exists). Otherwise, if we are
root, do the creation in an exim:exim subprocess. */
int euid = geteuid();
if (euid == exim_uid)
fd = Uopen(process_log_path, O_CREAT|O_APPEND|O_WRONLY, LOG_MODE);
else if (euid == root_uid)
fd = log_create_as_exim(process_log_path);
}
/* If we are neither exim nor root, or if we failed to create the log file,
give up. There is not much useful we can do with errors, since we don't want
to disrupt whatever is going on outside the signal handler. */
if (fd < 0) return;
(void)write(fd, process_info, process_info_len);
(void)close(fd);
}
/*************************************************
* Timeout handler *
*************************************************/
/* This handler is enabled most of the time that Exim is running. The handler
doesn't actually get used unless alarm() has been called to set a timer, to
place a time limit on a system call of some kind. When the handler is run, it
re-enables itself.
There are some other SIGALRM handlers that are used in special cases when more
than just a flag setting is required; for example, when reading a message's
input. These are normally set up in the code module that uses them, and the
SIGALRM handler is reset to this one afterwards.
Argument: the signal value (SIGALRM)
Returns: nothing
*/
void
sigalrm_handler(int sig)
{
sig = sig; /* Keep picky compilers happy */
sigalrm_seen = TRUE;
os_non_restarting_signal(SIGALRM, sigalrm_handler);
}
/*************************************************
* Sleep for a fractional time interval *
*************************************************/
/* This function is called by millisleep() and exim_wait_tick() to wait for a
period of time that may include a fraction of a second. The coding is somewhat
tedious. We do not expect setitimer() ever to fail, but if it does, the process
will wait for ever, so we panic in this instance. (There was a case of this
when a bug in a function that calls milliwait() caused it to pass invalid data.
That's when I added the check. :-)
We assume it to be not worth sleeping for under 100us; this value will
require revisiting as hardware advances. This avoids the issue of
a zero-valued timer setting meaning "never fire".
Argument: an itimerval structure containing the interval
Returns: nothing
*/
static void
milliwait(struct itimerval *itval)
{
sigset_t sigmask;
sigset_t old_sigmask;
if (itval->it_value.tv_usec < 100 && itval->it_value.tv_sec == 0)
return;
(void)sigemptyset(&sigmask); /* Empty mask */
(void)sigaddset(&sigmask, SIGALRM); /* Add SIGALRM */
(void)sigprocmask(SIG_BLOCK, &sigmask, &old_sigmask); /* Block SIGALRM */
if (setitimer(ITIMER_REAL, itval, NULL) < 0) /* Start timer */
log_write(0, LOG_MAIN|LOG_PANIC_DIE,
"setitimer() failed: %s", strerror(errno));
(void)sigfillset(&sigmask); /* All signals */
(void)sigdelset(&sigmask, SIGALRM); /* Remove SIGALRM */
(void)sigsuspend(&sigmask); /* Until SIGALRM */
(void)sigprocmask(SIG_SETMASK, &old_sigmask, NULL); /* Restore mask */
}
/*************************************************
* Millisecond sleep function *
*************************************************/
/* The basic sleep() function has a granularity of 1 second, which is too rough
in some cases - for example, when using an increasing delay to slow down
spammers.
Argument: number of millseconds
Returns: nothing
*/
void
millisleep(int msec)
{
struct itimerval itval;
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_usec = 0;
itval.it_value.tv_sec = msec/1000;
itval.it_value.tv_usec = (msec % 1000) * 1000;
milliwait(&itval);
}
/*************************************************
* Compare microsecond times *
*************************************************/
/*
Arguments:
tv1 the first time
tv2 the second time
Returns: -1, 0, or +1
*/
int
exim_tvcmp(struct timeval *t1, struct timeval *t2)
{
if (t1->tv_sec > t2->tv_sec) return +1;
if (t1->tv_sec < t2->tv_sec) return -1;
if (t1->tv_usec > t2->tv_usec) return +1;
if (t1->tv_usec < t2->tv_usec) return -1;
return 0;
}
/*************************************************
* Clock tick wait function *
*************************************************/
/* Exim uses a time + a pid to generate a unique identifier in two places: its
message IDs, and in file names for maildir deliveries. Because some OS now
re-use pids within the same second, sub-second times are now being used.
However, for absolute certaintly, we must ensure the clock has ticked before
allowing the relevant process to complete. At the time of implementation of
this code (February 2003), the speed of processors is such that the clock will
invariably have ticked already by the time a process has done its job. This
function prepares for the time when things are faster - and it also copes with
clocks that go backwards.
Arguments:
then_tv A timeval which was used to create uniqueness; its usec field
has been rounded down to the value of the resolution.
We want to be sure the current time is greater than this.
resolution The resolution that was used to divide the microseconds
(1 for maildir, larger for message ids)
Returns: nothing
*/
void
exim_wait_tick(struct timeval *then_tv, int resolution)
{
struct timeval now_tv;
long int now_true_usec;
(void)gettimeofday(&now_tv, NULL);
now_true_usec = now_tv.tv_usec;
now_tv.tv_usec = (now_true_usec/resolution) * resolution;
if (exim_tvcmp(&now_tv, then_tv) <= 0)
{
struct itimerval itval;
itval.it_interval.tv_sec = 0;
itval.it_interval.tv_usec = 0;
itval.it_value.tv_sec = then_tv->tv_sec - now_tv.tv_sec;
itval.it_value.tv_usec = then_tv->tv_usec + resolution - now_true_usec;
/* We know that, overall, "now" is less than or equal to "then". Therefore, a
negative value for the microseconds is possible only in the case when "now"
is more than a second less than "then". That means that itval.it_value.tv_sec
is greater than zero. The following correction is therefore safe. */
if (itval.it_value.tv_usec < 0)
{
itval.it_value.tv_usec += 1000000;
itval.it_value.tv_sec -= 1;
}
DEBUG(D_transport|D_receive)
{
if (!running_in_test_harness)
{
debug_printf("tick check: " TIME_T_FMT ".%06lu " TIME_T_FMT ".%06lu\n",
then_tv->tv_sec, (long) then_tv->tv_usec,
now_tv.tv_sec, (long) now_tv.tv_usec);
debug_printf("waiting " TIME_T_FMT ".%06lu\n",
itval.it_value.tv_sec, (long) itval.it_value.tv_usec);
}
}
milliwait(&itval);
}
}
/*************************************************
* Call fopen() with umask 777 and adjust mode *
*************************************************/
/* Exim runs with umask(0) so that files created with open() have the mode that
is specified in the open() call. However, there are some files, typically in
the spool directory, that are created with fopen(). They end up world-writeable
if no precautions are taken. Although the spool directory is not accessible to
the world, this is an untidiness. So this is a wrapper function for fopen()
that sorts out the mode of the created file.
Arguments:
filename the file name
options the fopen() options
mode the required mode
Returns: the fopened FILE or NULL
*/
FILE *
modefopen(const uschar *filename, const char *options, mode_t mode)
{
mode_t saved_umask = umask(0777);
FILE *f = Ufopen(filename, options);
(void)umask(saved_umask);
if (f != NULL) (void)fchmod(fileno(f), mode);
return f;
}
/*************************************************
* Ensure stdin, stdout, and stderr exist *
*************************************************/
/* Some operating systems grumble if an exec() happens without a standard
input, output, and error (fds 0, 1, 2) being defined. The worry is that some
file will be opened and will use these fd values, and then some other bit of
code will assume, for example, that it can write error messages to stderr.
This function ensures that fds 0, 1, and 2 are open if they do not already
exist, by connecting them to /dev/null.
This function is also used to ensure that std{in,out,err} exist at all times,
so that if any library that Exim calls tries to use them, it doesn't crash.
Arguments: None
Returns: Nothing
*/
void
exim_nullstd(void)
{
int i;
int devnull = -1;
struct stat statbuf;
for (i = 0; i <= 2; i++)
{
if (fstat(i, &statbuf) < 0 && errno == EBADF)
{
if (devnull < 0) devnull = open("/dev/null", O_RDWR);
if (devnull < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s",
string_open_failed(errno, "/dev/null"));
if (devnull != i) (void)dup2(devnull, i);
}
}
if (devnull > 2) (void)close(devnull);
}
/*************************************************
* Close unwanted file descriptors for delivery *
*************************************************/
/* This function is called from a new process that has been forked to deliver
an incoming message, either directly, or using exec.
We want any smtp input streams to be closed in this new process. However, it
has been observed that using fclose() here causes trouble. When reading in -bS
input, duplicate copies of messages have been seen. The files will be sharing a
file pointer with the parent process, and it seems that fclose() (at least on
some systems - I saw this on Solaris 2.5.1) messes with that file pointer, at
least sometimes. Hence we go for closing the underlying file descriptors.
If TLS is active, we want to shut down the TLS library, but without molesting
the parent's SSL connection.
For delivery of a non-SMTP message, we want to close stdin and stdout (and
stderr unless debugging) because the calling process might have set them up as
pipes and be waiting for them to close before it waits for the submission
process to terminate. If they aren't closed, they hold up the calling process
until the initial delivery process finishes, which is not what we want.
Exception: We do want it for synchronous delivery!
And notwithstanding all the above, if D_resolver is set, implying resolver
debugging, leave stdout open, because that's where the resolver writes its
debugging output.
When we close stderr (which implies we've also closed stdout), we also get rid
of any controlling terminal.
Arguments: None
Returns: Nothing
*/
static void
close_unwanted(void)
{
if (smtp_input)
{
#ifdef SUPPORT_TLS
tls_close(TRUE, FALSE); /* Shut down the TLS library */
#endif
(void)close(fileno(smtp_in));
(void)close(fileno(smtp_out));
smtp_in = NULL;
}
else
{
(void)close(0); /* stdin */
if ((debug_selector & D_resolver) == 0) (void)close(1); /* stdout */
if (debug_selector == 0) /* stderr */
{
if (!synchronous_delivery)
{
(void)close(2);
log_stderr = NULL;
}
(void)setsid();
}
}
}
/*************************************************
* Set uid and gid *
*************************************************/
/* This function sets a new uid and gid permanently, optionally calling
initgroups() to set auxiliary groups. There are some special cases when running
Exim in unprivileged modes. In these situations the effective uid will not be
root; if we already have the right effective uid/gid, and don't need to
initialize any groups, leave things as they are.
Arguments:
uid the uid
gid the gid
igflag TRUE if initgroups() wanted
msg text to use in debugging output and failure log
Returns: nothing; bombs out on failure
*/
void
exim_setugid(uid_t uid, gid_t gid, BOOL igflag, uschar *msg)
{
uid_t euid = geteuid();
gid_t egid = getegid();
if (euid == root_uid || euid != uid || egid != gid || igflag)
{
/* At least one OS returns +1 for initgroups failure, so just check for
non-zero. */
if (igflag)
{
struct passwd *pw = getpwuid(uid);
if (pw != NULL)
{
if (initgroups(pw->pw_name, gid) != 0)
log_write(0,LOG_MAIN|LOG_PANIC_DIE,"initgroups failed for uid=%ld: %s",
(long int)uid, strerror(errno));
}
else log_write(0, LOG_MAIN|LOG_PANIC_DIE, "cannot run initgroups(): "
"no passwd entry for uid=%ld", (long int)uid);
}
if (setgid(gid) < 0 || setuid(uid) < 0)
{
log_write(0, LOG_MAIN|LOG_PANIC_DIE, "unable to set gid=%ld or uid=%ld "
"(euid=%ld): %s", (long int)gid, (long int)uid, (long int)euid, msg);
}
}
/* Debugging output included uid/gid and all groups */
DEBUG(D_uid)
{
int group_count, save_errno;
gid_t group_list[NGROUPS_MAX];
debug_printf("changed uid/gid: %s\n uid=%ld gid=%ld pid=%ld\n", msg,
(long int)geteuid(), (long int)getegid(), (long int)getpid());
group_count = getgroups(NGROUPS_MAX, group_list);
save_errno = errno;
debug_printf(" auxiliary group list:");
if (group_count > 0)
{
int i;
for (i = 0; i < group_count; i++) debug_printf(" %d", (int)group_list[i]);
}
else if (group_count < 0)
debug_printf(" <error: %s>", strerror(save_errno));
else debug_printf(" <none>");
debug_printf("\n");
}
}
/*************************************************
* Exit point *
*************************************************/
/* Exim exits via this function so that it always clears up any open
databases.
Arguments:
rc return code
Returns: does not return
*/
void
exim_exit(int rc)
{
search_tidyup();
DEBUG(D_any)
debug_printf(">>>>>>>>>>>>>>>> Exim pid=%d terminating with rc=%d "
">>>>>>>>>>>>>>>>\n", (int)getpid(), rc);
exit(rc);
}
/*************************************************
* Extract port from host address *
*************************************************/
/* Called to extract the port from the values given to -oMa and -oMi.
It also checks the syntax of the address, and terminates it before the
port data when a port is extracted.
Argument:
address the address, with possible port on the end
Returns: the port, or zero if there isn't one
bombs out on a syntax error
*/
static int
check_port(uschar *address)
{
int port = host_address_extract_port(address);
if (string_is_ip_address(address, NULL) == 0)
{
fprintf(stderr, "exim abandoned: \"%s\" is not an IP address\n", address);
exit(EXIT_FAILURE);
}
return port;
}
/*************************************************
* Test/verify an address *
*************************************************/
/* This function is called by the -bv and -bt code. It extracts a working
address from a full RFC 822 address. This isn't really necessary per se, but it
has the effect of collapsing source routes.
Arguments:
s the address string
flags flag bits for verify_address()
exit_value to be set for failures
Returns: nothing
*/
static void
test_address(uschar *s, int flags, int *exit_value)
{
int start, end, domain;
uschar *parse_error = NULL;
uschar *address = parse_extract_address(s, &parse_error, &start, &end, &domain,
FALSE);
if (address == NULL)
{
fprintf(stdout, "syntax error: %s\n", parse_error);
*exit_value = 2;
}
else
{
int rc = verify_address(deliver_make_addr(address,TRUE), stdout, flags, -1,
-1, -1, NULL, NULL, NULL);
if (rc == FAIL) *exit_value = 2;
else if (rc == DEFER && *exit_value == 0) *exit_value = 1;
}
}
/*************************************************
* Show supported features *
*************************************************/
/* This function is called for -bV/--version and for -d to output the optional
features of the current Exim binary.
Arguments: a FILE for printing
Returns: nothing
*/
static void
show_whats_supported(FILE *f)
{
auth_info *authi;
#ifdef DB_VERSION_STRING
fprintf(f, "Berkeley DB: %s\n", DB_VERSION_STRING);
#elif defined(BTREEVERSION) && defined(HASHVERSION)
#ifdef USE_DB
fprintf(f, "Probably Berkeley DB version 1.8x (native mode)\n");
#else
fprintf(f, "Probably Berkeley DB version 1.8x (compatibility mode)\n");
#endif
#elif defined(_DBM_RDONLY) || defined(dbm_dirfno)
fprintf(f, "Probably ndbm\n");
#elif defined(USE_TDB)
fprintf(f, "Using tdb\n");
#else
#ifdef USE_GDBM
fprintf(f, "Probably GDBM (native mode)\n");
#else
fprintf(f, "Probably GDBM (compatibility mode)\n");
#endif
#endif
fprintf(f, "Support for:");
#ifdef SUPPORT_CRYPTEQ
fprintf(f, " crypteq");
#endif
#if HAVE_ICONV
fprintf(f, " iconv()");
#endif
#if HAVE_IPV6
fprintf(f, " IPv6");
#endif
#ifdef HAVE_SETCLASSRESOURCES
fprintf(f, " use_setclassresources");
#endif
#ifdef SUPPORT_PAM
fprintf(f, " PAM");
#endif
#ifdef EXIM_PERL
fprintf(f, " Perl");
#endif
#ifdef EXPAND_DLFUNC
fprintf(f, " Expand_dlfunc");
#endif
#ifdef USE_TCP_WRAPPERS
fprintf(f, " TCPwrappers");
#endif
#ifdef SUPPORT_TLS
#ifdef USE_GNUTLS
fprintf(f, " GnuTLS");
#else
fprintf(f, " OpenSSL");
#endif
#endif
#ifdef SUPPORT_TRANSLATE_IP_ADDRESS
fprintf(f, " translate_ip_address");
#endif
#ifdef SUPPORT_MOVE_FROZEN_MESSAGES
fprintf(f, " move_frozen_messages");
#endif
#ifdef WITH_CONTENT_SCAN
fprintf(f, " Content_Scanning");
#endif
#ifdef WITH_OLD_DEMIME
fprintf(f, " Old_Demime");
#endif
#ifndef DISABLE_DKIM
fprintf(f, " DKIM");
#endif
#ifndef DISABLE_DNSSEC
fprintf(f, " DNSSEC");
#endif
#ifndef DISABLE_EVENT
fprintf(f, " Event");
#endif
#ifdef SUPPORT_I18N
fprintf(f, " I18N");
#endif
#ifndef DISABLE_OCSP
fprintf(f, " OCSP");
#endif
#ifndef DISABLE_PRDR
fprintf(f, " PRDR");
#endif
#ifdef SUPPORT_PROXY
fprintf(f, " PROXY");
#endif
#ifdef SUPPORT_SOCKS
fprintf(f, " SOCKS");
#endif
#ifdef EXPERIMENTAL_SPF
fprintf(f, " Experimental_SPF");
#endif
#ifdef EXPERIMENTAL_SRS
fprintf(f, " Experimental_SRS");
#endif
#ifdef EXPERIMENTAL_BRIGHTMAIL
fprintf(f, " Experimental_Brightmail");
#endif
#ifdef EXPERIMENTAL_DANE
fprintf(f, " Experimental_DANE");
#endif
#ifdef EXPERIMENTAL_DCC
fprintf(f, " Experimental_DCC");
#endif
#ifdef EXPERIMENTAL_DMARC
fprintf(f, " Experimental_DMARC");
#endif
#ifdef EXPERIMENTAL_DSN_INFO
fprintf(f, " Experimental_DSN_info");
#endif
fprintf(f, "\n");
fprintf(f, "Lookups (built-in):");
#if defined(LOOKUP_LSEARCH) && LOOKUP_LSEARCH!=2
fprintf(f, " lsearch wildlsearch nwildlsearch iplsearch");
#endif
#if defined(LOOKUP_CDB) && LOOKUP_CDB!=2
fprintf(f, " cdb");
#endif
#if defined(LOOKUP_DBM) && LOOKUP_DBM!=2
fprintf(f, " dbm dbmjz dbmnz");
#endif
#if defined(LOOKUP_DNSDB) && LOOKUP_DNSDB!=2
fprintf(f, " dnsdb");
#endif
#if defined(LOOKUP_DSEARCH) && LOOKUP_DSEARCH!=2
fprintf(f, " dsearch");
#endif
#if defined(LOOKUP_IBASE) && LOOKUP_IBASE!=2
fprintf(f, " ibase");
#endif
#if defined(LOOKUP_LDAP) && LOOKUP_LDAP!=2
fprintf(f, " ldap ldapdn ldapm");
#endif
#if defined(LOOKUP_MYSQL) && LOOKUP_MYSQL!=2
fprintf(f, " mysql");
#endif
#if defined(LOOKUP_NIS) && LOOKUP_NIS!=2
fprintf(f, " nis nis0");
#endif
#if defined(LOOKUP_NISPLUS) && LOOKUP_NISPLUS!=2
fprintf(f, " nisplus");
#endif
#if defined(LOOKUP_ORACLE) && LOOKUP_ORACLE!=2
fprintf(f, " oracle");
#endif
#if defined(LOOKUP_PASSWD) && LOOKUP_PASSWD!=2
fprintf(f, " passwd");
#endif
#if defined(LOOKUP_PGSQL) && LOOKUP_PGSQL!=2
fprintf(f, " pgsql");
#endif
#if defined(LOOKUP_REDIS) && LOOKUP_REDIS!=2
fprintf(f, " redis");
#endif
#if defined(LOOKUP_SQLITE) && LOOKUP_SQLITE!=2
fprintf(f, " sqlite");
#endif
#if defined(LOOKUP_TESTDB) && LOOKUP_TESTDB!=2
fprintf(f, " testdb");
#endif
#if defined(LOOKUP_WHOSON) && LOOKUP_WHOSON!=2
fprintf(f, " whoson");
#endif
fprintf(f, "\n");
fprintf(f, "Authenticators:");
#ifdef AUTH_CRAM_MD5
fprintf(f, " cram_md5");
#endif
#ifdef AUTH_CYRUS_SASL
fprintf(f, " cyrus_sasl");
#endif
#ifdef AUTH_DOVECOT
fprintf(f, " dovecot");
#endif
#ifdef AUTH_GSASL
fprintf(f, " gsasl");
#endif
#ifdef AUTH_HEIMDAL_GSSAPI
fprintf(f, " heimdal_gssapi");
#endif
#ifdef AUTH_PLAINTEXT
fprintf(f, " plaintext");
#endif
#ifdef AUTH_SPA
fprintf(f, " spa");
#endif
#ifdef AUTH_TLS
fprintf(f, " tls");
#endif
fprintf(f, "\n");
fprintf(f, "Routers:");
#ifdef ROUTER_ACCEPT
fprintf(f, " accept");
#endif
#ifdef ROUTER_DNSLOOKUP
fprintf(f, " dnslookup");
#endif
#ifdef ROUTER_IPLITERAL
fprintf(f, " ipliteral");
#endif
#ifdef ROUTER_IPLOOKUP
fprintf(f, " iplookup");
#endif
#ifdef ROUTER_MANUALROUTE
fprintf(f, " manualroute");
#endif
#ifdef ROUTER_QUERYPROGRAM
fprintf(f, " queryprogram");
#endif
#ifdef ROUTER_REDIRECT
fprintf(f, " redirect");
#endif
fprintf(f, "\n");
fprintf(f, "Transports:");
#ifdef TRANSPORT_APPENDFILE
fprintf(f, " appendfile");
#ifdef SUPPORT_MAILDIR
fprintf(f, "/maildir");
#endif
#ifdef SUPPORT_MAILSTORE
fprintf(f, "/mailstore");
#endif
#ifdef SUPPORT_MBX
fprintf(f, "/mbx");
#endif
#endif
#ifdef TRANSPORT_AUTOREPLY
fprintf(f, " autoreply");
#endif
#ifdef TRANSPORT_LMTP
fprintf(f, " lmtp");
#endif
#ifdef TRANSPORT_PIPE
fprintf(f, " pipe");
#endif
#ifdef TRANSPORT_SMTP
fprintf(f, " smtp");
#endif
fprintf(f, "\n");
if (fixed_never_users[0] > 0)
{