Bug 1400: Fix GnuTLS PKCS11 issues
[exim.git] / src / src / readconf.c
CommitLineData
059ec3d9
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
c4ceed07 5/* Copyright (c) University of Cambridge 1995 - 2012 */
059ec3d9
PH
6/* See the file NOTICE for conditions of use and distribution. */
7
8/* Functions for reading the configuration file, and for displaying
9overall configuration values. Thanks to Brian Candler for the original
10implementation of the conditional .ifdef etc. */
11
12#include "exim.h"
13
14#define CSTATE_STACK_SIZE 10
15
16
17/* Structure for chain (stack) of .included files */
18
19typedef struct config_file_item {
20 struct config_file_item *next;
21 uschar *filename;
22 FILE *file;
23 int lineno;
24} config_file_item;
25
26/* Structure of table of conditional words and their state transitions */
27
28typedef struct cond_item {
29 uschar *name;
30 int namelen;
31 int action1;
32 int action2;
33 int pushpop;
34} cond_item;
35
36/* Structure of table of syslog facility names and values */
37
38typedef struct syslog_fac_item {
39 uschar *name;
40 int value;
41} syslog_fac_item;
42
43
44/* Static variables */
45
46static config_file_item *config_file_stack = NULL; /* For includes */
47
48static uschar *syslog_facility_str = NULL;
49static uschar next_section[24];
50static uschar time_buffer[24];
51
52/* State variables for conditional loading (.ifdef / .else / .endif) */
53
54static int cstate = 0;
55static int cstate_stack_ptr = -1;
56static int cstate_stack[CSTATE_STACK_SIZE];
57
58/* Table of state transitions for handling conditional inclusions. There are
59four possible state transitions:
60
61 .ifdef true
62 .ifdef false
63 .elifdef true (or .else)
64 .elifdef false
65
66.endif just causes the previous cstate to be popped off the stack */
67
68static int next_cstate[3][4] =
69 {
70 /* State 0: reading from file, or reading until next .else or .endif */
71 { 0, 1, 2, 2 },
72 /* State 1: condition failed, skipping until next .else or .endif */
73 { 2, 2, 0, 1 },
74 /* State 2: skipping until .endif */
75 { 2, 2, 2, 2 },
76 };
77
78/* Table of conditionals and the states to set. For each name, there are four
79values: the length of the name (to save computing it each time), the state to
80set if a macro was found in the line, the state to set if a macro was not found
81in the line, and a stack manipulation setting which is:
82
83 -1 pull state value off the stack
84 0 don't alter the stack
85 +1 push value onto stack, before setting new state
86*/
87
88static cond_item cond_list[] = {
89 { US"ifdef", 5, 0, 1, 1 },
90 { US"ifndef", 6, 1, 0, 1 },
91 { US"elifdef", 7, 2, 3, 0 },
92 { US"elifndef", 8, 3, 2, 0 },
93 { US"else", 4, 2, 2, 0 },
94 { US"endif", 5, 0, 0, -1 }
95};
96
97static int cond_list_size = sizeof(cond_list)/sizeof(cond_item);
98
99/* Table of syslog facility names and their values */
100
101static syslog_fac_item syslog_list[] = {
102 { US"mail", LOG_MAIL },
103 { US"user", LOG_USER },
104 { US"news", LOG_NEWS },
105 { US"uucp", LOG_UUCP },
106 { US"local0", LOG_LOCAL0 },
107 { US"local1", LOG_LOCAL1 },
108 { US"local2", LOG_LOCAL2 },
109 { US"local3", LOG_LOCAL3 },
110 { US"local4", LOG_LOCAL4 },
111 { US"local5", LOG_LOCAL5 },
112 { US"local6", LOG_LOCAL6 },
113 { US"local7", LOG_LOCAL7 },
114 { US"daemon", LOG_DAEMON }
115};
116
117static int syslog_list_size = sizeof(syslog_list)/sizeof(syslog_fac_item);
118
119
120
121
122/*************************************************
123* Main configuration options *
124*************************************************/
125
126/* The list of options that can be set in the main configuration file. This
127must be in alphabetic order because it is searched by binary chop. */
128
129static optionlist optionlist_config[] = {
130 { "*set_exim_group", opt_bool|opt_hidden, &exim_gid_set },
131 { "*set_exim_user", opt_bool|opt_hidden, &exim_uid_set },
132 { "*set_system_filter_group", opt_bool|opt_hidden, &system_filter_gid_set },
133 { "*set_system_filter_user", opt_bool|opt_hidden, &system_filter_uid_set },
134 { "accept_8bitmime", opt_bool, &accept_8bitmime },
135 { "acl_not_smtp", opt_stringptr, &acl_not_smtp },
54cdb463
PH
136#ifdef WITH_CONTENT_SCAN
137 { "acl_not_smtp_mime", opt_stringptr, &acl_not_smtp_mime },
138#endif
45b91596 139 { "acl_not_smtp_start", opt_stringptr, &acl_not_smtp_start },
059ec3d9
PH
140 { "acl_smtp_auth", opt_stringptr, &acl_smtp_auth },
141 { "acl_smtp_connect", opt_stringptr, &acl_smtp_connect },
142 { "acl_smtp_data", opt_stringptr, &acl_smtp_data },
fd98a5c6
JH
143#ifdef EXPERIMENTAL_PRDR
144 { "acl_smtp_data_prdr", opt_stringptr, &acl_smtp_data_prdr },
145#endif
80a47a2c
TK
146#ifndef DISABLE_DKIM
147 { "acl_smtp_dkim", opt_stringptr, &acl_smtp_dkim },
148#endif
059ec3d9
PH
149 { "acl_smtp_etrn", opt_stringptr, &acl_smtp_etrn },
150 { "acl_smtp_expn", opt_stringptr, &acl_smtp_expn },
151 { "acl_smtp_helo", opt_stringptr, &acl_smtp_helo },
152 { "acl_smtp_mail", opt_stringptr, &acl_smtp_mail },
153 { "acl_smtp_mailauth", opt_stringptr, &acl_smtp_mailauth },
8523533c
TK
154#ifdef WITH_CONTENT_SCAN
155 { "acl_smtp_mime", opt_stringptr, &acl_smtp_mime },
156#endif
8f128379 157 { "acl_smtp_notquit", opt_stringptr, &acl_smtp_notquit },
059ec3d9
PH
158 { "acl_smtp_predata", opt_stringptr, &acl_smtp_predata },
159 { "acl_smtp_quit", opt_stringptr, &acl_smtp_quit },
160 { "acl_smtp_rcpt", opt_stringptr, &acl_smtp_rcpt },
161#ifdef SUPPORT_TLS
162 { "acl_smtp_starttls", opt_stringptr, &acl_smtp_starttls },
163#endif
164 { "acl_smtp_vrfy", opt_stringptr, &acl_smtp_vrfy },
165 { "admin_groups", opt_gidlist, &admin_groups },
166 { "allow_domain_literals", opt_bool, &allow_domain_literals },
167 { "allow_mx_to_ip", opt_bool, &allow_mx_to_ip },
168 { "allow_utf8_domains", opt_bool, &allow_utf8_domains },
169 { "auth_advertise_hosts", opt_stringptr, &auth_advertise_hosts },
170 { "auto_thaw", opt_time, &auto_thaw },
8523533c
TK
171#ifdef WITH_CONTENT_SCAN
172 { "av_scanner", opt_stringptr, &av_scanner },
173#endif
059ec3d9 174 { "bi_command", opt_stringptr, &bi_command },
8523533c
TK
175#ifdef EXPERIMENTAL_BRIGHTMAIL
176 { "bmi_config_file", opt_stringptr, &bmi_config_file },
177#endif
059ec3d9
PH
178 { "bounce_message_file", opt_stringptr, &bounce_message_file },
179 { "bounce_message_text", opt_stringptr, &bounce_message_text },
180 { "bounce_return_body", opt_bool, &bounce_return_body },
181 { "bounce_return_message", opt_bool, &bounce_return_message },
182 { "bounce_return_size_limit", opt_mkint, &bounce_return_size_limit },
183 { "bounce_sender_authentication",opt_stringptr,&bounce_sender_authentication },
184 { "callout_domain_negative_expire", opt_time, &callout_cache_domain_negative_expire },
185 { "callout_domain_positive_expire", opt_time, &callout_cache_domain_positive_expire },
186 { "callout_negative_expire", opt_time, &callout_cache_negative_expire },
187 { "callout_positive_expire", opt_time, &callout_cache_positive_expire },
188 { "callout_random_local_part",opt_stringptr, &callout_random_local_part },
189 { "check_log_inodes", opt_int, &check_log_inodes },
190 { "check_log_space", opt_Kint, &check_log_space },
a0d6ba8a 191 { "check_rfc2047_length", opt_bool, &check_rfc2047_length },
059ec3d9
PH
192 { "check_spool_inodes", opt_int, &check_spool_inodes },
193 { "check_spool_space", opt_Kint, &check_spool_space },
194 { "daemon_smtp_port", opt_stringptr|opt_hidden, &daemon_smtp_port },
195 { "daemon_smtp_ports", opt_stringptr, &daemon_smtp_port },
4aee0225
PH
196 { "daemon_startup_retries", opt_int, &daemon_startup_retries },
197 { "daemon_startup_sleep", opt_time, &daemon_startup_sleep },
6a8f9482
TK
198#ifdef EXPERIMENTAL_DCC
199 { "dcc_direct_add_header", opt_bool, &dcc_direct_add_header },
200 { "dccifd_address", opt_stringptr, &dccifd_address },
201 { "dccifd_options", opt_stringptr, &dccifd_options },
202#endif
059ec3d9
PH
203 { "delay_warning", opt_timelist, &delay_warning },
204 { "delay_warning_condition", opt_stringptr, &delay_warning_condition },
205 { "deliver_drop_privilege", opt_bool, &deliver_drop_privilege },
206 { "deliver_queue_load_max", opt_fixed, &deliver_queue_load_max },
207 { "delivery_date_remove", opt_bool, &delivery_date_remove },
54fc8428
PH
208#ifdef ENABLE_DISABLE_FSYNC
209 { "disable_fsync", opt_bool, &disable_fsync },
210#endif
7e66e54d 211 { "disable_ipv6", opt_bool, &disable_ipv6 },
80a47a2c
TK
212#ifndef DISABLE_DKIM
213 { "dkim_verify_signers", opt_stringptr, &dkim_verify_signers },
4840604e
TL
214#endif
215#ifdef EXPERIMENTAL_DMARC
216 { "dmarc_forensic_sender", opt_stringptr, &dmarc_forensic_sender },
217 { "dmarc_history_file", opt_stringptr, &dmarc_history_file },
218 { "dmarc_tld_file", opt_stringptr, &dmarc_tld_file },
80a47a2c 219#endif
059ec3d9
PH
220 { "dns_again_means_nonexist", opt_stringptr, &dns_again_means_nonexist },
221 { "dns_check_names_pattern", opt_stringptr, &check_dns_names_pattern },
e5a9dba6
PH
222 { "dns_csa_search_limit", opt_int, &dns_csa_search_limit },
223 { "dns_csa_use_reverse", opt_bool, &dns_csa_use_reverse },
83712b39 224 { "dns_dnssec_ok", opt_int, &dns_dnssec_ok },
059ec3d9
PH
225 { "dns_ipv4_lookup", opt_stringptr, &dns_ipv4_lookup },
226 { "dns_retrans", opt_time, &dns_retrans },
227 { "dns_retry", opt_int, &dns_retry },
e97d1f08 228 { "dns_use_edns0", opt_int, &dns_use_edns0 },
059ec3d9
PH
229 /* This option is now a no-op, retained for compability */
230 { "drop_cr", opt_bool, &drop_cr },
231/*********************************************************/
0e22dfd1 232 { "dsn_from", opt_stringptr, &dsn_from },
059ec3d9
PH
233 { "envelope_to_remove", opt_bool, &envelope_to_remove },
234 { "errors_copy", opt_stringptr, &errors_copy },
235 { "errors_reply_to", opt_stringptr, &errors_reply_to },
236 { "exim_group", opt_gid, &exim_gid },
237 { "exim_path", opt_stringptr, &exim_path },
238 { "exim_user", opt_uid, &exim_uid },
239 { "extra_local_interfaces", opt_stringptr, &extra_local_interfaces },
240 { "extract_addresses_remove_arguments", opt_bool, &extract_addresses_remove_arguments },
241 { "finduser_retries", opt_int, &finduser_retries },
242 { "freeze_tell", opt_stringptr, &freeze_tell },
243 { "gecos_name", opt_stringptr, &gecos_name },
244 { "gecos_pattern", opt_stringptr, &gecos_pattern },
83da1223 245#ifdef SUPPORT_TLS
2519e60d 246 { "gnutls_allow_auto_pkcs11", opt_bool, &gnutls_allow_auto_pkcs11 },
e6060e2c 247 { "gnutls_compat_mode", opt_bool, &gnutls_compat_mode },
b1770b6e 248 /* These three gnutls_require_* options stopped working in Exim 4.80 */
83da1223
PH
249 { "gnutls_require_kx", opt_stringptr, &gnutls_require_kx },
250 { "gnutls_require_mac", opt_stringptr, &gnutls_require_mac },
251 { "gnutls_require_protocols", opt_stringptr, &gnutls_require_proto },
252#endif
059ec3d9
PH
253 { "header_line_maxsize", opt_int, &header_line_maxsize },
254 { "header_maxsize", opt_int, &header_maxsize },
255 { "headers_charset", opt_stringptr, &headers_charset },
256 { "helo_accept_junk_hosts", opt_stringptr, &helo_accept_junk_hosts },
257 { "helo_allow_chars", opt_stringptr, &helo_allow_chars },
258 { "helo_lookup_domains", opt_stringptr, &helo_lookup_domains },
259 { "helo_try_verify_hosts", opt_stringptr, &helo_try_verify_hosts },
260 { "helo_verify_hosts", opt_stringptr, &helo_verify_hosts },
261 { "hold_domains", opt_stringptr, &hold_domains },
262 { "host_lookup", opt_stringptr, &host_lookup },
263 { "host_lookup_order", opt_stringptr, &host_lookup_order },
264 { "host_reject_connection", opt_stringptr, &host_reject_connection },
265 { "hosts_connection_nolog", opt_stringptr, &hosts_connection_nolog },
266 { "hosts_treat_as_local", opt_stringptr, &hosts_treat_as_local },
267#ifdef LOOKUP_IBASE
268 { "ibase_servers", opt_stringptr, &ibase_servers },
269#endif
270 { "ignore_bounce_errors_after", opt_time, &ignore_bounce_errors_after },
271 { "ignore_fromline_hosts", opt_stringptr, &ignore_fromline_hosts },
272 { "ignore_fromline_local", opt_bool, &ignore_fromline_local },
273 { "keep_malformed", opt_time, &keep_malformed },
274#ifdef LOOKUP_LDAP
bc19a55b
PP
275 { "ldap_ca_cert_dir", opt_stringptr, &eldap_ca_cert_dir },
276 { "ldap_ca_cert_file", opt_stringptr, &eldap_ca_cert_file },
277 { "ldap_cert_file", opt_stringptr, &eldap_cert_file },
278 { "ldap_cert_key", opt_stringptr, &eldap_cert_key },
279 { "ldap_cipher_suite", opt_stringptr, &eldap_cipher_suite },
059ec3d9 280 { "ldap_default_servers", opt_stringptr, &eldap_default_servers },
bc19a55b
PP
281 { "ldap_require_cert", opt_stringptr, &eldap_require_cert },
282 { "ldap_start_tls", opt_bool, &eldap_start_tls },
059ec3d9
PH
283 { "ldap_version", opt_int, &eldap_version },
284#endif
285 { "local_from_check", opt_bool, &local_from_check },
286 { "local_from_prefix", opt_stringptr, &local_from_prefix },
287 { "local_from_suffix", opt_stringptr, &local_from_suffix },
288 { "local_interfaces", opt_stringptr, &local_interfaces },
289 { "local_scan_timeout", opt_time, &local_scan_timeout },
290 { "local_sender_retain", opt_bool, &local_sender_retain },
291 { "localhost_number", opt_stringptr, &host_number_string },
292 { "log_file_path", opt_stringptr, &log_file_path },
293 { "log_selector", opt_stringptr, &log_selector_string },
294 { "log_timezone", opt_bool, &log_timezone },
295 { "lookup_open_max", opt_int, &lookup_open_max },
296 { "max_username_length", opt_int, &max_username_length },
ddea74fa 297 { "message_body_newlines", opt_bool, &message_body_newlines },
059ec3d9
PH
298 { "message_body_visible", opt_mkint, &message_body_visible },
299 { "message_id_header_domain", opt_stringptr, &message_id_domain },
300 { "message_id_header_text", opt_stringptr, &message_id_text },
301 { "message_logs", opt_bool, &message_logs },
302 { "message_size_limit", opt_stringptr, &message_size_limit },
303#ifdef SUPPORT_MOVE_FROZEN_MESSAGES
304 { "move_frozen_messages", opt_bool, &move_frozen_messages },
305#endif
306 { "mua_wrapper", opt_bool, &mua_wrapper },
307#ifdef LOOKUP_MYSQL
308 { "mysql_servers", opt_stringptr, &mysql_servers },
309#endif
310 { "never_users", opt_uidlist, &never_users },
77bb000f
PP
311#ifdef SUPPORT_TLS
312 { "openssl_options", opt_stringptr, &openssl_options },
313#endif
059ec3d9
PH
314#ifdef LOOKUP_ORACLE
315 { "oracle_servers", opt_stringptr, &oracle_servers },
316#endif
317 { "percent_hack_domains", opt_stringptr, &percent_hack_domains },
318#ifdef EXIM_PERL
319 { "perl_at_start", opt_bool, &opt_perl_at_start },
320 { "perl_startup", opt_stringptr, &opt_perl_startup },
321#endif
322#ifdef LOOKUP_PGSQL
323 { "pgsql_servers", opt_stringptr, &pgsql_servers },
324#endif
325 { "pid_file_path", opt_stringptr, &pid_file_path },
326 { "pipelining_advertise_hosts", opt_stringptr, &pipelining_advertise_hosts },
fd98a5c6
JH
327#ifdef EXPERIMENTAL_PRDR
328 { "prdr_enable", opt_bool, &prdr_enable },
329#endif
059ec3d9
PH
330 { "preserve_message_logs", opt_bool, &preserve_message_logs },
331 { "primary_hostname", opt_stringptr, &primary_hostname },
332 { "print_topbitchars", opt_bool, &print_topbitchars },
333 { "process_log_path", opt_stringptr, &process_log_path },
334 { "prod_requires_admin", opt_bool, &prod_requires_admin },
335 { "qualify_domain", opt_stringptr, &qualify_domain_sender },
336 { "qualify_recipient", opt_stringptr, &qualify_domain_recipient },
337 { "queue_domains", opt_stringptr, &queue_domains },
338 { "queue_list_requires_admin",opt_bool, &queue_list_requires_admin },
339 { "queue_only", opt_bool, &queue_only },
340 { "queue_only_file", opt_stringptr, &queue_only_file },
341 { "queue_only_load", opt_fixed, &queue_only_load },
8669f003 342 { "queue_only_load_latch", opt_bool, &queue_only_load_latch },
059ec3d9
PH
343 { "queue_only_override", opt_bool, &queue_only_override },
344 { "queue_run_in_order", opt_bool, &queue_run_in_order },
345 { "queue_run_max", opt_int, &queue_run_max },
346 { "queue_smtp_domains", opt_stringptr, &queue_smtp_domains },
347 { "receive_timeout", opt_time, &receive_timeout },
348 { "received_header_text", opt_stringptr, &received_header_text },
349 { "received_headers_max", opt_int, &received_headers_max },
350 { "recipient_unqualified_hosts", opt_stringptr, &recipient_unqualified_hosts },
351 { "recipients_max", opt_int, &recipients_max },
352 { "recipients_max_reject", opt_bool, &recipients_max_reject },
9bdd29ad
TL
353#ifdef EXPERIMENTAL_REDIS
354 { "redis_servers", opt_stringptr, &redis_servers },
355#endif
059ec3d9
PH
356 { "remote_max_parallel", opt_int, &remote_max_parallel },
357 { "remote_sort_domains", opt_stringptr, &remote_sort_domains },
358 { "retry_data_expire", opt_time, &retry_data_expire },
359 { "retry_interval_max", opt_time, &retry_interval_max },
360 { "return_path_remove", opt_bool, &return_path_remove },
361 { "return_size_limit", opt_mkint|opt_hidden, &bounce_return_size_limit },
362 { "rfc1413_hosts", opt_stringptr, &rfc1413_hosts },
363 { "rfc1413_query_timeout", opt_time, &rfc1413_query_timeout },
364 { "sender_unqualified_hosts", opt_stringptr, &sender_unqualified_hosts },
365 { "smtp_accept_keepalive", opt_bool, &smtp_accept_keepalive },
366 { "smtp_accept_max", opt_int, &smtp_accept_max },
367 { "smtp_accept_max_nonmail", opt_int, &smtp_accept_max_nonmail },
368 { "smtp_accept_max_nonmail_hosts", opt_stringptr, &smtp_accept_max_nonmail_hosts },
369 { "smtp_accept_max_per_connection", opt_int, &smtp_accept_max_per_connection },
370 { "smtp_accept_max_per_host", opt_stringptr, &smtp_accept_max_per_host },
371 { "smtp_accept_queue", opt_int, &smtp_accept_queue },
372 { "smtp_accept_queue_per_connection", opt_int, &smtp_accept_queue_per_connection },
373 { "smtp_accept_reserve", opt_int, &smtp_accept_reserve },
374 { "smtp_active_hostname", opt_stringptr, &raw_active_hostname },
375 { "smtp_banner", opt_stringptr, &smtp_banner },
376 { "smtp_check_spool_space", opt_bool, &smtp_check_spool_space },
377 { "smtp_connect_backlog", opt_int, &smtp_connect_backlog },
378 { "smtp_enforce_sync", opt_bool, &smtp_enforce_sync },
379 { "smtp_etrn_command", opt_stringptr, &smtp_etrn_command },
380 { "smtp_etrn_serialize", opt_bool, &smtp_etrn_serialize },
381 { "smtp_load_reserve", opt_fixed, &smtp_load_reserve },
382 { "smtp_max_synprot_errors", opt_int, &smtp_max_synprot_errors },
383 { "smtp_max_unknown_commands",opt_int, &smtp_max_unknown_commands },
384 { "smtp_ratelimit_hosts", opt_stringptr, &smtp_ratelimit_hosts },
385 { "smtp_ratelimit_mail", opt_stringptr, &smtp_ratelimit_mail },
386 { "smtp_ratelimit_rcpt", opt_stringptr, &smtp_ratelimit_rcpt },
387 { "smtp_receive_timeout", opt_time, &smtp_receive_timeout },
388 { "smtp_reserve_hosts", opt_stringptr, &smtp_reserve_hosts },
389 { "smtp_return_error_details",opt_bool, &smtp_return_error_details },
8523533c
TK
390#ifdef WITH_CONTENT_SCAN
391 { "spamd_address", opt_stringptr, &spamd_address },
65a7d8c3
NM
392#endif
393#ifdef EXPERIMENTAL_SPF
394 { "spf_guess", opt_stringptr, &spf_guess },
8523533c 395#endif
059ec3d9
PH
396 { "split_spool_directory", opt_bool, &split_spool_directory },
397 { "spool_directory", opt_stringptr, &spool_directory },
31480e42
PH
398#ifdef LOOKUP_SQLITE
399 { "sqlite_lock_timeout", opt_int, &sqlite_lock_timeout },
400#endif
8523533c
TK
401#ifdef EXPERIMENTAL_SRS
402 { "srs_config", opt_stringptr, &srs_config },
384152a6
TK
403 { "srs_hashlength", opt_int, &srs_hashlength },
404 { "srs_hashmin", opt_int, &srs_hashmin },
405 { "srs_maxage", opt_int, &srs_maxage },
406 { "srs_secrets", opt_stringptr, &srs_secrets },
407 { "srs_usehash", opt_bool, &srs_usehash },
408 { "srs_usetimestamp", opt_bool, &srs_usetimestamp },
8523533c 409#endif
38a0a95f 410 { "strict_acl_vars", opt_bool, &strict_acl_vars },
059ec3d9
PH
411 { "strip_excess_angle_brackets", opt_bool, &strip_excess_angle_brackets },
412 { "strip_trailing_dot", opt_bool, &strip_trailing_dot },
413 { "syslog_duplication", opt_bool, &syslog_duplication },
414 { "syslog_facility", opt_stringptr, &syslog_facility_str },
415 { "syslog_processname", opt_stringptr, &syslog_processname },
416 { "syslog_timestamp", opt_bool, &syslog_timestamp },
417 { "system_filter", opt_stringptr, &system_filter },
418 { "system_filter_directory_transport", opt_stringptr,&system_filter_directory_transport },
419 { "system_filter_file_transport",opt_stringptr,&system_filter_file_transport },
420 { "system_filter_group", opt_gid, &system_filter_gid },
421 { "system_filter_pipe_transport",opt_stringptr,&system_filter_pipe_transport },
422 { "system_filter_reply_transport",opt_stringptr,&system_filter_reply_transport },
423 { "system_filter_user", opt_uid, &system_filter_uid },
424 { "tcp_nodelay", opt_bool, &tcp_nodelay },
5dc43717
JJ
425#ifdef USE_TCP_WRAPPERS
426 { "tcp_wrappers_daemon_name", opt_stringptr, &tcp_wrappers_daemon_name },
427#endif
059ec3d9
PH
428 { "timeout_frozen_after", opt_time, &timeout_frozen_after },
429 { "timezone", opt_stringptr, &timezone_string },
430#ifdef SUPPORT_TLS
431 { "tls_advertise_hosts", opt_stringptr, &tls_advertise_hosts },
432 { "tls_certificate", opt_stringptr, &tls_certificate },
433 { "tls_crl", opt_stringptr, &tls_crl },
3375e053 434 { "tls_dh_max_bits", opt_int, &tls_dh_max_bits },
059ec3d9 435 { "tls_dhparam", opt_stringptr, &tls_dhparam },
817d9f57 436# if defined(EXPERIMENTAL_OCSP) && !defined(USE_GNUTLS)
3f7eeb86 437 { "tls_ocsp_file", opt_stringptr, &tls_ocsp_file },
817d9f57
JH
438# endif
439 { "tls_on_connect_ports", opt_stringptr, &tls_in.on_connect_ports },
059ec3d9
PH
440 { "tls_privatekey", opt_stringptr, &tls_privatekey },
441 { "tls_remember_esmtp", opt_bool, &tls_remember_esmtp },
442 { "tls_require_ciphers", opt_stringptr, &tls_require_ciphers },
443 { "tls_try_verify_hosts", opt_stringptr, &tls_try_verify_hosts },
444 { "tls_verify_certificates", opt_stringptr, &tls_verify_certificates },
445 { "tls_verify_hosts", opt_stringptr, &tls_verify_hosts },
446#endif
447 { "trusted_groups", opt_gidlist, &trusted_groups },
448 { "trusted_users", opt_uidlist, &trusted_users },
449 { "unknown_login", opt_stringptr, &unknown_login },
450 { "unknown_username", opt_stringptr, &unknown_username },
451 { "untrusted_set_sender", opt_stringptr, &untrusted_set_sender },
452 { "uucp_from_pattern", opt_stringptr, &uucp_from_pattern },
453 { "uucp_from_sender", opt_stringptr, &uucp_from_sender },
454 { "warn_message_file", opt_stringptr, &warn_message_file },
455 { "write_rejectlog", opt_bool, &write_rejectlog }
456};
457
458static int optionlist_config_size =
459 sizeof(optionlist_config)/sizeof(optionlist);
460
461
462
463/*************************************************
464* Find the name of an option *
465*************************************************/
466
467/* This function is to aid debugging. Various functions take arguments that are
468pointer variables in the options table or in option tables for various drivers.
469For debugging output, it is useful to be able to find the name of the option
470which is currently being processed. This function finds it, if it exists, by
471searching the table(s).
472
473Arguments: a value that is presumed to be in the table above
474Returns: the option name, or an empty string
475*/
476
477uschar *
478readconf_find_option(void *p)
479{
480int i;
481router_instance *r;
482transport_instance *t;
483
484for (i = 0; i < optionlist_config_size; i++)
485 if (p == optionlist_config[i].value) return US optionlist_config[i].name;
486
487for (r = routers; r != NULL; r = r->next)
488 {
489 router_info *ri = r->info;
490 for (i = 0; i < ri->options_count[0]; i++)
491 {
492 if ((ri->options[i].type & opt_mask) != opt_stringptr) continue;
493 if (p == (char *)(r->options_block) + (long int)(ri->options[i].value))
494 return US ri->options[i].name;
495 }
496 }
497
498for (t = transports; t != NULL; t = t->next)
499 {
500 transport_info *ti = t->info;
501 for (i = 0; i < ti->options_count[0]; i++)
502 {
503 if ((ti->options[i].type & opt_mask) != opt_stringptr) continue;
504 if (p == (char *)(t->options_block) + (long int)(ti->options[i].value))
505 return US ti->options[i].name;
506 }
507 }
508
509return US"";
510}
511
512
513
514
cf00dad6
PH
515/*************************************************
516* Deal with an assignment to a macro *
517*************************************************/
518
519/* This function is called when a line that starts with an upper case letter is
520encountered. The argument "line" should contain a complete logical line, and
521start with the first letter of the macro name. The macro name and the
522replacement text are extracted and stored. Redefinition of existing,
523non-command line, macros is permitted using '==' instead of '='.
524
525Arguments:
526 s points to the start of the logical line
527
528Returns: nothing
529*/
530
531static void
532read_macro_assignment(uschar *s)
533{
534uschar name[64];
535int namelen = 0;
536BOOL redef = FALSE;
537macro_item *m;
538macro_item *mlast = NULL;
539
540while (isalnum(*s) || *s == '_')
541 {
542 if (namelen >= sizeof(name) - 1)
543 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
ef840681 544 "macro name too long (maximum is " SIZE_T_FMT " characters)", sizeof(name) - 1);
cf00dad6
PH
545 name[namelen++] = *s++;
546 }
547name[namelen] = 0;
548
549while (isspace(*s)) s++;
550if (*s++ != '=')
551 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "malformed macro definition");
552
553if (*s == '=')
554 {
555 redef = TRUE;
556 s++;
557 }
558while (isspace(*s)) s++;
559
560/* If an existing macro of the same name was defined on the command line, we
561just skip this definition. It's an error to attempt to redefine a macro without
562redef set to TRUE, or to redefine a macro when it hasn't been defined earlier.
563It is also an error to define a macro whose name begins with the name of a
564previously defined macro. Note: it is documented that the other way round
565works. */
566
567for (m = macros; m != NULL; m = m->next)
568 {
569 int len = Ustrlen(m->name);
570
571 if (Ustrcmp(m->name, name) == 0)
572 {
573 if (!m->command_line && !redef)
574 log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "macro \"%s\" is already "
575 "defined (use \"==\" if you want to redefine it", name);
576 break;
577 }
578
579 if (len < namelen && Ustrstr(name, m->name) != NULL)
580 log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "\"%s\" cannot be defined as "
581 "a macro because previously defined macro \"%s\" is a substring",
582 name, m->name);
583
584 /* We cannot have this test, because it is documented that a substring
585 macro is permitted (there is even an example).
586 *
587 * if (len > namelen && Ustrstr(m->name, name) != NULL)
588 * log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "\"%s\" cannot be defined as "
589 * "a macro because it is a substring of previously defined macro \"%s\"",
590 * name, m->name);
591 */
592
593 mlast = m;
594 }
595
596/* Check for an overriding command-line definition. */
597
598if (m != NULL && m->command_line) return;
599
600/* Redefinition must refer to an existing macro. */
601
602if (redef)
603 {
604 if (m == NULL)
605 log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "can't redefine an undefined macro "
606 "\"%s\"", name);
607 }
608
609/* We have a new definition. The macro_item structure includes a final vector
610called "name" which is one byte long. Thus, adding "namelen" gives us enough
611room to store the "name" string. */
612
613else
614 {
615 m = store_get(sizeof(macro_item) + namelen);
616 if (macros == NULL) macros = m; else mlast->next = m;
617 Ustrncpy(m->name, name, namelen);
618 m->name[namelen] = 0;
619 m->next = NULL;
620 m->command_line = FALSE;
621 }
622
623/* Set the value of the new or redefined macro */
624
625m->replacement = string_copy(s);
626}
627
628
629
630
059ec3d9
PH
631
632/*************************************************
633* Read configuration line *
634*************************************************/
635
636/* A logical line of text is read from the configuration file into the big
637buffer, taking account of macros, .includes, and continuations. The size of
638big_buffer is increased if necessary. The count of configuration lines is
639maintained. Physical input lines starting with # (ignoring leading white space,
640and after macro replacement) and empty logical lines are always ignored.
641Leading and trailing spaces are removed.
642
643If we hit a line of the form "begin xxxx", the xxxx is placed in the
644next_section vector, and the function returns NULL, indicating the end of a
645configuration section. On end-of-file, NULL is returned with next_section
646empty.
647
648Arguments: none
649
650Returns: a pointer to the first non-blank in the line,
651 or NULL if eof or end of section is reached
652*/
653
654static uschar *
655get_config_line(void)
656{
657int startoffset = 0; /* To first non-blank char in logical line */
658int len = 0; /* Of logical line so far */
659int newlen;
660uschar *s, *ss;
661macro_item *m;
662BOOL macro_found;
663
664/* Loop for handling continuation lines, skipping comments, and dealing with
665.include files. */
666
667for (;;)
668 {
669 if (Ufgets(big_buffer+len, big_buffer_size-len, config_file) == NULL)
670 {
671 if (config_file_stack != NULL) /* EOF inside .include */
672 {
f1e894f3 673 (void)fclose(config_file);
059ec3d9
PH
674 config_file = config_file_stack->file;
675 config_filename = config_file_stack->filename;
676 config_lineno = config_file_stack->lineno;
677 config_file_stack = config_file_stack->next;
678 continue;
679 }
680
681 /* EOF at top level */
682
683 if (cstate_stack_ptr >= 0)
684 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
685 "Unexpected end of configuration file: .endif missing");
686
687 if (len != 0) break; /* EOF after continuation */
688 next_section[0] = 0; /* EOF at start of logical line */
689 return NULL;
690 }
691
692 config_lineno++;
693 newlen = len + Ustrlen(big_buffer + len);
694
695 /* Handle pathologically long physical lines - yes, it did happen - by
696 extending big_buffer at this point. The code also copes with very long
697 logical lines. */
698
699 while (newlen == big_buffer_size - 1 && big_buffer[newlen - 1] != '\n')
700 {
701 uschar *newbuffer;
702 big_buffer_size += BIG_BUFFER_SIZE;
703 newbuffer = store_malloc(big_buffer_size);
704
705 /* This use of strcpy is OK because we know that the string in the old
706 buffer is shorter than the new buffer. */
707
708 Ustrcpy(newbuffer, big_buffer);
709 store_free(big_buffer);
710 big_buffer = newbuffer;
711 if (Ufgets(big_buffer+newlen, big_buffer_size-newlen, config_file) == NULL)
712 break;
713 newlen += Ustrlen(big_buffer + newlen);
714 }
715
716 /* Find the true start of the physical line - leading spaces are always
717 ignored. */
718
719 ss = big_buffer + len;
720 while (isspace(*ss)) ss++;
721
722 /* Process the physical line for macros. If this is the start of the logical
723 line, skip over initial text at the start of the line if it starts with an
724 upper case character followed by a sequence of name characters and an equals
725 sign, because that is the definition of a new macro, and we don't do
726 replacement therein. */
727
728 s = ss;
729 if (len == 0 && isupper(*s))
730 {
731 while (isalnum(*s) || *s == '_') s++;
732 while (isspace(*s)) s++;
733 if (*s != '=') s = ss; /* Not a macro definition */
734 }
735
736 /* For each defined macro, scan the line (from after XXX= if present),
737 replacing all occurrences of the macro. */
738
739 macro_found = FALSE;
740 for (m = macros; m != NULL; m = m->next)
741 {
742 uschar *p, *pp;
743 uschar *t = s;
744
745 while ((p = Ustrstr(t, m->name)) != NULL)
746 {
747 int moveby;
748 int namelen = Ustrlen(m->name);
749 int replen = Ustrlen(m->replacement);
750
751 /* Expand the buffer if necessary */
752
753 while (newlen - namelen + replen + 1 > big_buffer_size)
754 {
755 int newsize = big_buffer_size + BIG_BUFFER_SIZE;
756 uschar *newbuffer = store_malloc(newsize);
757 memcpy(newbuffer, big_buffer, newlen + 1);
758 p = newbuffer + (p - big_buffer);
759 s = newbuffer + (s - big_buffer);
760 ss = newbuffer + (ss - big_buffer);
761 t = newbuffer + (t - big_buffer);
762 big_buffer_size = newsize;
763 store_free(big_buffer);
764 big_buffer = newbuffer;
765 }
766
767 /* Shuffle the remaining characters up or down in the buffer before
768 copying in the replacement text. Don't rescan the replacement for this
769 same macro. */
770
771 pp = p + namelen;
772 moveby = replen - namelen;
773 if (moveby != 0)
774 {
775 memmove(p + replen, pp, (big_buffer + newlen) - pp + 1);
776 newlen += moveby;
777 }
778 Ustrncpy(p, m->replacement, replen);
779 t = p + replen;
780 macro_found = TRUE;
781 }
782 }
783
784 /* An empty macro replacement at the start of a line could mean that ss no
785 longer points to the first non-blank character. */
786
787 while (isspace(*ss)) ss++;
788
789 /* Check for comment lines - these are physical lines. */
790
791 if (*ss == '#') continue;
792
793 /* Handle conditionals, which are also applied to physical lines. Conditions
794 are of the form ".ifdef ANYTEXT" and are treated as true if any macro
795 expansion occured on the rest of the line. A preliminary test for the leading
796 '.' saves effort on most lines. */
797
798 if (*ss == '.')
799 {
800 int i;
801
802 /* Search the list of conditional directives */
803
804 for (i = 0; i < cond_list_size; i++)
805 {
806 int n;
807 cond_item *c = cond_list+i;
808 if (Ustrncmp(ss+1, c->name, c->namelen) != 0) continue;
809
810 /* The following character must be white space or end of string */
811
812 n = ss[1 + c->namelen];
813 if (n != ' ' && n != 't' && n != '\n' && n != 0) break;
814
815 /* .ifdef and .ifndef push the current state onto the stack, then set
816 a new one from the table. Stack overflow is an error */
817
818 if (c->pushpop > 0)
819 {
820 if (cstate_stack_ptr >= CSTATE_STACK_SIZE - 1)
821 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
822 ".%s nested too deeply", c->name);
823 cstate_stack[++cstate_stack_ptr] = cstate;
824 cstate = next_cstate[cstate][macro_found? c->action1 : c->action2];
825 }
826
827 /* For any of the others, stack underflow is an error. The next state
828 comes either from the stack (.endif) or from the table. */
829
830 else
831 {
832 if (cstate_stack_ptr < 0)
833 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
834 ".%s without matching .ifdef", c->name);
835 cstate = (c->pushpop < 0)? cstate_stack[cstate_stack_ptr--] :
836 next_cstate[cstate][macro_found? c->action1 : c->action2];
837 }
838
839 /* Having dealt with a directive, break the loop */
840
841 break;
842 }
843
844 /* If we have handled a conditional directive, continue with the next
845 physical line. Otherwise, fall through. */
846
847 if (i < cond_list_size) continue;
848 }
849
850 /* If the conditional state is not 0 (actively using these lines), ignore
851 this input line. */
852
853 if (cstate != 0) continue; /* Conditional skip */
854
855 /* Handle .include lines - these are also physical lines. */
856
857 if (Ustrncmp(ss, ".include", 8) == 0 &&
858 (isspace(ss[8]) ||
859 (Ustrncmp(ss+8, "_if_exists", 10) == 0 && isspace(ss[18]))))
860 {
861 uschar *t;
862 int include_if_exists = isspace(ss[8])? 0 : 10;
863 config_file_item *save;
864 struct stat statbuf;
865
866 ss += 9 + include_if_exists;
867 while (isspace(*ss)) ss++;
868 t = ss + Ustrlen(ss);
869 while (t > ss && isspace(t[-1])) t--;
870 if (*ss == '\"' && t[-1] == '\"')
871 {
872 ss++;
873 t--;
874 }
875 *t = 0;
876
145396a6
PH
877 if (*ss != '/')
878 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, ".include specifies a non-"
879 "absolute path \"%s\"", ss);
880
059ec3d9
PH
881 if (include_if_exists != 0 && (Ustat(ss, &statbuf) != 0)) continue;
882
883 save = store_get(sizeof(config_file_item));
884 save->next = config_file_stack;
885 config_file_stack = save;
886 save->file = config_file;
887 save->filename = config_filename;
888 save->lineno = config_lineno;
889
890 config_file = Ufopen(ss, "rb");
891 if (config_file == NULL)
892 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "failed to open included "
893 "configuration file %s", ss);
894 config_filename = string_copy(ss);
895 config_lineno = 0;
896 continue;
897 }
898
899 /* If this is the start of the logical line, remember where the non-blank
900 data starts. Otherwise shuffle down continuation lines to remove leading
901 white space. */
902
903 if (len == 0)
904 startoffset = ss - big_buffer;
905 else
906 {
907 s = big_buffer + len;
908 if (ss > s)
909 {
910 memmove(s, ss, (newlen - len) - (ss - s) + 1);
911 newlen -= ss - s;
912 }
913 }
914
915 /* Accept the new addition to the line. Remove trailing white space. */
916
917 len = newlen;
918 while (len > 0 && isspace(big_buffer[len-1])) len--;
919 big_buffer[len] = 0;
920
921 /* We are done if the line does not end in backslash and contains some data.
922 Empty logical lines are ignored. For continuations, remove the backslash and
923 go round the loop to read the continuation line. */
924
925 if (len > 0)
926 {
927 if (big_buffer[len-1] != '\\') break; /* End of logical line */
928 big_buffer[--len] = 0; /* Remove backslash */
929 }
930 } /* Loop for reading multiple physical lines */
931
932/* We now have a logical line. Test for the end of a configuration section (or,
933more accurately, for the start of the next section). Place the name of the next
934section in next_section, and return NULL. If the name given is longer than
935next_section, truncate it. It will be unrecognized later, because all the known
936section names do fit. Leave space for pluralizing. */
937
938s = big_buffer + startoffset; /* First non-space character */
939if (strncmpic(s, US"begin ", 6) == 0)
940 {
941 s += 6;
942 while (isspace(*s)) s++;
943 if (big_buffer + len - s > sizeof(next_section) - 2)
944 s[sizeof(next_section) - 2] = 0;
945 Ustrcpy(next_section, s);
946 return NULL;
947 }
948
949/* Return the first non-blank character. */
950
951return s;
952}
953
954
955
956/*************************************************
957* Read a name *
958*************************************************/
959
960/* The yield is the pointer to the next uschar. Names longer than the
961output space are silently truncated. This function is also used from acl.c when
962parsing ACLs.
963
964Arguments:
965 name where to put the name
966 len length of name
967 s input pointer
968
969Returns: new input pointer
970*/
971
972uschar *
973readconf_readname(uschar *name, int len, uschar *s)
974{
975int p = 0;
976while (isspace(*s)) s++;
977if (isalpha(*s))
978 {
979 while (isalnum(*s) || *s == '_')
980 {
981 if (p < len-1) name[p++] = *s;
982 s++;
983 }
984 }
985name[p] = 0;
986while (isspace(*s)) s++;
987return s;
988}
989
990
991
992
993/*************************************************
994* Read a time value *
995*************************************************/
996
997/* This function is also called from outside, to read argument
998time values. The format of a time value is:
999
1000 [<n>w][<n>d][<n>h][<n>m][<n>s]
1001
1002as long as at least one is present. If a format error is encountered,
1003return a negative value. The value must be terminated by the given
1004terminator.
1005
1006Arguments:
1007 s input pointer
1008 terminator required terminating character
1009 return_msec if TRUE, allow fractional seconds and return milliseconds
1010
1011Returns: the time value, or -1 on syntax error
1012 value is seconds if return_msec is FALSE
1013 value is milliseconds if return_msec is TRUE
1014*/
1015
1016int
1017readconf_readtime(uschar *s, int terminator, BOOL return_msec)
1018{
1019int yield = 0;
1020for (;;)
1021 {
1022 int value, count;
1023 double fraction;
1024
1025 if (!isdigit(*s)) return -1;
1026 (void)sscanf(CS s, "%d%n", &value, &count);
1027 s += count;
1028
1029 switch (*s)
1030 {
1031 case 'w': value *= 7;
1032 case 'd': value *= 24;
1033 case 'h': value *= 60;
1034 case 'm': value *= 60;
1035 case 's': s++;
1036 break;
1037
1038 case '.':
1039 if (!return_msec) return -1;
1040 (void)sscanf(CS s, "%lf%n", &fraction, &count);
1041 s += count;
1042 if (*s++ != 's') return -1;
1043 yield += (int)(fraction * 1000.0);
1044 break;
1045
1046 default: return -1;
1047 }
1048
1049 if (return_msec) value *= 1000;
1050 yield += value;
1051 if (*s == terminator) return yield;
1052 }
1053/* Control never reaches here. */
1054}
1055
1056
1057
1058/*************************************************
1059* Read a fixed point value *
1060*************************************************/
1061
1062/* The value is returned *1000
1063
1064Arguments:
1065 s input pointer
1066 terminator required terminator
1067
1068Returns: the value, or -1 on error
1069*/
1070
1071static int
1072readconf_readfixed(uschar *s, int terminator)
1073{
1074int yield = 0;
1075int value, count;
1076if (!isdigit(*s)) return -1;
1077(void)sscanf(CS s, "%d%n", &value, &count);
1078s += count;
1079yield = value * 1000;
1080if (*s == '.')
1081 {
1082 int m = 100;
1083 while (isdigit((*(++s))))
1084 {
1085 yield += (*s - '0') * m;
1086 m /= 10;
1087 }
1088 }
1089
1090return (*s == terminator)? yield : (-1);
1091}
1092
1093
1094
1095/*************************************************
1096* Find option in list *
1097*************************************************/
1098
1099/* The lists are always in order, so binary chop can be used.
1100
1101Arguments:
1102 name the option name to search for
1103 ol the first entry in the option list
1104 last one more than the offset of the last entry in the option list
1105
1106Returns: pointer to an option entry, or NULL if not found
1107*/
1108
1109static optionlist *
1110find_option(uschar *name, optionlist *ol, int last)
1111{
1112int first = 0;
1113while (last > first)
1114 {
1115 int middle = (first + last)/2;
1116 int c = Ustrcmp(name, ol[middle].name);
1117 if (c == 0) return ol + middle;
1118 else if (c > 0) first = middle + 1;
1119 else last = middle;
1120 }
1121return NULL;
1122}
1123
1124
1125
1126/*************************************************
1127* Find a set flag in option list *
1128*************************************************/
1129
1130/* Because some versions of Unix make no restrictions on the values of uids and
1131gids (even negative ones), we cannot represent "unset" by a special value.
1132There is therefore a separate boolean variable for each one indicating whether
1133a value is set or not. This function returns a pointer to the boolean, given
1134the original option name. It is a major disaster if the flag cannot be found.
1135
1136Arguments:
1137 name the name of the uid or gid option
1138 oltop points to the start of the relevant option list
1139 last one more than the offset of the last item in the option list
1140 data_block NULL when reading main options => data values in the option
1141 list are absolute addresses; otherwise they are byte offsets
1142 in data_block (used for driver options)
1143
1144Returns: a pointer to the boolean flag.
1145*/
1146
1147static BOOL *
1148get_set_flag(uschar *name, optionlist *oltop, int last, void *data_block)
1149{
1150optionlist *ol;
1151uschar name2[64];
1152sprintf(CS name2, "*set_%.50s", name);
1153ol = find_option(name2, oltop, last);
1154if (ol == NULL) log_write(0, LOG_MAIN|LOG_PANIC_DIE,
1155 "Exim internal error: missing set flag for %s", name);
1156return (data_block == NULL)? (BOOL *)(ol->value) :
1157 (BOOL *)((uschar *)data_block + (long int)(ol->value));
1158}
1159
1160
1161
1162
1163/*************************************************
1164* Output extra characters message and die *
1165*************************************************/
1166
1167/* Called when an option line has junk on the end. Sometimes this is because
1168the sysadmin thinks comments are permitted.
1169
1170Arguments:
1171 s points to the extra characters
1172 t1..t3 strings to insert in the log message
1173
1174Returns: doesn't return; dies
1175*/
1176
1177static void
1178extra_chars_error(uschar *s, uschar *t1, uschar *t2, uschar *t3)
1179{
1180uschar *comment = US"";
1181if (*s == '#') comment = US" (# is comment only at line start)";
1182log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1183 "extra characters follow %s%s%s%s", t1, t2, t3, comment);
1184}
1185
1186
1187
1188/*************************************************
1189* Read rewrite information *
1190*************************************************/
1191
1192/* Each line of rewrite information contains:
1193
1194. A complete address in the form user@domain, possibly with
1195 leading * for each part; or alternatively, a regex.
1196
1197. A replacement string (which will be expanded).
1198
1199. An optional sequence of one-letter flags, indicating which
1200 headers etc. to apply this rule to.
1201
1202All this is decoded and placed into a control block. The OR of the flags is
1203maintained in a common word.
1204
1205Arguments:
1206 p points to the string that makes up the rule
1207 existflags points to the overall flag word
1208 isglobal TRUE if reading global rewrite rules
1209
1210Returns: the control block for the parsed rule.
1211*/
1212
1213static rewrite_rule *
1214readconf_one_rewrite(uschar *p, int *existflags, BOOL isglobal)
1215{
1216rewrite_rule *next = store_get(sizeof(rewrite_rule));
1217
1218next->next = NULL;
1219next->key = string_dequote(&p);
1220
1221while (isspace(*p)) p++;
1222if (*p == 0)
1223 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1224 "missing rewrite replacement string");
1225
1226next->flags = 0;
1227next->replacement = string_dequote(&p);
1228
1229while (*p != 0) switch (*p++)
1230 {
1231 case ' ': case '\t': break;
1232
1233 case 'q': next->flags |= rewrite_quit; break;
1234 case 'w': next->flags |= rewrite_whole; break;
1235
1236 case 'h': next->flags |= rewrite_all_headers; break;
1237 case 's': next->flags |= rewrite_sender; break;
1238 case 'f': next->flags |= rewrite_from; break;
1239 case 't': next->flags |= rewrite_to; break;
1240 case 'c': next->flags |= rewrite_cc; break;
1241 case 'b': next->flags |= rewrite_bcc; break;
1242 case 'r': next->flags |= rewrite_replyto; break;
1243
1244 case 'E': next->flags |= rewrite_all_envelope; break;
1245 case 'F': next->flags |= rewrite_envfrom; break;
1246 case 'T': next->flags |= rewrite_envto; break;
1247
1248 case 'Q': next->flags |= rewrite_qualify; break;
1249 case 'R': next->flags |= rewrite_repeat; break;
1250
1251 case 'S':
1252 next->flags |= rewrite_smtp;
1253 if (next->key[0] != '^' && Ustrncmp(next->key, "\\N^", 3) != 0)
1254 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1255 "rewrite rule has the S flag but is not a regular expression");
1256 break;
1257
1258 default:
1259 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1260 "unknown rewrite flag character '%c' "
1261 "(could be missing quotes round replacement item)", p[-1]);
1262 break;
1263 }
1264
1265/* If no action flags are set, set all the "normal" rewrites. */
1266
1267if ((next->flags & (rewrite_all | rewrite_smtp)) == 0)
1268 next->flags |= isglobal? rewrite_all : rewrite_all_headers;
1269
1270/* Remember which exist, for optimization, and return the rule */
1271
1272*existflags |= next->flags;
1273return next;
1274}
1275
1276
1277
1278
1279/*************************************************
1280* Read global rewrite information *
1281*************************************************/
1282
1283/* Each line is a single rewrite rule; it is parsed into a control block
1284by readconf_one_rewrite(), and its flags are ORed into the global flag
1285word rewrite_existflags. */
1286
1287void
1288readconf_rewrites(void)
1289{
1290rewrite_rule **chain = &global_rewrite_rules;
1291uschar *p;
1292
1293while ((p = get_config_line()) != NULL)
1294 {
1295 rewrite_rule *next = readconf_one_rewrite(p, &rewrite_existflags, TRUE);
1296 *chain = next;
1297 chain = &(next->next);
1298 }
1299}
1300
1301
1302
1303/*************************************************
1304* Read a string *
1305*************************************************/
1306
1307/* Strings are read into the normal store pool. As long we aren't too
1308near the end of the current block, the string will just use what is necessary
1309on the top of the stacking pool, because string_cat() uses the extension
1310mechanism.
1311
1312Argument:
1313 s the rest of the input line
1314 name the option name (for errors)
1315
1316Returns: pointer to the string
1317*/
1318
1319static uschar *
1320read_string(uschar *s, uschar *name)
1321{
1322uschar *yield;
1323uschar *ss;
1324
1325if (*s != '\"') return string_copy(s);
1326
1327ss = s;
1328yield = string_dequote(&s);
1329
1330if (s == ss+1 || s[-1] != '\"')
1331 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1332 "missing quote at end of string value for %s", name);
1333
1334if (*s != 0) extra_chars_error(s, US"string value for ", name, US"");
1335
1336return yield;
1337}
1338
1339
1340/*************************************************
1341* Handle option line *
1342*************************************************/
1343
1344/* This function is called from several places to process a line containing the
1345setting of an option. The first argument is the line to be decoded; it has been
1346checked not to be empty and not to start with '#'. Trailing newlines and white
1347space have been removed. The second argument is a pointer to the list of
1348variable names that are to be recognized, together with their types and
1349locations, and the third argument gives the number of entries in the list.
1350
1351The fourth argument is a pointer to a data block. If it is NULL, then the data
1352values in the options list are absolute addresses. Otherwise, they are byte
1353offsets in the data block.
1354
1355String option data may continue onto several lines; this function reads further
1356data from config_file if necessary.
1357
1358The yield of this function is normally zero. If a string continues onto
1359multiple lines, then the data value is permitted to be followed by a comma
1360or a semicolon (for use in drivers) and the yield is that character.
1361
1362Arguments:
1363 buffer contains the configuration line to be handled
1364 oltop points to the start of the relevant option list
1365 last one more than the offset of the last item in the option list
1366 data_block NULL when reading main options => data values in the option
1367 list are absolute addresses; otherwise they are byte offsets
1368 in data_block when they have opt_public set; otherwise
1369 they are byte offsets in data_block->options_block.
1370 unknown_txt format string to use in panic message for unknown option;
1371 must contain %s for option name
1372 if given as NULL, don't panic on unknown option
1373
1374Returns: TRUE if an option was read successfully,
1375 FALSE false for an unknown option if unknown_txt == NULL,
1376 otherwise panic and die on an unknown option
1377*/
1378
1379static BOOL
1380readconf_handle_option(uschar *buffer, optionlist *oltop, int last,
1381 void *data_block, uschar *unknown_txt)
1382{
1383int ptr = 0;
1384int offset = 0;
1385int n, count, type, value;
1386int issecure = 0;
1387uid_t uid;
1388gid_t gid;
1389BOOL boolvalue = TRUE;
1390BOOL freesptr = TRUE;
1391optionlist *ol, *ol2;
1392struct passwd *pw;
1393void *reset_point;
1394int intbase = 0;
1395uschar *inttype = US"";
1396uschar *sptr;
1397uschar *s = buffer;
532be449
PP
1398uschar *saved_condition, *strtemp;
1399uschar **str_target;
059ec3d9
PH
1400uschar name[64];
1401uschar name2[64];
1402
1403/* There may be leading spaces; thereafter, we expect an option name starting
1404with a letter. */
1405
1406while (isspace(*s)) s++;
1407if (!isalpha(*s))
1408 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "option setting expected: %s", s);
1409
1410/* Read the name of the option, and skip any subsequent white space. If
1411it turns out that what we read was "hide", set the flag indicating that
1412this is a secure option, and loop to read the next word. */
1413
1414for (n = 0; n < 2; n++)
1415 {
1416 while (isalnum(*s) || *s == '_')
1417 {
1418 if (ptr < sizeof(name)-1) name[ptr++] = *s;
1419 s++;
1420 }
1421 name[ptr] = 0;
1422 while (isspace(*s)) s++;
1423 if (Ustrcmp(name, "hide") != 0) break;
1424 issecure = opt_secure;
1425 ptr = 0;
1426 }
1427
1428/* Deal with "no_" or "not_" here for booleans */
1429
1430if (Ustrncmp(name, "no_", 3) == 0)
1431 {
1432 boolvalue = FALSE;
1433 offset = 3;
1434 }
1435
1436if (Ustrncmp(name, "not_", 4) == 0)
1437 {
1438 boolvalue = FALSE;
1439 offset = 4;
1440 }
1441
1442/* Search the list for the given name. A non-existent name, or an option that
1443is set twice, is a disaster. */
1444
1445ol = find_option(name + offset, oltop, last);
1446
1447if (ol == NULL)
1448 {
1449 if (unknown_txt == NULL) return FALSE;
1450 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, CS unknown_txt, name);
1451 }
1452
846726c5
JH
1453if ((ol->type & opt_set) && !(ol->type & (opt_rep_con | opt_rep_str)))
1454 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1455 "\"%s\" option set for the second time", name);
059ec3d9
PH
1456
1457ol->type |= opt_set | issecure;
1458type = ol->type & opt_mask;
1459
1460/* Types with data values must be followed by '='; the "no[t]_" prefix
1461applies only to boolean values. */
1462
1463if (type < opt_bool || type > opt_bool_last)
1464 {
1465 if (offset != 0)
1466 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1467 "negation prefix applied to a non-boolean option");
1468 if (*s == 0)
1469 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1470 "unexpected end of line (data missing) after %s", name);
1471 if (*s != '=')
1472 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "missing \"=\" after %s", name);
1473 }
1474
1475/* If a boolean wasn't preceded by "no[t]_" it can be followed by = and
1476true/false/yes/no, or, in the case of opt_expanded_bool, a general string that
1477ultimately expands to one of those values. */
1478
1479else if (*s != 0 && (offset != 0 || *s != '='))
1480 extra_chars_error(s, US"boolean option ", name, US"");
1481
1482/* Skip white space after = */
1483
1484if (*s == '=') while (isspace((*(++s))));
1485
1486/* If there is a data block and the opt_public flag is not set, change
1487the data block pointer to the private options block. */
1488
1489if (data_block != NULL && (ol->type & opt_public) == 0)
1490 data_block = (void *)(((driver_instance *)data_block)->options_block);
1491
1492/* Now get the data according to the type. */
1493
1494switch (type)
1495 {
1496 /* If a string value is not enclosed in quotes, it consists of
1497 the rest of the current line, verbatim. Otherwise, string escapes
1498 are processed.
1499
1500 A transport is specified as a string, which is then looked up in the
1501 list of transports. A search type is specified as one of a number of
1502 known strings.
1503
1504 A set or rewrite rules for a driver is specified as a string, which is
1505 then parsed into a suitable chain of control blocks.
1506
1507 Uids and gids are specified as strings which are then looked up in the
1508 passwd file. Lists of uids and gids are similarly specified as colon-
1509 separated strings. */
1510
1511 case opt_stringptr:
1512 case opt_uid:
1513 case opt_gid:
1514 case opt_expand_uid:
1515 case opt_expand_gid:
1516 case opt_uidlist:
1517 case opt_gidlist:
1518 case opt_rewrite:
1519
1520 reset_point = sptr = read_string(s, name);
1521
1522 /* Having read a string, we now have several different ways of using it,
1523 depending on the data type, so do another switch. If keeping the actual
1524 string is not required (because it is interpreted), freesptr is set TRUE,
1525 and at the end we reset the pool. */
1526
1527 switch (type)
1528 {
1529 /* If this was a string, set the variable to point to the new string,
1530 and set the flag so its store isn't reclaimed. If it was a list of rewrite
1531 rules, we still keep the string (for printing), and parse the rules into a
1532 control block and flags word. */
1533
1534 case opt_stringptr:
532be449
PP
1535 if (data_block == NULL)
1536 str_target = (uschar **)(ol->value);
1537 else
1538 str_target = (uschar **)((uschar *)data_block + (long int)(ol->value));
846726c5 1539 if (ol->type & opt_rep_con)
532be449 1540 {
6a8de854
PP
1541 /* We already have a condition, we're conducting a crude hack to let
1542 multiple condition rules be chained together, despite storing them in
1543 text form. */
532be449 1544 saved_condition = *str_target;
6a8de854 1545 strtemp = string_sprintf("${if and{{bool_lax{%s}}{bool_lax{%s}}}}",
532be449
PP
1546 saved_condition, sptr);
1547 *str_target = string_copy_malloc(strtemp);
846726c5
JH
1548 /* TODO(pdp): there is a memory leak here and just below
1549 when we set 3 or more conditions; I still don't
1550 understand the store mechanism enough to know
1551 what's the safe way to free content from an earlier store.
6a8de854
PP
1552 AFAICT, stores stack, so freeing an early stored item also stores
1553 all data alloc'd after it. If we knew conditions were adjacent,
1554 we could survive that, but we don't. So I *think* we need to take
1555 another bit from opt_type to indicate "malloced"; this seems like
1556 quite a hack, especially for this one case. It also means that
1557 we can't ever reclaim the store from the *first* condition.
1558
1559 Because we only do this once, near process start-up, I'm prepared to
1560 let this slide for the time being, even though it rankles. */
532be449 1561 }
846726c5
JH
1562 else if (*str_target && (ol->type & opt_rep_str))
1563 {
1564 uschar sep = Ustrncmp(name, "headers_add", 11)==0 ? '\n' : ':';
1565 saved_condition = *str_target;
d9d29e05 1566 strtemp = saved_condition + Ustrlen(saved_condition)-1;
846726c5
JH
1567 if (*strtemp == sep) *strtemp = 0; /* eliminate trailing list-sep */
1568 strtemp = string_sprintf("%s%c%s", saved_condition, sep, sptr);
1569 *str_target = string_copy_malloc(strtemp);
1570 }
532be449
PP
1571 else
1572 {
1573 *str_target = sptr;
1574 freesptr = FALSE;
1575 }
1576 break;
1577
059ec3d9
PH
1578 case opt_rewrite:
1579 if (data_block == NULL)
1580 *((uschar **)(ol->value)) = sptr;
1581 else
1582 *((uschar **)((uschar *)data_block + (long int)(ol->value))) = sptr;
1583 freesptr = FALSE;
1584 if (type == opt_rewrite)
1585 {
1586 int sep = 0;
1587 int *flagptr;
1588 uschar *p = sptr;
1589 rewrite_rule **chain;
1590 optionlist *ol3;
1591
1592 sprintf(CS name2, "*%.50s_rules", name);
1593 ol2 = find_option(name2, oltop, last);
1594 sprintf(CS name2, "*%.50s_flags", name);
1595 ol3 = find_option(name2, oltop, last);
1596
1597 if (ol2 == NULL || ol3 == NULL)
1598 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1599 "rewrite rules not available for driver");
1600
1601 if (data_block == NULL)
1602 {
1603 chain = (rewrite_rule **)(ol2->value);
1604 flagptr = (int *)(ol3->value);
1605 }
1606 else
1607 {
1608 chain = (rewrite_rule **)((uschar *)data_block + (long int)(ol2->value));
1609 flagptr = (int *)((uschar *)data_block + (long int)(ol3->value));
1610 }
1611
1612 while ((p = string_nextinlist(&sptr, &sep, big_buffer, BIG_BUFFER_SIZE))
1613 != NULL)
1614 {
1615 rewrite_rule *next = readconf_one_rewrite(p, flagptr, FALSE);
1616 *chain = next;
1617 chain = &(next->next);
1618 }
1619
1620 if ((*flagptr & (rewrite_all_envelope | rewrite_smtp)) != 0)
1621 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "rewrite rule specifies a "
1622 "non-header rewrite - not allowed at transport time -");
1623 }
1624 break;
1625
1626 /* If it was an expanded uid, see if there is any expansion to be
1627 done by checking for the presence of a $ character. If there is, save it
1628 in the corresponding *expand_user option field. Otherwise, fall through
1629 to treat it as a fixed uid. Ensure mutual exclusivity of the two kinds
1630 of data. */
1631
1632 case opt_expand_uid:
1633 sprintf(CS name2, "*expand_%.50s", name);
1634 ol2 = find_option(name2, oltop, last);
1635 if (ol2 != NULL)
1636 {
1637 uschar *ss = (Ustrchr(sptr, '$') != NULL)? sptr : NULL;
1638
1639 if (data_block == NULL)
1640 *((uschar **)(ol2->value)) = ss;
1641 else
1642 *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = ss;
1643
1644 if (ss != NULL)
1645 {
1646 *(get_set_flag(name, oltop, last, data_block)) = FALSE;
1647 freesptr = FALSE;
1648 break;
1649 }
1650 }
1651
1652 /* Look up a fixed uid, and also make use of the corresponding gid
1653 if a passwd entry is returned and the gid has not been set. */
1654
1655 case opt_uid:
1656 if (!route_finduser(sptr, &pw, &uid))
1657 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "user %s was not found", sptr);
1658 if (data_block == NULL)
1659 *((uid_t *)(ol->value)) = uid;
1660 else
1661 *((uid_t *)((uschar *)data_block + (long int)(ol->value))) = uid;
1662
1663 /* Set the flag indicating a fixed value is set */
1664
1665 *(get_set_flag(name, oltop, last, data_block)) = TRUE;
1666
1667 /* Handle matching gid if we have a passwd entry: done by finding the
1668 same name with terminating "user" changed to "group"; if not found,
1669 ignore. Also ignore if the value is already set. */
1670
1671 if (pw == NULL) break;
1672 Ustrcpy(name+Ustrlen(name)-4, "group");
1673 ol2 = find_option(name, oltop, last);
1674 if (ol2 != NULL && ((ol2->type & opt_mask) == opt_gid ||
1675 (ol2->type & opt_mask) == opt_expand_gid))
1676 {
1677 BOOL *set_flag = get_set_flag(name, oltop, last, data_block);
1678 if (! *set_flag)
1679 {
1680 if (data_block == NULL)
1681 *((gid_t *)(ol2->value)) = pw->pw_gid;
1682 else
1683 *((gid_t *)((uschar *)data_block + (long int)(ol2->value))) = pw->pw_gid;
1684 *set_flag = TRUE;
1685 }
1686 }
1687 break;
1688
1689 /* If it was an expanded gid, see if there is any expansion to be
1690 done by checking for the presence of a $ character. If there is, save it
1691 in the corresponding *expand_user option field. Otherwise, fall through
1692 to treat it as a fixed gid. Ensure mutual exclusivity of the two kinds
1693 of data. */
1694
1695 case opt_expand_gid:
1696 sprintf(CS name2, "*expand_%.50s", name);
1697 ol2 = find_option(name2, oltop, last);
1698 if (ol2 != NULL)
1699 {
1700 uschar *ss = (Ustrchr(sptr, '$') != NULL)? sptr : NULL;
1701
1702 if (data_block == NULL)
1703 *((uschar **)(ol2->value)) = ss;
1704 else
1705 *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = ss;
1706
1707 if (ss != NULL)
1708 {
1709 *(get_set_flag(name, oltop, last, data_block)) = FALSE;
1710 freesptr = FALSE;
1711 break;
1712 }
1713 }
1714
1715 /* Handle freestanding gid */
1716
1717 case opt_gid:
1718 if (!route_findgroup(sptr, &gid))
1719 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "group %s was not found", sptr);
1720 if (data_block == NULL)
1721 *((gid_t *)(ol->value)) = gid;
1722 else
1723 *((gid_t *)((uschar *)data_block + (long int)(ol->value))) = gid;
1724 *(get_set_flag(name, oltop, last, data_block)) = TRUE;
1725 break;
1726
1727 /* If it was a uid list, look up each individual entry, and build
1728 a vector of uids, with a count in the first element. Put the vector
1729 in malloc store so we can free the string. (We are reading into
1730 permanent store already.) */
1731
1732 case opt_uidlist:
1733 {
1734 int count = 1;
1735 uid_t *list;
1736 int ptr = 0;
0925ede6
PH
1737 uschar *p;
1738 uschar *op = expand_string (sptr);
1739
1740 if (op == NULL)
1741 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "failed to expand %s: %s",
1742 name, expand_string_message);
059ec3d9 1743
0925ede6 1744 p = op;
059ec3d9 1745 if (*p != 0) count++;
0925ede6 1746 while (*p != 0) if (*p++ == ':' && *p != 0) count++;
059ec3d9
PH
1747 list = store_malloc(count*sizeof(uid_t));
1748 list[ptr++] = (uid_t)(count - 1);
1749
1750 if (data_block == NULL)
1751 *((uid_t **)(ol->value)) = list;
1752 else
1753 *((uid_t **)((uschar *)data_block + (long int)(ol->value))) = list;
1754
0925ede6 1755 p = op;
059ec3d9
PH
1756 while (count-- > 1)
1757 {
1758 int sep = 0;
1759 (void)string_nextinlist(&p, &sep, big_buffer, BIG_BUFFER_SIZE);
1760 if (!route_finduser(big_buffer, NULL, &uid))
1761 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "user %s was not found",
1762 big_buffer);
1763 list[ptr++] = uid;
1764 }
1765 }
1766 break;
1767
1768 /* If it was a gid list, look up each individual entry, and build
1769 a vector of gids, with a count in the first element. Put the vector
1770 in malloc store so we can free the string. (We are reading into permanent
1771 store already.) */
1772
1773 case opt_gidlist:
1774 {
1775 int count = 1;
1776 gid_t *list;
1777 int ptr = 0;
0925ede6
PH
1778 uschar *p;
1779 uschar *op = expand_string (sptr);
1780
1781 if (op == NULL)
1782 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "failed to expand %s: %s",
1783 name, expand_string_message);
059ec3d9 1784
0925ede6 1785 p = op;
059ec3d9 1786 if (*p != 0) count++;
0925ede6 1787 while (*p != 0) if (*p++ == ':' && *p != 0) count++;
059ec3d9
PH
1788 list = store_malloc(count*sizeof(gid_t));
1789 list[ptr++] = (gid_t)(count - 1);
1790
1791 if (data_block == NULL)
1792 *((gid_t **)(ol->value)) = list;
1793 else
1794 *((gid_t **)((uschar *)data_block + (long int)(ol->value))) = list;
1795
0925ede6 1796 p = op;
059ec3d9
PH
1797 while (count-- > 1)
1798 {
1799 int sep = 0;
1800 (void)string_nextinlist(&p, &sep, big_buffer, BIG_BUFFER_SIZE);
1801 if (!route_findgroup(big_buffer, &gid))
1802 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "group %s was not found",
1803 big_buffer);
1804 list[ptr++] = gid;
1805 }
1806 }
1807 break;
1808 }
1809
1810 /* Release store if the value of the string doesn't need to be kept. */
1811
1812 if (freesptr) store_reset(reset_point);
1813 break;
1814
1815 /* Expanded boolean: if no characters follow, or if there are no dollar
1816 characters, this is a fixed-valued boolean, and we fall through. Otherwise,
1817 save the string for later expansion in the alternate place. */
1818
1819 case opt_expand_bool:
1820 if (*s != 0 && Ustrchr(s, '$') != 0)
1821 {
1822 sprintf(CS name2, "*expand_%.50s", name);
1823 ol2 = find_option(name2, oltop, last);
1824 if (ol2 != NULL)
1825 {
1826 reset_point = sptr = read_string(s, name);
1827 if (data_block == NULL)
1828 *((uschar **)(ol2->value)) = sptr;
1829 else
1830 *((uschar **)((uschar *)data_block + (long int)(ol2->value))) = sptr;
1831 freesptr = FALSE;
1832 break;
1833 }
1834 }
1835 /* Fall through */
1836
1837 /* Boolean: if no characters follow, the value is boolvalue. Otherwise
1838 look for yes/not/true/false. Some booleans are stored in a single bit in
1839 a single int. There's a special fudge for verify settings; without a suffix
1840 they set both xx_sender and xx_recipient. The table points to the sender
1841 value; search subsequently for the recipient. There's another special case:
1842 opt_bool_set also notes when a boolean has been set. */
1843
1844 case opt_bool:
1845 case opt_bit:
1846 case opt_bool_verify:
1847 case opt_bool_set:
1848 if (*s != 0)
1849 {
1850 s = readconf_readname(name2, 64, s);
1851 if (strcmpic(name2, US"true") == 0 || strcmpic(name2, US"yes") == 0)
1852 boolvalue = TRUE;
1853 else if (strcmpic(name2, US"false") == 0 || strcmpic(name2, US"no") == 0)
1854 boolvalue = FALSE;
1855 else log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1856 "\"%s\" is not a valid value for the \"%s\" option", name2, name);
1857 if (*s != 0) extra_chars_error(s, string_sprintf("\"%s\" ", name2),
1858 US"for boolean option ", name);
1859 }
1860
1861 /* Handle single-bit type. */
1862
1863 if (type == opt_bit)
1864 {
1865 int bit = 1 << ((ol->type >> 16) & 31);
1866 int *ptr = (data_block == NULL)?
1867 (int *)(ol->value) :
1868 (int *)((uschar *)data_block + (long int)ol->value);
1869 if (boolvalue) *ptr |= bit; else *ptr &= ~bit;
1870 break;
1871 }
1872
1873 /* Handle full BOOL types */
1874
1875 if (data_block == NULL)
1876 *((BOOL *)(ol->value)) = boolvalue;
1877 else
1878 *((BOOL *)((uschar *)data_block + (long int)(ol->value))) = boolvalue;
1879
1880 /* Verify fudge */
1881
1882 if (type == opt_bool_verify)
1883 {
1884 sprintf(CS name2, "%.50s_recipient", name + offset);
1885 ol2 = find_option(name2, oltop, last);
1886 if (ol2 != NULL)
1887 {
1888 if (data_block == NULL)
1889 *((BOOL *)(ol2->value)) = boolvalue;
1890 else
1891 *((BOOL *)((uschar *)data_block + (long int)(ol2->value))) = boolvalue;
1892 }
1893 }
1894
1895 /* Note that opt_bool_set type is set, if there is somewhere to do so */
1896
1897 else if (type == opt_bool_set)
1898 {
1899 sprintf(CS name2, "*set_%.50s", name + offset);
1900 ol2 = find_option(name2, oltop, last);
1901 if (ol2 != NULL)
1902 {
1903 if (data_block == NULL)
1904 *((BOOL *)(ol2->value)) = TRUE;
1905 else
1906 *((BOOL *)((uschar *)data_block + (long int)(ol2->value))) = TRUE;
1907 }
1908 }
1909 break;
1910
1911 /* Octal integer */
1912
1913 case opt_octint:
1914 intbase = 8;
1915 inttype = US"octal ";
1916
1917 /* Integer: a simple(ish) case; allow octal and hex formats, and
1918 suffixes K and M. The different types affect output, not input. */
1919
1920 case opt_mkint:
1921 case opt_int:
1922 {
1923 uschar *endptr;
7e8d92ba
PH
1924 long int lvalue;
1925
059ec3d9 1926 errno = 0;
7e8d92ba 1927 lvalue = strtol(CS s, CSS &endptr, intbase);
059ec3d9
PH
1928
1929 if (endptr == s)
1930 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "%sinteger expected for %s",
1931 inttype, name);
1932
1933 if (errno != ERANGE)
1934 {
1935 if (tolower(*endptr) == 'k')
1936 {
7e8d92ba
PH
1937 if (lvalue > INT_MAX/1024 || lvalue < INT_MIN/1024) errno = ERANGE;
1938 else lvalue *= 1024;
059ec3d9
PH
1939 endptr++;
1940 }
1941 else if (tolower(*endptr) == 'm')
1942 {
7e8d92ba 1943 if (lvalue > INT_MAX/(1024*1024) || lvalue < INT_MIN/(1024*1024))
059ec3d9 1944 errno = ERANGE;
7e8d92ba 1945 else lvalue *= 1024*1024;
059ec3d9
PH
1946 endptr++;
1947 }
1948 }
1949
7e8d92ba
PH
1950 if (errno == ERANGE || lvalue > INT_MAX || lvalue < INT_MIN)
1951 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1952 "absolute value of integer \"%s\" is too large (overflow)", s);
059ec3d9
PH
1953
1954 while (isspace(*endptr)) endptr++;
1955 if (*endptr != 0)
1956 extra_chars_error(endptr, inttype, US"integer value for ", name);
7e8d92ba
PH
1957
1958 value = (int)lvalue;
059ec3d9
PH
1959 }
1960
1961 if (data_block == NULL)
1962 *((int *)(ol->value)) = value;
1963 else
1964 *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
1965 break;
1966
1967 /* Integer held in K: again, allow octal and hex formats, and suffixes K and
1968 M. */
1969
1970 case opt_Kint:
1971 {
1972 uschar *endptr;
1973 errno = 0;
1974 value = strtol(CS s, CSS &endptr, intbase);
1975
1976 if (endptr == s)
1977 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "%sinteger expected for %s",
1978 inttype, name);
1979
1980 if (errno != ERANGE)
1981 {
1982 if (tolower(*endptr) == 'm')
1983 {
1984 if (value > INT_MAX/1024 || value < INT_MIN/1024) errno = ERANGE;
1985 else value *= 1024;
1986 endptr++;
1987 }
1988 else if (tolower(*endptr) == 'k')
1989 {
1990 endptr++;
1991 }
1992 else
1993 {
1994 value = (value + 512)/1024;
1995 }
1996 }
1997
1998 if (errno == ERANGE) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
1999 "absolute value of integer \"%s\" is too large (overflow)", s);
2000
2001 while (isspace(*endptr)) endptr++;
2002 if (*endptr != 0)
2003 extra_chars_error(endptr, inttype, US"integer value for ", name);
2004 }
2005
2006 if (data_block == NULL)
2007 *((int *)(ol->value)) = value;
2008 else
2009 *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
2010 break;
2011
2012 /* Fixed-point number: held to 3 decimal places. */
2013
2014 case opt_fixed:
2015 if (sscanf(CS s, "%d%n", &value, &count) != 1)
2016 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2017 "fixed-point number expected for %s", name);
2018
2019 if (value < 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2020 "integer \"%s\" is too large (overflow)", s);
2021
2022 value *= 1000;
2023
2024 if (value < 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2025 "integer \"%s\" is too large (overflow)", s);
2026
2027 if (s[count] == '.')
2028 {
2029 int d = 100;
2030 while (isdigit(s[++count]))
2031 {
2032 value += (s[count] - '0') * d;
2033 d /= 10;
2034 }
2035 }
2036
2037 while (isspace(s[count])) count++;
2038
2039 if (s[count] != 0)
2040 extra_chars_error(s+count, US"fixed-point value for ", name, US"");
2041
2042 if (data_block == NULL)
2043 *((int *)(ol->value)) = value;
2044 else
2045 *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
2046 break;
2047
2048 /* There's a special routine to read time values. */
2049
2050 case opt_time:
2051 value = readconf_readtime(s, 0, FALSE);
2052 if (value < 0)
2053 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "invalid time value for %s",
2054 name);
2055 if (data_block == NULL)
2056 *((int *)(ol->value)) = value;
2057 else
2058 *((int *)((uschar *)data_block + (long int)(ol->value))) = value;
2059 break;
2060
2061 /* A time list is a list of colon-separated times, with the first
2062 element holding the size of the list and the second the number of
2063 entries used. */
2064
2065 case opt_timelist:
2066 {
2067 int count = 0;
2068 int *list = (data_block == NULL)?
2069 (int *)(ol->value) :
2070 (int *)((uschar *)data_block + (long int)(ol->value));
2071
2072 if (*s != 0) for (count = 1; count <= list[0] - 2; count++)
2073 {
2074 int terminator = 0;
2075 uschar *snext = Ustrchr(s, ':');
2076 if (snext != NULL)
2077 {
2078 uschar *ss = snext;
2079 while (ss > s && isspace(ss[-1])) ss--;
2080 terminator = *ss;
2081 }
2082 value = readconf_readtime(s, terminator, FALSE);
2083 if (value < 0)
2084 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "invalid time value for %s",
2085 name);
2086 if (count > 1 && value <= list[count])
2087 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2088 "time value out of order for %s", name);
2089 list[count+1] = value;
2090 if (snext == NULL) break;
2091 s = snext + 1;
2092 while (isspace(*s)) s++;
2093 }
2094
2095 if (count > list[0] - 2)
2096 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "too many time values for %s",
2097 name);
2098 if (count > 0 && list[2] == 0) count = 0;
2099 list[1] = count;
2100 }
2101
2102 break;
2103 }
2104
2105return TRUE;
2106}
2107
2108
2109
2110/*************************************************
2111* Print a time value *
2112*************************************************/
2113
2114/*
2115Argument: a time value in seconds
2116Returns: pointer to a fixed buffer containing the time as a string,
2117 in readconf_readtime() format
2118*/
2119
2120uschar *
2121readconf_printtime(int t)
2122{
2123int s, m, h, d, w;
2124uschar *p = time_buffer;
2125
ea49d0e1
PH
2126if (t < 0)
2127 {
2128 *p++ = '-';
2129 t = -t;
2130 }
2131
059ec3d9
PH
2132s = t % 60;
2133t /= 60;
2134m = t % 60;
2135t /= 60;
2136h = t % 24;
2137t /= 24;
2138d = t % 7;
2139w = t/7;
2140
2141if (w > 0) { sprintf(CS p, "%dw", w); while (*p) p++; }
2142if (d > 0) { sprintf(CS p, "%dd", d); while (*p) p++; }
2143if (h > 0) { sprintf(CS p, "%dh", h); while (*p) p++; }
2144if (m > 0) { sprintf(CS p, "%dm", m); while (*p) p++; }
2145if (s > 0 || p == time_buffer) sprintf(CS p, "%ds", s);
2146
2147return time_buffer;
2148}
2149
2150
2151
2152/*************************************************
2153* Print an individual option value *
2154*************************************************/
2155
2156/* This is used by the -bP option, so prints to the standard output.
2157The entire options list is passed in as an argument, because some options come
2158in pairs - typically uid/gid settings, which can either be explicit numerical
2159values, or strings to be expanded later. If the numerical value is unset,
2160search for "*expand_<name>" to see if there is a string equivalent.
2161
2162Arguments:
2163 ol option entry, or NULL for an unknown option
2164 name option name
2165 options_block NULL for main configuration options; otherwise points to
2166 a driver block; if the option doesn't have opt_public
2167 set, then options_block->options_block is where the item
2168 resides.
2169 oltop points to the option list in which ol exists
2170 last one more than the offset of the last entry in optop
12f69989 2171 no_labels do not show "foo = " at the start.
059ec3d9
PH
2172
2173Returns: nothing
2174*/
2175
2176static void
2177print_ol(optionlist *ol, uschar *name, void *options_block,
12f69989 2178 optionlist *oltop, int last, BOOL no_labels)
059ec3d9
PH
2179{
2180struct passwd *pw;
2181struct group *gr;
2182optionlist *ol2;
2183void *value;
2184uid_t *uidlist;
2185gid_t *gidlist;
2186uschar *s;
2187uschar name2[64];
2188
2189if (ol == NULL)
2190 {
2191 printf("%s is not a known option\n", name);
2192 return;
2193 }
2194
2195/* Non-admin callers cannot see options that have been flagged secure by the
2196"hide" prefix. */
2197
2198if (!admin_user && (ol->type & opt_secure) != 0)
2199 {
12f69989
PP
2200 const char * const hidden = "<value not displayable>";
2201 if (no_labels)
2202 printf("%s\n", hidden);
2203 else
2204 printf("%s = %s\n", name, hidden);
059ec3d9
PH
2205 return;
2206 }
2207
2208/* Else show the value of the option */
2209
2210value = ol->value;
2211if (options_block != NULL)
2212 {
2213 if ((ol->type & opt_public) == 0)
2214 options_block = (void *)(((driver_instance *)options_block)->options_block);
2215 value = (void *)((uschar *)options_block + (long int)value);
2216 }
2217
2218switch(ol->type & opt_mask)
2219 {
2220 case opt_stringptr:
2221 case opt_rewrite: /* Show the text value */
2222 s = *((uschar **)value);
12f69989
PP
2223 if (!no_labels) printf("%s = ", name);
2224 printf("%s\n", (s == NULL)? US"" : string_printing2(s, FALSE));
059ec3d9
PH
2225 break;
2226
2227 case opt_int:
12f69989
PP
2228 if (!no_labels) printf("%s = ", name);
2229 printf("%d\n", *((int *)value));
059ec3d9
PH
2230 break;
2231
2232 case opt_mkint:
2233 {
2234 int x = *((int *)value);
2235 if (x != 0 && (x & 1023) == 0)
2236 {
2237 int c = 'K';
2238 x >>= 10;
2239 if ((x & 1023) == 0)
2240 {
2241 c = 'M';
2242 x >>= 10;
2243 }
12f69989
PP
2244 if (!no_labels) printf("%s = ", name);
2245 printf("%d%c\n", x, c);
2246 }
2247 else
2248 {
2249 if (!no_labels) printf("%s = ", name);
2250 printf("%d\n", x);
059ec3d9 2251 }
059ec3d9
PH
2252 }
2253 break;
2254
2255 case opt_Kint:
2256 {
2257 int x = *((int *)value);
12f69989
PP
2258 if (!no_labels) printf("%s = ", name);
2259 if (x == 0) printf("0\n");
2260 else if ((x & 1023) == 0) printf("%dM\n", x >> 10);
2261 else printf("%dK\n", x);
059ec3d9
PH
2262 }
2263 break;
2264
2265 case opt_octint:
12f69989
PP
2266 if (!no_labels) printf("%s = ", name);
2267 printf("%#o\n", *((int *)value));
059ec3d9
PH
2268 break;
2269
2270 /* Can be negative only when "unset", in which case integer */
2271
2272 case opt_fixed:
2273 {
2274 int x = *((int *)value);
2275 int f = x % 1000;
2276 int d = 100;
2277 if (x < 0) printf("%s =\n", name); else
2278 {
12f69989
PP
2279 if (!no_labels) printf("%s = ", name);
2280 printf("%d.", x/1000);
059ec3d9
PH
2281 do
2282 {
2283 printf("%d", f/d);
2284 f %= d;
2285 d /= 10;
2286 }
2287 while (f != 0);
2288 printf("\n");
2289 }
2290 }
2291 break;
2292
2293 /* If the numerical value is unset, try for the string value */
2294
2295 case opt_expand_uid:
2296 if (! *get_set_flag(name, oltop, last, options_block))
2297 {
2298 sprintf(CS name2, "*expand_%.50s", name);
2299 ol2 = find_option(name2, oltop, last);
2300 if (ol2 != NULL)
2301 {
2302 void *value2 = ol2->value;
2303 if (options_block != NULL)
2304 value2 = (void *)((uschar *)options_block + (long int)value2);
2305 s = *((uschar **)value2);
12f69989
PP
2306 if (!no_labels) printf("%s = ", name);
2307 printf("%s\n", (s == NULL)? US"" : string_printing(s));
059ec3d9
PH
2308 break;
2309 }
2310 }
2311
2312 /* Else fall through */
2313
2314 case opt_uid:
12f69989 2315 if (!no_labels) printf("%s = ", name);
059ec3d9 2316 if (! *get_set_flag(name, oltop, last, options_block))
12f69989 2317 printf("\n");
059ec3d9
PH
2318 else
2319 {
2320 pw = getpwuid(*((uid_t *)value));
2321 if (pw == NULL)
12f69989
PP
2322 printf("%ld\n", (long int)(*((uid_t *)value)));
2323 else printf("%s\n", pw->pw_name);
059ec3d9
PH
2324 }
2325 break;
2326
2327 /* If the numerical value is unset, try for the string value */
2328
2329 case opt_expand_gid:
2330 if (! *get_set_flag(name, oltop, last, options_block))
2331 {
2332 sprintf(CS name2, "*expand_%.50s", name);
2333 ol2 = find_option(name2, oltop, last);
2334 if (ol2 != NULL && (ol2->type & opt_mask) == opt_stringptr)
2335 {
2336 void *value2 = ol2->value;
2337 if (options_block != NULL)
2338 value2 = (void *)((uschar *)options_block + (long int)value2);
2339 s = *((uschar **)value2);
12f69989
PP
2340 if (!no_labels) printf("%s = ", name);
2341 printf("%s\n", (s == NULL)? US"" : string_printing(s));
059ec3d9
PH
2342 break;
2343 }
2344 }
2345
2346 /* Else fall through */
2347
2348 case opt_gid:
12f69989 2349 if (!no_labels) printf("%s = ", name);
059ec3d9 2350 if (! *get_set_flag(name, oltop, last, options_block))
12f69989 2351 printf("\n");
059ec3d9
PH
2352 else
2353 {
2354 gr = getgrgid(*((int *)value));
2355 if (gr == NULL)
12f69989
PP
2356 printf("%ld\n", (long int)(*((int *)value)));
2357 else printf("%s\n", gr->gr_name);
059ec3d9
PH
2358 }
2359 break;
2360
2361 case opt_uidlist:
2362 uidlist = *((uid_t **)value);
12f69989 2363 if (!no_labels) printf("%s =", name);
059ec3d9
PH
2364 if (uidlist != NULL)
2365 {
2366 int i;
2367 uschar sep = ' ';
12f69989 2368 if (no_labels) sep = '\0';
059ec3d9
PH
2369 for (i = 1; i <= (int)(uidlist[0]); i++)
2370 {
2371 uschar *name = NULL;
2372 pw = getpwuid(uidlist[i]);
2373 if (pw != NULL) name = US pw->pw_name;
12f69989
PP
2374 if (sep != '\0') printf("%c", sep);
2375 if (name != NULL) printf("%s", name);
2376 else printf("%ld", (long int)(uidlist[i]));
059ec3d9
PH
2377 sep = ':';
2378 }
2379 }
2380 printf("\n");
2381 break;
2382
2383 case opt_gidlist:
2384 gidlist = *((gid_t **)value);
12f69989 2385 if (!no_labels) printf("%s =", name);
059ec3d9
PH
2386 if (gidlist != NULL)
2387 {
2388 int i;
2389 uschar sep = ' ';
12f69989 2390 if (no_labels) sep = '\0';
059ec3d9
PH
2391 for (i = 1; i <= (int)(gidlist[0]); i++)
2392 {
2393 uschar *name = NULL;
2394 gr = getgrgid(gidlist[i]);
2395 if (gr != NULL) name = US gr->gr_name;
12f69989
PP
2396 if (sep != '\0') printf("%c", sep);
2397 if (name != NULL) printf("%s", name);
2398 else printf("%ld", (long int)(gidlist[i]));
059ec3d9
PH
2399 sep = ':';
2400 }
2401 }
2402 printf("\n");
2403 break;
2404
2405 case opt_time:
12f69989
PP
2406 if (!no_labels) printf("%s = ", name);
2407 printf("%s\n", readconf_printtime(*((int *)value)));
059ec3d9
PH
2408 break;
2409
2410 case opt_timelist:
2411 {
2412 int i;
2413 int *list = (int *)value;
12f69989 2414 if (!no_labels) printf("%s = ", name);
059ec3d9
PH
2415 for (i = 0; i < list[1]; i++)
2416 printf("%s%s", (i == 0)? "" : ":", readconf_printtime(list[i+2]));
2417 printf("\n");
2418 }
2419 break;
2420
2421 case opt_bit:
2422 printf("%s%s\n", ((*((int *)value)) & (1 << ((ol->type >> 16) & 31)))?
2423 "" : "no_", name);
2424 break;
2425
2426 case opt_expand_bool:
2427 sprintf(CS name2, "*expand_%.50s", name);
2428 ol2 = find_option(name2, oltop, last);
2429 if (ol2 != NULL && ol2->value != NULL)
2430 {
2431 void *value2 = ol2->value;
2432 if (options_block != NULL)
2433 value2 = (void *)((uschar *)options_block + (long int)value2);
2434 s = *((uschar **)value2);
2435 if (s != NULL)
2436 {
12f69989
PP
2437 if (!no_labels) printf("%s = ", name);
2438 printf("%s\n", string_printing(s));
059ec3d9
PH
2439 break;
2440 }
2441 /* s == NULL => string not set; fall through */
2442 }
2443
2444 /* Fall through */
2445
2446 case opt_bool:
2447 case opt_bool_verify:
2448 case opt_bool_set:
2449 printf("%s%s\n", (*((BOOL *)value))? "" : "no_", name);
2450 break;
2451 }
2452}
2453
2454
2455
2456/*************************************************
2457* Print value from main configuration *
2458*************************************************/
2459
2460/* This function, called as a result of encountering the -bP option,
2461causes the value of any main configuration variable to be output if the
2462second argument is NULL. There are some special values:
2463
2464 all print all main configuration options
2465 configure_file print the name of the configuration file
2466 routers print the routers' configurations
2467 transports print the transports' configuration
2468 authenticators print the authenticators' configuration
5d9c27ec 2469 macros print the macros' configuration
059ec3d9
PH
2470 router_list print a list of router names
2471 transport_list print a list of transport names
2472 authenticator_list print a list of authentication mechanism names
5d9c27ec 2473 macro_list print a list of macro names
059ec3d9
PH
2474 +name print a named list item
2475 local_scan print the local_scan options
2476
5d9c27ec
TK
2477If the second argument is not NULL, it must be one of "router", "transport",
2478"authenticator" or "macro" in which case the first argument identifies the
2479driver whose options are to be printed.
059ec3d9
PH
2480
2481Arguments:
2482 name option name if type == NULL; else driver name
2483 type NULL or driver type name, as described above
12f69989 2484 no_labels avoid the "foo = " at the start of an item
059ec3d9
PH
2485
2486Returns: nothing
2487*/
2488
2489void
12f69989 2490readconf_print(uschar *name, uschar *type, BOOL no_labels)
059ec3d9
PH
2491{
2492BOOL names_only = FALSE;
2493optionlist *ol;
2494optionlist *ol2 = NULL;
2495driver_instance *d = NULL;
5d9c27ec 2496macro_item *m;
059ec3d9
PH
2497int size = 0;
2498
2499if (type == NULL)
2500 {
2501 if (*name == '+')
2502 {
2503 int i;
2504 tree_node *t;
2505 BOOL found = FALSE;
2506 static uschar *types[] = { US"address", US"domain", US"host",
2507 US"localpart" };
2508 static tree_node **anchors[] = { &addresslist_anchor, &domainlist_anchor,
2509 &hostlist_anchor, &localpartlist_anchor };
2510
2511 for (i = 0; i < 4; i++)
2512 {
2513 t = tree_search(*(anchors[i]), name+1);
2514 if (t != NULL)
2515 {
2516 found = TRUE;
12f69989
PP
2517 if (no_labels)
2518 printf("%s\n", ((namedlist_block *)(t->data.ptr))->string);
2519 else
2520 printf("%slist %s = %s\n", types[i], name+1,
2521 ((namedlist_block *)(t->data.ptr))->string);
059ec3d9
PH
2522 }
2523 }
2524
2525 if (!found)
2526 printf("no address, domain, host, or local part list called \"%s\" "
2527 "exists\n", name+1);
2528
2529 return;
2530 }
2531
2532 if (Ustrcmp(name, "configure_file") == 0)
2533 {
2534 printf("%s\n", CS config_main_filename);
2535 return;
2536 }
2537
2538 if (Ustrcmp(name, "all") == 0)
2539 {
2540 for (ol = optionlist_config;
2541 ol < optionlist_config + optionlist_config_size; ol++)
2542 {
2543 if ((ol->type & opt_hidden) == 0)
12f69989
PP
2544 print_ol(ol, US ol->name, NULL,
2545 optionlist_config, optionlist_config_size,
2546 no_labels);
059ec3d9
PH
2547 }
2548 return;
2549 }
2550
2551 if (Ustrcmp(name, "local_scan") == 0)
2552 {
2553 #ifndef LOCAL_SCAN_HAS_OPTIONS
2554 printf("local_scan() options are not supported\n");
2555 #else
2556 for (ol = local_scan_options;
2557 ol < local_scan_options + local_scan_options_count; ol++)
2558 {
2559 print_ol(ol, US ol->name, NULL, local_scan_options,
12f69989 2560 local_scan_options_count, no_labels);
059ec3d9
PH
2561 }
2562 #endif
2563 return;
2564 }
2565
2566 if (Ustrcmp(name, "routers") == 0)
2567 {
2568 type = US"router";
2569 name = NULL;
2570 }
2571 else if (Ustrcmp(name, "transports") == 0)
2572 {
2573 type = US"transport";
2574 name = NULL;
2575 }
2576
2577 else if (Ustrcmp(name, "authenticators") == 0)
2578 {
2579 type = US"authenticator";
2580 name = NULL;
2581 }
2582
5d9c27ec 2583 else if (Ustrcmp(name, "macros") == 0)
059ec3d9 2584 {
5d9c27ec 2585 type = US"macro";
059ec3d9 2586 name = NULL;
059ec3d9
PH
2587 }
2588
2589 else if (Ustrcmp(name, "router_list") == 0)
2590 {
2591 type = US"router";
2592 name = NULL;
2593 names_only = TRUE;
2594 }
5d9c27ec 2595
059ec3d9
PH
2596 else if (Ustrcmp(name, "transport_list") == 0)
2597 {
2598 type = US"transport";
2599 name = NULL;
2600 names_only = TRUE;
2601 }
5d9c27ec
TK
2602
2603 else if (Ustrcmp(name, "authenticator_list") == 0)
2604 {
2605 type = US"authenticator";
2606 name = NULL;
2607 names_only = TRUE;
2608 }
2609
2610 else if (Ustrcmp(name, "macro_list") == 0)
2611 {
2612 type = US"macro";
2613 name = NULL;
2614 names_only = TRUE;
2615 }
2616
059ec3d9
PH
2617 else
2618 {
2619 print_ol(find_option(name, optionlist_config, optionlist_config_size),
12f69989 2620 name, NULL, optionlist_config, optionlist_config_size, no_labels);
059ec3d9
PH
2621 return;
2622 }
2623 }
2624
2625/* Handle the options for a router or transport. Skip options that are flagged
2626as hidden. Some of these are options with names starting with '*', used for
2627internal alternative representations of other options (which the printing
2628function will sort out). Others are synonyms kept for backward compatibility.
2629*/
2630
2631if (Ustrcmp(type, "router") == 0)
2632 {
2633 d = (driver_instance *)routers;
2634 ol2 = optionlist_routers;
2635 size = optionlist_routers_size;
2636 }
2637else if (Ustrcmp(type, "transport") == 0)
2638 {
2639 d = (driver_instance *)transports;
2640 ol2 = optionlist_transports;
2641 size = optionlist_transports_size;
2642 }
2643else if (Ustrcmp(type, "authenticator") == 0)
2644 {
2645 d = (driver_instance *)auths;
2646 ol2 = optionlist_auths;
2647 size = optionlist_auths_size;
2648 }
2649
5d9c27ec
TK
2650else if (Ustrcmp(type, "macro") == 0)
2651 {
2652 /* People store passwords in macros and they were previously not available
2653 for printing. So we have an admin_users restriction. */
2654 if (!admin_user)
2655 {
2656 fprintf(stderr, "exim: permission denied\n");
2657 exit(EXIT_FAILURE);
2658 }
2659 for (m = macros; m != NULL; m = m->next)
2660 {
2661 if (name == NULL || Ustrcmp(name, m->name) == 0)
2662 {
2663 if (names_only)
2664 printf("%s\n", CS m->name);
2665 else
2666 printf("%s=%s\n", CS m->name, CS m->replacement);
2667 if (name != NULL)
2668 return;
2669 }
2670 }
2671 if (name != NULL)
2672 printf("%s %s not found\n", type, name);
2673 return;
2674 }
2675
059ec3d9
PH
2676if (names_only)
2677 {
2678 for (; d != NULL; d = d->next) printf("%s\n", CS d->name);
2679 return;
2680 }
2681
2682/* Either search for a given driver, or print all of them */
2683
2684for (; d != NULL; d = d->next)
2685 {
2686 if (name == NULL)
2687 printf("\n%s %s:\n", d->name, type);
2688 else if (Ustrcmp(d->name, name) != 0) continue;
2689
2690 for (ol = ol2; ol < ol2 + size; ol++)
2691 {
2692 if ((ol->type & opt_hidden) == 0)
12f69989 2693 print_ol(ol, US ol->name, d, ol2, size, no_labels);
059ec3d9
PH
2694 }
2695
2696 for (ol = d->info->options;
2697 ol < d->info->options + *(d->info->options_count); ol++)
2698 {
2699 if ((ol->type & opt_hidden) == 0)
12f69989 2700 print_ol(ol, US ol->name, d, d->info->options, *(d->info->options_count), no_labels);
059ec3d9
PH
2701 }
2702 if (name != NULL) return;
2703 }
2704if (name != NULL) printf("%s %s not found\n", type, name);
2705}
2706
2707
2708
2709/*************************************************
2710* Read a named list item *
2711*************************************************/
2712
2713/* This function reads a name and a list (i.e. string). The name is used to
2714save the list in a tree, sorted by its name. Each entry also has a number,
2715which can be used for caching tests, but if the string contains any expansion
2716items other than $key, the number is set negative to inhibit caching. This
2717mechanism is used for domain, host, and address lists that are referenced by
2718the "+name" syntax.
2719
2720Arguments:
2721 anchorp points to the tree anchor
2722 numberp points to the current number for this tree
2723 max the maximum number permitted
2724 s the text of the option line, starting immediately after the name
2725 of the list type
2726 tname the name of the list type, for messages
2727
2728Returns: nothing
2729*/
2730
2731static void
2732read_named_list(tree_node **anchorp, int *numberp, int max, uschar *s,
2733 uschar *tname)
2734{
2735BOOL forcecache = FALSE;
2736uschar *ss;
2737tree_node *t;
2738namedlist_block *nb = store_get(sizeof(namedlist_block));
2739
2740if (Ustrncmp(s, "_cache", 6) == 0)
2741 {
2742 forcecache = TRUE;
2743 s += 6;
2744 }
2745
2746if (!isspace(*s))
2747 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "unrecognized configuration line");
2748
2749if (*numberp >= max)
2750 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "too many named %ss (max is %d)\n",
2751 tname, max);
2752
2753while (isspace(*s)) s++;
2754ss = s;
2755while (isalnum(*s) || *s == '_') s++;
2756t = store_get(sizeof(tree_node) + s-ss);
2757Ustrncpy(t->name, ss, s-ss);
2758t->name[s-ss] = 0;
2759while (isspace(*s)) s++;
2760
2761if (!tree_insertnode(anchorp, t))
2762 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2763 "duplicate name \"%s\" for a named %s", t->name, tname);
2764
2765t->data.ptr = nb;
2766nb->number = *numberp;
2767*numberp += 1;
2768
2769if (*s++ != '=') log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
2770 "missing '=' after \"%s\"", t->name);
2771while (isspace(*s)) s++;
2772nb->string = read_string(s, t->name);
2773nb->cache_data = NULL;
2774
2775/* Check the string for any expansions; if any are found, mark this list
2776uncacheable unless the user has explicited forced caching. */
2777
2778if (!forcecache && Ustrchr(nb->string, '$') != NULL) nb->number = -1;
2779}
2780
2781
2782
2783
2784/*************************************************
2785* Unpick data for a rate limit *
2786*************************************************/
2787
2788/* This function is called to unpick smtp_ratelimit_{mail,rcpt} into four
2789separate values.
2790
2791Arguments:
2792 s string, in the form t,b,f,l
2793 where t is the threshold (integer)
2794 b is the initial delay (time)
2795 f is the multiplicative factor (fixed point)
2796 k is the maximum time (time)
2797 threshold where to store threshold
2798 base where to store base in milliseconds
2799 factor where to store factor in milliseconds
2800 limit where to store limit
2801
2802Returns: nothing (panics on error)
2803*/
2804
2805static void
2806unpick_ratelimit(uschar *s, int *threshold, int *base, double *factor,
2807 int *limit)
2808{
2809uschar bstring[16], lstring[16];
2810
2811if (sscanf(CS s, "%d, %15[0123456789smhdw.], %lf, %15s", threshold, bstring,
2812 factor, lstring) == 4)
2813 {
2814 *base = readconf_readtime(bstring, 0, TRUE);
2815 *limit = readconf_readtime(lstring, 0, TRUE);
2816 if (*base >= 0 && *limit >= 0) return;
2817 }
2818log_write(0, LOG_MAIN|LOG_PANIC_DIE, "malformed ratelimit data: %s", s);
2819}
2820
2821
2822
2823
3375e053
PP
2824/*************************************************
2825* Drop privs for checking TLS config *
2826*************************************************/
2827
2828/* We want to validate TLS options during readconf, but do not want to be
2829root when we call into the TLS library, in case of library linkage errors
2830which cause segfaults; before this check, those were always done as the Exim
2831runtime user and it makes sense to continue with that.
2832
2833Assumes: tls_require_ciphers has been set, if it will be
2834 exim_user has been set, if it will be
2835 exim_group has been set, if it will be
2836
2837Returns: bool for "okay"; false will cause caller to immediately exit.
2838*/
2839
2840#ifdef SUPPORT_TLS
2841static BOOL
2842tls_dropprivs_validate_require_cipher(void)
2843{
2844const uschar *errmsg;
2845pid_t pid;
2846int rc, status;
2847void (*oldsignal)(int);
2848
2849oldsignal = signal(SIGCHLD, SIG_DFL);
2850
2851fflush(NULL);
2852if ((pid = fork()) < 0)
2853 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "fork failed for TLS check");
2854
2855if (pid == 0)
2856 {
1d7a353e
PP
2857 /* in some modes, will have dropped privilege already */
2858 if (!geteuid())
2859 exim_setugid(exim_uid, exim_gid, FALSE,
2860 US"calling tls_validate_require_cipher");
3375e053
PP
2861
2862 errmsg = tls_validate_require_cipher();
2863 if (errmsg)
2864 {
2865 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
2866 "tls_require_ciphers invalid: %s", errmsg);
2867 }
2868 fflush(NULL);
2869 _exit(0);
2870 }
2871
2872do {
2873 rc = waitpid(pid, &status, 0);
2874} while (rc < 0 && errno == EINTR);
2875
9d26b8c0 2876DEBUG(D_tls)
3375e053
PP
2877 debug_printf("tls_validate_require_cipher child %d ended: status=0x%x\n",
2878 (int)pid, status);
2879
2880signal(SIGCHLD, oldsignal);
2881
2882return status == 0;
2883}
2884#endif /* SUPPORT_TLS */
2885
2886
2887
2888
059ec3d9
PH
2889/*************************************************
2890* Read main configuration options *
2891*************************************************/
2892
2893/* This function is the first to be called for configuration reading. It
2894opens the configuration file and reads general configuration settings until
2895it reaches the end of the configuration section. The file is then left open so
2896that the remaining configuration data can subsequently be read if needed for
2897this run of Exim.
2898
2899The configuration file must be owned either by root or exim, and be writeable
2900only by root or uid/gid exim. The values for Exim's uid and gid can be changed
2901in the config file, so the test is done on the compiled in values. A slight
2902anomaly, to be carefully documented.
2903
2904The name of the configuration file is taken from a list that is included in the
2905binary of Exim. It can be altered from the command line, but if that is done,
2906root privilege is immediately withdrawn unless the caller is root or exim.
2907The first file on the list that exists is used.
2908
2909For use on multiple systems that share file systems, first look for a
2910configuration file whose name has the current node name on the end. If that is
2911not found, try the generic name. For really contorted configurations, that run
2912multiple Exims with different uid settings, first try adding the effective uid
2913before the node name. These complications are going to waste resources on most
2914systems. Therefore they are available only when requested by compile-time
2915options. */
2916
2917void
2918readconf_main(void)
2919{
2920int sep = 0;
2921struct stat statbuf;
2922uschar *s, *filename;
2923uschar *list = config_main_filelist;
2924
2925/* Loop through the possible file names */
2926
2927while((filename = string_nextinlist(&list, &sep, big_buffer, big_buffer_size))
2928 != NULL)
2929 {
2930 /* Cut out all the fancy processing unless specifically wanted */
2931
2932 #if defined(CONFIGURE_FILE_USE_NODE) || defined(CONFIGURE_FILE_USE_EUID)
2933 uschar *suffix = filename + Ustrlen(filename);
2934
2935 /* Try for the node-specific file if a node name exists */
2936
2937 #ifdef CONFIGURE_FILE_USE_NODE
2938 struct utsname uts;
2939 if (uname(&uts) >= 0)
2940 {
2941 #ifdef CONFIGURE_FILE_USE_EUID
2942 sprintf(CS suffix, ".%ld.%.256s", (long int)original_euid, uts.nodename);
2943 config_file = Ufopen(filename, "rb");
2944 if (config_file == NULL)
2945 #endif /* CONFIGURE_FILE_USE_EUID */
2946 {
2947 sprintf(CS suffix, ".%.256s", uts.nodename);
2948 config_file = Ufopen(filename, "rb");
2949 }
2950 }
2951 #endif /* CONFIGURE_FILE_USE_NODE */
2952
2953 /* Otherwise, try the generic name, possibly with the euid added */
2954
2955 #ifdef CONFIGURE_FILE_USE_EUID
2956 if (config_file == NULL)
2957 {
2958 sprintf(CS suffix, ".%ld", (long int)original_euid);
2959 config_file = Ufopen(filename, "rb");
2960 }
2961 #endif /* CONFIGURE_FILE_USE_EUID */
2962
2963 /* Finally, try the unadorned name */
2964
2965 if (config_file == NULL)
2966 {
2967 *suffix = 0;
2968 config_file = Ufopen(filename, "rb");
2969 }
2970 #else /* if neither defined */
2971
2972 /* This is the common case when the fancy processing is not included. */
2973
2974 config_file = Ufopen(filename, "rb");
2975 #endif
2976
2977 /* If the file does not exist, continue to try any others. For any other
2978 error, break out (and die). */
2979
2980 if (config_file != NULL || errno != ENOENT) break;
2981 }
2982
2983/* On success, save the name for verification; config_filename is used when
2984logging configuration errors (it changes for .included files) whereas
2985config_main_filename is the name shown by -bP. Failure to open a configuration
2986file is a serious disaster. */
2987
2988if (config_file != NULL)
2989 {
2990 config_filename = config_main_filename = string_copy(filename);
2991 }
2992else
2993 {
2994 if (filename == NULL)
2995 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "non-existent configuration file(s): "
2996 "%s", config_main_filelist);
2997 else
2998 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", string_open_failed(errno,
2999 "configuration file %s", filename));
3000 }
3001
e2f5dc15 3002/* Check the status of the file we have opened, if we have retained root
fea24b2e 3003privileges and the file isn't /dev/null (which *should* be 0666). */
059ec3d9 3004
fea24b2e 3005if (trusted_config && Ustrcmp(filename, US"/dev/null"))
059ec3d9
PH
3006 {
3007 if (fstat(fileno(config_file), &statbuf) != 0)
3008 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to stat configuration file %s",
3009 big_buffer);
3010
c1d94452 3011 if ((statbuf.st_uid != root_uid /* owner not root */
059ec3d9
PH
3012 #ifdef CONFIGURE_OWNER
3013 && statbuf.st_uid != config_uid /* owner not the special one */
3014 #endif
3015 ) || /* or */
c1d94452 3016 (statbuf.st_gid != root_gid /* group not root & */
35edf2ff
PH
3017 #ifdef CONFIGURE_GROUP
3018 && statbuf.st_gid != config_gid /* group not the special one */
8e669ac1 3019 #endif
35edf2ff 3020 && (statbuf.st_mode & 020) != 0) || /* group writeable */
059ec3d9
PH
3021 /* or */
3022 ((statbuf.st_mode & 2) != 0)) /* world writeable */
3023
3024 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Exim configuration file %s has the "
3025 "wrong owner, group, or mode", big_buffer);
3026 }
3027
3028/* Process the main configuration settings. They all begin with a lower case
3029letter. If we see something starting with an upper case letter, it is taken as
3030a macro definition. */
3031
3032while ((s = get_config_line()) != NULL)
3033 {
cf00dad6 3034 if (isupper(s[0])) read_macro_assignment(s);
059ec3d9
PH
3035
3036 else if (Ustrncmp(s, "domainlist", 10) == 0)
3037 read_named_list(&domainlist_anchor, &domainlist_count,
3038 MAX_NAMED_LIST, s+10, US"domain list");
3039
3040 else if (Ustrncmp(s, "hostlist", 8) == 0)
3041 read_named_list(&hostlist_anchor, &hostlist_count,
3042 MAX_NAMED_LIST, s+8, US"host list");
3043
3044 else if (Ustrncmp(s, US"addresslist", 11) == 0)
3045 read_named_list(&addresslist_anchor, &addresslist_count,
3046 MAX_NAMED_LIST, s+11, US"address list");
3047
3048 else if (Ustrncmp(s, US"localpartlist", 13) == 0)
3049 read_named_list(&localpartlist_anchor, &localpartlist_count,
3050 MAX_NAMED_LIST, s+13, US"local part list");
3051
3052 else
3053 (void) readconf_handle_option(s, optionlist_config, optionlist_config_size,
3054 NULL, US"main option \"%s\" unknown");
3055 }
3056
3057
3058/* If local_sender_retain is set, local_from_check must be unset. */
3059
3060if (local_sender_retain && local_from_check)
3061 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "both local_from_check and "
3062 "local_sender_retain are set; this combination is not allowed");
3063
3064/* If the timezone string is empty, set it to NULL, implying no TZ variable
3065wanted. */
3066
3067if (timezone_string != NULL && *timezone_string == 0) timezone_string = NULL;
3068
944a9c55
PH
3069/* The max retry interval must not be greater than 24 hours. */
3070
3071if (retry_interval_max > 24*60*60) retry_interval_max = 24*60*60;
3072
059ec3d9
PH
3073/* remote_max_parallel must be > 0 */
3074
3075if (remote_max_parallel <= 0) remote_max_parallel = 1;
3076
6a3f1455
PH
3077/* Save the configured setting of freeze_tell, so we can re-instate it at the
3078start of a new SMTP message. */
3079
3080freeze_tell_config = freeze_tell;
3081
059ec3d9
PH
3082/* The primary host name may be required for expansion of spool_directory
3083and log_file_path, so make sure it is set asap. It is obtained from uname(),
3084but if that yields an unqualified value, make a FQDN by using gethostbyname to
3085canonize it. Some people like upper case letters in their host names, so we
3086don't force the case. */
3087
3088if (primary_hostname == NULL)
3089 {
3090 uschar *hostname;
3091 struct utsname uts;
3092 if (uname(&uts) < 0)
3093 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "uname() failed to yield host name");
3094 hostname = US uts.nodename;
3095
3096 if (Ustrchr(hostname, '.') == NULL)
3097 {
3098 int af = AF_INET;
3099 struct hostent *hostdata;
3100
3101 #if HAVE_IPV6
7e66e54d 3102 if (!disable_ipv6 && (dns_ipv4_lookup == NULL ||
059ec3d9 3103 match_isinlist(hostname, &dns_ipv4_lookup, 0, NULL, NULL, MCL_DOMAIN,
7e66e54d 3104 TRUE, NULL) != OK))
059ec3d9
PH
3105 af = AF_INET6;
3106 #else
3107 af = AF_INET;
3108 #endif
3109
3110 for (;;)
3111 {
3112 #if HAVE_IPV6
3113 #if HAVE_GETIPNODEBYNAME
3114 int error_num;
3115 hostdata = getipnodebyname(CS hostname, af, 0, &error_num);
3116 #else
3117 hostdata = gethostbyname2(CS hostname, af);
3118 #endif
3119 #else
3120 hostdata = gethostbyname(CS hostname);
3121 #endif
3122
3123 if (hostdata != NULL)
3124 {
3125 hostname = US hostdata->h_name;
3126 break;
3127 }
3128
3129 if (af == AF_INET) break;
3130 af = AF_INET;
3131 }
3132 }
3133
3134 primary_hostname = string_copy(hostname);
3135 }
3136
3137/* Set up default value for smtp_active_hostname */
3138
3139smtp_active_hostname = primary_hostname;
3140
3141/* If spool_directory wasn't set in the build-time configuration, it must have
3142got set above. Of course, writing to the log may not work if log_file_path is
3143not set, but it will at least get to syslog or somewhere, with any luck. */
3144
3145if (*spool_directory == 0)
3146 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "spool_directory undefined: cannot "
3147 "proceed");
3148
3149/* Expand the spool directory name; it may, for example, contain the primary
3150host name. Same comment about failure. */
3151
3152s = expand_string(spool_directory);
3153if (s == NULL)
3154 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to expand spool_directory "
3155 "\"%s\": %s", spool_directory, expand_string_message);
3156spool_directory = s;
3157
3158/* Expand log_file_path, which must contain "%s" in any component that isn't
f1e5fef5
PP
3159the null string or "syslog". It is also allowed to contain one instance of %D
3160or %M. However, it must NOT contain % followed by anything else. */
059ec3d9
PH
3161
3162if (*log_file_path != 0)
3163 {
3164 uschar *ss, *sss;
3165 int sep = ':'; /* Fixed for log file path */
3166 s = expand_string(log_file_path);
3167 if (s == NULL)
3168 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to expand log_file_path "
3169 "\"%s\": %s", log_file_path, expand_string_message);
3170
3171 ss = s;
3172 while ((sss = string_nextinlist(&ss,&sep,big_buffer,big_buffer_size)) != NULL)
3173 {
3174 uschar *t;
3175 if (sss[0] == 0 || Ustrcmp(sss, "syslog") == 0) continue;
3176 t = Ustrstr(sss, "%s");
3177 if (t == NULL)
3178 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "log_file_path \"%s\" does not "
3179 "contain \"%%s\"", sss);
3180 *t = 'X';
3181 t = Ustrchr(sss, '%');
3182 if (t != NULL)
3183 {
f1e5fef5 3184 if ((t[1] != 'D' && t[1] != 'M') || Ustrchr(t+2, '%') != NULL)
059ec3d9
PH
3185 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "log_file_path \"%s\" contains "
3186 "unexpected \"%%\" character", s);
3187 }
3188 }
3189
3190 log_file_path = s;
3191 }
3192
3193/* Interpret syslog_facility into an integer argument for 'ident' param to
3194openlog(). Default is LOG_MAIL set in globals.c. Allow the user to omit the
3195leading "log_". */
3196
3197if (syslog_facility_str != NULL)
3198 {
3199 int i;
3200 uschar *s = syslog_facility_str;
3201
3202 if ((Ustrlen(syslog_facility_str) >= 4) &&
3203 (strncmpic(syslog_facility_str, US"log_", 4) == 0))
3204 s += 4;
3205
3206 for (i = 0; i < syslog_list_size; i++)
3207 {
3208 if (strcmpic(s, syslog_list[i].name) == 0)
3209 {
3210 syslog_facility = syslog_list[i].value;
3211 break;
3212 }
3213 }
3214
3215 if (i >= syslog_list_size)
3216 {
3217 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3218 "failed to interpret syslog_facility \"%s\"", syslog_facility_str);
3219 }
3220 }
3221
3222/* Expand pid_file_path */
3223
3224if (*pid_file_path != 0)
3225 {
3226 s = expand_string(pid_file_path);
3227 if (s == NULL)
3228 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to expand pid_file_path "
3229 "\"%s\": %s", pid_file_path, expand_string_message);
3230 pid_file_path = s;
3231 }
3232
921b12ca
TF
3233/* Set default value of process_log_path */
3234
3235if (process_log_path == NULL || *process_log_path =='\0')
3236 process_log_path = string_sprintf("%s/exim-process.info", spool_directory);
3237
059ec3d9
PH
3238/* Compile the regex for matching a UUCP-style "From_" line in an incoming
3239message. */
3240
3241regex_From = regex_must_compile(uucp_from_pattern, FALSE, TRUE);
3242
3243/* Unpick the SMTP rate limiting options, if set */
3244
3245if (smtp_ratelimit_mail != NULL)
3246 {
3247 unpick_ratelimit(smtp_ratelimit_mail, &smtp_rlm_threshold,
3248 &smtp_rlm_base, &smtp_rlm_factor, &smtp_rlm_limit);
3249 }
3250
3251if (smtp_ratelimit_rcpt != NULL)
3252 {
3253 unpick_ratelimit(smtp_ratelimit_rcpt, &smtp_rlr_threshold,
3254 &smtp_rlr_base, &smtp_rlr_factor, &smtp_rlr_limit);
3255 }
3256
3257/* The qualify domains default to the primary host name */
3258
3259if (qualify_domain_sender == NULL)
3260 qualify_domain_sender = primary_hostname;
3261if (qualify_domain_recipient == NULL)
3262 qualify_domain_recipient = qualify_domain_sender;
3263
3264/* Setting system_filter_user in the configuration sets the gid as well if a
3265name is given, but a numerical value does not. */
3266
3267if (system_filter_uid_set && !system_filter_gid_set)
3268 {
3269 struct passwd *pw = getpwuid(system_filter_uid);
3270 if (pw == NULL)
3271 log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to look up uid %ld",
3272 (long int)system_filter_uid);
3273 system_filter_gid = pw->pw_gid;
3274 system_filter_gid_set = TRUE;
3275 }
3276
3277/* If the errors_reply_to field is set, check that it is syntactically valid
3278and ensure it contains a domain. */
3279
3280if (errors_reply_to != NULL)
3281 {
3282 uschar *errmess;
3283 int start, end, domain;
3284 uschar *recipient = parse_extract_address(errors_reply_to, &errmess,
3285 &start, &end, &domain, FALSE);
3286
3287 if (recipient == NULL)
3288 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3289 "error in errors_reply_to (%s): %s", errors_reply_to, errmess);
3290
3291 if (domain == 0)
3292 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3293 "errors_reply_to (%s) does not contain a domain", errors_reply_to);
3294 }
3295
3296/* If smtp_accept_queue or smtp_accept_max_per_host is set, then
3297smtp_accept_max must also be set. */
3298
3299if (smtp_accept_max == 0 &&
3300 (smtp_accept_queue > 0 || smtp_accept_max_per_host != NULL))
3301 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3302 "smtp_accept_max must be set if smtp_accept_queue or "
3303 "smtp_accept_max_per_host is set");
3304
3305/* Set up the host number if anything is specified. It is an expanded string
3306so that it can be computed from the host name, for example. We do this last
3307so as to ensure that everything else is set up before the expansion. */
3308
3309if (host_number_string != NULL)
3310 {
ef840681 3311 long int n;
059ec3d9
PH
3312 uschar *end;
3313 uschar *s = expand_string(host_number_string);
ef840681
PP
3314 if (s == NULL)
3315 log_write(0, LOG_MAIN|LOG_PANIC_DIE,
3316 "failed to expand localhost_number \"%s\": %s",
3317 host_number_string, expand_string_message);
3318 n = Ustrtol(s, &end, 0);
059ec3d9
PH
3319 while (isspace(*end)) end++;
3320 if (*end != 0)
3321 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3322 "localhost_number value is not a number: %s", s);
3323 if (n > LOCALHOST_MAX)
3324 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3325 "localhost_number is greater than the maximum allowed value (%d)",
3326 LOCALHOST_MAX);
3327 host_number = n;
3328 }
3329
3330#ifdef SUPPORT_TLS
3331/* If tls_verify_hosts is set, tls_verify_certificates must also be set */
3332
3333if ((tls_verify_hosts != NULL || tls_try_verify_hosts != NULL) &&
3334 tls_verify_certificates == NULL)
3335 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3336 "tls_%sverify_hosts is set, but tls_verify_certificates is not set",
3337 (tls_verify_hosts != NULL)? "" : "try_");
77bb000f 3338
3375e053
PP
3339/* This also checks that the library linkage is working and we can call
3340routines in it, so call even if tls_require_ciphers is unset */
3341if (!tls_dropprivs_validate_require_cipher())
3342 exit(1);
3343
3344/* Magic number: at time of writing, 1024 has been the long-standing value
3345used by so many clients, and what Exim used to use always, that it makes
3346sense to just min-clamp this max-clamp at that. */
3347if (tls_dh_max_bits < 1024)
3348 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3349 "tls_dh_max_bits is too small, must be at least 1024 for interop");
3350
77bb000f
PP
3351/* If openssl_options is set, validate it */
3352if (openssl_options != NULL)
3353 {
3354# ifdef USE_GNUTLS
3355 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
a053d125 3356 "openssl_options is set but we're using GnuTLS");
77bb000f
PP
3357# else
3358 long dummy;
3359 if (!(tls_openssl_options_parse(openssl_options, &dummy)))
3360 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
a053d125 3361 "openssl_options parse error: %s", openssl_options);
77bb000f
PP
3362# endif
3363 }
059ec3d9
PH
3364#endif
3365}
3366
3367
3368
3369/*************************************************
3370* Initialize one driver *
3371*************************************************/
3372
3373/* This is called once the driver's generic options, if any, have been read.
3374We can now find the driver, set up defaults for the private options, and
3375unset any "set" bits in the private options table (which might have been
3376set by another incarnation of the same driver).
3377
3378Arguments:
3379 d pointer to driver instance block, with generic
3380 options filled in
3381 drivers_available vector of available drivers
3382 size_of_info size of each block in drivers_available
3383 class class of driver, for error message
3384
3385Returns: pointer to the driver info block
3386*/
3387
3388static driver_info *
3389init_driver(driver_instance *d, driver_info *drivers_available,
3390 int size_of_info, uschar *class)
3391{
3392driver_info *dd;
3393
3394for (dd = drivers_available; dd->driver_name[0] != 0;
3395 dd = (driver_info *)(((uschar *)dd) + size_of_info))
3396 {
3397 if (Ustrcmp(d->driver_name, dd->driver_name) == 0)
3398 {
3399 int i;
3400 int len = dd->options_len;
3401 d->info = dd;
3402 d->options_block = store_get(len);
3403 memcpy(d->options_block, dd->options_block, len);
3404 for (i = 0; i < *(dd->options_count); i++)
3405 dd->options[i].type &= ~opt_set;
3406 return dd;
3407 }
3408 }
3409
3410log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
3411 "%s %s: cannot find %s driver \"%s\"", class, d->name, class, d->driver_name);
3412
3413return NULL; /* never obeyed */
3414}
3415
3416
3417
3418
3419/*************************************************
3420* Initialize driver list *
3421*************************************************/
3422
3423/* This function is called for routers, transports, and authentication
3424mechanisms. It reads the data from the current point in the configuration file
3425up to the end of the section, and sets up a chain of instance blocks according
3426to the file's contents. The file will already have been opened by a call to
3427readconf_main, and must be left open for subsequent reading of further data.
3428
3429Any errors cause a panic crash. Note that the blocks with names driver_info and
3430driver_instance must map the first portions of all the _info and _instance
3431blocks for this shared code to work.
3432
3433Arguments:
3434 class "router", "transport", or "authenticator"
3435 anchor &routers, &transports, &auths
3436 drivers_available available drivers
3437 size_of_info size of each info block
3438 instance_default points to default data for an instance
3439 instance_size size of instance block
3440 driver_optionlist generic option list
3441 driver_optionlist_count count of generic option list
3442
3443Returns: nothing
3444*/
3445
3446void
3447readconf_driver_init(
3448 uschar *class,
3449 driver_instance **anchor,
3450 driver_info *drivers_available,
3451 int size_of_info,
3452 void *instance_default,
3453 int instance_size,
3454 optionlist *driver_optionlist,
3455 int driver_optionlist_count)
3456{
3457driver_instance **p = anchor;
3458driver_instance *d = NULL;
3459uschar *buffer;
3460
059ec3d9
PH
3461while ((buffer = get_config_line()) != NULL)
3462 {
3463 uschar name[64];
cf00dad6 3464 uschar *s;
059ec3d9 3465
cf00dad6
PH
3466 /* Read the first name on the line and test for the start of a new driver. A
3467 macro definition indicates the end of the previous driver. If this isn't the
3468 start of a new driver, the line will be re-read. */
059ec3d9 3469
cf00dad6
PH
3470 s = readconf_readname(name, sizeof(name), buffer);
3471
3472 /* Handle macro definition, first finishing off the initialization of the
3473 previous driver, if any. */
3474
3475 if (isupper(*name) && *s == '=')
3476 {
3477 if (d != NULL)
3478 {
3479 if (d->driver_name == NULL)
3480 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3481 "no driver defined for %s \"%s\"", class, d->name);
3482 (d->info->init)(d);
3483 d = NULL;
3484 }
3485 read_macro_assignment(buffer);
3486 continue;
3487 }
059ec3d9
PH
3488
3489 /* If the line starts with a name terminated by a colon, we are at the
3490 start of the definition of a new driver. The rest of the line must be
3491 blank. */
3492
3493 if (*s++ == ':')
3494 {
3495 int i;
3496
3497 /* Finish off initializing the previous driver. */
3498
3499 if (d != NULL)
3500 {
3501 if (d->driver_name == NULL)
3502 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3503 "no driver defined for %s \"%s\"", class, d->name);
3504 (d->info->init)(d);
3505 }
3506
3507 /* Check that we haven't already got a driver of this name */
3508
3509 for (d = *anchor; d != NULL; d = d->next)
3510 if (Ustrcmp(name, d->name) == 0)
3511 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3512 "there are two %ss called \"%s\"", class, name);
3513
3514 /* Set up a new driver instance data block on the chain, with
3515 its default values installed. */
3516
3517 d = store_get(instance_size);
3518 memcpy(d, instance_default, instance_size);
3519 *p = d;
3520 p = &(d->next);
3521 d->name = string_copy(name);
3522
3523 /* Clear out the "set" bits in the generic options */
3524
3525 for (i = 0; i < driver_optionlist_count; i++)
3526 driver_optionlist[i].type &= ~opt_set;
3527
3528 /* Check nothing more on this line, then do the next loop iteration. */
3529
3530 while (isspace(*s)) s++;
3531 if (*s != 0) extra_chars_error(s, US"driver name ", name, US"");
3532 continue;
3533 }
3534
cf00dad6
PH
3535 /* Not the start of a new driver. Give an error if we have not set up a
3536 current driver yet. */
059ec3d9
PH
3537
3538 if (d == NULL) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
3539 "%s name missing", class);
3540
3541 /* First look to see if this is a generic option; if it is "driver",
3542 initialize the driver. If is it not a generic option, we can look for a
3543 private option provided that the driver has been previously set up. */
3544
3545 if (readconf_handle_option(buffer, driver_optionlist,
3546 driver_optionlist_count, d, NULL))
3547 {
3548 if (d->info == NULL && d->driver_name != NULL)
3549 init_driver(d, drivers_available, size_of_info, class);
3550 }
3551
3552 /* Handle private options - pass the generic block because some may
3553 live therein. A flag with each option indicates if it is in the public
3554 block. */
3555
3556 else if (d->info != NULL)
3557 {
3558 readconf_handle_option(buffer, d->info->options,
3559 *(d->info->options_count), d, US"option \"%s\" unknown");
3560 }
3561
3562 /* The option is not generic and the driver name has not yet been given. */
3563
3564 else log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "option \"%s\" unknown "
3565 "(\"driver\" must be specified before any private options)", name);
3566 }
3567
3568/* Run the initialization function for the final driver. */
3569
3570if (d != NULL)
3571 {
3572 if (d->driver_name == NULL)
3573 log_write(0, LOG_PANIC_DIE|LOG_CONFIG,
3574 "no driver defined for %s \"%s\"", class, d->name);
3575 (d->info->init)(d);
3576 }
3577}
3578
3579
3580
3581/*************************************************
3582* Check driver dependency *
3583*************************************************/
3584
3585/* This function is passed a driver instance and a string. It checks whether
3586any of the string options for the driver contains the given string as an
3587expansion variable.
3588
3589Arguments:
3590 d points to a driver instance block
3591 s the string to search for
3592
3593Returns: TRUE if a dependency is found
3594*/
3595
3596BOOL
3597readconf_depends(driver_instance *d, uschar *s)
3598{
3599int count = *(d->info->options_count);
3600optionlist *ol;
3601uschar *ss;
3602
3603for (ol = d->info->options; ol < d->info->options + count; ol++)
3604 {
3605 void *options_block;
3606 uschar *value;
3607 int type = ol->type & opt_mask;
3608 if (type != opt_stringptr) continue;
3609 options_block = ((ol->type & opt_public) == 0)? d->options_block : (void *)d;
3610 value = *(uschar **)((uschar *)options_block + (long int)(ol->value));
3611 if (value != NULL && (ss = Ustrstr(value, s)) != NULL)
3612 {
3613 if (ss <= value || (ss[-1] != '$' && ss[-1] != '{') ||
3614 isalnum(ss[Ustrlen(s)])) continue;
3615 DEBUG(D_transport) debug_printf("driver %s: \"%s\" option depends on %s\n",
3616 d->name, ol->name, s);
3617 return TRUE;
3618 }
3619 }
3620
3621DEBUG(D_transport) debug_printf("driver %s does not depend on %s\n", d->name, s);
3622return FALSE;
3623}
3624
3625
3626
3627
3628/*************************************************
3629* Decode an error type for retries *
3630*************************************************/
3631
3632/* This function is global because it is also called from the main
3633program when testing retry information. It decodes strings such as "quota_7d"
3634into numerical error codes.
3635
3636Arguments:
3637 pp points to start of text
3638 p points past end of text
3639 basic_errno points to an int to receive the main error number
3640 more_errno points to an int to receive the secondary error data
3641
3642Returns: NULL if decoded correctly; else points to error text
3643*/
3644
3645uschar *
3646readconf_retry_error(uschar *pp, uschar *p, int *basic_errno, int *more_errno)
3647{
3648int len;
3649uschar *q = pp;
3650while (q < p && *q != '_') q++;
3651len = q - pp;
3652
3653if (len == 5 && strncmpic(pp, US"quota", len) == 0)
3654 {
3655 *basic_errno = ERRNO_EXIMQUOTA;
3656 if (q != p && (*more_errno = readconf_readtime(q+1, *p, FALSE)) < 0)
3657 return US"bad time value";
3658 }
3659
3660else if (len == 7 && strncmpic(pp, US"refused", len) == 0)
3661 {
3662 *basic_errno = ECONNREFUSED;
3663 if (q != p)
3664 {
3665 if (strncmpic(q+1, US"MX", p-q-1) == 0) *more_errno = 'M';
3666 else if (strncmpic(q+1, US"A", p-q-1) == 0) *more_errno = 'A';
3667 else return US"A or MX expected after \"refused\"";
3668 }
3669 }
3670
3671else if (len == 7 && strncmpic(pp, US"timeout", len) == 0)
3672 {
3673 *basic_errno = ETIMEDOUT;
3674 if (q != p)
3675 {
3676 int i;
3677 int xlen = p - q - 1;
3678 uschar *x = q + 1;
3679
3680 static uschar *extras[] =
3681 { US"A", US"MX", US"connect", US"connect_A", US"connect_MX" };
3682 static int values[] =
3683 { 'A', 'M', RTEF_CTOUT, RTEF_CTOUT|'A', RTEF_CTOUT|'M' };
3684
3685 for (i = 0; i < sizeof(extras)/sizeof(uschar *); i++)
3686 {
3687 if (strncmpic(x, extras[i], xlen) == 0)
3688 {
3689 *more_errno = values[i];
3690 break;
3691 }
3692 }
3693
3694 if (i >= sizeof(extras)/sizeof(uschar *))
3695 {
3696 if (strncmpic(x, US"DNS", xlen) == 0)
3697 {
3698 log_write(0, LOG_MAIN|LOG_PANIC, "\"timeout_dns\" is no longer "
3699 "available in retry rules (it has never worked) - treated as "
3700 "\"timeout\"");
3701 }
3702 else return US"\"A\", \"MX\", or \"connect\" expected after \"timeout\"";
3703 }
3704 }
3705 }
3706
e97957bc
PH
3707else if (strncmpic(pp, US"mail_4", 6) == 0 ||
3708 strncmpic(pp, US"rcpt_4", 6) == 0 ||
3709 strncmpic(pp, US"data_4", 6) == 0)
059ec3d9
PH
3710 {
3711 BOOL bad = FALSE;
3712 int x = 255; /* means "any 4xx code" */
3713 if (p != pp + 8) bad = TRUE; else
3714 {
3715 int a = pp[6], b = pp[7];
3716 if (isdigit(a))
3717 {
3718 x = (a - '0') * 10;
3719 if (isdigit(b)) x += b - '0';
3720 else if (b == 'x') x += 100;
3721 else bad = TRUE;
3722 }
3723 else if (a != 'x' || b != 'x') bad = TRUE;
3724 }
3725
e97957bc
PH
3726 if (bad)
3727 return string_sprintf("%.4s_4 must be followed by xx, dx, or dd, where "
3728 "x is literal and d is any digit", pp);
059ec3d9 3729
e97957bc
PH
3730 *basic_errno = (*pp == 'm')? ERRNO_MAIL4XX :
3731 (*pp == 'r')? ERRNO_RCPT4XX : ERRNO_DATA4XX;
059ec3d9
PH
3732 *more_errno = x << 8;
3733 }
3734
3735else if (len == 4 && strncmpic(pp, US"auth", len) == 0 &&
3736 strncmpic(q+1, US"failed", p-q-1) == 0)
059ec3d9 3737 *basic_errno = ERRNO_AUTHFAIL;
e97957bc 3738
48da4259 3739else if (strncmpic(pp, US"lost_connection", p - pp) == 0)
e97957bc
PH
3740 *basic_errno = ERRNO_SMTPCLOSED;
3741
48da4259 3742else if (strncmpic(pp, US"tls_required", p - pp) == 0)
e97957bc 3743 *basic_errno = ERRNO_TLSREQUIRED;
059ec3d9
PH
3744
3745else if (len != 1 || Ustrncmp(pp, "*", 1) != 0)
ef840681 3746 return string_sprintf("unknown or malformed retry error \"%.*s\"", (int) (p-pp), pp);
059ec3d9
PH
3747
3748return NULL;
3749}
3750
3751
3752
3753
3754/*************************************************
3755* Read retry information *
3756*************************************************/
3757
3758/* Each line of retry information contains:
3759
3760. A domain name pattern or an address pattern;
3761
3762. An error name, possibly with additional data, or *;
3763
3764. An optional sequence of retry items, each consisting of an identifying
3765 letter, a cutoff time, and optional parameters.
3766
3767All this is decoded and placed into a control block. */
3768
3769
3770/* Subroutine to read an argument, preceded by a comma and terminated
3771by comma, semicolon, whitespace, or newline. The types are: 0 = time value,
37721 = fixed point number (returned *1000).
3773
3774Arguments:
3775 paddr pointer to pointer to current character; updated
3776 type 0 => read a time; 1 => read a fixed point number
3777
3778Returns: time in seconds or fixed point number * 1000
3779*/
3780
3781static int
3782retry_arg(uschar **paddr, int type)
3783{
3784uschar *p = *paddr;
3785uschar *pp;
3786
3787if (*p++ != ',') log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "comma expected");
3788
3789while (isspace(*p)) p++;
3790pp = p;
3791while (isalnum(*p) || (type == 1 && *p == '.')) p++;
3792
3793if (*p != 0 && !isspace(*p) && *p != ',' && *p != ';')
3794 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "comma or semicolon expected");
3795
3796*paddr = p;
3797switch (type)
3798 {
3799 case 0:
3800 return readconf_readtime(pp, *p, FALSE);
3801 case 1:
3802 return readconf_readfixed(pp, *p);
3803 }
3804return 0; /* Keep picky compilers happy */
3805}
3806
3807/* The function proper */
3808
3809void
3810readconf_retries(void)
3811{
3812retry_config **chain = &retries;
3813retry_config *next;
3814uschar *p;
3815
3816while ((p = get_config_line()) != NULL)
3817 {
3818 retry_rule **rchain;
3819 uschar *pp, *error;
3820
3821 next = store_get(sizeof(retry_config));
3822 next->next = NULL;
3823 *chain = next;
3824 chain = &(next->next);
3825 next->basic_errno = next->more_errno = 0;
3826 next->senders = NULL;
3827 next->rules = NULL;
3828 rchain = &(next->rules);
3829
3830 next->pattern = string_dequote(&p);
3831 while (isspace(*p)) p++;
3832 pp = p;
3833 while (mac_isgraph(*p)) p++;
3834 if (p - pp <= 0) log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
41eff010 3835 "missing error type in retry rule");
059ec3d9
PH
3836
3837 /* Test error names for things we understand. */
3838
3839 if ((error = readconf_retry_error(pp, p, &(next->basic_errno),
3840 &(next->more_errno))) != NULL)
3841 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "%s", error);
3842
3843 /* There may be an optional address list of senders to be used as another
3844 constraint on the rule. This was added later, so the syntax is a bit of a
3845 fudge. Anything that is not a retry rule starting "F," or "G," is treated as
3846 an address list. */
3847
3848 while (isspace(*p)) p++;
3849 if (Ustrncmp(p, "senders", 7) == 0)
3850 {
3851 p += 7;
3852 while (isspace(*p)) p++;
3853 if (*p++ != '=') log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
3854 "\"=\" expected after \"senders\" in retry rule");
3855 while (isspace(*p)) p++;
3856 next->senders = string_dequote(&p);
3857 }
3858
3859 /* Now the retry rules. Keep the maximum timeout encountered. */
3860
3861 while (isspace(*p)) p++;
3862
3863 while (*p != 0)
3864 {
3865 retry_rule *rule = store_get(sizeof(retry_rule));
3866 *rchain = rule;
3867 rchain = &(rule->next);
3868 rule->next = NULL;
3869 rule->rule = toupper(*p++);
3870 rule->timeout = retry_arg(&p, 0);
3871 if (rule->timeout > retry_maximum_timeout)
3872 retry_maximum_timeout = rule->timeout;
3873
3874 switch (rule->rule)
3875 {
3876 case 'F': /* Fixed interval */
3877 rule->p1 = retry_arg(&p, 0);
3878 break;
3879
3880 case 'G': /* Geometrically increasing intervals */
6af56900 3881 case 'H': /* Ditto, but with randomness */
059ec3d9
PH
3882 rule->p1 = retry_arg(&p, 0);
3883 rule->p2 = retry_arg(&p, 1);
3884 break;
3885
3886 default:
3887 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "unknown retry rule letter");
3888 break;
3889 }
3890
3891 if (rule->timeout <= 0 || rule->p1 <= 0 ||
6af56900 3892 (rule->rule != 'F' && rule->p2 < 1000))
059ec3d9
PH
3893 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
3894 "bad parameters for retry rule");
3895
3896 while (isspace(*p)) p++;
3897 if (*p == ';')
3898 {
3899 p++;
3900 while (isspace(*p)) p++;
3901 }
3902 else if (*p != 0)
3903 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "semicolon expected");
3904 }
3905 }
3906}
3907
3908
3909
3910/*************************************************
3911* Initialize authenticators *
3912*************************************************/
3913
3914/* Read the authenticators section of the configuration file.
3915
3916Arguments: none
3917Returns: nothing
3918*/
3919
3920static void
3921auths_init(void)
3922{
3923auth_instance *au, *bu;
3924readconf_driver_init(US"authenticator",
3925 (driver_instance **)(&auths), /* chain anchor */
3926 (driver_info *)auths_available, /* available drivers */
3927 sizeof(auth_info), /* size of info block */
3928 &auth_defaults, /* default values for generic options */
3929 sizeof(auth_instance), /* size of instance block */
3930 optionlist_auths, /* generic options */
3931 optionlist_auths_size);
3932
3933for (au = auths; au != NULL; au = au->next)
3934 {
3935 if (au->public_name == NULL)
3936 log_write(0, LOG_PANIC_DIE|LOG_CONFIG, "no public name specified for "
3937 "the %s authenticator", au->name);
3938 for (bu = au->next; bu != NULL; bu = bu->next)
3939 {
3940 if (strcmpic(au->public_name, bu->public_name) == 0)
3941 {
3942 if ((au->client && bu->client) || (au->server && bu->server))
3943 log_write(0, LOG_PANIC_DIE|LOG_CONFIG, "two %s authenticators "
3944 "(%s and %s) have the same public name (%s)",
3945 (au->client)? US"client" : US"server", au->name, bu->name,
3946 au->public_name);
3947 }
3948 }
3949 }
3950}
3951
3952
3953
3954
3955/*************************************************
3956* Read ACL information *
3957*************************************************/
3958
3959/* If this run of Exim is not doing something that involves receiving a
3960message, we can just skip over the ACL information. No need to parse it.
3961
3962First, we have a function for acl_read() to call back to get the next line. We
3963need to remember the line we passed, because at the end it will contain the
3964name of the next ACL. */
3965
3966static uschar *acl_line;
3967
3968static uschar *
3969acl_callback(void)
3970{
3971acl_line = get_config_line();
3972return acl_line;
3973}
3974
3975
3976/* Now the main function:
3977
cb46fd2b 3978Arguments: none
059ec3d9
PH
3979Returns: nothing
3980*/
3981
3982static void
cb46fd2b 3983readconf_acl(void)
059ec3d9
PH
3984{
3985uschar *p;
3986
cf00dad6
PH
3987/* Read each ACL and add it into the tree. Macro (re)definitions are allowed
3988between ACLs. */
059ec3d9
PH
3989
3990acl_line = get_config_line();
3991
3992while(acl_line != NULL)
3993 {
3994 uschar name[64];
3995 tree_node *node;
3996 uschar *error;
3997
3998 p = readconf_readname(name, sizeof(name), acl_line);
cf00dad6
PH
3999 if (isupper(*name) && *p == '=')
4000 {
4001 read_macro_assignment(acl_line);
4002 acl_line = get_config_line();
4003 continue;
4004 }
4005
4006 if (*p != ':' || name[0] == 0)
4007 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "missing or malformed ACL name");
059ec3d9
PH
4008
4009 node = store_get(sizeof(tree_node) + Ustrlen(name));
4010 Ustrcpy(node->name, name);
4011 if (!tree_insertnode(&acl_anchor, node))
4012 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
4013 "there are two ACLs called \"%s\"", name);
4014
4015 node->data.ptr = acl_read(acl_callback, &error);
4016
4017 if (node->data.ptr == NULL && error != NULL)
4018 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "error in ACL: %s", error);
4019 }
4020}
4021
4022
4023
4024/*************************************************
4025* Read configuration for local_scan() *
4026*************************************************/
4027
4028/* This function is called after "begin local_scan" is encountered in the
4029configuration file. If the local_scan() function allows for configuration
4030options, we can process them. Otherwise, we expire in a panic.
4031
4032Arguments: none
4033Returns: nothing
4034*/
4035
4036static void
4037local_scan_init(void)
4038{
4039#ifndef LOCAL_SCAN_HAS_OPTIONS
4040log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN, "local_scan() options not supported: "
4041 "(LOCAL_SCAN_HAS_OPTIONS not defined in Local/Makefile)");
4042#else
4043
4044uschar *p;
4045while ((p = get_config_line()) != NULL)
4046 {
4047 (void) readconf_handle_option(p, local_scan_options, local_scan_options_count,
4048 NULL, US"local_scan option \"%s\" unknown");
4049 }
4050#endif
4051}
4052
4053
4054
4055/*************************************************
4056* Read rest of configuration (after main) *
4057*************************************************/
4058
4059/* This function reads the rest of the runtime configuration, after the main
4060configuration. It is called only when actually needed. Each subsequent section
4061of the configuration starts with a line of the form
4062
4063 begin name
4064
4065where the name is "routers", "transports", etc. A section is terminated by
4066hitting the next "begin" line, and the next name is left in next_section.
4067Because it may confuse people as to whether the names are singular or plural,
4068we add "s" if it's missing. There is always enough room in next_section for
4069this. This function is basically just a switch.
4070
351a5bc8 4071Arguments: none
059ec3d9
PH
4072Returns: nothing
4073*/
4074
4075static uschar *section_list[] = {
4076 US"acls",
4077 US"authenticators",
4078 US"local_scans",
4079 US"retrys",
4080 US"rewrites",
4081 US"routers",
4082 US"transports"};
4083
4084void
351a5bc8 4085readconf_rest(void)
059ec3d9
PH
4086{
4087int had = 0;
4088
4089while(next_section[0] != 0)
4090 {
4091 int bit;
4092 int first = 0;
4093 int last = sizeof(section_list) / sizeof(uschar *);
4094 int mid = last/2;
4095 int n = Ustrlen(next_section);
4096
4097 if (tolower(next_section[n-1]) != 's') Ustrcpy(next_section+n, "s");
4098
4099 for (;;)
4100 {
4101 int c = strcmpic(next_section, section_list[mid]);
4102 if (c == 0) break;
4103 if (c > 0) first = mid + 1; else last = mid;
4104 if (first >= last)
4105 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
4106 "\"%.*s\" is not a known configuration section name", n, next_section);
4107 mid = (last + first)/2;
4108 }
4109
4110 bit = 1 << mid;
4111 if (((had ^= bit) & bit) == 0)
4112 log_write(0, LOG_PANIC_DIE|LOG_CONFIG_IN,
4113 "\"%.*s\" section is repeated in the configuration file", n,
4114 next_section);
4115
4116 switch(mid)
4117 {
cb46fd2b 4118 case 0: readconf_acl(); break;
059ec3d9
PH
4119 case 1: auths_init(); break;
4120 case 2: local_scan_init(); break;
4121 case 3: readconf_retries(); break;
4122 case 4: readconf_rewrites(); break;
4123 case 5: route_init(); break;
4124 case 6: transport_init(); break;
4125 }
4126 }
4127
f1e894f3 4128(void)fclose(config_file);
059ec3d9
PH
4129}
4130
4131/* End of readconf.c */