1 /* $NetBSD: trivial-rewrite.c,v 1.3 2020/03/18 19:05:21 christos Exp $ */ 2 3 /*++ 4 /* NAME 5 /* trivial-rewrite 8 6 /* SUMMARY 7 /* Postfix address rewriting and resolving daemon 8 /* SYNOPSIS 9 /* \fBtrivial-rewrite\fR [generic Postfix daemon options] 10 /* DESCRIPTION 11 /* The \fBtrivial-rewrite\fR(8) daemon processes three types of client 12 /* service requests: 13 /* .IP "\fBrewrite \fIcontext address\fR" 14 /* Rewrite an address to standard form, according to the 15 /* address rewriting context: 16 /* .RS 17 /* .IP \fBlocal\fR 18 /* Append the domain names specified with \fB$myorigin\fR or 19 /* \fB$mydomain\fR to incomplete addresses; do \fBswap_bangpath\fR 20 /* and \fBallow_percent_hack\fR processing as described below, and 21 /* strip source routed addresses (\fI@site,@site:user@domain\fR) 22 /* to \fIuser@domain\fR form. 23 /* .IP \fBremote\fR 24 /* Append the domain name specified with 25 /* \fB$remote_header_rewrite_domain\fR to incomplete 26 /* addresses. Otherwise the result is identical to that of 27 /* the \fBlocal\fR address rewriting context. This prevents 28 /* Postfix from appending the local domain to spam from poorly 29 /* written remote clients. 30 /* .RE 31 /* .IP "\fBresolve \fIsender\fR \fIaddress\fR" 32 /* Resolve the address to a (\fItransport\fR, \fInexthop\fR, 33 /* \fIrecipient\fR, \fIflags\fR) quadruple. The meaning of 34 /* the results is as follows: 35 /* .RS 36 /* .IP \fItransport\fR 37 /* The delivery agent to use. This is the first field of an entry 38 /* in the \fBmaster.cf\fR file. 39 /* .IP \fInexthop\fR 40 /* The host to send to and optional delivery method information. 41 /* .IP \fIrecipient\fR 42 /* The envelope recipient address that is passed on to \fInexthop\fR. 43 /* .IP \fIflags\fR 44 /* The address class, whether the address requires relaying, 45 /* whether the address has problems, and whether the request failed. 46 /* .RE 47 /* .IP "\fBverify \fIsender\fR \fIaddress\fR" 48 /* Resolve the address for address verification purposes. 49 /* SERVER PROCESS MANAGEMENT 50 /* .ad 51 /* .fi 52 /* The \fBtrivial-rewrite\fR(8) servers run under control by 53 /* the Postfix master 54 /* server. Each server can handle multiple simultaneous connections. 55 /* When all servers are busy while a client connects, the master 56 /* creates a new server process, provided that the trivial-rewrite 57 /* server process limit is not exceeded. 58 /* Each trivial-rewrite server terminates after 59 /* serving at least \fB$max_use\fR clients of after \fB$max_idle\fR 60 /* seconds of idle time. 61 /* STANDARDS 62 /* .ad 63 /* .fi 64 /* None. The command does not interact with the outside world. 65 /* SECURITY 66 /* .ad 67 /* .fi 68 /* The \fBtrivial-rewrite\fR(8) daemon is not security sensitive. 69 /* By default, this daemon does not talk to remote or local users. 70 /* It can run at a fixed low privilege in a chrooted environment. 71 /* DIAGNOSTICS 72 /* Problems and transactions are logged to \fBsyslogd\fR(8) 73 /* or \fBpostlogd\fR(8). 74 /* CONFIGURATION PARAMETERS 75 /* .ad 76 /* .fi 77 /* On busy mail systems a long time may pass before a \fBmain.cf\fR 78 /* change affecting \fBtrivial-rewrite\fR(8) is picked up. Use the command 79 /* "\fBpostfix reload\fR" to speed up a change. 80 /* 81 /* The text below provides only a parameter summary. See 82 /* \fBpostconf\fR(5) for more details including examples. 83 /* COMPATIBILITY CONTROLS 84 /* .ad 85 /* .fi 86 /* .IP "\fBresolve_dequoted_address (yes)\fR" 87 /* Resolve a recipient address safely instead of correctly, by 88 /* looking inside quotes. 89 /* .PP 90 /* Available with Postfix version 2.1 and later: 91 /* .IP "\fBresolve_null_domain (no)\fR" 92 /* Resolve an address that ends in the "@" null domain as if the 93 /* local hostname were specified, instead of rejecting the address as 94 /* invalid. 95 /* .PP 96 /* Available with Postfix version 2.3 and later: 97 /* .IP "\fBresolve_numeric_domain (no)\fR" 98 /* Resolve "user@ipaddress" as "user@[ipaddress]", instead of 99 /* rejecting the address as invalid. 100 /* .PP 101 /* Available with Postfix version 2.5 and later: 102 /* .IP "\fBallow_min_user (no)\fR" 103 /* Allow a sender or recipient address to have `-' as the first 104 /* character. 105 /* ADDRESS REWRITING CONTROLS 106 /* .ad 107 /* .fi 108 /* .IP "\fBmyorigin ($myhostname)\fR" 109 /* The domain name that locally-posted mail appears to come 110 /* from, and that locally posted mail is delivered to. 111 /* .IP "\fBallow_percent_hack (yes)\fR" 112 /* Enable the rewriting of the form "user%domain" to "user@domain". 113 /* .IP "\fBappend_at_myorigin (yes)\fR" 114 /* With locally submitted mail, append the string "@$myorigin" to mail 115 /* addresses without domain information. 116 /* .IP "\fBappend_dot_mydomain (Postfix >= 3.0: no, Postfix < 3.0: yes)\fR" 117 /* With locally submitted mail, append the string ".$mydomain" to 118 /* addresses that have no ".domain" information. 119 /* .IP "\fBrecipient_delimiter (empty)\fR" 120 /* The set of characters that can separate a user name from its 121 /* extension (example: user+foo), or a .forward file name from its 122 /* extension (example: .forward+foo). 123 /* .IP "\fBswap_bangpath (yes)\fR" 124 /* Enable the rewriting of "site!user" into "user@site". 125 /* .PP 126 /* Available in Postfix 2.2 and later: 127 /* .IP "\fBremote_header_rewrite_domain (empty)\fR" 128 /* Don't rewrite message headers from remote clients at all when 129 /* this parameter is empty; otherwise, rewrite message headers and 130 /* append the specified domain name to incomplete addresses. 131 /* ROUTING CONTROLS 132 /* .ad 133 /* .fi 134 /* The following is applicable to Postfix version 2.0 and later. 135 /* Earlier versions do not have support for: virtual_transport, 136 /* relay_transport, virtual_alias_domains, virtual_mailbox_domains 137 /* or proxy_interfaces. 138 /* .IP "\fBlocal_transport (local:$myhostname)\fR" 139 /* The default mail delivery transport and next-hop destination 140 /* for final delivery to domains listed with mydestination, and for 141 /* [ipaddress] destinations that match $inet_interfaces or $proxy_interfaces. 142 /* .IP "\fBvirtual_transport (virtual)\fR" 143 /* The default mail delivery transport and next-hop destination for 144 /* final delivery to domains listed with $virtual_mailbox_domains. 145 /* .IP "\fBrelay_transport (relay)\fR" 146 /* The default mail delivery transport and next-hop destination for 147 /* remote delivery to domains listed with $relay_domains. 148 /* .IP "\fBdefault_transport (smtp)\fR" 149 /* The default mail delivery transport and next-hop destination for 150 /* destinations that do not match $mydestination, $inet_interfaces, 151 /* $proxy_interfaces, $virtual_alias_domains, $virtual_mailbox_domains, 152 /* or $relay_domains. 153 /* .IP "\fBparent_domain_matches_subdomains (see 'postconf -d' output)\fR" 154 /* A list of Postfix features where the pattern "example.com" also 155 /* matches subdomains of example.com, 156 /* instead of requiring an explicit ".example.com" pattern. 157 /* .IP "\fBrelayhost (empty)\fR" 158 /* The next-hop destination of non-local mail; overrides non-local 159 /* domains in recipient addresses. 160 /* .IP "\fBtransport_maps (empty)\fR" 161 /* Optional lookup tables with mappings from recipient address to 162 /* (message delivery transport, next-hop destination). 163 /* .PP 164 /* Available in Postfix version 2.3 and later: 165 /* .IP "\fBsender_dependent_relayhost_maps (empty)\fR" 166 /* A sender-dependent override for the global relayhost parameter 167 /* setting. 168 /* .PP 169 /* Available in Postfix version 2.5 and later: 170 /* .IP "\fBempty_address_relayhost_maps_lookup_key (<>)\fR" 171 /* The sender_dependent_relayhost_maps search string that will be 172 /* used instead of the null sender address. 173 /* .PP 174 /* Available in Postfix version 2.7 and later: 175 /* .IP "\fBempty_address_default_transport_maps_lookup_key (<>)\fR" 176 /* The sender_dependent_default_transport_maps search string that 177 /* will be used instead of the null sender address. 178 /* .IP "\fBsender_dependent_default_transport_maps (empty)\fR" 179 /* A sender-dependent override for the global default_transport 180 /* parameter setting. 181 /* ADDRESS VERIFICATION CONTROLS 182 /* .ad 183 /* .fi 184 /* Postfix version 2.1 introduces sender and recipient address verification. 185 /* This feature is implemented by sending probe email messages that 186 /* are not actually delivered. 187 /* By default, address verification probes use the same route 188 /* as regular mail. To override specific aspects of message 189 /* routing for address verification probes, specify one or more 190 /* of the following: 191 /* .IP "\fBaddress_verify_local_transport ($local_transport)\fR" 192 /* Overrides the local_transport parameter setting for address 193 /* verification probes. 194 /* .IP "\fBaddress_verify_virtual_transport ($virtual_transport)\fR" 195 /* Overrides the virtual_transport parameter setting for address 196 /* verification probes. 197 /* .IP "\fBaddress_verify_relay_transport ($relay_transport)\fR" 198 /* Overrides the relay_transport parameter setting for address 199 /* verification probes. 200 /* .IP "\fBaddress_verify_default_transport ($default_transport)\fR" 201 /* Overrides the default_transport parameter setting for address 202 /* verification probes. 203 /* .IP "\fBaddress_verify_relayhost ($relayhost)\fR" 204 /* Overrides the relayhost parameter setting for address verification 205 /* probes. 206 /* .IP "\fBaddress_verify_transport_maps ($transport_maps)\fR" 207 /* Overrides the transport_maps parameter setting for address verification 208 /* probes. 209 /* .PP 210 /* Available in Postfix version 2.3 and later: 211 /* .IP "\fBaddress_verify_sender_dependent_relayhost_maps ($sender_dependent_relayhost_maps)\fR" 212 /* Overrides the sender_dependent_relayhost_maps parameter setting for address 213 /* verification probes. 214 /* .PP 215 /* Available in Postfix version 2.7 and later: 216 /* .IP "\fBaddress_verify_sender_dependent_default_transport_maps ($sender_dependent_default_transport_maps)\fR" 217 /* Overrides the sender_dependent_default_transport_maps parameter 218 /* setting for address verification probes. 219 /* MISCELLANEOUS CONTROLS 220 /* .ad 221 /* .fi 222 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR" 223 /* The default location of the Postfix main.cf and master.cf 224 /* configuration files. 225 /* .IP "\fBdaemon_timeout (18000s)\fR" 226 /* How much time a Postfix daemon process may take to handle a 227 /* request before it is terminated by a built-in watchdog timer. 228 /* .IP "\fBempty_address_recipient (MAILER-DAEMON)\fR" 229 /* The recipient of mail addressed to the null address. 230 /* .IP "\fBipc_timeout (3600s)\fR" 231 /* The time limit for sending or receiving information over an internal 232 /* communication channel. 233 /* .IP "\fBmax_idle (100s)\fR" 234 /* The maximum amount of time that an idle Postfix daemon process waits 235 /* for an incoming connection before terminating voluntarily. 236 /* .IP "\fBmax_use (100)\fR" 237 /* The maximal number of incoming connections that a Postfix daemon 238 /* process will service before terminating voluntarily. 239 /* .IP "\fBrelocated_maps (empty)\fR" 240 /* Optional lookup tables with new contact information for users or 241 /* domains that no longer exist. 242 /* .IP "\fBprocess_id (read-only)\fR" 243 /* The process ID of a Postfix command or daemon process. 244 /* .IP "\fBprocess_name (read-only)\fR" 245 /* The process name of a Postfix command or daemon process. 246 /* .IP "\fBqueue_directory (see 'postconf -d' output)\fR" 247 /* The location of the Postfix top-level queue directory. 248 /* .IP "\fBshow_user_unknown_table_name (yes)\fR" 249 /* Display the name of the recipient table in the "User unknown" 250 /* responses. 251 /* .IP "\fBsyslog_facility (mail)\fR" 252 /* The syslog facility of Postfix logging. 253 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR" 254 /* A prefix that is prepended to the process name in syslog 255 /* records, so that, for example, "smtpd" becomes "prefix/smtpd". 256 /* .PP 257 /* Available in Postfix version 2.0 and later: 258 /* .IP "\fBhelpful_warnings (yes)\fR" 259 /* Log warnings about problematic configuration settings, and provide 260 /* helpful suggestions. 261 /* .PP 262 /* Available in Postfix 3.3 and later: 263 /* .IP "\fBservice_name (read-only)\fR" 264 /* The master.cf service name of a Postfix daemon process. 265 /* SEE ALSO 266 /* postconf(5), configuration parameters 267 /* transport(5), transport table format 268 /* relocated(5), format of the "user has moved" table 269 /* master(8), process manager 270 /* postlogd(8), Postfix logging 271 /* syslogd(8), system logging 272 /* README FILES 273 /* .ad 274 /* .fi 275 /* Use "\fBpostconf readme_directory\fR" or 276 /* "\fBpostconf html_directory\fR" to locate this information. 277 /* .na 278 /* .nf 279 /* ADDRESS_CLASS_README, Postfix address classes howto 280 /* ADDRESS_VERIFICATION_README, Postfix address verification 281 /* LICENSE 282 /* .ad 283 /* .fi 284 /* The Secure Mailer license must be distributed with this software. 285 /* AUTHOR(S) 286 /* Wietse Venema 287 /* IBM T.J. Watson Research 288 /* P.O. Box 704 289 /* Yorktown Heights, NY 10598, USA 290 /* 291 /* Wietse Venema 292 /* Google, Inc. 293 /* 111 8th Avenue 294 /* New York, NY 10011, USA 295 /*--*/ 296 297 /* System library. */ 298 299 #include <sys_defs.h> 300 #include <unistd.h> 301 #include <stdlib.h> 302 #include <string.h> 303 304 /* Utility library. */ 305 306 #include <msg.h> 307 #include <vstring.h> 308 #include <vstream.h> 309 #include <vstring_vstream.h> 310 #include <split_at.h> 311 #include <stringops.h> 312 #include <dict.h> 313 #include <events.h> 314 315 /* Global library. */ 316 317 #include <mail_params.h> 318 #include <mail_version.h> 319 #include <mail_proto.h> 320 #include <resolve_local.h> 321 #include <mail_conf.h> 322 #include <resolve_clnt.h> 323 #include <rewrite_clnt.h> 324 #include <tok822.h> 325 #include <mail_addr.h> 326 327 /* Multi server skeleton. */ 328 329 #include <mail_server.h> 330 331 /* Application-specific. */ 332 333 #include <trivial-rewrite.h> 334 #include <transport.h> 335 336 static VSTRING *command; 337 338 /* 339 * Tunable parameters. 340 */ 341 char *var_transport_maps; 342 bool var_swap_bangpath; 343 bool var_append_dot_mydomain; 344 bool var_append_at_myorigin; 345 bool var_percent_hack; 346 char *var_local_transport; 347 char *var_virt_transport; 348 char *var_relay_transport; 349 int var_resolve_dequoted; 350 char *var_virt_alias_maps; /* XXX virtual_alias_domains */ 351 char *var_virt_mailbox_maps; /* XXX virtual_mailbox_domains */ 352 char *var_virt_alias_doms; 353 char *var_virt_mailbox_doms; 354 char *var_relocated_maps; 355 char *var_def_transport; 356 char *var_snd_def_xport_maps; 357 char *var_empty_addr; 358 int var_show_unk_rcpt_table; 359 int var_resolve_nulldom; 360 char *var_remote_rwr_domain; 361 char *var_snd_relay_maps; 362 char *var_null_relay_maps_key; 363 char *var_null_def_xport_maps_key; 364 int var_resolve_num_dom; 365 bool var_allow_min_user; 366 367 /* 368 * Shadow personality for address verification. 369 */ 370 char *var_vrfy_xport_maps; 371 char *var_vrfy_local_xport; 372 char *var_vrfy_virt_xport; 373 char *var_vrfy_relay_xport; 374 char *var_vrfy_def_xport; 375 char *var_vrfy_snd_def_xport_maps; 376 char *var_vrfy_relayhost; 377 char *var_vrfy_relay_maps; 378 379 /* 380 * Different resolver personalities depending on the kind of request. 381 */ 382 RES_CONTEXT resolve_regular = { 383 VAR_LOCAL_TRANSPORT, &var_local_transport, 384 VAR_VIRT_TRANSPORT, &var_virt_transport, 385 VAR_RELAY_TRANSPORT, &var_relay_transport, 386 VAR_DEF_TRANSPORT, &var_def_transport, 387 VAR_SND_DEF_XPORT_MAPS, &var_snd_def_xport_maps, 0, 388 VAR_RELAYHOST, &var_relayhost, 389 VAR_SND_RELAY_MAPS, &var_snd_relay_maps, 0, 390 VAR_TRANSPORT_MAPS, &var_transport_maps, 0 391 }; 392 393 RES_CONTEXT resolve_verify = { 394 VAR_VRFY_LOCAL_XPORT, &var_vrfy_local_xport, 395 VAR_VRFY_VIRT_XPORT, &var_vrfy_virt_xport, 396 VAR_VRFY_RELAY_XPORT, &var_vrfy_relay_xport, 397 VAR_VRFY_DEF_XPORT, &var_vrfy_def_xport, 398 VAR_VRFY_SND_DEF_XPORT_MAPS, &var_vrfy_snd_def_xport_maps, 0, 399 VAR_VRFY_RELAYHOST, &var_vrfy_relayhost, 400 VAR_VRFY_RELAY_MAPS, &var_vrfy_relay_maps, 0, 401 VAR_VRFY_XPORT_MAPS, &var_vrfy_xport_maps, 0 402 }; 403 404 /* 405 * Connection management. When file-based lookup tables change we should 406 * restart at our convenience, but avoid client read errors. We restart 407 * rather than reopen, because the process may be chrooted (and if it isn't 408 * we still need code that handles the chrooted case anyway). 409 * 410 * Three variants are implemented. Only one should be used. 411 * 412 * ifdef DETACH_AND_ASK_CLIENTS_TO_RECONNECT 413 * 414 * This code detaches the trivial-rewrite process from the master, stops 415 * accepting new clients, and handles established clients in the background, 416 * asking them to reconnect the next time they send a request. The master 417 * creates a new process that accepts connections. This is reasonably safe 418 * because the number of trivial-rewrite server processes is small compared 419 * to the number of trivial-rewrite client processes. The few extra 420 * background processes should not make a difference in Postfix's footprint. 421 * However, once a daemon detaches from the master, its exit status will be 422 * lost, and abnormal termination may remain undetected. Timely restart is 423 * achieved by checking the table changed status every 10 seconds or so 424 * before responding to a client request. 425 * 426 * ifdef CHECK_TABLE_STATS_PERIODICALLY 427 * 428 * This code runs every 10 seconds and terminates the process when lookup 429 * tables have changed. This is subject to race conditions when established 430 * clients send a request while the server exits; those clients may read EOF 431 * instead of a server reply. If the experience with the oldest option 432 * (below) is anything to go by, however, then this is unlikely to be a 433 * problem during real deployment. 434 * 435 * ifdef CHECK_TABLE_STATS_BEFORE_ACCEPT 436 * 437 * This is the old code. It checks the table changed status when a new client 438 * connects (i.e. before the server calls accept()), and terminates 439 * immediately. This is invisible for the connecting client, but is subject 440 * to race conditions when established clients send a request while the 441 * server exits; those clients may read EOF instead of a server reply. This 442 * has, however, not been a problem in real deployment. With the old code, 443 * timely restart is achieved by setting the ipc_ttl parameter to 60 444 * seconds, so that the table change status is checked several times a 445 * minute. 446 */ 447 int server_flags; 448 449 /* 450 * Define exactly one of these. 451 */ 452 /* #define DETACH_AND_ASK_CLIENTS_TO_RECONNECT /* correct and complex */ 453 #define CHECK_TABLE_STATS_PERIODICALLY /* quick */ 454 /* #define CHECK_TABLE_STATS_BEFORE_ACCEPT /* slow */ 455 456 /* rewrite_service - read request and send reply */ 457 458 static void rewrite_service(VSTREAM *stream, char *unused_service, char **argv) 459 { 460 int status = -1; 461 462 #ifdef DETACH_AND_ASK_CLIENTS_TO_RECONNECT 463 static time_t last; 464 time_t now; 465 const char *table; 466 467 #endif 468 469 /* 470 * Sanity check. This service takes no command-line arguments. 471 */ 472 if (argv[0]) 473 msg_fatal("unexpected command-line argument: %s", argv[0]); 474 475 /* 476 * Client connections are long-lived. Be sure to refesh timely. 477 */ 478 #ifdef DETACH_AND_ASK_CLIENTS_TO_RECONNECT 479 if (server_flags == 0 && (now = event_time()) - last > 10) { 480 if ((table = dict_changed_name()) != 0) { 481 msg_info("table %s has changed -- restarting", table); 482 if (multi_server_drain() == 0) 483 server_flags = 1; 484 } 485 last = now; 486 } 487 #endif 488 489 /* 490 * This routine runs whenever a client connects to the UNIX-domain socket 491 * dedicated to address rewriting. All connection-management stuff is 492 * handled by the common code in multi_server.c. 493 */ 494 if (attr_scan(stream, ATTR_FLAG_STRICT | ATTR_FLAG_MORE, 495 RECV_ATTR_STR(MAIL_ATTR_REQ, command), 496 ATTR_TYPE_END) == 1) { 497 if (strcmp(vstring_str(command), REWRITE_ADDR) == 0) { 498 status = rewrite_proto(stream); 499 } else if (strcmp(vstring_str(command), RESOLVE_REGULAR) == 0) { 500 status = resolve_proto(&resolve_regular, stream); 501 } else if (strcmp(vstring_str(command), RESOLVE_VERIFY) == 0) { 502 status = resolve_proto(&resolve_verify, stream); 503 } else { 504 msg_warn("bad command %.30s", printable(vstring_str(command), '?')); 505 } 506 } 507 if (status < 0) 508 multi_server_disconnect(stream); 509 } 510 511 /* pre_accept - see if tables have changed */ 512 513 #ifdef CHECK_TABLE_STATS_BEFORE_ACCEPT 514 515 static void pre_accept(char *unused_name, char **unused_argv) 516 { 517 const char *table; 518 519 if ((table = dict_changed_name()) != 0) { 520 msg_info("table %s has changed -- restarting", table); 521 exit(0); 522 } 523 } 524 525 #endif 526 527 static void check_table_stats(int unused_event, void *unused_context) 528 { 529 const char *table; 530 531 if ((table = dict_changed_name()) != 0) { 532 msg_info("table %s has changed -- restarting", table); 533 exit(0); 534 } 535 event_request_timer(check_table_stats, (void *) 0, 10); 536 } 537 538 /* pre_jail_init - initialize before entering chroot jail */ 539 540 static void pre_jail_init(char *unused_name, char **unused_argv) 541 { 542 command = vstring_alloc(100); 543 rewrite_init(); 544 resolve_init(); 545 if (*RES_PARAM_VALUE(resolve_regular.transport_maps)) 546 resolve_regular.transport_info = 547 transport_pre_init(resolve_regular.transport_maps_name, 548 RES_PARAM_VALUE(resolve_regular.transport_maps)); 549 if (*RES_PARAM_VALUE(resolve_verify.transport_maps)) 550 resolve_verify.transport_info = 551 transport_pre_init(resolve_verify.transport_maps_name, 552 RES_PARAM_VALUE(resolve_verify.transport_maps)); 553 if (*RES_PARAM_VALUE(resolve_regular.snd_relay_maps)) 554 resolve_regular.snd_relay_info = 555 maps_create(resolve_regular.snd_relay_maps_name, 556 RES_PARAM_VALUE(resolve_regular.snd_relay_maps), 557 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX 558 | DICT_FLAG_NO_REGSUB | DICT_FLAG_UTF8_REQUEST); 559 if (*RES_PARAM_VALUE(resolve_verify.snd_relay_maps)) 560 resolve_verify.snd_relay_info = 561 maps_create(resolve_verify.snd_relay_maps_name, 562 RES_PARAM_VALUE(resolve_verify.snd_relay_maps), 563 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX 564 | DICT_FLAG_NO_REGSUB | DICT_FLAG_UTF8_REQUEST); 565 if (*RES_PARAM_VALUE(resolve_regular.snd_def_xp_maps)) 566 resolve_regular.snd_def_xp_info = 567 maps_create(resolve_regular.snd_def_xp_maps_name, 568 RES_PARAM_VALUE(resolve_regular.snd_def_xp_maps), 569 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX 570 | DICT_FLAG_NO_REGSUB | DICT_FLAG_UTF8_REQUEST); 571 if (*RES_PARAM_VALUE(resolve_verify.snd_def_xp_maps)) 572 resolve_verify.snd_def_xp_info = 573 maps_create(resolve_verify.snd_def_xp_maps_name, 574 RES_PARAM_VALUE(resolve_verify.snd_def_xp_maps), 575 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX 576 | DICT_FLAG_NO_REGSUB | DICT_FLAG_UTF8_REQUEST); 577 } 578 579 /* post_jail_init - initialize after entering chroot jail */ 580 581 static void post_jail_init(char *unused_name, char **unused_argv) 582 { 583 if (resolve_regular.transport_info) 584 transport_post_init(resolve_regular.transport_info); 585 if (resolve_verify.transport_info) 586 transport_post_init(resolve_verify.transport_info); 587 check_table_stats(0, (void *) 0); 588 } 589 590 MAIL_VERSION_STAMP_DECLARE; 591 592 /* main - pass control to the multi-threaded skeleton code */ 593 594 int main(int argc, char **argv) 595 { 596 static const CONFIG_STR_TABLE str_table[] = { 597 VAR_TRANSPORT_MAPS, DEF_TRANSPORT_MAPS, &var_transport_maps, 0, 0, 598 VAR_LOCAL_TRANSPORT, DEF_LOCAL_TRANSPORT, &var_local_transport, 1, 0, 599 VAR_VIRT_TRANSPORT, DEF_VIRT_TRANSPORT, &var_virt_transport, 1, 0, 600 VAR_RELAY_TRANSPORT, DEF_RELAY_TRANSPORT, &var_relay_transport, 1, 0, 601 VAR_DEF_TRANSPORT, DEF_DEF_TRANSPORT, &var_def_transport, 1, 0, 602 VAR_VIRT_ALIAS_MAPS, DEF_VIRT_ALIAS_MAPS, &var_virt_alias_maps, 0, 0, 603 VAR_VIRT_ALIAS_DOMS, DEF_VIRT_ALIAS_DOMS, &var_virt_alias_doms, 0, 0, 604 VAR_VIRT_MAILBOX_MAPS, DEF_VIRT_MAILBOX_MAPS, &var_virt_mailbox_maps, 0, 0, 605 VAR_VIRT_MAILBOX_DOMS, DEF_VIRT_MAILBOX_DOMS, &var_virt_mailbox_doms, 0, 0, 606 VAR_RELOCATED_MAPS, DEF_RELOCATED_MAPS, &var_relocated_maps, 0, 0, 607 VAR_EMPTY_ADDR, DEF_EMPTY_ADDR, &var_empty_addr, 1, 0, 608 VAR_VRFY_XPORT_MAPS, DEF_VRFY_XPORT_MAPS, &var_vrfy_xport_maps, 0, 0, 609 VAR_VRFY_LOCAL_XPORT, DEF_VRFY_LOCAL_XPORT, &var_vrfy_local_xport, 1, 0, 610 VAR_VRFY_VIRT_XPORT, DEF_VRFY_VIRT_XPORT, &var_vrfy_virt_xport, 1, 0, 611 VAR_VRFY_RELAY_XPORT, DEF_VRFY_RELAY_XPORT, &var_vrfy_relay_xport, 1, 0, 612 VAR_VRFY_DEF_XPORT, DEF_VRFY_DEF_XPORT, &var_vrfy_def_xport, 1, 0, 613 VAR_VRFY_RELAYHOST, DEF_VRFY_RELAYHOST, &var_vrfy_relayhost, 0, 0, 614 VAR_REM_RWR_DOMAIN, DEF_REM_RWR_DOMAIN, &var_remote_rwr_domain, 0, 0, 615 VAR_SND_RELAY_MAPS, DEF_SND_RELAY_MAPS, &var_snd_relay_maps, 0, 0, 616 VAR_NULL_RELAY_MAPS_KEY, DEF_NULL_RELAY_MAPS_KEY, &var_null_relay_maps_key, 1, 0, 617 VAR_VRFY_RELAY_MAPS, DEF_VRFY_RELAY_MAPS, &var_vrfy_relay_maps, 0, 0, 618 VAR_SND_DEF_XPORT_MAPS, DEF_SND_DEF_XPORT_MAPS, &var_snd_def_xport_maps, 0, 0, 619 VAR_NULL_DEF_XPORT_MAPS_KEY, DEF_NULL_DEF_XPORT_MAPS_KEY, &var_null_def_xport_maps_key, 1, 0, 620 VAR_VRFY_SND_DEF_XPORT_MAPS, DEF_VRFY_SND_DEF_XPORT_MAPS, &var_vrfy_snd_def_xport_maps, 0, 0, 621 0, 622 }; 623 static const CONFIG_BOOL_TABLE bool_table[] = { 624 VAR_SWAP_BANGPATH, DEF_SWAP_BANGPATH, &var_swap_bangpath, 625 VAR_APP_AT_MYORIGIN, DEF_APP_AT_MYORIGIN, &var_append_at_myorigin, 626 VAR_PERCENT_HACK, DEF_PERCENT_HACK, &var_percent_hack, 627 VAR_RESOLVE_DEQUOTED, DEF_RESOLVE_DEQUOTED, &var_resolve_dequoted, 628 VAR_SHOW_UNK_RCPT_TABLE, DEF_SHOW_UNK_RCPT_TABLE, &var_show_unk_rcpt_table, 629 VAR_RESOLVE_NULLDOM, DEF_RESOLVE_NULLDOM, &var_resolve_nulldom, 630 VAR_RESOLVE_NUM_DOM, DEF_RESOLVE_NUM_DOM, &var_resolve_num_dom, 631 VAR_ALLOW_MIN_USER, DEF_ALLOW_MIN_USER, &var_allow_min_user, 632 0, 633 }; 634 static const CONFIG_NBOOL_TABLE nbool_table[] = { 635 VAR_APP_DOT_MYDOMAIN, DEF_APP_DOT_MYDOMAIN, &var_append_dot_mydomain, 636 0, 637 }; 638 639 /* 640 * Fingerprint executables and core dumps. 641 */ 642 MAIL_VERSION_STAMP_ALLOCATE; 643 644 multi_server_main(argc, argv, rewrite_service, 645 CA_MAIL_SERVER_STR_TABLE(str_table), 646 CA_MAIL_SERVER_BOOL_TABLE(bool_table), 647 CA_MAIL_SERVER_NBOOL_TABLE(nbool_table), 648 CA_MAIL_SERVER_PRE_INIT(pre_jail_init), 649 CA_MAIL_SERVER_POST_INIT(post_jail_init), 650 #ifdef CHECK_TABLE_STATS_BEFORE_ACCEPT 651 CA_MAIL_SERVER_PRE_ACCEPT(pre_accept), 652 #endif 653 0); 654 } 655