c535ea12195651262f9a8332f9c906c6142760da
[exim.git] / src / src / globals.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2023 */
6 /* Copyright (c) University of Cambridge 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
9
10 /* All the global variables are defined together in this one module, so
11 that they are easy to find. */
12
13 #include "exim.h"
14
15
16 /* Generic options for auths, all of which live inside auth_instance
17 data blocks and hence have the opt_public flag set. */
18
19 optionlist optionlist_auths[] = {
20   { "client_condition", opt_stringptr | opt_public,
21                  OPT_OFF(auth_instance, client_condition) },
22   { "client_set_id", opt_stringptr | opt_public,
23                  OPT_OFF(auth_instance, set_client_id) },
24   { "driver",        opt_stringptr | opt_public,
25                  OPT_OFF(auth_instance, driver_name) },
26   { "public_name",   opt_stringptr | opt_public,
27                  OPT_OFF(auth_instance, public_name) },
28   { "server_advertise_condition", opt_stringptr | opt_public,
29                  OPT_OFF(auth_instance, advertise_condition)},
30   { "server_condition", opt_stringptr | opt_public,
31                  OPT_OFF(auth_instance, server_condition) },
32   { "server_debug_print", opt_stringptr | opt_public,
33                  OPT_OFF(auth_instance, server_debug_string) },
34   { "server_mail_auth_condition", opt_stringptr | opt_public,
35                  OPT_OFF(auth_instance, mail_auth_condition) },
36   { "server_set_id", opt_stringptr | opt_public,
37                  OPT_OFF(auth_instance, set_id) }
38 };
39
40 int     optionlist_auths_size = nelem(optionlist_auths);
41
42 /* An empty host aliases list. */
43
44 uschar *no_aliases             = NULL;
45
46
47 /* For comments on these variables, see globals.h. I'm too idle to
48 duplicate them here... */
49
50 #ifdef EXIM_PERL
51 uschar *opt_perl_startup       = NULL;
52 BOOL    opt_perl_at_start      = FALSE;
53 BOOL    opt_perl_started       = FALSE;
54 BOOL    opt_perl_taintmode     = FALSE;
55 #endif
56
57 #ifdef EXPAND_DLFUNC
58 tree_node *dlobj_anchor        = NULL;
59 #endif
60
61 #ifdef LOOKUP_IBASE
62 uschar *ibase_servers          = NULL;
63 #endif
64
65 #ifdef LOOKUP_LDAP
66 uschar *eldap_ca_cert_dir      = NULL;
67 uschar *eldap_ca_cert_file     = NULL;
68 uschar *eldap_cert_file        = NULL;
69 uschar *eldap_cert_key         = NULL;
70 uschar *eldap_cipher_suite     = NULL;
71 uschar *eldap_default_servers  = NULL;
72 uschar *eldap_require_cert     = NULL;
73 int     eldap_version          = -1;
74 BOOL    eldap_start_tls        = FALSE;
75 #endif
76
77 #ifdef LOOKUP_MYSQL
78 uschar *mysql_servers          = NULL;
79 #endif
80
81 #ifdef LOOKUP_ORACLE
82 uschar *oracle_servers         = NULL;
83 #endif
84
85 #ifdef LOOKUP_PGSQL
86 uschar *pgsql_servers          = NULL;
87 #endif
88
89 #ifdef LOOKUP_REDIS
90 uschar *redis_servers          = NULL;
91 #endif
92
93 #ifdef LOOKUP_SQLITE
94 uschar *sqlite_dbfile          = NULL;
95 int     sqlite_lock_timeout    = 5;
96 #endif
97
98 #ifdef SUPPORT_MOVE_FROZEN_MESSAGES
99 BOOL    move_frozen_messages   = FALSE;
100 #endif
101
102 /* These variables are outside the #ifdef because it keeps the code less
103 cluttered in several places (e.g. during logging) if we can always refer to
104 them. Also, the tls_ variables are now always visible.  Note that these are
105 only used for smtp connections, not for service-daemon access. */
106
107 tls_support tls_in = {
108  .active =              {.sock = -1}
109  /* all other elements zero */
110 };
111 tls_support tls_out = {
112  .active =              {.sock = -1},
113  /* all other elements zero */
114 };
115
116 uschar *dsn_envid              = NULL;
117 int     dsn_ret                = 0;
118 const pcre2_code  *regex_DSN         = NULL;
119 uschar *dsn_advertise_hosts    = NULL;
120
121 #ifndef DISABLE_TLS
122 BOOL    gnutls_compat_mode     = FALSE;
123 BOOL    gnutls_allow_auto_pkcs11 = FALSE;
124 uschar *hosts_require_alpn     = NULL;
125 uschar *openssl_options        = NULL;
126 const pcre2_code *regex_STARTTLS     = NULL;
127 uschar *tls_advertise_hosts    = US"*";
128 uschar *tls_alpn               = US"smtp:esmtp";
129 uschar *tls_certificate        = NULL;
130 uschar *tls_crl                = NULL;
131 /* This default matches NSS DH_MAX_P_BITS value at current time (2012), because
132 that's the interop problem which has been observed: GnuTLS suggesting a higher
133 bit-count as "NORMAL" (2432) and Thunderbird dropping connection. */
134 int     tls_dh_max_bits        = 2236;
135 uschar *tls_dhparam            = NULL;
136 uschar *tls_eccurve            = US"auto";
137 # ifndef DISABLE_OCSP
138 uschar *tls_ocsp_file          = NULL;
139 # endif
140 uschar *tls_privatekey         = NULL;
141 BOOL    tls_remember_esmtp     = FALSE;
142 uschar *tls_require_ciphers    = NULL;
143 # ifndef DISABLE_TLS_RESUME
144 uschar *tls_resumption_hosts   = NULL;
145 # endif
146 uschar *tls_try_verify_hosts   = NULL;
147 uschar *tls_verify_certificates= US"system";
148 uschar *tls_verify_hosts       = NULL;
149 int     tls_watch_fd           = -1;
150 time_t  tls_watch_trigger_time = (time_t)0;
151 #else   /*DISABLE_TLS*/
152 uschar *tls_advertise_hosts    = NULL;
153 #endif
154
155 #ifndef DISABLE_PRDR
156 /* Per Recipient Data Response variables */
157 BOOL    prdr_enable            = FALSE;
158 BOOL    prdr_requested         = FALSE;
159 const pcre2_code *regex_PRDR         = NULL;
160 #endif
161
162 #ifdef SUPPORT_I18N
163 const pcre2_code *regex_UTF8         = NULL;
164 #endif
165
166 /* Input-reading functions for messages, so we can use special ones for
167 incoming TCP/IP. The defaults use stdin. We never need these for any
168 stand-alone tests. */
169
170 #if !defined(STAND_ALONE) && !defined(MACRO_PREDEF)
171 int     (*lwr_receive_getc)(unsigned)   = stdin_getc;
172 uschar * (*lwr_receive_getbuf)(unsigned *) = NULL;
173 int     (*lwr_receive_ungetc)(int)      = stdin_ungetc;
174 BOOL    (*lwr_receive_hasc)(void)       = stdin_hasc;
175
176 int     (*receive_getc)(unsigned)       = stdin_getc;
177 uschar * (*receive_getbuf)(unsigned *)  = NULL;
178 void    (*receive_get_cache)(unsigned)  = NULL;
179 BOOL    (*receive_hasc)(void)           = stdin_hasc;
180 int     (*receive_ungetc)(int)          = stdin_ungetc;
181 int     (*receive_feof)(void)           = stdin_feof;
182 int     (*receive_ferror)(void)         = stdin_ferror;
183 #endif
184
185
186 /* List of per-address expansion variables for clearing and saving/restoring
187 when verifying one address while routing/verifying another. We have to have
188 the size explicit, because it is referenced from more than one module. */
189
190 const uschar **address_expansions[ADDRESS_EXPANSIONS_COUNT] = {
191   CUSS &deliver_address_data,
192   CUSS &deliver_domain,
193   CUSS &deliver_domain_data,
194   CUSS &deliver_domain_orig,
195   CUSS &deliver_domain_parent,
196   CUSS &deliver_localpart,
197   CUSS &deliver_localpart_data,
198   CUSS &deliver_localpart_orig,
199   CUSS &deliver_localpart_parent,
200   CUSS &deliver_localpart_prefix,
201   CUSS &deliver_localpart_suffix,
202   CUSS (uschar **)(&deliver_recipients),
203   CUSS &deliver_host,
204   CUSS &deliver_home,
205   CUSS &address_file,
206   CUSS &address_pipe,
207   CUSS &self_hostname,
208   NULL };
209
210 int address_expansions_count = sizeof(address_expansions)/sizeof(uschar **);
211
212 /******************************************************************************/
213 /* General global variables.  Boolean flags are done as a group
214 so that only one bit each is needed, packed, for all those we never
215 need to take a pointer - and only a char for the rest.
216 This means a struct, unfortunately since it clutters the sourcecode. */
217
218 struct global_flags f =
219 {
220         .acl_temp_details       = FALSE,
221         .active_local_from_check = FALSE,
222         .active_local_sender_retain = FALSE,
223         .address_test_mode      = FALSE,
224         .admin_user             = FALSE,
225         .allow_auth_unadvertised= FALSE,
226         .allow_unqualified_recipient = TRUE,    /* For local messages */
227         .allow_unqualified_sender = TRUE,       /* Reset for SMTP */
228         .authentication_local   = FALSE,
229
230         .background_daemon      = TRUE,
231         .bdat_readers_wanted    = FALSE,
232
233         .chunking_offered       = FALSE,
234         .config_changed         = FALSE,
235         .continue_more          = FALSE,
236
237         .daemon_listen          = FALSE,
238         .daemon_scion           = FALSE,
239         .debug_daemon           = FALSE,
240         .deliver_firsttime      = FALSE,
241         .deliver_force          = FALSE,
242         .deliver_freeze         = FALSE,
243         .deliver_force_thaw     = FALSE,
244         .deliver_manual_thaw    = FALSE,
245         .deliver_selectstring_regex = FALSE,
246         .deliver_selectstring_sender_regex = FALSE,
247         .disable_callout_flush  = FALSE,
248         .disable_delay_flush    = FALSE,
249         .disable_logging        = FALSE,
250 #ifndef DISABLE_DKIM
251         .dkim_disable_verify      = FALSE,
252         .dkim_init_done           = FALSE,
253 #endif
254 #ifdef SUPPORT_DMARC
255         .dmarc_has_been_checked  = FALSE,
256         .dmarc_disable_verify    = FALSE,
257         .dmarc_enable_forensic   = FALSE,
258 #endif
259         .dont_deliver           = FALSE,
260         .dot_ends               = TRUE,
261
262         .enable_dollar_recipients = FALSE,
263         .expand_string_forcedfail = FALSE,
264
265         .filter_running         = FALSE,
266
267         .header_rewritten       = FALSE,
268         .helo_verified          = FALSE,
269         .helo_verify_failed     = FALSE,
270         .host_checking_callout  = FALSE,
271         .host_find_failed_syntax= FALSE,
272
273         .inetd_wait_mode        = FALSE,
274         .is_inetd               = FALSE,
275
276         .local_error_message    = FALSE,
277         .log_testing_mode       = FALSE,
278
279 #ifdef WITH_CONTENT_SCAN
280         .no_mbox_unspool        = FALSE,
281 #endif
282         .no_multiline_responses = FALSE,
283         .notifier_socket_en     = TRUE,
284
285         .parse_allow_group      = FALSE,
286         .parse_found_group      = FALSE,
287         .pipelining_enable      = TRUE,
288 #if defined(SUPPORT_PROXY) || defined(SUPPORT_SOCKS)
289         .proxy_session_failed   = FALSE,
290 #endif
291
292         .queue_2stage           = FALSE,
293         .queue_only_policy      = FALSE,
294         .queue_run_local        = FALSE,
295         .queue_running          = FALSE,
296         .queue_smtp             = FALSE,
297
298         .really_exim            = TRUE,
299         .receive_call_bombout   = FALSE,
300         .recipients_discarded   = FALSE,
301         .running_in_test_harness = FALSE,
302
303         .search_find_defer      = FALSE,
304         .sender_address_forced  = FALSE,
305         .sender_host_notsocket  = FALSE,
306         .sender_host_unknown    = FALSE,
307         .sender_local           = FALSE,
308         .sender_name_forced     = FALSE,
309         .sender_set_untrusted   = FALSE,
310         .smtp_authenticated     = FALSE,
311 #ifndef DISABLE_PIPE_CONNECT
312         .smtp_in_early_pipe_advertised = FALSE,
313         .smtp_in_early_pipe_no_auth = FALSE,
314         .smtp_in_early_pipe_used = FALSE,
315 #endif
316         .smtp_in_pipelining_advertised = FALSE,
317         .smtp_in_pipelining_used = FALSE,
318         .smtp_in_quit           = FALSE,
319         .spool_file_wireformat  = FALSE,
320         .submission_mode        = FALSE,
321         .suppress_local_fixups  = FALSE,
322         .suppress_local_fixups_default = FALSE,
323         .synchronous_delivery   = FALSE,
324         .system_filtering       = FALSE,
325
326         .taint_check_slow       = FALSE,
327         .testsuite_delays       = TRUE,
328         .tcp_fastopen_ok        = FALSE,
329         .tcp_in_fastopen        = FALSE,
330         .tcp_in_fastopen_data   = FALSE,
331         .tcp_in_fastopen_logged = FALSE,
332         .tcp_out_fastopen_logged= FALSE,
333         .timestamps_utc         = FALSE,
334         .transport_filter_timed_out = FALSE,
335         .trusted_caller         = FALSE,
336         .trusted_config         = TRUE,
337 };
338
339 /******************************************************************************/
340 /* These are the flags which are either variables or mainsection options,
341 so an address is needed for access, or are exported to local_scan. */
342
343 BOOL    accept_8bitmime        = TRUE; /* deliberately not RFC compliant */
344 BOOL    allow_domain_literals  = FALSE;
345 BOOL    allow_mx_to_ip         = FALSE;
346 BOOL    allow_utf8_domains     = FALSE;
347 BOOL    authentication_failed  = FALSE;
348
349 BOOL    bounce_return_body     = TRUE;
350 BOOL    bounce_return_message  = TRUE;
351 BOOL    check_rfc2047_length   = TRUE;
352 BOOL    commandline_checks_require_admin = FALSE;
353
354 #ifdef EXPERIMENTAL_DCC
355 BOOL    dcc_direct_add_header  = FALSE;
356 #endif
357 BOOL    debug_store            = FALSE;
358 BOOL    delivery_date_remove   = TRUE;
359 BOOL    deliver_drop_privilege = FALSE;
360 #ifdef ENABLE_DISABLE_FSYNC
361 BOOL    disable_fsync          = FALSE;
362 #endif
363 BOOL    disable_ipv6           = FALSE;
364 BOOL    dns_csa_use_reverse    = TRUE;
365 BOOL    drop_cr                = FALSE;         /* No longer used */
366
367 BOOL    envelope_to_remove     = TRUE;
368 BOOL    exim_gid_set           = TRUE;          /* This gid is always set */
369 BOOL    exim_uid_set           = TRUE;          /* This uid is always set */
370 BOOL    extract_addresses_remove_arguments = TRUE;
371
372 BOOL    host_checking          = FALSE;
373 BOOL    host_lookup_deferred   = FALSE;
374 BOOL    host_lookup_failed     = FALSE;
375 BOOL    ignore_fromline_local  = FALSE;
376
377 BOOL    local_from_check       = TRUE;
378 BOOL    local_sender_retain    = FALSE;
379 BOOL    log_timezone           = FALSE;
380 BOOL    message_body_newlines  = FALSE;
381 BOOL    message_logs           = TRUE;
382 #ifdef SUPPORT_I18N
383 BOOL    message_smtputf8       = FALSE;
384 #endif
385 BOOL    mua_wrapper            = FALSE;
386
387 BOOL    preserve_message_logs  = FALSE;
388 BOOL    print_topbitchars      = FALSE;
389 BOOL    prod_requires_admin    = TRUE;
390 #if defined(SUPPORT_PROXY) || defined(SUPPORT_SOCKS) || defined(EXPERIMETAL_XCLIENT)
391 BOOL    proxy_session          = FALSE;
392 #endif
393
394 #ifndef DISABLE_QUEUE_RAMP
395 BOOL    queue_fast_ramp         = TRUE;
396 #endif
397 BOOL    queue_list_requires_admin = TRUE;
398 BOOL    queue_only             = FALSE;
399 BOOL    queue_only_load_latch  = TRUE;
400 BOOL    queue_only_override    = TRUE;
401 BOOL    queue_run_in_order     = FALSE;
402 BOOL    recipients_max_reject  = FALSE;
403 BOOL    return_path_remove     = TRUE;
404
405 BOOL    smtp_batched_input     = FALSE;
406 BOOL    sender_helo_dnssec     = FALSE;
407 BOOL    sender_host_dnssec     = FALSE;
408 BOOL    smtp_accept_keepalive  = TRUE;
409 BOOL    smtp_check_spool_space = TRUE;
410 BOOL    smtp_enforce_sync      = TRUE;
411 BOOL    smtp_etrn_serialize    = TRUE;
412 BOOL    smtp_input             = FALSE;
413 BOOL    smtp_return_error_details = FALSE;
414 #ifdef SUPPORT_SPF
415 BOOL    spf_result_guessed     = FALSE;
416 #endif
417 BOOL    split_spool_directory  = FALSE;
418 BOOL    spool_wireformat       = FALSE;
419 BOOL    strict_acl_vars        = FALSE;
420 BOOL    strip_excess_angle_brackets = FALSE;
421 BOOL    strip_trailing_dot     = FALSE;
422 BOOL    syslog_duplication     = TRUE;
423 BOOL    syslog_pid             = TRUE;
424 BOOL    syslog_timestamp       = TRUE;
425 BOOL    system_filter_gid_set  = FALSE;
426 BOOL    system_filter_uid_set  = FALSE;
427
428 BOOL    tcp_nodelay            = TRUE;
429 BOOL    write_rejectlog        = TRUE;
430
431 /******************************************************************************/
432
433 header_line *acl_added_headers = NULL;
434 tree_node *acl_anchor          = NULL;
435 uschar *acl_arg[9]             = {NULL, NULL, NULL, NULL, NULL,
436                                   NULL, NULL, NULL, NULL};
437 int     acl_narg               = 0;
438
439 int     acl_level              = 0;
440
441 uschar *acl_not_smtp           = NULL;
442 #ifdef WITH_CONTENT_SCAN
443 uschar *acl_not_smtp_mime      = NULL;
444 #endif
445 uschar *acl_not_smtp_start     = NULL;
446 uschar *acl_removed_headers    = NULL;
447 uschar *acl_smtp_auth          = NULL;
448 uschar *acl_smtp_connect       = NULL;
449 uschar *acl_smtp_data          = NULL;
450 #ifndef DISABLE_PRDR
451 uschar *acl_smtp_data_prdr     = US"accept";
452 #endif
453 #ifndef DISABLE_DKIM
454 uschar *acl_smtp_dkim          = NULL;
455 #endif
456 uschar *acl_smtp_etrn          = NULL;
457 uschar *acl_smtp_expn          = NULL;
458 uschar *acl_smtp_helo          = NULL;
459 uschar *acl_smtp_mail          = NULL;
460 uschar *acl_smtp_mailauth      = NULL;
461 #ifdef WITH_CONTENT_SCAN
462 uschar *acl_smtp_mime          = NULL;
463 #endif
464 uschar *acl_smtp_notquit       = NULL;
465 uschar *acl_smtp_predata       = NULL;
466 uschar *acl_smtp_quit          = NULL;
467 uschar *acl_smtp_rcpt          = NULL;
468 uschar *acl_smtp_starttls      = NULL;
469 uschar *acl_smtp_vrfy          = NULL;
470
471 tree_node *acl_var_c           = NULL;
472 tree_node *acl_var_m           = NULL;
473 uschar *acl_verify_message     = NULL;
474 string_item *acl_warn_logged   = NULL;
475
476 /* Names of SMTP places for use in ACL error messages, and corresponding SMTP
477 error codes - keep in step with definitions of ACL_WHERE_xxxx in macros.h. */
478
479 uschar *acl_wherenames[]       = { US"RCPT",
480                                    US"MAIL",
481                                    US"PREDATA",
482                                    US"MIME",
483                                    US"DKIM",
484                                    US"DATA",
485 #ifndef DISABLE_PRDR
486                                    US"PRDR",
487 #endif
488                                    US"non-SMTP",
489                                    US"AUTH",
490                                    US"connection",
491                                    US"ETRN",
492                                    US"EXPN",
493                                    US"EHLO or HELO",
494                                    US"MAILAUTH",
495                                    US"non-SMTP-start",
496                                    US"NOTQUIT",
497                                    US"QUIT",
498                                    US"STARTTLS",
499                                    US"VRFY",
500                                    US"delivery",
501                                    US"unknown"
502                                  };
503
504 uschar *acl_wherecodes[]       = { US"550",     /* RCPT */
505                                    US"550",     /* MAIL */
506                                    US"550",     /* PREDATA */
507                                    US"550",     /* MIME */
508                                    US"550",     /* DKIM */
509                                    US"550",     /* DATA */
510 #ifndef DISABLE_PRDR
511                                    US"550",    /* RCPT PRDR */
512 #endif
513                                    US"0",       /* not SMTP; not relevant */
514                                    US"503",     /* AUTH */
515                                    US"550",     /* connect */
516                                    US"458",     /* ETRN */
517                                    US"550",     /* EXPN */
518                                    US"550",     /* HELO/EHLO */
519                                    US"0",       /* MAILAUTH; not relevant */
520                                    US"0",       /* not SMTP; not relevant */
521                                    US"0",       /* NOTQUIT; not relevant */
522                                    US"0",       /* QUIT; not relevant */
523                                    US"550",     /* STARTTLS */
524                                    US"252",     /* VRFY */
525                                    US"0",       /* delivery; not relevant */
526                                    US"0"        /* unknown; not relevant */
527                                  };
528
529 uschar *add_environment        = NULL;
530 address_item  *addr_duplicate  = NULL;
531
532 address_item address_defaults = {
533   .next =               NULL,
534   .parent =             NULL,
535   .first =              NULL,
536   .dupof =              NULL,
537   .start_router =       NULL,
538   .router =             NULL,
539   .transport =          NULL,
540   .host_list =          NULL,
541   .host_used =          NULL,
542   .fallback_hosts =     NULL,
543   .reply =              NULL,
544   .retries =            NULL,
545   .address =            NULL,
546   .unique =             NULL,
547   .cc_local_part =      NULL,
548   .lc_local_part =      NULL,
549   .local_part =         NULL,
550   .prefix =             NULL,
551   .prefix_v =           NULL,
552   .suffix =             NULL,
553   .suffix_v =           NULL,
554   .domain =             NULL,
555   .address_retry_key =  NULL,
556   .domain_retry_key =   NULL,
557   .current_dir =        NULL,
558   .home_dir =           NULL,
559   .message =            NULL,
560   .user_message =       NULL,
561   .onetime_parent =     NULL,
562   .pipe_expandn =       NULL,
563   .return_filename =    NULL,
564   .self_hostname =      NULL,
565   .shadow_message =     NULL,
566 #ifndef DISABLE_TLS
567   .cipher =             NULL,
568   .ourcert =            NULL,
569   .peercert =           NULL,
570   .peerdn =             NULL,
571   .ocsp =               OCSP_NOT_REQ,
572 #endif
573 #ifdef EXPERIMENTAL_DSN_INFO
574   .smtp_greeting =      NULL,
575   .helo_response =      NULL,
576 #endif
577   .authenticator =      NULL,
578   .auth_id =            NULL,
579   .auth_sndr =          NULL,
580   .dsn_orcpt =          NULL,
581   .dsn_flags =          0,
582   .dsn_aware =          0,
583   .uid =                (uid_t)(-1),
584   .gid =                (gid_t)(-1),
585   .flags =              { 0 },
586   .domain_cache =       { 0 },                /* domain_cache - any larger array should be zeroed */
587   .localpart_cache =    { 0 },                /* localpart_cache - ditto */
588   .mode =               -1,
589   .more_errno =         0,
590   .delivery_time =      {.tv_sec = 0, .tv_usec = 0},
591   .basic_errno =        ERRNO_UNKNOWNERROR,
592   .child_count =        0,
593   .return_file =        -1,
594   .special_action =     SPECIAL_NONE,
595   .transport_return =   DEFER,
596   .prop = {                                     /* fields that are propagated to children */
597     .address_data =     NULL,
598     .domain_data =      NULL,
599     .localpart_data =   NULL,
600     .errors_address =   NULL,
601     .extra_headers =    NULL,
602     .remove_headers =   NULL,
603     .variables =        NULL,
604     .ignore_error =     FALSE,
605 #ifdef SUPPORT_I18N
606     .utf8_msg =         FALSE,
607     .utf8_downcvt =     FALSE,
608     .utf8_downcvt_maybe = FALSE
609 #endif
610   }
611 };
612
613 const uschar *address_file           = NULL;
614 const uschar *address_pipe           = NULL;
615 tree_node *addresslist_anchor  = NULL;
616 int     addresslist_count      = 0;
617 gid_t  *admin_groups           = NULL;
618
619 #ifdef EXPERIMENTAL_ARC
620 struct arc_set *arc_received    = NULL;
621 int     arc_received_instance   = 0;
622 int     arc_oldest_pass         = 0;
623 const uschar *arc_state         = NULL;
624 const uschar *arc_state_reason  = NULL;
625 #endif
626
627 uschar *authenticated_fail_id  = NULL;
628 uschar *authenticated_id       = NULL;
629 uschar *authenticated_sender   = NULL;
630 auth_instance  *auths          = NULL;
631 uschar *auth_advertise_hosts   = US"*";
632 auth_instance auth_defaults    = {
633     .next =             NULL,
634     .name =             NULL,
635     .info =             NULL,
636     .options_block =    NULL,
637     .driver_name =      NULL,
638     .advertise_condition = NULL,
639     .client_condition = NULL,
640     .public_name =      NULL,
641     .set_id =           NULL,
642     .set_client_id =    NULL,
643     .mail_auth_condition = NULL,
644     .server_debug_string = NULL,
645     .server_condition = NULL,
646     .client =           FALSE,
647     .server =           FALSE,
648     .advertised =       FALSE
649 };
650
651 uschar *auth_defer_msg         = US"reason not recorded";
652 uschar *auth_defer_user_msg    = US"";
653 const uschar *auth_vars[AUTH_VARS];
654 uschar *authenticator_name     = NULL;
655 int     auto_thaw              = 0;
656 #ifdef WITH_CONTENT_SCAN
657 int     av_failed              = FALSE; /* boolean but accessed as vtype_int*/
658 uschar *av_scanner             = US"sophie:/var/run/sophie";  /* AV scanner */
659 #endif
660
661 #if BASE_62 == 62
662 uschar *base62_chars=
663     US"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
664 #else
665 uschar *base62_chars= US"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
666 #endif
667
668 uschar *bi_command             = NULL;
669 uschar *big_buffer             = NULL;
670 int     big_buffer_size        = BIG_BUFFER_SIZE;
671 #ifdef EXPERIMENTAL_BRIGHTMAIL
672 uschar *bmi_alt_location       = NULL;
673 uschar *bmi_base64_tracker_verdict = NULL;
674 uschar *bmi_base64_verdict     = NULL;
675 uschar *bmi_config_file        = US"/opt/brightmail/etc/brightmail.cfg";
676 int     bmi_deliver            = 1;
677 int     bmi_run                = 0;
678 uschar *bmi_verdicts           = NULL;
679 #endif
680 int     bsmtp_transaction_linecount = 0;
681 int     body_8bitmime          = 0;
682 int     body_linecount         = 0;
683 int     body_zerocount         = 0;
684 uschar *bounce_message_file    = NULL;
685 uschar *bounce_message_text    = NULL;
686 const uschar *bounce_recipient = NULL;
687 int     bounce_return_linesize_limit = 998;
688 int     bounce_return_size_limit = 100*1024;
689 uschar *bounce_sender_authentication = NULL;
690
691 uschar *callout_address        = NULL;
692 int     callout_cache_domain_positive_expire = 7*24*60*60;
693 int     callout_cache_domain_negative_expire = 3*60*60;
694 int     callout_cache_positive_expire = 24*60*60;
695 int     callout_cache_negative_expire = 2*60*60;
696 uschar *callout_random_local_part = US"$primary_hostname-$tod_epoch-testing";
697 uschar *check_dns_names_pattern= US"(?i)^(?>(?(1)\\.|())[^\\W](?>[a-z0-9/_-]*[^\\W])?)+(\\.?)$";
698 int     check_log_inodes       = 100;
699 int_eximarith_t check_log_space = 10*1024;      /* 10K Kbyte == 10MB */
700 int     check_spool_inodes     = 100;
701 int_eximarith_t check_spool_space = 10*1024;    /* 10K Kbyte == 10MB */
702
703 uschar *chunking_advertise_hosts = US"*";
704 unsigned chunking_datasize     = 0;
705 unsigned chunking_data_left    = 0;
706 chunking_state_t chunking_state= CHUNKING_NOT_OFFERED;
707 const pcre2_code *regex_CHUNKING     = NULL;
708
709 #ifdef EXPERIMENTAL_ESMTP_LIMITS
710 const pcre2_code *regex_LIMITS        = NULL;
711 #endif
712
713 uschar *client_authenticator   = NULL;
714 uschar *client_authenticated_id = NULL;
715 uschar *client_authenticated_sender = NULL;
716 #ifndef DISABLE_CLIENT_CMD_LOG
717 gstring *client_cmd_log        = NULL;
718 #endif
719 int     clmacro_count          = 0;
720 uschar *clmacros[MAX_CLMACROS];
721 FILE   *config_file            = NULL;
722 const uschar *config_filename  = NULL;
723 int     config_lineno          = 0;
724 #ifdef CONFIGURE_GROUP
725 gid_t   config_gid             = CONFIGURE_GROUP;
726 #else
727 gid_t   config_gid             = 0;
728 #endif
729 const uschar * config_main_filelist = US CONFIGURE_FILE
730                          "\0<-----------Space to patch configure_filename->";
731 uschar *config_main_filename   = NULL;
732 uschar *config_main_directory  = NULL;
733
734 #ifdef CONFIGURE_OWNER
735 uid_t   config_uid             = CONFIGURE_OWNER;
736 #else
737 uid_t   config_uid             = 0;
738 #endif
739
740 uint64_t connection_id         = 0L;
741 int     connection_max_messages= -1;
742 uschar *continue_proxy_cipher  = NULL;
743 BOOL    continue_proxy_dane    = FALSE;
744 uschar *continue_proxy_sni     = NULL;
745 uschar *continue_hostname      = NULL;
746 uschar *continue_host_address  = NULL;
747 int     continue_sequence      = 1;
748 uschar *continue_transport     = NULL;
749 #ifdef EXPERIMENTAL_ESMTP_LIMITS
750 unsigned continue_limit_mail   = 0;
751 unsigned continue_limit_rcpt   = 0;
752 unsigned continue_limit_rcptdom= 0;
753 #endif
754
755 uschar *csa_status             = NULL;
756 cut_t   cutthrough = {
757   .callout_hold_only =  FALSE,                          /* verify-only: normal delivery */
758   .delivery =           FALSE,                          /* when to attempt */
759   .defer_pass =         FALSE,                          /* on defer: spool locally */
760   .is_tls =             FALSE,                          /* not a TLS conn yet */
761   .cctx =               {.sock = -1},                   /* open connection */
762   .nrcpt =              0,                              /* number of addresses */
763 };
764
765 int     daemon_notifier_fd     = -1;
766 uschar *daemon_smtp_port       = US"smtp";
767 int     daemon_startup_retries = 9;
768 int     daemon_startup_sleep   = 30;
769
770 #ifdef EXPERIMENTAL_DCC
771 uschar *dcc_header             = NULL;
772 uschar *dcc_result             = NULL;
773 uschar *dccifd_address         = US"/usr/local/dcc/var/dccifd";
774 uschar *dccifd_options         = US"header";
775 #endif
776
777 int     debug_fd               = -1;
778 FILE   *debug_file             = NULL;
779 int     debug_notall[]         = {
780   Di_memory,
781   Di_noutf8,
782   -1
783 };
784 bit_table debug_options[]      = { /* must be in alphabetical order and use
785                                  only the enum values from macro.h */
786   BIT_TABLE(D, acl),
787   BIT_TABLE(D, all),
788   BIT_TABLE(D, auth),
789   BIT_TABLE(D, deliver),
790   BIT_TABLE(D, dns),
791   BIT_TABLE(D, dnsbl),
792   BIT_TABLE(D, exec),
793   BIT_TABLE(D, expand),
794   BIT_TABLE(D, filter),
795   BIT_TABLE(D, hints_lookup),
796   BIT_TABLE(D, host_lookup),
797   BIT_TABLE(D, ident),
798   BIT_TABLE(D, interface),
799   BIT_TABLE(D, lists),
800   BIT_TABLE(D, load),
801   BIT_TABLE(D, local_scan),
802   BIT_TABLE(D, lookup),
803   BIT_TABLE(D, memory),
804   BIT_TABLE(D, noutf8),
805   BIT_TABLE(D, pid),
806   BIT_TABLE(D, process_info),
807   BIT_TABLE(D, queue_run),
808   BIT_TABLE(D, receive),
809   BIT_TABLE(D, resolver),
810   BIT_TABLE(D, retry),
811   BIT_TABLE(D, rewrite),
812   BIT_TABLE(D, route),
813   BIT_TABLE(D, timestamp),
814   BIT_TABLE(D, tls),
815   BIT_TABLE(D, transport),
816   BIT_TABLE(D, uid),
817   BIT_TABLE(D, verify),
818 };
819 int      debug_options_count    = nelem(debug_options);
820 uschar   debuglog_name[LOG_NAME_SIZE] = {0};
821 unsigned debug_pretrigger_bsize = 0;
822 uschar * debug_pretrigger_buf   = NULL;
823 unsigned int debug_selector     = 0;
824
825 int     delay_warning[DELAY_WARNING_SIZE] = { DELAY_WARNING_SIZE, 1, 24*60*60 };
826 uschar *delay_warning_condition=
827   US"${if or {"
828             "{ !eq{$h_list-id:$h_list-post:$h_list-subscribe:}{} }"
829             "{ match{$h_precedence:}{(?i)bulk|list|junk} }"
830             "{ match{$h_auto-submitted:}{(?i)auto-generated|auto-replied} }"
831             "} {no}{yes}}";
832 uschar *deliver_address_data   = NULL;
833 int     deliver_datafile       = -1;
834 const uschar *deliver_domain   = NULL;
835 uschar *deliver_domain_data    = NULL;
836 const uschar *deliver_domain_orig = NULL;
837 const uschar *deliver_domain_parent = NULL;
838 time_t  deliver_frozen_at      = 0;
839 uschar *deliver_home           = NULL;
840 const uschar *deliver_host     = NULL;
841 const uschar *deliver_host_address = NULL;
842 int     deliver_host_port      = 0;
843 uschar *deliver_in_buffer      = NULL;
844 ino_t   deliver_inode          = 0;
845 const uschar *deliver_localpart= NULL;
846 uschar *deliver_localpart_data = NULL;
847 const uschar *deliver_localpart_orig = NULL;
848 const uschar *deliver_localpart_parent = NULL;
849 const uschar *deliver_localpart_prefix = NULL;
850 const uschar *deliver_localpart_prefix_v = NULL;
851 const uschar *deliver_localpart_suffix = NULL;
852 const uschar *deliver_localpart_suffix_v = NULL;
853 uschar *deliver_out_buffer     = NULL;
854 int     deliver_queue_load_max = -1;
855 address_item  *deliver_recipients = NULL;
856 uschar *deliver_selectstring   = NULL;
857 uschar *deliver_selectstring_sender = NULL;
858
859 #ifndef DISABLE_DKIM
860 unsigned dkim_collect_input      = 0;
861 uschar *dkim_cur_signer          = NULL;
862 int     dkim_key_length          = 0;
863 void   *dkim_signatures          = NULL;
864 uschar *dkim_signers             = NULL;
865 uschar *dkim_signing_domain      = NULL;
866 uschar *dkim_signing_selector    = NULL;
867 gstring *dkim_signing_record     = NULL;
868 uschar *dkim_verify_hashes       = US"sha256:sha512";
869 uschar *dkim_verify_keytypes     = US"ed25519:rsa";
870 uschar *dkim_verify_min_keysizes = US"rsa=1024 ed25519=250";
871 BOOL    dkim_verify_minimal      = FALSE;
872 uschar *dkim_verify_overall      = NULL;
873 uschar *dkim_verify_signers      = US"$dkim_signers";
874 uschar *dkim_verify_status       = NULL;
875 uschar *dkim_verify_reason       = NULL;
876 #endif
877 #ifdef SUPPORT_DMARC
878 uschar *dmarc_domain_policy     = NULL;
879 uschar *dmarc_forensic_sender   = NULL;
880 uschar *dmarc_history_file      = NULL;
881 uschar *dmarc_status            = NULL;
882 uschar *dmarc_status_text       = NULL;
883 uschar *dmarc_tld_file          = NULL;
884 uschar *dmarc_used_domain       = NULL;
885 #endif
886
887 uschar *dns_again_means_nonexist = NULL;
888 int     dns_csa_search_limit   = 5;
889 int     dns_cname_loops        = 1;
890 #ifdef SUPPORT_DANE
891 int     dns_dane_ok            = -1;
892 #endif
893 uschar *dns_ipv4_lookup        = NULL;
894 int     dns_retrans            = 0;
895 int     dns_retry              = 0;
896 int     dns_dnssec_ok          = -1; /* <0 = not coerced */
897 uschar *dns_trust_aa           = NULL;
898 int     dns_use_edns0          = -1; /* <0 = not coerced */
899 uschar *dnslist_domain         = NULL;
900 uschar *dnslist_matched        = NULL;
901 uschar *dnslist_text           = NULL;
902 uschar *dnslist_value          = NULL;
903 tree_node *domainlist_anchor   = NULL;
904 int     domainlist_count       = 0;
905 const uschar *driver_srcfile   = NULL;
906 int     driver_srcline         = 0;
907 uschar *dsn_from               = US DEFAULT_DSN_FROM;
908 unsigned int dtrigger_selector = 0;
909
910 int     errno_quota            = ERRNO_QUOTA;
911 uschar *errors_copy            = NULL;
912 int     error_handling         = ERRORS_SENDER;
913 uschar *errors_reply_to        = NULL;
914 int     errors_sender_rc       = EXIT_FAILURE;
915 #ifndef DISABLE_EVENT
916 uschar *event_action             = NULL;        /* expansion for delivery events */
917 uschar *event_data               = NULL;        /* auxiliary data variable for event */
918 int     event_defer_errno        = 0;
919 const uschar *event_name         = NULL;        /* event name variable */
920 #endif
921
922
923 gid_t   exim_gid               = EXIM_GID;
924 uschar *exim_path              = US BIN_DIRECTORY "/exim"
925                         "\0<---------------Space to patch exim_path->";
926 uid_t   exim_uid               = EXIM_UID;
927 int     expand_level           = 0;             /* Nesting depth, indent for debug */
928 int     expand_forbid          = 0;
929 int     expand_nlength[EXPAND_MAXN+1];
930 int     expand_nmax            = -1;
931 const uschar *expand_nstring[EXPAND_MAXN+1];
932 uschar *expand_string_message;
933 uschar *extra_local_interfaces = NULL;
934
935 int     fake_response          = OK;
936 uschar *fake_response_text     = US"Your message has been rejected but is "
937                                    "being kept for evaluation.\nIf it was a "
938                                    "legitimate message, it may still be "
939                                    "delivered to the target recipient(s).";
940 int     filter_n[FILTER_VARIABLE_COUNT];
941 int     filter_sn[FILTER_VARIABLE_COUNT];
942 int     filter_test            = FTEST_NONE;
943 const uschar * filter_test_sfile = NULL;
944 const uschar * filter_test_ufile = NULL;
945 uschar *filter_thisaddress     = NULL;
946 int     finduser_retries       = 0;
947 uid_t   fixed_never_users[]    = { FIXED_NEVER_USERS };
948 uschar *freeze_tell            = NULL;
949 uschar *freeze_tell_config     = NULL;
950 uschar *fudged_queue_times     = US"";
951
952 uschar *gecos_name             = NULL;
953 uschar *gecos_pattern          = NULL;
954 rewrite_rule  *global_rewrite_rules = NULL;
955
956 volatile sig_atomic_t had_command_timeout = 0;
957 volatile sig_atomic_t had_command_sigterm = 0;
958 volatile sig_atomic_t had_data_timeout    = 0;
959 volatile sig_atomic_t had_data_sigint     = 0;
960 const uschar *headers_charset  = US HEADERS_CHARSET;
961 int     header_insert_maxlen   = 64 * 1024;
962 header_line  *header_last      = NULL;
963 header_line  *header_list      = NULL;
964 int     header_maxsize         = HEADER_MAXSIZE;
965 int     header_line_maxsize    = 0;
966
967 header_name header_names[] = {
968   /* name               len     allow_resent    htype */
969   { US"bcc",            3,      TRUE,           htype_bcc },
970   { US"cc",             2,      TRUE,           htype_cc },
971   { US"date",           4,      TRUE,           htype_date },
972   { US"delivery-date", 13,      FALSE,          htype_delivery_date },
973   { US"envelope-to",   11,      FALSE,          htype_envelope_to },
974   { US"from",           4,      TRUE,           htype_from },
975   { US"message-id",    10,      TRUE,           htype_id },
976   { US"received",       8,      FALSE,          htype_received },
977   { US"reply-to",       8,      FALSE,          htype_reply_to },
978   { US"return-path",   11,      FALSE,          htype_return_path },
979   { US"sender",         6,      TRUE,           htype_sender },
980   { US"subject",        7,      FALSE,          htype_subject },
981   { US"to",             2,      TRUE,           htype_to }
982 };
983
984 int header_names_size          = nelem(header_names);
985
986 uschar *helo_accept_junk_hosts = NULL;
987 uschar *helo_allow_chars       = US"";
988 uschar *helo_lookup_domains    = US"@ : @[]";
989 uschar *helo_try_verify_hosts  = NULL;
990 uschar *helo_verify_hosts      = NULL;
991 const uschar *hex_digits       = CUS"0123456789abcdef";
992 uschar *hold_domains           = NULL;
993 uschar *host_data              = NULL;
994 uschar *host_lookup            = NULL;
995 uschar *host_lookup_order      = US"bydns:byaddr";
996 uschar *host_lookup_msg        = US"";
997 int     host_number            = 0;
998 uschar *host_number_string     = NULL;
999 uschar *host_reject_connection = NULL;
1000 uschar *hosts_connection_nolog = NULL;
1001 #ifdef SUPPORT_PROXY
1002 uschar *hosts_proxy            = NULL;
1003 #endif
1004 uschar *hosts_treat_as_local   = NULL;
1005 uschar *hosts_require_helo     = US"*";
1006 #ifdef EXPERIMENTAL_XCLIENT
1007 uschar *hosts_xclient          = NULL;
1008 #endif
1009 tree_node *hostlist_anchor     = NULL;
1010 int     hostlist_count         = 0;
1011
1012
1013 int     ignore_bounce_errors_after = 10*7*24*60*60;  /* 10 weeks */
1014 uschar *ignore_fromline_hosts  = NULL;
1015 int     inetd_wait_timeout     = -1;
1016 uschar *initial_cwd            = NULL;
1017 uschar *interface_address      = NULL;
1018 int     interface_port         = -1;
1019 uschar *iterate_item           = NULL;
1020
1021 int     journal_fd             = -1;
1022
1023 uschar *keep_environment       = NULL;
1024
1025 int     keep_malformed         = 4*24*60*60;    /* 4 days */
1026
1027 uschar *eldap_dn               = NULL;
1028 const uschar *letter_digit_hyphen_dot =
1029     US"abcdefghijklmnopqrstuvwxyz"
1030       ".-0123456789"
1031       "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
1032 #ifdef EXPERIMENTAL_ESMTP_LIMITS
1033 uschar *limits_advertise_hosts = US"*";
1034 #endif
1035 int     load_average           = -2;
1036 uschar *local_from_prefix      = NULL;
1037 uschar *local_from_suffix      = NULL;
1038
1039 #if HAVE_IPV6
1040 uschar *local_interfaces       = US"<; ::0 ; 0.0.0.0";
1041 #else
1042 uschar *local_interfaces       = US"0.0.0.0";
1043 #endif
1044
1045 #ifdef HAVE_LOCAL_SCAN
1046 uschar *local_scan_data        = NULL;
1047 int     local_scan_timeout     = 5*60;
1048 #endif
1049 gid_t   local_user_gid         = (gid_t)(-1);
1050 uid_t   local_user_uid         = (uid_t)(-1);
1051
1052 tree_node *localpartlist_anchor= NULL;
1053 int     localpartlist_count    = 0;
1054 uschar *log_buffer             = NULL;
1055
1056 int     log_default[]          = { /* for initializing log_selector */
1057   Li_acl_warn_skipped,
1058   Li_connection_reject,
1059   Li_delay_delivery,
1060   Li_dkim,
1061   Li_dnslist_defer,
1062   Li_etrn,
1063   Li_host_lookup_failed,
1064   Li_lost_incoming_connection,
1065   Li_outgoing_interface, /* see d_log_interface in deliver.c */
1066   Li_msg_id,
1067   Li_queue_run,
1068   Li_queue_time_exclusive,
1069   Li_rejected_header,
1070   Li_retry_defer,
1071   Li_sender_verify_fail,
1072   Li_size_reject,
1073   Li_skip_delivery,
1074   Li_smtp_confirmation,
1075   Li_tls_certificate_verified,
1076   Li_tls_cipher,
1077   -1
1078 };
1079
1080 uschar *log_file_path          = US LOG_FILE_PATH
1081                            "\0<--------------Space to patch log_file_path->";
1082
1083 int     log_notall[]           = {
1084   -1
1085 };
1086 bit_table log_options[]        = { /* must be in alphabetical order,
1087                                 with definitions from enum logbit. */
1088   BIT_TABLE(L, 8bitmime),
1089   BIT_TABLE(L, acl_warn_skipped),
1090   BIT_TABLE(L, address_rewrite),
1091   BIT_TABLE(L, all),
1092   BIT_TABLE(L, all_parents),
1093   BIT_TABLE(L, arguments),
1094   BIT_TABLE(L, connection_id),
1095   BIT_TABLE(L, connection_reject),
1096   BIT_TABLE(L, delay_delivery),
1097   BIT_TABLE(L, deliver_time),
1098   BIT_TABLE(L, delivery_size),
1099 #ifndef DISABLE_DKIM
1100   BIT_TABLE(L, dkim),
1101   BIT_TABLE(L, dkim_verbose),
1102 #endif
1103   BIT_TABLE(L, dnslist_defer),
1104   BIT_TABLE(L, dnssec),
1105   BIT_TABLE(L, etrn),
1106   BIT_TABLE(L, host_lookup_failed),
1107   BIT_TABLE(L, ident_timeout),
1108   BIT_TABLE(L, incoming_interface),
1109   BIT_TABLE(L, incoming_port),
1110   BIT_TABLE(L, lost_incoming_connection),
1111   BIT_TABLE(L, millisec),
1112   BIT_TABLE(L, msg_id),
1113   BIT_TABLE(L, msg_id_created),
1114   BIT_TABLE(L, outgoing_interface),
1115   BIT_TABLE(L, outgoing_port),
1116   BIT_TABLE(L, pid),
1117   BIT_TABLE(L, pipelining),
1118   BIT_TABLE(L, protocol_detail),
1119 #if defined(SUPPORT_PROXY) || defined(SUPPORT_SOCKS)
1120   BIT_TABLE(L, proxy),
1121 #endif
1122   BIT_TABLE(L, queue_run),
1123   BIT_TABLE(L, queue_time),
1124   BIT_TABLE(L, queue_time_exclusive),
1125   BIT_TABLE(L, queue_time_overall),
1126   BIT_TABLE(L, receive_time),
1127   BIT_TABLE(L, received_recipients),
1128   BIT_TABLE(L, received_sender),
1129   BIT_TABLE(L, rejected_header),
1130   { US"rejected_headers", Li_rejected_header },
1131   BIT_TABLE(L, retry_defer),
1132   BIT_TABLE(L, return_path_on_delivery),
1133   BIT_TABLE(L, sender_on_delivery),
1134   BIT_TABLE(L, sender_verify_fail),
1135   BIT_TABLE(L, size_reject),
1136   BIT_TABLE(L, skip_delivery),
1137   BIT_TABLE(L, smtp_confirmation),
1138   BIT_TABLE(L, smtp_connection),
1139   BIT_TABLE(L, smtp_incomplete_transaction),
1140   BIT_TABLE(L, smtp_mailauth),
1141   BIT_TABLE(L, smtp_no_mail),
1142   BIT_TABLE(L, smtp_protocol_error),
1143   BIT_TABLE(L, smtp_syntax_error),
1144   BIT_TABLE(L, subject),
1145   BIT_TABLE(L, tls_certificate_verified),
1146   BIT_TABLE(L, tls_cipher),
1147   BIT_TABLE(L, tls_peerdn),
1148   BIT_TABLE(L, tls_resumption),
1149   BIT_TABLE(L, tls_sni),
1150   BIT_TABLE(L, unknown_in_list),
1151 };
1152 int     log_options_count      = nelem(log_options);
1153
1154 int     log_reject_target      = 0;
1155 unsigned int log_selector[log_selector_size]; /* initialized in main() */
1156 uschar *log_selector_string    = NULL;
1157 FILE   *log_stderr             = NULL;
1158 uschar *login_sender_address   = NULL;
1159 uschar *lookup_dnssec_authenticated = NULL;
1160 int     lookup_open_max        = 25;
1161 uschar *lookup_value           = NULL;
1162
1163 macro_item *macros_user        = NULL;
1164 uschar *mailstore_basename     = NULL;
1165 #ifdef WITH_CONTENT_SCAN
1166 uschar *malware_name           = NULL;  /* Virus Name */
1167 #endif
1168 int     max_received_linelength= 0;
1169 int     max_username_length    = 0;
1170 int     message_age            = 0;
1171 uschar *message_body           = NULL;
1172 uschar *message_body_end       = NULL;
1173 int     message_body_size      = 0;
1174 int     message_body_visible   = 500;
1175 int     message_ended          = END_NOTSTARTED;
1176 uschar *message_headers        = NULL;
1177 uschar *message_id;
1178 uschar *message_id_domain      = NULL;
1179 uschar *message_id_text        = NULL;
1180 uschar  message_id_option[MESSAGE_ID_LENGTH + 3];
1181 uschar *message_id_external;
1182 int     message_linecount      = 0;
1183 int     message_size           = 0;
1184 uschar *message_size_limit     = US"50M";
1185 #ifdef SUPPORT_I18N
1186 int     message_utf8_downconvert = 0;   /* -1 ifneeded; 0 never; 1 always */
1187 #endif
1188 uschar  message_subdir[2]      = { 0, 0 };
1189 const uschar *message_reference= NULL;
1190
1191 /* MIME ACL expandables */
1192 #ifdef WITH_CONTENT_SCAN
1193 int     mime_anomaly_level     = 0;
1194 const uschar *mime_anomaly_text      = NULL;
1195 uschar *mime_boundary          = NULL;
1196 uschar *mime_charset           = NULL;
1197 uschar *mime_content_description = NULL;
1198 uschar *mime_content_disposition = NULL;
1199 uschar *mime_content_id        = NULL;
1200 unsigned int mime_content_size = 0;
1201 uschar *mime_content_transfer_encoding = NULL;
1202 uschar *mime_content_type      = NULL;
1203 uschar *mime_decoded_filename  = NULL;
1204 uschar *mime_filename          = NULL;
1205 int     mime_is_multipart      = 0;
1206 int     mime_is_coverletter    = 0;
1207 int     mime_is_rfc822         = 0;
1208 int     mime_part_count        = -1;
1209 #endif
1210
1211 uid_t  *never_users            = NULL;
1212 uschar *notifier_socket        = US"$spool_directory/" NOTIFIER_SOCKET_NAME ;
1213
1214 const int on                   = 1;     /* for setsockopt */
1215 const int off                  = 0;
1216
1217 uid_t   original_euid;
1218 gid_t   originator_gid;
1219 uschar *originator_login       = NULL;
1220 uschar *originator_name        = NULL;
1221 uid_t   originator_uid;
1222 uschar *override_local_interfaces = NULL;
1223 const uschar *override_pid_file_path = NULL;
1224
1225 BOOL    panic_coredump         = FALSE;
1226 pcre2_general_context * pcre_gen_ctx = NULL;
1227 pcre2_compile_context * pcre_gen_cmp_ctx = NULL;
1228 pcre2_match_context * pcre_gen_mtc_ctx = NULL;
1229 pcre2_general_context * pcre_mlc_ctx = NULL;
1230 pcre2_compile_context * pcre_mlc_cmp_ctx = NULL;
1231
1232 uschar *percent_hack_domains   = NULL;
1233 const uschar *pid_file_path    = US PID_FILE_PATH
1234                            "\0<--------------Space to patch pid_file_path->";
1235 #ifndef DISABLE_PIPE_CONNECT
1236 uschar *pipe_connect_advertise_hosts = US"*";
1237 #endif
1238 uschar *pipelining_advertise_hosts = US"*";
1239 uschar *primary_hostname       = NULL;
1240 uschar *process_info;
1241 int     process_info_len       = 0;
1242 uschar *process_log_path       = NULL;
1243 const uschar *process_purpose  = US"fresh-exec";
1244
1245 #if defined(SUPPORT_PROXY) || defined(SUPPORT_SOCKS) || defined(EXPERIMENTAL_XCLIENT)
1246 uschar *proxy_external_address = NULL;
1247 int     proxy_external_port    = 0;
1248 uschar *proxy_local_address    = NULL;
1249 int     proxy_local_port       = 0;
1250 int     proxy_protocol_timeout = 3;
1251 #endif
1252
1253 uschar *prvscheck_address      = NULL;
1254 uschar *prvscheck_keynum       = NULL;
1255 uschar *prvscheck_result       = NULL;
1256
1257
1258 qrunner *qrunners              = NULL;
1259
1260 const uschar *qualify_domain_recipient = NULL;
1261 uschar *qualify_domain_sender  = NULL;
1262 uschar *queue_domains          = NULL;
1263 int     queue_interval         = -1;
1264 uschar *queue_name             = US"";
1265 uschar *queue_name_dest        = NULL;
1266 uschar *queue_only_file        = NULL;
1267 int     queue_only_load        = -1;
1268 uschar *queue_run_max          = US"5";
1269 pid_t   queue_run_pid          = (pid_t)0;
1270 int     queue_run_pipe         = -1;
1271 unsigned queue_size            = 0;
1272 time_t  queue_size_next        = 0;
1273 uschar *queue_smtp_domains     = NULL;
1274
1275 uint32_t random_seed           = 0;
1276 tree_node *ratelimiters_cmd    = NULL;
1277 tree_node *ratelimiters_conn   = NULL;
1278 tree_node *ratelimiters_mail   = NULL;
1279 uschar *raw_active_hostname    = NULL;
1280 const uschar *raw_sender       = NULL;
1281 const uschar **raw_recipients  = NULL;
1282 int     raw_recipients_count   = 0;
1283
1284 int     rcpt_count             = 0;
1285 int     rcpt_fail_count        = 0;
1286 int     rcpt_defer_count       = 0;
1287 gid_t   real_gid;
1288 uid_t   real_uid;
1289 int     receive_linecount      = 0;
1290 int     receive_messagecount   = 0;
1291 int     receive_timeout        = 0;
1292 int     received_count         = 0;
1293 const uschar *received_for     = NULL;
1294
1295 /*  This is the default text for Received headers generated by Exim. The
1296 date  will be automatically added on the end. */
1297
1298 uschar *received_header_text   = US
1299      "Received: "
1300      "${if def:sender_rcvhost {from $sender_rcvhost\n\t}"
1301        "{${if def:sender_ident {from ${quote_local_part:$sender_ident} }}"
1302          "${if def:sender_helo_name {(helo=$sender_helo_name)\n\t}}}}"
1303      "by $primary_hostname "
1304      "${if def:received_protocol {with $received_protocol }}"
1305 #ifndef DISABLE_TLS
1306      "${if def:tls_in_ver        { ($tls_in_ver)}}"
1307      "${if def:tls_in_cipher_std { tls $tls_in_cipher_std\n\t}}"
1308 #endif
1309      "(Exim $version_number)\n\t"
1310      "${if def:sender_address {(envelope-from <$sender_address>)\n\t}}"
1311      "id $message_exim_id"
1312      "${if def:received_for {\n\tfor $received_for}}"
1313      "\0<---------------Space to patch received_header_text->";
1314
1315 int     received_headers_max   = 30;
1316 uschar *received_protocol      = NULL;
1317 struct timeval received_time   = { 0, 0 };
1318 struct timeval received_time_complete = { 0, 0 };
1319 uschar *recipient_data         = NULL;
1320 uschar *recipient_unqualified_hosts = NULL;
1321 uschar *recipient_verify_failure = NULL;
1322 int     recipients_count       = 0;
1323 recipient_item  *recipients_list = NULL;
1324 int     recipients_list_max    = 0;
1325 int     recipients_max         = 50000;
1326 const pcre2_code *regex_AUTH         = NULL;
1327 const pcre2_code *regex_check_dns_names = NULL;
1328 const pcre2_code *regex_From         = NULL;
1329 const pcre2_code *regex_IGNOREQUOTA  = NULL;
1330 const pcre2_code *regex_PIPELINING   = NULL;
1331 const pcre2_code *regex_SIZE         = NULL;
1332 #ifndef DISABLE_PIPE_CONNECT
1333 const pcre2_code *regex_EARLY_PIPE   = NULL;
1334 #endif
1335 int    regex_cachesize               = 0;
1336 const pcre2_code *regex_ismsgid      = NULL;
1337 const pcre2_code *regex_smtp_code    = NULL;
1338 const uschar *regex_vars[REGEX_VARS] = { NULL };
1339 #ifdef WHITELIST_D_MACROS
1340 const pcre2_code *regex_whitelisted_macro = NULL;
1341 #endif
1342 #ifdef WITH_CONTENT_SCAN
1343 uschar *regex_match_string     = NULL;
1344 #endif
1345 int     remote_delivery_count  = 0;
1346 int     remote_max_parallel    = 4;
1347 uschar *remote_sort_domains    = NULL;
1348 int     retry_data_expire      = 7*24*60*60;
1349 int     retry_interval_max     = 24*60*60;
1350 int     retry_maximum_timeout  = 0;        /* set from retry config */
1351 retry_config  *retries         = NULL;
1352 const uschar *return_path            = NULL;
1353 int     rewrite_existflags     = 0;
1354 uschar *rfc1413_hosts          = US"@[]";
1355 int     rfc1413_query_timeout  = 0;
1356 uid_t   root_gid               = ROOT_GID;
1357 uid_t   root_uid               = ROOT_UID;
1358
1359 router_instance  *routers  = NULL;
1360 router_instance  router_defaults = {
1361     .next =                     NULL,
1362     .name =                     NULL,
1363     .info =                     NULL,
1364     .options_block =            NULL,
1365     .driver_name =              NULL,
1366
1367     .address_data =             NULL,
1368 #ifdef EXPERIMENTAL_BRIGHTMAIL
1369     .bmi_rule =                 NULL,
1370 #endif
1371     .cannot_route_message =     NULL,
1372     .condition =                NULL,
1373     .current_directory =        NULL,
1374     .debug_string =             NULL,
1375     .domains =                  NULL,
1376     .errors_to =                NULL,
1377     .expand_gid =               NULL,
1378     .expand_uid =               NULL,
1379     .expand_more =              NULL,
1380     .expand_unseen =            NULL,
1381     .extra_headers =            NULL,
1382     .fallback_hosts =           NULL,
1383     .home_directory =           NULL,
1384     .ignore_target_hosts =      NULL,
1385     .local_parts =              NULL,
1386     .pass_router_name =         NULL,
1387     .prefix =                   NULL,
1388     .redirect_router_name =     NULL,
1389     .remove_headers =           NULL,
1390     .require_files =            NULL,
1391     .router_home_directory =    NULL,
1392     .self =                     US"freeze",
1393     .senders =                  NULL,
1394     .suffix =                   NULL,
1395     .translate_ip_address =     NULL,
1396     .transport_name =           NULL,
1397
1398     .address_test =             TRUE,
1399 #ifdef EXPERIMENTAL_BRIGHTMAIL
1400     .bmi_deliver_alternate =    FALSE,
1401     .bmi_deliver_default =      FALSE,
1402     .bmi_dont_deliver =         FALSE,
1403 #endif
1404     .expn =                     TRUE,
1405     .caseful_local_part =       FALSE,
1406     .check_local_user =         FALSE,
1407     .disable_logging =          FALSE,
1408     .fail_verify_recipient =    FALSE,
1409     .fail_verify_sender =       FALSE,
1410     .gid_set =                  FALSE,
1411     .initgroups =               FALSE,
1412     .log_as_local =             TRUE_UNSET,
1413     .more =                     TRUE,
1414     .pass_on_timeout =          FALSE,
1415     .prefix_optional =          FALSE,
1416     .repeat_use =               TRUE,
1417     .retry_use_local_part =     TRUE_UNSET,
1418     .same_domain_copy_routing = FALSE,
1419     .self_rewrite =             FALSE,
1420     .set =                      NULL,
1421     .suffix_optional =          FALSE,
1422     .verify_only =              FALSE,
1423     .verify_recipient =         TRUE,
1424     .verify_sender =            TRUE,
1425     .uid_set =                  FALSE,
1426     .unseen =                   FALSE,
1427     .dsn_lasthop =              FALSE,
1428
1429     .self_code =                self_freeze,
1430     .uid =                      (uid_t)(-1),
1431     .gid =                      (gid_t)(-1),
1432
1433     .fallback_hostlist =        NULL,
1434     .transport =                NULL,
1435     .pass_router =              NULL,
1436     .redirect_router =          NULL,
1437
1438     .dnssec =                   { .request= US"*", .require=NULL },
1439 };
1440
1441 uschar *router_name            = NULL;
1442 tree_node *router_var          = NULL;
1443
1444 ip_address_item *running_interfaces = NULL;
1445
1446 /* This is a weird one. The following string gets patched in the binary by the
1447 script that sets up a copy of Exim for running in the test harness. It seems
1448 that compilers are now clever, and share constant strings if they can.
1449 Elsewhere in Exim the string "<" is used. The compiler optimization seems to
1450 make use of the end of this string in order to save space. So the patching then
1451 wrecks this. We defeat this optimization by adding some additional characters
1452 onto the end of the string. */
1453
1454 uschar *running_status         = US">>>running<<<" "\0EXTRA";
1455
1456 int     runrc                  = 0;
1457
1458 uschar *search_error_message   = NULL;
1459 uschar *self_hostname          = NULL;
1460 const uschar *sender_address   = NULL;
1461 unsigned int sender_address_cache[(MAX_NAMED_LIST * 2)/32];
1462 uschar *sender_address_data    = NULL;
1463 const uschar *sender_address_unrewritten = NULL;
1464 uschar *sender_data            = NULL;
1465 unsigned int sender_domain_cache[(MAX_NAMED_LIST * 2)/32];
1466 uschar *sender_fullhost        = NULL;
1467 uschar *sender_helo_name       = NULL;
1468 uschar **sender_host_aliases   = &no_aliases;
1469 uschar *sender_host_address    = NULL;
1470 uschar *sender_host_authenticated = NULL;
1471 uschar *sender_host_auth_pubname  = NULL;
1472 unsigned int sender_host_cache[(MAX_NAMED_LIST * 2)/32];
1473 uschar *sender_host_name       = NULL;
1474 int     sender_host_port       = 0;
1475 uschar *sender_ident           = NULL;
1476 uschar *sender_rate            = NULL;
1477 uschar *sender_rate_limit      = NULL;
1478 uschar *sender_rate_period     = NULL;
1479 uschar *sender_rcvhost         = NULL;
1480 uschar *sender_unqualified_hosts = NULL;
1481 uschar *sender_verify_failure = NULL;
1482 address_item *sender_verified_list  = NULL;
1483 address_item *sender_verified_failed = NULL;
1484 int     sender_verified_rc     = -1;
1485 uschar *sending_ip_address     = NULL;
1486 int     sending_port           = -1;
1487 SIGNAL_BOOL sigalrm_seen       = FALSE;
1488 const uschar *sigalarm_setter  = NULL;
1489 const uschar **sighup_argv     = NULL;
1490 int     slow_lookup_log        = 0;     /* millisecs, zero disables */
1491 int     smtp_accept_count      = 0;
1492 int     smtp_accept_max        = 20;
1493 int     smtp_accept_max_nonmail= 10;
1494 uschar *smtp_accept_max_nonmail_hosts = US"*";
1495 uschar *smtp_accept_max_per_connection = US"1000";
1496 uschar *smtp_accept_max_per_host = NULL;
1497 int     smtp_accept_queue      = 0;
1498 int     smtp_accept_queue_per_connection = 10;
1499 int     smtp_accept_reserve    = 0;
1500 uschar *smtp_active_hostname   = NULL;
1501 int     smtp_backlog_monitor   = 0;
1502 uschar *smtp_banner            = US"$smtp_active_hostname ESMTP "
1503                              "Exim $version_number $tod_full"
1504                              "\0<---------------Space to patch smtp_banner->";
1505 int     smtp_ch_index          = 0;
1506 uschar *smtp_cmd_argument      = NULL;
1507 uschar *smtp_cmd_buffer        = NULL;
1508 struct timeval smtp_connection_start  = {0,0};
1509 uschar  smtp_connection_had[SMTP_HBUFF_SIZE];
1510 int     smtp_connect_backlog   = 20;
1511 double  smtp_delay_mail        = 0.0;
1512 double  smtp_delay_rcpt        = 0.0;
1513 FILE   *smtp_in                = NULL;
1514 int     smtp_listen_backlog    = 0;
1515 int     smtp_load_reserve      = -1;
1516 int     smtp_mailcmd_count     = 0;
1517 int     smtp_mailcmd_max       = -1;
1518 FILE   *smtp_out               = NULL;
1519 uschar *smtp_etrn_command      = NULL;
1520 int     smtp_max_synprot_errors= 3;
1521 int     smtp_max_unknown_commands = 3;
1522 uschar *smtp_notquit_reason    = NULL;
1523 unsigned smtp_peer_options     = 0;
1524 unsigned smtp_peer_options_wrap= 0;
1525 uschar *smtp_ratelimit_hosts   = NULL;
1526 uschar *smtp_ratelimit_mail    = NULL;
1527 uschar *smtp_ratelimit_rcpt    = NULL;
1528 uschar *smtp_read_error        = US"";
1529 int     smtp_receive_timeout   = 5*60;
1530 uschar *smtp_receive_timeout_s = NULL;
1531 uschar *smtp_reserve_hosts     = NULL;
1532 int     smtp_rlm_base          = 0;
1533 double  smtp_rlm_factor        = 0.0;
1534 int     smtp_rlm_limit         = 0;
1535 int     smtp_rlm_threshold     = INT_MAX;
1536 int     smtp_rlr_base          = 0;
1537 double  smtp_rlr_factor        = 0.0;
1538 int     smtp_rlr_limit         = 0;
1539 int     smtp_rlr_threshold     = INT_MAX;
1540 #ifdef SUPPORT_I18N
1541 uschar *smtputf8_advertise_hosts = US"*";       /* overridden under test-harness */
1542 #endif
1543
1544 #ifdef WITH_CONTENT_SCAN
1545 uschar *spamd_address          = US"127.0.0.1 783";
1546 uschar *spam_bar               = NULL;
1547 uschar *spam_report            = NULL;
1548 uschar *spam_action            = NULL;
1549 uschar *spam_score             = NULL;
1550 uschar *spam_score_int         = NULL;
1551 #endif
1552 #ifdef SUPPORT_SPF
1553 uschar *spf_guess              = US"v=spf1 a/24 mx/24 ptr ?all";
1554 uschar *spf_header_comment     = NULL;
1555 uschar *spf_received           = NULL;
1556 uschar *spf_result             = NULL;
1557 uschar *spf_smtp_comment       = NULL;
1558 uschar *spf_smtp_comment_template
1559                     /* Used to be: "Please%_see%_http://www.open-spf.org/Why?id=%{S}&ip=%{C}&receiver=%{R}" */
1560                                = US"Please%_see%_http://www.open-spf.org/Why";
1561
1562 #endif
1563
1564 FILE   *spool_data_file        = NULL;
1565 uschar *spool_directory        = US SPOOL_DIRECTORY
1566                            "\0<--------------Space to patch spool_directory->";
1567 #ifdef SUPPORT_SRS
1568 uschar *srs_recipient          = NULL;
1569 #endif
1570 int     string_datestamp_offset= -1;
1571 int     string_datestamp_length= 0;
1572 int     string_datestamp_type  = -1;
1573 const uschar *submission_domain = NULL;
1574 const uschar *submission_name  = NULL;
1575 int     syslog_facility        = LOG_MAIL;
1576 const uschar *syslog_processname= US"exim";
1577 uschar *system_filter          = NULL;
1578
1579 uschar *system_filter_directory_transport = NULL;
1580 uschar *system_filter_file_transport = NULL;
1581 uschar *system_filter_pipe_transport = NULL;
1582 uschar *system_filter_reply_transport = NULL;
1583
1584 gid_t   system_filter_gid      = 0;
1585 uid_t   system_filter_uid      = (uid_t)-1;
1586
1587 blob    tcp_fastopen_nodata    = { .data = NULL, .len = 0 };
1588 tfo_state_t tcp_out_fastopen   = TFO_NOT_USED;
1589 #ifdef USE_TCP_WRAPPERS
1590 uschar *tcp_wrappers_daemon_name = US TCP_WRAPPERS_DAEMON_NAME;
1591 #endif
1592 int     test_harness_load_avg  = 0;
1593 int     thismessage_size_limit = 0;
1594 int     timeout_frozen_after   = 0;
1595 #ifdef MEASURE_TIMING
1596 struct timeval timestamp_startup;
1597 #endif
1598
1599 transport_instance  *transports = NULL;
1600
1601 transport_instance  transport_defaults = {
1602     /* All non-mentioned elements zero/NULL/FALSE */
1603     .batch_max =                1,
1604     .multi_domain =             TRUE,
1605     .max_addresses =            US"100",
1606     .connection_max_messages =  500,
1607     .uid =                      (uid_t)(-1),
1608     .gid =                      (gid_t)(-1),
1609     .filter_timeout =           300,
1610     .retry_use_local_part =     TRUE_UNSET,     /* retry_use_local_part: BOOL, but set neither
1611                                                  1 nor 0 so can detect unset */
1612 };
1613
1614 int     transport_count;
1615 uschar *transport_name          = NULL;
1616 int     transport_newlines;
1617 const uschar **transport_filter_argv  = NULL;
1618 int     transport_filter_timeout;
1619 int     transport_write_timeout= 0;
1620
1621 tree_node  *tree_dns_fails     = NULL;
1622 tree_node  *tree_duplicates    = NULL;
1623 tree_node  *tree_nonrecipients = NULL;
1624 tree_node  *tree_unusable      = NULL;
1625
1626 gid_t  *trusted_groups         = NULL;
1627 uid_t  *trusted_users          = NULL;
1628 uschar *timezone_string        = US TIMEZONE_DEFAULT;
1629
1630 uschar *unknown_login          = NULL;
1631 uschar *unknown_username       = NULL;
1632 uschar *untrusted_set_sender   = NULL;
1633
1634 /*  A regex for matching a "From_" line in an incoming message, in the form
1635
1636     From ph10 Fri Jan  5 12:35 GMT 1996
1637
1638 which  the "mail" commands send to the MTA (undocumented, of course), or in
1639 the  form
1640
1641     From ph10 Fri, 7 Jan 97 14:00:00 GMT
1642
1643 which  is apparently used by some UUCPs, despite it not being in RFC 976.
1644 Because  of variations in time formats, just match up to the minutes. That
1645 should  be sufficient. Examples have been seen of time fields like 12:1:03,
1646 so  just require one digit for hours and minutes. The weekday is also absent
1647 in  some forms. */
1648
1649 uschar *uucp_from_pattern      = US
1650    "^From\\s+(\\S+)\\s+(?:[a-zA-Z]{3},?\\s+)?"    /* Common start */
1651    "(?:"                                          /* Non-extracting bracket */
1652    "[a-zA-Z]{3}\\s+\\d?\\d|"                      /* First form */
1653    "\\d?\\d\\s+[a-zA-Z]{3}\\s+\\d\\d(?:\\d\\d)?"  /* Second form */
1654    ")"                                            /* End alternation */
1655    "\\s+\\d\\d?:\\d\\d?";                         /* Start of time */
1656
1657 uschar *uucp_from_sender       = US"$1";
1658
1659 uschar *verify_mode            = NULL;
1660 uschar *version_copyright      =
1661  US"Copyright (c) University of Cambridge, 1995 - 2018\n"
1662    "(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2022";
1663 uschar *version_date           = US"?";
1664 uschar *version_cnumber        = US"????";
1665 uschar *version_string         = US"?";
1666
1667 uschar *warn_message_file      = NULL;
1668 int     warning_count          = 0;
1669 const uschar *warnmsg_delay    = NULL;
1670 const uschar *warnmsg_recipients = NULL;
1671
1672 /*  End of globals.c */