-
Notifications
You must be signed in to change notification settings - Fork 175
/
readconf.c
4392 lines (3619 loc) · 134 KB
/
readconf.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. */
/* Functions for reading the configuration file, and for displaying
overall configuration values. Thanks to Brian Candler for the original
implementation of the conditional .ifdef etc. */
#include "exim.h"
extern char **environ;
static void fn_smtp_receive_timeout(const uschar * name, const uschar * str);
static void save_config_line(const uschar* line);
static void save_config_position(const uschar *file, int line);
static void print_config(BOOL admin);
#define CSTATE_STACK_SIZE 10
/* Structure for chain (stack) of .included files */
typedef struct config_file_item {
struct config_file_item *next;
uschar *filename;
FILE *file;
int lineno;
} config_file_item;
/* Structure for chain of configuration lines (-bP config) */
typedef struct config_line_item {
struct config_line_item *next;
uschar *line;
} config_line_item;
static config_line_item* config_lines;
/* Structure of table of conditional words and their state transitions */
typedef struct cond_item {
uschar *name;
int namelen;
int action1;
int action2;
int pushpop;
} cond_item;
/* Structure of table of syslog facility names and values */
typedef struct syslog_fac_item {
uschar *name;
int value;
} syslog_fac_item;
/* constants */
static const char * const hidden = "<value not displayable>";
/* Static variables */
static config_file_item *config_file_stack = NULL; /* For includes */
static uschar *syslog_facility_str = NULL;
static uschar next_section[24];
static uschar time_buffer[24];
/* State variables for conditional loading (.ifdef / .else / .endif) */
static int cstate = 0;
static int cstate_stack_ptr = -1;
static int cstate_stack[CSTATE_STACK_SIZE];
/* Table of state transitions for handling conditional inclusions. There are
four possible state transitions:
.ifdef true
.ifdef false
.elifdef true (or .else)
.elifdef false
.endif just causes the previous cstate to be popped off the stack */
static int next_cstate[3][4] =
{
/* State 0: reading from file, or reading until next .else or .endif */
{ 0, 1, 2, 2 },
/* State 1: condition failed, skipping until next .else or .endif */
{ 2, 2, 0, 1 },
/* State 2: skipping until .endif */
{ 2, 2, 2, 2 },
};
/* Table of conditionals and the states to set. For each name, there are four
values: the length of the name (to save computing it each time), the state to
set if a macro was found in the line, the state to set if a macro was not found
in the line, and a stack manipulation setting which is:
-1 pull state value off the stack
0 don't alter the stack
+1 push value onto stack, before setting new state
*/
static cond_item cond_list[] = {
{ US"ifdef", 5, 0, 1, 1 },
{ US"ifndef", 6, 1, 0, 1 },
{ US"elifdef", 7, 2, 3, 0 },
{ US"elifndef", 8, 3, 2, 0 },
{ US"else", 4, 2, 2, 0 },
{ US"endif", 5, 0, 0, -1 }
};
static int cond_list_size = sizeof(cond_list)/sizeof(cond_item);
/* Table of syslog facility names and their values */
static syslog_fac_item syslog_list[] = {
{ US"mail", LOG_MAIL },
{ US"user", LOG_USER },
{ US"news", LOG_NEWS },
{ US"uucp", LOG_UUCP },
{ US"local0", LOG_LOCAL0 },
{ US"local1", LOG_LOCAL1 },
{ US"local2", LOG_LOCAL2 },
{ US"local3", LOG_LOCAL3 },
{ US"local4", LOG_LOCAL4 },
{ US"local5", LOG_LOCAL5 },
{ US"local6", LOG_LOCAL6 },
{ US"local7", LOG_LOCAL7 },
{ US"daemon", LOG_DAEMON }
};
static int syslog_list_size = sizeof(syslog_list)/sizeof(syslog_fac_item);
/*************************************************
* Main configuration options *
*************************************************/
/* The list of options that can be set in the main configuration file. This
must be in alphabetic order because it is searched by binary chop. */
static optionlist optionlist_config[] = {
{ "*set_exim_group", opt_bool|opt_hidden, &exim_gid_set },
{ "*set_exim_user", opt_bool|opt_hidden, &exim_uid_set },
{ "*set_system_filter_group", opt_bool|opt_hidden, &system_filter_gid_set },
{ "*set_system_filter_user", opt_bool|opt_hidden, &system_filter_uid_set },
{ "accept_8bitmime", opt_bool, &accept_8bitmime },
{ "acl_not_smtp", opt_stringptr, &acl_not_smtp },
#ifdef WITH_CONTENT_SCAN
{ "acl_not_smtp_mime", opt_stringptr, &acl_not_smtp_mime },
#endif
{ "acl_not_smtp_start", opt_stringptr, &acl_not_smtp_start },
{ "acl_smtp_auth", opt_stringptr, &acl_smtp_auth },
{ "acl_smtp_connect", opt_stringptr, &acl_smtp_connect },
{ "acl_smtp_data", opt_stringptr, &acl_smtp_data },
#ifndef DISABLE_PRDR
{ "acl_smtp_data_prdr", opt_stringptr, &acl_smtp_data_prdr },
#endif
#ifndef DISABLE_DKIM
{ "acl_smtp_dkim", opt_stringptr, &acl_smtp_dkim },
#endif
{ "acl_smtp_etrn", opt_stringptr, &acl_smtp_etrn },
{ "acl_smtp_expn", opt_stringptr, &acl_smtp_expn },
{ "acl_smtp_helo", opt_stringptr, &acl_smtp_helo },
{ "acl_smtp_mail", opt_stringptr, &acl_smtp_mail },
{ "acl_smtp_mailauth", opt_stringptr, &acl_smtp_mailauth },
#ifdef WITH_CONTENT_SCAN
{ "acl_smtp_mime", opt_stringptr, &acl_smtp_mime },
#endif
{ "acl_smtp_notquit", opt_stringptr, &acl_smtp_notquit },
{ "acl_smtp_predata", opt_stringptr, &acl_smtp_predata },
{ "acl_smtp_quit", opt_stringptr, &acl_smtp_quit },
{ "acl_smtp_rcpt", opt_stringptr, &acl_smtp_rcpt },
#ifdef SUPPORT_TLS
{ "acl_smtp_starttls", opt_stringptr, &acl_smtp_starttls },
#endif
{ "acl_smtp_vrfy", opt_stringptr, &acl_smtp_vrfy },
{ "add_environment", opt_stringptr, &add_environment },
{ "admin_groups", opt_gidlist, &admin_groups },
{ "allow_domain_literals", opt_bool, &allow_domain_literals },
{ "allow_mx_to_ip", opt_bool, &allow_mx_to_ip },
{ "allow_utf8_domains", opt_bool, &allow_utf8_domains },
{ "auth_advertise_hosts", opt_stringptr, &auth_advertise_hosts },
{ "auto_thaw", opt_time, &auto_thaw },
#ifdef WITH_CONTENT_SCAN
{ "av_scanner", opt_stringptr, &av_scanner },
#endif
{ "bi_command", opt_stringptr, &bi_command },
#ifdef EXPERIMENTAL_BRIGHTMAIL
{ "bmi_config_file", opt_stringptr, &bmi_config_file },
#endif
{ "bounce_message_file", opt_stringptr, &bounce_message_file },
{ "bounce_message_text", opt_stringptr, &bounce_message_text },
{ "bounce_return_body", opt_bool, &bounce_return_body },
{ "bounce_return_linesize_limit", opt_mkint, &bounce_return_linesize_limit },
{ "bounce_return_message", opt_bool, &bounce_return_message },
{ "bounce_return_size_limit", opt_mkint, &bounce_return_size_limit },
{ "bounce_sender_authentication",opt_stringptr,&bounce_sender_authentication },
{ "callout_domain_negative_expire", opt_time, &callout_cache_domain_negative_expire },
{ "callout_domain_positive_expire", opt_time, &callout_cache_domain_positive_expire },
{ "callout_negative_expire", opt_time, &callout_cache_negative_expire },
{ "callout_positive_expire", opt_time, &callout_cache_positive_expire },
{ "callout_random_local_part",opt_stringptr, &callout_random_local_part },
{ "check_log_inodes", opt_int, &check_log_inodes },
{ "check_log_space", opt_Kint, &check_log_space },
{ "check_rfc2047_length", opt_bool, &check_rfc2047_length },
{ "check_spool_inodes", opt_int, &check_spool_inodes },
{ "check_spool_space", opt_Kint, &check_spool_space },
{ "daemon_smtp_port", opt_stringptr|opt_hidden, &daemon_smtp_port },
{ "daemon_smtp_ports", opt_stringptr, &daemon_smtp_port },
{ "daemon_startup_retries", opt_int, &daemon_startup_retries },
{ "daemon_startup_sleep", opt_time, &daemon_startup_sleep },
#ifdef EXPERIMENTAL_DCC
{ "dcc_direct_add_header", opt_bool, &dcc_direct_add_header },
{ "dccifd_address", opt_stringptr, &dccifd_address },
{ "dccifd_options", opt_stringptr, &dccifd_options },
#endif
{ "delay_warning", opt_timelist, &delay_warning },
{ "delay_warning_condition", opt_stringptr, &delay_warning_condition },
{ "deliver_drop_privilege", opt_bool, &deliver_drop_privilege },
{ "deliver_queue_load_max", opt_fixed, &deliver_queue_load_max },
{ "delivery_date_remove", opt_bool, &delivery_date_remove },
#ifdef ENABLE_DISABLE_FSYNC
{ "disable_fsync", opt_bool, &disable_fsync },
#endif
{ "disable_ipv6", opt_bool, &disable_ipv6 },
#ifndef DISABLE_DKIM
{ "dkim_verify_signers", opt_stringptr, &dkim_verify_signers },
#endif
#ifdef EXPERIMENTAL_DMARC
{ "dmarc_forensic_sender", opt_stringptr, &dmarc_forensic_sender },
{ "dmarc_history_file", opt_stringptr, &dmarc_history_file },
{ "dmarc_tld_file", opt_stringptr, &dmarc_tld_file },
#endif
{ "dns_again_means_nonexist", opt_stringptr, &dns_again_means_nonexist },
{ "dns_check_names_pattern", opt_stringptr, &check_dns_names_pattern },
{ "dns_csa_search_limit", opt_int, &dns_csa_search_limit },
{ "dns_csa_use_reverse", opt_bool, &dns_csa_use_reverse },
{ "dns_dnssec_ok", opt_int, &dns_dnssec_ok },
{ "dns_ipv4_lookup", opt_stringptr, &dns_ipv4_lookup },
{ "dns_retrans", opt_time, &dns_retrans },
{ "dns_retry", opt_int, &dns_retry },
{ "dns_trust_aa", opt_stringptr, &dns_trust_aa },
{ "dns_use_edns0", opt_int, &dns_use_edns0 },
/* This option is now a no-op, retained for compability */
{ "drop_cr", opt_bool, &drop_cr },
/*********************************************************/
{ "dsn_advertise_hosts", opt_stringptr, &dsn_advertise_hosts },
{ "dsn_from", opt_stringptr, &dsn_from },
{ "envelope_to_remove", opt_bool, &envelope_to_remove },
{ "errors_copy", opt_stringptr, &errors_copy },
{ "errors_reply_to", opt_stringptr, &errors_reply_to },
#ifndef DISABLE_EVENT
{ "event_action", opt_stringptr, &event_action },
#endif
{ "exim_group", opt_gid, &exim_gid },
{ "exim_path", opt_stringptr, &exim_path },
{ "exim_user", opt_uid, &exim_uid },
{ "extra_local_interfaces", opt_stringptr, &extra_local_interfaces },
{ "extract_addresses_remove_arguments", opt_bool, &extract_addresses_remove_arguments },
{ "finduser_retries", opt_int, &finduser_retries },
{ "freeze_tell", opt_stringptr, &freeze_tell },
{ "gecos_name", opt_stringptr, &gecos_name },
{ "gecos_pattern", opt_stringptr, &gecos_pattern },
#ifdef SUPPORT_TLS
{ "gnutls_allow_auto_pkcs11", opt_bool, &gnutls_allow_auto_pkcs11 },
{ "gnutls_compat_mode", opt_bool, &gnutls_compat_mode },
/* These three gnutls_require_* options stopped working in Exim 4.80 */
/* From 4.83 we log a warning; a future relase will remove them */
{ "gnutls_require_kx", opt_stringptr, &gnutls_require_kx },
{ "gnutls_require_mac", opt_stringptr, &gnutls_require_mac },
{ "gnutls_require_protocols", opt_stringptr, &gnutls_require_proto },
#endif
{ "header_line_maxsize", opt_int, &header_line_maxsize },
{ "header_maxsize", opt_int, &header_maxsize },
{ "headers_charset", opt_stringptr, &headers_charset },
{ "helo_accept_junk_hosts", opt_stringptr, &helo_accept_junk_hosts },
{ "helo_allow_chars", opt_stringptr, &helo_allow_chars },
{ "helo_lookup_domains", opt_stringptr, &helo_lookup_domains },
{ "helo_try_verify_hosts", opt_stringptr, &helo_try_verify_hosts },
{ "helo_verify_hosts", opt_stringptr, &helo_verify_hosts },
{ "hold_domains", opt_stringptr, &hold_domains },
{ "host_lookup", opt_stringptr, &host_lookup },
{ "host_lookup_order", opt_stringptr, &host_lookup_order },
{ "host_reject_connection", opt_stringptr, &host_reject_connection },
{ "hosts_connection_nolog", opt_stringptr, &hosts_connection_nolog },
#ifdef SUPPORT_PROXY
{ "hosts_proxy", opt_stringptr, &hosts_proxy },
#endif
{ "hosts_treat_as_local", opt_stringptr, &hosts_treat_as_local },
#ifdef LOOKUP_IBASE
{ "ibase_servers", opt_stringptr, &ibase_servers },
#endif
{ "ignore_bounce_errors_after", opt_time, &ignore_bounce_errors_after },
{ "ignore_fromline_hosts", opt_stringptr, &ignore_fromline_hosts },
{ "ignore_fromline_local", opt_bool, &ignore_fromline_local },
{ "keep_environment", opt_stringptr, &keep_environment },
{ "keep_malformed", opt_time, &keep_malformed },
#ifdef LOOKUP_LDAP
{ "ldap_ca_cert_dir", opt_stringptr, &eldap_ca_cert_dir },
{ "ldap_ca_cert_file", opt_stringptr, &eldap_ca_cert_file },
{ "ldap_cert_file", opt_stringptr, &eldap_cert_file },
{ "ldap_cert_key", opt_stringptr, &eldap_cert_key },
{ "ldap_cipher_suite", opt_stringptr, &eldap_cipher_suite },
{ "ldap_default_servers", opt_stringptr, &eldap_default_servers },
{ "ldap_require_cert", opt_stringptr, &eldap_require_cert },
{ "ldap_start_tls", opt_bool, &eldap_start_tls },
{ "ldap_version", opt_int, &eldap_version },
#endif
{ "local_from_check", opt_bool, &local_from_check },
{ "local_from_prefix", opt_stringptr, &local_from_prefix },
{ "local_from_suffix", opt_stringptr, &local_from_suffix },
{ "local_interfaces", opt_stringptr, &local_interfaces },
{ "local_scan_timeout", opt_time, &local_scan_timeout },
{ "local_sender_retain", opt_bool, &local_sender_retain },
{ "localhost_number", opt_stringptr, &host_number_string },
{ "log_file_path", opt_stringptr, &log_file_path },
{ "log_selector", opt_stringptr, &log_selector_string },
{ "log_timezone", opt_bool, &log_timezone },
{ "lookup_open_max", opt_int, &lookup_open_max },
{ "max_username_length", opt_int, &max_username_length },
{ "message_body_newlines", opt_bool, &message_body_newlines },
{ "message_body_visible", opt_mkint, &message_body_visible },
{ "message_id_header_domain", opt_stringptr, &message_id_domain },
{ "message_id_header_text", opt_stringptr, &message_id_text },
{ "message_logs", opt_bool, &message_logs },
{ "message_size_limit", opt_stringptr, &message_size_limit },
#ifdef SUPPORT_MOVE_FROZEN_MESSAGES
{ "move_frozen_messages", opt_bool, &move_frozen_messages },
#endif
{ "mua_wrapper", opt_bool, &mua_wrapper },
#ifdef LOOKUP_MYSQL
{ "mysql_servers", opt_stringptr, &mysql_servers },
#endif
{ "never_users", opt_uidlist, &never_users },
#ifdef SUPPORT_TLS
{ "openssl_options", opt_stringptr, &openssl_options },
#endif
#ifdef LOOKUP_ORACLE
{ "oracle_servers", opt_stringptr, &oracle_servers },
#endif
{ "percent_hack_domains", opt_stringptr, &percent_hack_domains },
#ifdef EXIM_PERL
{ "perl_at_start", opt_bool, &opt_perl_at_start },
{ "perl_startup", opt_stringptr, &opt_perl_startup },
#endif
#ifdef LOOKUP_PGSQL
{ "pgsql_servers", opt_stringptr, &pgsql_servers },
#endif
{ "pid_file_path", opt_stringptr, &pid_file_path },
{ "pipelining_advertise_hosts", opt_stringptr, &pipelining_advertise_hosts },
#ifndef DISABLE_PRDR
{ "prdr_enable", opt_bool, &prdr_enable },
#endif
{ "preserve_message_logs", opt_bool, &preserve_message_logs },
{ "primary_hostname", opt_stringptr, &primary_hostname },
{ "print_topbitchars", opt_bool, &print_topbitchars },
{ "process_log_path", opt_stringptr, &process_log_path },
{ "prod_requires_admin", opt_bool, &prod_requires_admin },
{ "qualify_domain", opt_stringptr, &qualify_domain_sender },
{ "qualify_recipient", opt_stringptr, &qualify_domain_recipient },
{ "queue_domains", opt_stringptr, &queue_domains },
{ "queue_list_requires_admin",opt_bool, &queue_list_requires_admin },
{ "queue_only", opt_bool, &queue_only },
{ "queue_only_file", opt_stringptr, &queue_only_file },
{ "queue_only_load", opt_fixed, &queue_only_load },
{ "queue_only_load_latch", opt_bool, &queue_only_load_latch },
{ "queue_only_override", opt_bool, &queue_only_override },
{ "queue_run_in_order", opt_bool, &queue_run_in_order },
{ "queue_run_max", opt_int, &queue_run_max },
{ "queue_smtp_domains", opt_stringptr, &queue_smtp_domains },
{ "receive_timeout", opt_time, &receive_timeout },
{ "received_header_text", opt_stringptr, &received_header_text },
{ "received_headers_max", opt_int, &received_headers_max },
{ "recipient_unqualified_hosts", opt_stringptr, &recipient_unqualified_hosts },
{ "recipients_max", opt_int, &recipients_max },
{ "recipients_max_reject", opt_bool, &recipients_max_reject },
#ifdef LOOKUP_REDIS
{ "redis_servers", opt_stringptr, &redis_servers },
#endif
{ "remote_max_parallel", opt_int, &remote_max_parallel },
{ "remote_sort_domains", opt_stringptr, &remote_sort_domains },
{ "retry_data_expire", opt_time, &retry_data_expire },
{ "retry_interval_max", opt_time, &retry_interval_max },
{ "return_path_remove", opt_bool, &return_path_remove },
{ "return_size_limit", opt_mkint|opt_hidden, &bounce_return_size_limit },
{ "rfc1413_hosts", opt_stringptr, &rfc1413_hosts },
{ "rfc1413_query_timeout", opt_time, &rfc1413_query_timeout },
{ "sender_unqualified_hosts", opt_stringptr, &sender_unqualified_hosts },
{ "slow_lookup_log", opt_int, &slow_lookup_log },
{ "smtp_accept_keepalive", opt_bool, &smtp_accept_keepalive },
{ "smtp_accept_max", opt_int, &smtp_accept_max },
{ "smtp_accept_max_nonmail", opt_int, &smtp_accept_max_nonmail },
{ "smtp_accept_max_nonmail_hosts", opt_stringptr, &smtp_accept_max_nonmail_hosts },
{ "smtp_accept_max_per_connection", opt_int, &smtp_accept_max_per_connection },
{ "smtp_accept_max_per_host", opt_stringptr, &smtp_accept_max_per_host },
{ "smtp_accept_queue", opt_int, &smtp_accept_queue },
{ "smtp_accept_queue_per_connection", opt_int, &smtp_accept_queue_per_connection },
{ "smtp_accept_reserve", opt_int, &smtp_accept_reserve },
{ "smtp_active_hostname", opt_stringptr, &raw_active_hostname },
{ "smtp_banner", opt_stringptr, &smtp_banner },
{ "smtp_check_spool_space", opt_bool, &smtp_check_spool_space },
{ "smtp_connect_backlog", opt_int, &smtp_connect_backlog },
{ "smtp_enforce_sync", opt_bool, &smtp_enforce_sync },
{ "smtp_etrn_command", opt_stringptr, &smtp_etrn_command },
{ "smtp_etrn_serialize", opt_bool, &smtp_etrn_serialize },
{ "smtp_load_reserve", opt_fixed, &smtp_load_reserve },
{ "smtp_max_synprot_errors", opt_int, &smtp_max_synprot_errors },
{ "smtp_max_unknown_commands",opt_int, &smtp_max_unknown_commands },
{ "smtp_ratelimit_hosts", opt_stringptr, &smtp_ratelimit_hosts },
{ "smtp_ratelimit_mail", opt_stringptr, &smtp_ratelimit_mail },
{ "smtp_ratelimit_rcpt", opt_stringptr, &smtp_ratelimit_rcpt },
{ "smtp_receive_timeout", opt_func, &fn_smtp_receive_timeout },
{ "smtp_reserve_hosts", opt_stringptr, &smtp_reserve_hosts },
{ "smtp_return_error_details",opt_bool, &smtp_return_error_details },
#ifdef SUPPORT_I18N
{ "smtputf8_advertise_hosts", opt_stringptr, &smtputf8_advertise_hosts },
#endif
#ifdef WITH_CONTENT_SCAN
{ "spamd_address", opt_stringptr, &spamd_address },
#endif
#ifdef EXPERIMENTAL_SPF
{ "spf_guess", opt_stringptr, &spf_guess },
#endif
{ "split_spool_directory", opt_bool, &split_spool_directory },
{ "spool_directory", opt_stringptr, &spool_directory },
#ifdef LOOKUP_SQLITE
{ "sqlite_lock_timeout", opt_int, &sqlite_lock_timeout },
#endif
#ifdef EXPERIMENTAL_SRS
{ "srs_config", opt_stringptr, &srs_config },
{ "srs_hashlength", opt_int, &srs_hashlength },
{ "srs_hashmin", opt_int, &srs_hashmin },
{ "srs_maxage", opt_int, &srs_maxage },
{ "srs_secrets", opt_stringptr, &srs_secrets },
{ "srs_usehash", opt_bool, &srs_usehash },
{ "srs_usetimestamp", opt_bool, &srs_usetimestamp },
#endif
{ "strict_acl_vars", opt_bool, &strict_acl_vars },
{ "strip_excess_angle_brackets", opt_bool, &strip_excess_angle_brackets },
{ "strip_trailing_dot", opt_bool, &strip_trailing_dot },
{ "syslog_duplication", opt_bool, &syslog_duplication },
{ "syslog_facility", opt_stringptr, &syslog_facility_str },
{ "syslog_processname", opt_stringptr, &syslog_processname },
{ "syslog_timestamp", opt_bool, &syslog_timestamp },
{ "system_filter", opt_stringptr, &system_filter },
{ "system_filter_directory_transport", opt_stringptr,&system_filter_directory_transport },
{ "system_filter_file_transport",opt_stringptr,&system_filter_file_transport },
{ "system_filter_group", opt_gid, &system_filter_gid },
{ "system_filter_pipe_transport",opt_stringptr,&system_filter_pipe_transport },
{ "system_filter_reply_transport",opt_stringptr,&system_filter_reply_transport },
{ "system_filter_user", opt_uid, &system_filter_uid },
{ "tcp_nodelay", opt_bool, &tcp_nodelay },
#ifdef USE_TCP_WRAPPERS
{ "tcp_wrappers_daemon_name", opt_stringptr, &tcp_wrappers_daemon_name },
#endif
{ "timeout_frozen_after", opt_time, &timeout_frozen_after },
{ "timezone", opt_stringptr, &timezone_string },
{ "tls_advertise_hosts", opt_stringptr, &tls_advertise_hosts },
#ifdef SUPPORT_TLS
{ "tls_certificate", opt_stringptr, &tls_certificate },
{ "tls_crl", opt_stringptr, &tls_crl },
{ "tls_dh_max_bits", opt_int, &tls_dh_max_bits },
{ "tls_dhparam", opt_stringptr, &tls_dhparam },
{ "tls_eccurve", opt_stringptr, &tls_eccurve },
# ifndef DISABLE_OCSP
{ "tls_ocsp_file", opt_stringptr, &tls_ocsp_file },
# endif
{ "tls_on_connect_ports", opt_stringptr, &tls_in.on_connect_ports },
{ "tls_privatekey", opt_stringptr, &tls_privatekey },
{ "tls_remember_esmtp", opt_bool, &tls_remember_esmtp },
{ "tls_require_ciphers", opt_stringptr, &tls_require_ciphers },
{ "tls_try_verify_hosts", opt_stringptr, &tls_try_verify_hosts },
{ "tls_verify_certificates", opt_stringptr, &tls_verify_certificates },
{ "tls_verify_hosts", opt_stringptr, &tls_verify_hosts },
#endif
{ "trusted_groups", opt_gidlist, &trusted_groups },
{ "trusted_users", opt_uidlist, &trusted_users },
{ "unknown_login", opt_stringptr, &unknown_login },
{ "unknown_username", opt_stringptr, &unknown_username },
{ "untrusted_set_sender", opt_stringptr, &untrusted_set_sender },
{ "uucp_from_pattern", opt_stringptr, &uucp_from_pattern },
{ "uucp_from_sender", opt_stringptr, &uucp_from_sender },
{ "warn_message_file", opt_stringptr, &warn_message_file },
{ "write_rejectlog", opt_bool, &write_rejectlog }
};
static int optionlist_config_size =
sizeof(optionlist_config)/sizeof(optionlist);
/*************************************************
* Find the name of an option *
*************************************************/
/* This function is to aid debugging. Various functions take arguments that are
pointer variables in the options table or in option tables for various drivers.
For debugging output, it is useful to be able to find the name of the option
which is currently being processed. This function finds it, if it exists, by
searching the table(s).
Arguments: a value that is presumed to be in the table above
Returns: the option name, or an empty string
*/
uschar *
readconf_find_option(void *p)
{
int i;
router_instance *r;
transport_instance *t;
for (i = 0; i < optionlist_config_size; i++)
if (p == optionlist_config[i].value) return US optionlist_config[i].name;
for (r = routers; r != NULL; r = r->next)
{
router_info *ri = r->info;
for (i = 0; i < *ri->options_count; i++)
{
if ((ri->options[i].type & opt_mask) != opt_stringptr) continue;
if (p == (char *)(r->options_block) + (long int)(ri->options[i].value))
return US ri->options[i].name;
}
}
for (t = transports; t != NULL; t = t->next)
{
transport_info *ti = t->info;
for (i = 0; i < *ti->options_count; i++)
{
optionlist * op = &ti->options[i];
if ((op->type & opt_mask) != opt_stringptr) continue;
if (p == ( op->type & opt_public
? (char *)t
: (char *)t->options_block
)
+ (long int)op->value)
return US op->name;
}
}
return US"";
}
/*************************************************
* Deal with an assignment to a macro *
*************************************************/
/* This function is called when a line that starts with an upper case letter is
encountered. The argument "line" should contain a complete logical line, and
start with the first letter of the macro name. The macro name and the
replacement text are extracted and stored. Redefinition of existing,
non-command line, macros is permitted using '==' instead of '='.
Arguments:
s points to the start of the logical line
Returns: nothing
*/
static void
read_macro_assignment(uschar *s)
{
uschar name[64];
int namelen = 0;
BOOL redef = FALSE;
macro_item *m;
macro_item *mlast = NULL;
while (isalnum(*s) || *s == '_')
{
if (namelen >= sizeof(name) - 1)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
"macro name too long (maximum is " SIZE_T_FMT " characters)", sizeof(name) - 1);
name[namelen++] = *s++;
}
name[namelen] = 0;
while (isspace(*s)) s++;
if (*s++ != '=')
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "malformed macro definition");
if (*s == '=')
{
redef = TRUE;
s++;
}
while (isspace(*s)) s++;
/* If an existing macro of the same name was defined on the command line, we
just skip this definition. It's an error to attempt to redefine a macro without
redef set to TRUE, or to redefine a macro when it hasn't been defined earlier.
It is also an error to define a macro whose name begins with the name of a
previously defined macro. Note: it is documented that the other way round
works. */
for (m = macros; m != NULL; m = m->next)
{
int len = Ustrlen(m->name);
if (Ustrcmp(m->name, name) == 0)
{
if (!m->command_line && !redef)
log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "macro \"%s\" is already "
"defined (use \"==\" if you want to redefine it", name);
break;
}
if (len < namelen && Ustrstr(name, m->name) != NULL)
log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "\"%s\" cannot be defined as "
"a macro because previously defined macro \"%s\" is a substring",
name, m->name);
/* We cannot have this test, because it is documented that a substring
macro is permitted (there is even an example).
*
* if (len > namelen && Ustrstr(m->name, name) != NULL)
* log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "\"%s\" cannot be defined as "
* "a macro because it is a substring of previously defined macro \"%s\"",
* name, m->name);
*/
mlast = m;
}
/* Check for an overriding command-line definition. */
if (m != NULL && m->command_line) return;
/* Redefinition must refer to an existing macro. */
if (redef)
{
if (m == NULL)
log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "can't redefine an undefined macro "
"\"%s\"", name);
}
/* We have a new definition. The macro_item structure includes a final vector
called "name" which is one byte long. Thus, adding "namelen" gives us enough
room to store the "name" string. */
else
{
m = store_get(sizeof(macro_item) + namelen);
if (macros == NULL) macros = m; else mlast->next = m;
Ustrncpy(m->name, name, namelen);
m->name[namelen] = 0;
m->next = NULL;
m->command_line = FALSE;
}
/* Set the value of the new or redefined macro */
m->replacement = string_copy(s);
}
/*************************************************
* Read configuration line *
*************************************************/
/* A logical line of text is read from the configuration file into the big
buffer, taking account of macros, .includes, and continuations. The size of
big_buffer is increased if necessary. The count of configuration lines is
maintained. Physical input lines starting with # (ignoring leading white space,
and after macro replacement) and empty logical lines are always ignored.
Leading and trailing spaces are removed.
If we hit a line of the form "begin xxxx", the xxxx is placed in the
next_section vector, and the function returns NULL, indicating the end of a
configuration section. On end-of-file, NULL is returned with next_section
empty.
Arguments: none
Returns: a pointer to the first non-blank in the line,
or NULL if eof or end of section is reached
*/
static uschar *
get_config_line(void)
{
int startoffset = 0; /* To first non-blank char in logical line */
int len = 0; /* Of logical line so far */
int newlen;
uschar *s, *ss;
macro_item *m;
BOOL macro_found;
/* Loop for handling continuation lines, skipping comments, and dealing with
.include files. */
for (;;)
{
if (Ufgets(big_buffer+len, big_buffer_size-len, config_file) == NULL)
{
if (config_file_stack != NULL) /* EOF inside .include */
{
(void)fclose(config_file);
config_file = config_file_stack->file;
config_filename = config_file_stack->filename;
config_lineno = config_file_stack->lineno;
config_file_stack = config_file_stack->next;
if (config_lines)
save_config_position(config_filename, config_lineno);
continue;
}
/* EOF at top level */
if (cstate_stack_ptr >= 0)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
"Unexpected end of configuration file: .endif missing");
if (len != 0) break; /* EOF after continuation */
next_section[0] = 0; /* EOF at start of logical line */
return NULL;
}
config_lineno++;
newlen = len + Ustrlen(big_buffer + len);
if (config_lines && config_lineno == 1)
save_config_position(config_filename, config_lineno);
/* Handle pathologically long physical lines - yes, it did happen - by
extending big_buffer at this point. The code also copes with very long
logical lines. */
while (newlen == big_buffer_size - 1 && big_buffer[newlen - 1] != '\n')
{
uschar *newbuffer;
big_buffer_size += BIG_BUFFER_SIZE;
newbuffer = store_malloc(big_buffer_size);
/* This use of strcpy is OK because we know that the string in the old
buffer is shorter than the new buffer. */
Ustrcpy(newbuffer, big_buffer);
store_free(big_buffer);
big_buffer = newbuffer;
if (Ufgets(big_buffer+newlen, big_buffer_size-newlen, config_file) == NULL)
break;
newlen += Ustrlen(big_buffer + newlen);
}
/* Find the true start of the physical line - leading spaces are always
ignored. */
ss = big_buffer + len;
while (isspace(*ss)) ss++;
/* Process the physical line for macros. If this is the start of the logical
line, skip over initial text at the start of the line if it starts with an
upper case character followed by a sequence of name characters and an equals
sign, because that is the definition of a new macro, and we don't do
replacement therein. */
s = ss;
if (len == 0 && isupper(*s))
{
while (isalnum(*s) || *s == '_') s++;
while (isspace(*s)) s++;
if (*s != '=') s = ss; /* Not a macro definition */
}
/* For each defined macro, scan the line (from after XXX= if present),
replacing all occurrences of the macro. */
macro_found = FALSE;
for (m = macros; m != NULL; m = m->next)
{
uschar *p, *pp;
uschar *t = s;
while ((p = Ustrstr(t, m->name)) != NULL)
{
int moveby;
int namelen = Ustrlen(m->name);
int replen = Ustrlen(m->replacement);
/* Expand the buffer if necessary */
while (newlen - namelen + replen + 1 > big_buffer_size)
{
int newsize = big_buffer_size + BIG_BUFFER_SIZE;
uschar *newbuffer = store_malloc(newsize);
memcpy(newbuffer, big_buffer, newlen + 1);
p = newbuffer + (p - big_buffer);
s = newbuffer + (s - big_buffer);
ss = newbuffer + (ss - big_buffer);
t = newbuffer + (t - big_buffer);
big_buffer_size = newsize;
store_free(big_buffer);
big_buffer = newbuffer;
}
/* Shuffle the remaining characters up or down in the buffer before
copying in the replacement text. Don't rescan the replacement for this
same macro. */
pp = p + namelen;
moveby = replen - namelen;
if (moveby != 0)
{
memmove(p + replen, pp, (big_buffer + newlen) - pp + 1);
newlen += moveby;
}
Ustrncpy(p, m->replacement, replen);
t = p + replen;
macro_found = TRUE;
}
}
/* An empty macro replacement at the start of a line could mean that ss no
longer points to the first non-blank character. */
while (isspace(*ss)) ss++;
/* Check for comment lines - these are physical lines. */
if (*ss == '#') continue;
/* Handle conditionals, which are also applied to physical lines. Conditions
are of the form ".ifdef ANYTEXT" and are treated as true if any macro
expansion occured on the rest of the line. A preliminary test for the leading
'.' saves effort on most lines. */
if (*ss == '.')
{
int i;
/* Search the list of conditional directives */
for (i = 0; i < cond_list_size; i++)
{
int n;
cond_item *c = cond_list+i;
if (Ustrncmp(ss+1, c->name, c->namelen) != 0) continue;
/* The following character must be white space or end of string */
n = ss[1 + c->namelen];
if (n != ' ' && n != 't' && n != '\n' && n != 0) break;
/* .ifdef and .ifndef push the current state onto the stack, then set
a new one from the table. Stack overflow is an error */
if (c->pushpop > 0)
{
if (cstate_stack_ptr >= CSTATE_STACK_SIZE - 1)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
".%s nested too deeply", c->name);
cstate_stack[++cstate_stack_ptr] = cstate;
cstate = next_cstate[cstate][macro_found? c->action1 : c->action2];
}
/* For any of the others, stack underflow is an error. The next state
comes either from the stack (.endif) or from the table. */
else
{
if (cstate_stack_ptr < 0)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
".%s without matching .ifdef", c->name);
cstate = (c->pushpop < 0)? cstate_stack[cstate_stack_ptr--] :
next_cstate[cstate][macro_found? c->action1 : c->action2];
}
/* Having dealt with a directive, break the loop */
break;
}
/* If we have handled a conditional directive, continue with the next
physical line. Otherwise, fall through. */
if (i < cond_list_size) continue;
}
/* If the conditional state is not 0 (actively using these lines), ignore
this input line. */
if (cstate != 0) continue; /* Conditional skip */
/* Handle .include lines - these are also physical lines. */
if (Ustrncmp(ss, ".include", 8) == 0 &&
(isspace(ss[8]) ||
(Ustrncmp(ss+8, "_if_exists", 10) == 0 && isspace(ss[18]))))
{
uschar *t;
int include_if_exists = isspace(ss[8])? 0 : 10;
config_file_item *save;
struct stat statbuf;
ss += 9 + include_if_exists;
while (isspace(*ss)) ss++;
t = ss + Ustrlen(ss);
while (t > ss && isspace(t[-1])) t--;
if (*ss == '\"' && t[-1] == '\"')
{
ss++;
t--;
}
*t = 0;
if (*ss != '/')
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, ".include specifies a non-"
"absolute path \"%s\"", ss);
if (include_if_exists != 0 && (Ustat(ss, &statbuf) != 0)) continue;
if (config_lines)
save_config_position(config_filename, config_lineno);
save = store_get(sizeof(config_file_item));
save->next = config_file_stack;
config_file_stack = save;
save->file = config_file;
save->filename = config_filename;
save->lineno = config_lineno;
config_file = Ufopen(ss, "rb");
if (config_file == NULL)
log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "failed to open included "
"configuration file %s", ss);
config_filename = string_copy(ss);
config_lineno = 0;
continue;
}
/* If this is the start of the logical line, remember where the non-blank
data starts. Otherwise shuffle down continuation lines to remove leading
white space. */
if (len == 0)
startoffset = ss - big_buffer;
else
{
s = big_buffer + len;
if (ss > s)
{
memmove(s, ss, (newlen - len) - (ss - s) + 1);
newlen -= ss - s;
}
}
/* Accept the new addition to the line. Remove trailing white space. */
len = newlen;
while (len > 0 && isspace(big_buffer[len-1])) len--;
big_buffer[len] = 0;
/* We are done if the line does not end in backslash and contains some data.
Empty logical lines are ignored. For continuations, remove the backslash and
go round the loop to read the continuation line. */
if (len > 0)
{
if (big_buffer[len-1] != '\\') break; /* End of logical line */
big_buffer[--len] = 0; /* Remove backslash */
}
} /* Loop for reading multiple physical lines */
/* We now have a logical line. Test for the end of a configuration section (or,
more accurately, for the start of the next section). Place the name of the next
section in next_section, and return NULL. If the name given is longer than
next_section, truncate it. It will be unrecognized later, because all the known
section names do fit. Leave space for pluralizing. */
s = big_buffer + startoffset; /* First non-space character */
if (config_lines)
save_config_line(s);
if (strncmpic(s, US"begin ", 6) == 0)
{
s += 6;
while (isspace(*s)) s++;
if (big_buffer + len - s > sizeof(next_section) - 2)
s[sizeof(next_section) - 2] = 0;
Ustrcpy(next_section, s);
return NULL;
}