1 /* $NetBSD: smtp.c,v 1.7 2013/09/25 19:12:35 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* smtp 8 6 /* SUMMARY 7 /* Postfix SMTP+LMTP client 8 /* SYNOPSIS 9 /* \fBsmtp\fR [generic Postfix daemon options] 10 /* DESCRIPTION 11 /* The Postfix SMTP+LMTP client implements the SMTP and LMTP mail 12 /* delivery protocols. It processes message delivery requests from 13 /* the queue manager. Each request specifies a queue file, a sender 14 /* address, a domain or host to deliver to, and recipient information. 15 /* This program expects to be run from the \fBmaster\fR(8) process 16 /* manager. 17 /* 18 /* The SMTP+LMTP client updates the queue file and marks recipients 19 /* as finished, or it informs the queue manager that delivery should 20 /* be tried again at a later time. Delivery status reports are sent 21 /* to the \fBbounce\fR(8), \fBdefer\fR(8) or \fBtrace\fR(8) daemon as 22 /* appropriate. 23 /* 24 /* The SMTP+LMTP client looks up a list of mail exchanger addresses for 25 /* the destination host, sorts the list by preference, and connects 26 /* to each listed address until it finds a server that responds. 27 /* 28 /* When a server is not reachable, or when mail delivery fails due 29 /* to a recoverable error condition, the SMTP+LMTP client will try to 30 /* deliver the mail to an alternate host. 31 /* 32 /* After a successful mail transaction, a connection may be saved 33 /* to the \fBscache\fR(8) connection cache server, so that it 34 /* may be used by any SMTP+LMTP client for a subsequent transaction. 35 /* 36 /* By default, connection caching is enabled temporarily for 37 /* destinations that have a high volume of mail in the active 38 /* queue. Connection caching can be enabled permanently for 39 /* specific destinations. 40 /* SMTP DESTINATION SYNTAX 41 /* .ad 42 /* .fi 43 /* SMTP destinations have the following form: 44 /* .IP \fIdomainname\fR 45 /* .IP \fIdomainname\fR:\fIport\fR 46 /* Look up the mail exchangers for the specified domain, and 47 /* connect to the specified port (default: \fBsmtp\fR). 48 /* .IP [\fIhostname\fR] 49 /* .IP [\fIhostname\fR]:\fIport\fR 50 /* Look up the address(es) of the specified host, and connect to 51 /* the specified port (default: \fBsmtp\fR). 52 /* .IP [\fIaddress\fR] 53 /* .IP [\fIaddress\fR]:\fIport\fR 54 /* Connect to the host at the specified address, and connect 55 /* to the specified port (default: \fBsmtp\fR). An IPv6 address 56 /* must be formatted as [\fBipv6\fR:\fIaddress\fR]. 57 /* LMTP DESTINATION SYNTAX 58 /* .ad 59 /* .fi 60 /* LMTP destinations have the following form: 61 /* .IP \fBunix\fR:\fIpathname\fR 62 /* Connect to the local UNIX-domain server that is bound to the specified 63 /* \fIpathname\fR. If the process runs chrooted, an absolute pathname 64 /* is interpreted relative to the Postfix queue directory. 65 /* .IP \fBinet\fR:\fIhostname\fR 66 /* .IP \fBinet\fB:\fIhostname\fR:\fIport\fR 67 /* .IP \fBinet\fR:[\fIaddress\fR] 68 /* .IP \fBinet\fR:[\fIaddress\fR]:\fIport\fR 69 /* Connect to the specified TCP port on the specified local or 70 /* remote host. If no port is specified, connect to the port defined as 71 /* \fBlmtp\fR in \fBservices\fR(4). 72 /* If no such service is found, the \fBlmtp_tcp_port\fR configuration 73 /* parameter (default value of 24) will be used. 74 /* An IPv6 address must be formatted as [\fBipv6\fR:\fIaddress\fR]. 75 /* .PP 76 /* SECURITY 77 /* .ad 78 /* .fi 79 /* The SMTP+LMTP client is moderately security-sensitive. It 80 /* talks to SMTP or LMTP servers and to DNS servers on the 81 /* network. The SMTP+LMTP client can be run chrooted at fixed 82 /* low privilege. 83 /* STANDARDS 84 /* RFC 821 (SMTP protocol) 85 /* RFC 822 (ARPA Internet Text Messages) 86 /* RFC 1651 (SMTP service extensions) 87 /* RFC 1652 (8bit-MIME transport) 88 /* RFC 1870 (Message Size Declaration) 89 /* RFC 2033 (LMTP protocol) 90 /* RFC 2034 (SMTP Enhanced Error Codes) 91 /* RFC 2045 (MIME: Format of Internet Message Bodies) 92 /* RFC 2046 (MIME: Media Types) 93 /* RFC 2554 (AUTH command) 94 /* RFC 2821 (SMTP protocol) 95 /* RFC 2920 (SMTP Pipelining) 96 /* RFC 3207 (STARTTLS command) 97 /* RFC 3461 (SMTP DSN Extension) 98 /* RFC 3463 (Enhanced Status Codes) 99 /* RFC 4954 (AUTH command) 100 /* RFC 5321 (SMTP protocol) 101 /* DIAGNOSTICS 102 /* Problems and transactions are logged to \fBsyslogd\fR(8). 103 /* Corrupted message files are marked so that the queue manager can 104 /* move them to the \fBcorrupt\fR queue for further inspection. 105 /* 106 /* Depending on the setting of the \fBnotify_classes\fR parameter, 107 /* the postmaster is notified of bounces, protocol problems, and of 108 /* other trouble. 109 /* BUGS 110 /* SMTP and LMTP connection caching does not work with TLS. The necessary 111 /* support for TLS object passivation and re-activation does not 112 /* exist without closing the session, which defeats the purpose. 113 /* 114 /* SMTP and LMTP connection caching assumes that SASL credentials 115 /* are valid for all destinations that map onto the same IP 116 /* address and TCP port. 117 /* CONFIGURATION PARAMETERS 118 /* .ad 119 /* .fi 120 /* Before Postfix version 2.3, the LMTP client is a separate 121 /* program that implements only a subset of the functionality 122 /* available with SMTP: there is no support for TLS, and 123 /* connections are cached in-process, making it ineffective 124 /* when the client is used for multiple domains. 125 /* 126 /* Most smtp_\fIxxx\fR configuration parameters have an 127 /* lmtp_\fIxxx\fR "mirror" parameter for the equivalent LMTP 128 /* feature. This document describes only those LMTP-related 129 /* parameters that aren't simply "mirror" parameters. 130 /* 131 /* Changes to \fBmain.cf\fR are picked up automatically, as \fBsmtp\fR(8) 132 /* processes run for only a limited amount of time. Use the command 133 /* "\fBpostfix reload\fR" to speed up a change. 134 /* 135 /* The text below provides only a parameter summary. See 136 /* \fBpostconf\fR(5) for more details including examples. 137 /* COMPATIBILITY CONTROLS 138 /* .ad 139 /* .fi 140 /* .IP "\fBignore_mx_lookup_error (no)\fR" 141 /* Ignore DNS MX lookups that produce no response. 142 /* .IP "\fBsmtp_always_send_ehlo (yes)\fR" 143 /* Always send EHLO at the start of an SMTP session. 144 /* .IP "\fBsmtp_never_send_ehlo (no)\fR" 145 /* Never send EHLO at the start of an SMTP session. 146 /* .IP "\fBsmtp_defer_if_no_mx_address_found (no)\fR" 147 /* Defer mail delivery when no MX record resolves to an IP address. 148 /* .IP "\fBsmtp_line_length_limit (998)\fR" 149 /* The maximal length of message header and body lines that Postfix 150 /* will send via SMTP. 151 /* .IP "\fBsmtp_pix_workaround_delay_time (10s)\fR" 152 /* How long the Postfix SMTP client pauses before sending 153 /* ".<CR><LF>" in order to work around the PIX firewall 154 /* "<CR><LF>.<CR><LF>" bug. 155 /* .IP "\fBsmtp_pix_workaround_threshold_time (500s)\fR" 156 /* How long a message must be queued before the Postfix SMTP client 157 /* turns on the PIX firewall "<CR><LF>.<CR><LF>" 158 /* bug workaround for delivery through firewalls with "smtp fixup" 159 /* mode turned on. 160 /* .IP "\fBsmtp_pix_workarounds (disable_esmtp, delay_dotcrlf)\fR" 161 /* A list that specifies zero or more workarounds for CISCO PIX 162 /* firewall bugs. 163 /* .IP "\fBsmtp_pix_workaround_maps (empty)\fR" 164 /* Lookup tables, indexed by the remote SMTP server address, with 165 /* per-destination workarounds for CISCO PIX firewall bugs. 166 /* .IP "\fBsmtp_quote_rfc821_envelope (yes)\fR" 167 /* Quote addresses in Postfix SMTP client MAIL FROM and RCPT TO commands 168 /* as required 169 /* by RFC 5321. 170 /* .IP "\fBsmtp_reply_filter (empty)\fR" 171 /* A mechanism to transform replies from remote SMTP servers one 172 /* line at a time. 173 /* .IP "\fBsmtp_skip_5xx_greeting (yes)\fR" 174 /* Skip remote SMTP servers that greet with a 5XX status code (go away, 175 /* do 176 /* not try again later). 177 /* .IP "\fBsmtp_skip_quit_response (yes)\fR" 178 /* Do not wait for the response to the SMTP QUIT command. 179 /* .PP 180 /* Available in Postfix version 2.0 and earlier: 181 /* .IP "\fBsmtp_skip_4xx_greeting (yes)\fR" 182 /* Skip SMTP servers that greet with a 4XX status code (go away, try 183 /* again later). 184 /* .PP 185 /* Available in Postfix version 2.2 and later: 186 /* .IP "\fBsmtp_discard_ehlo_keyword_address_maps (empty)\fR" 187 /* Lookup tables, indexed by the remote SMTP server address, with 188 /* case insensitive lists of EHLO keywords (pipelining, starttls, auth, 189 /* etc.) that the Postfix SMTP client will ignore in the EHLO response from a 190 /* remote SMTP server. 191 /* .IP "\fBsmtp_discard_ehlo_keywords (empty)\fR" 192 /* A case insensitive list of EHLO keywords (pipelining, starttls, 193 /* auth, etc.) that the Postfix SMTP client will ignore in the EHLO 194 /* response from a remote SMTP server. 195 /* .IP "\fBsmtp_generic_maps (empty)\fR" 196 /* Optional lookup tables that perform address rewriting in the 197 /* Postfix SMTP client, typically to transform a locally valid address into 198 /* a globally valid address when sending mail across the Internet. 199 /* .PP 200 /* Available in Postfix version 2.2.9 and later: 201 /* .IP "\fBsmtp_cname_overrides_servername (version dependent)\fR" 202 /* Allow DNS CNAME records to override the servername that the 203 /* Postfix SMTP client uses for logging, SASL password lookup, TLS 204 /* policy decisions, or TLS certificate verification. 205 /* .PP 206 /* Available in Postfix version 2.3 and later: 207 /* .IP "\fBlmtp_discard_lhlo_keyword_address_maps (empty)\fR" 208 /* Lookup tables, indexed by the remote LMTP server address, with 209 /* case insensitive lists of LHLO keywords (pipelining, starttls, 210 /* auth, etc.) that the Postfix LMTP client will ignore in the LHLO 211 /* response 212 /* from a remote LMTP server. 213 /* .IP "\fBlmtp_discard_lhlo_keywords (empty)\fR" 214 /* A case insensitive list of LHLO keywords (pipelining, starttls, 215 /* auth, etc.) that the Postfix LMTP client will ignore in the LHLO 216 /* response 217 /* from a remote LMTP server. 218 /* .PP 219 /* Available in Postfix version 2.4.4 and later: 220 /* .IP "\fBsend_cyrus_sasl_authzid (no)\fR" 221 /* When authenticating to a remote SMTP or LMTP server with the 222 /* default setting "no", send no SASL authoriZation ID (authzid); send 223 /* only the SASL authentiCation ID (authcid) plus the authcid's password. 224 /* .PP 225 /* Available in Postfix version 2.5 and later: 226 /* .IP "\fBsmtp_header_checks (empty)\fR" 227 /* Restricted \fBheader_checks\fR(5) tables for the Postfix SMTP client. 228 /* .IP "\fBsmtp_mime_header_checks (empty)\fR" 229 /* Restricted \fBmime_header_checks\fR(5) tables for the Postfix SMTP 230 /* client. 231 /* .IP "\fBsmtp_nested_header_checks (empty)\fR" 232 /* Restricted \fBnested_header_checks\fR(5) tables for the Postfix SMTP 233 /* client. 234 /* .IP "\fBsmtp_body_checks (empty)\fR" 235 /* Restricted \fBbody_checks\fR(5) tables for the Postfix SMTP client. 236 /* .PP 237 /* Available in Postfix version 2.6 and later: 238 /* .IP "\fBtcp_windowsize (0)\fR" 239 /* An optional workaround for routers that break TCP window scaling. 240 /* .PP 241 /* Available in Postfix version 2.8 and later: 242 /* .IP "\fBsmtp_dns_resolver_options (empty)\fR" 243 /* DNS Resolver options for the Postfix SMTP client. 244 /* .PP 245 /* Available in Postfix version 2.9 and later: 246 /* .IP "\fBsmtp_per_record_deadline (no)\fR" 247 /* Change the behavior of the smtp_*_timeout time limits, from a 248 /* time limit per read or write system call, to a time limit to send 249 /* or receive a complete record (an SMTP command line, SMTP response 250 /* line, SMTP message content line, or TLS protocol message). 251 /* .IP "\fBsmtp_send_dummy_mail_auth (no)\fR" 252 /* Whether or not to append the "AUTH=<>" option to the MAIL 253 /* FROM command in SASL-authenticated SMTP sessions. 254 /* MIME PROCESSING CONTROLS 255 /* .ad 256 /* .fi 257 /* Available in Postfix version 2.0 and later: 258 /* .IP "\fBdisable_mime_output_conversion (no)\fR" 259 /* Disable the conversion of 8BITMIME format to 7BIT format. 260 /* .IP "\fBmime_boundary_length_limit (2048)\fR" 261 /* The maximal length of MIME multipart boundary strings. 262 /* .IP "\fBmime_nesting_limit (100)\fR" 263 /* The maximal recursion level that the MIME processor will handle. 264 /* EXTERNAL CONTENT INSPECTION CONTROLS 265 /* .ad 266 /* .fi 267 /* Available in Postfix version 2.1 and later: 268 /* .IP "\fBsmtp_send_xforward_command (no)\fR" 269 /* Send the non-standard XFORWARD command when the Postfix SMTP server 270 /* EHLO response announces XFORWARD support. 271 /* SASL AUTHENTICATION CONTROLS 272 /* .ad 273 /* .fi 274 /* .IP "\fBsmtp_sasl_auth_enable (no)\fR" 275 /* Enable SASL authentication in the Postfix SMTP client. 276 /* .IP "\fBsmtp_sasl_password_maps (empty)\fR" 277 /* Optional Postfix SMTP client lookup tables with one username:password 278 /* entry 279 /* per remote hostname or domain, or sender address when sender-dependent 280 /* authentication is enabled. 281 /* .IP "\fBsmtp_sasl_security_options (noplaintext, noanonymous)\fR" 282 /* Postfix SMTP client SASL security options; as of Postfix 2.3 283 /* the list of available 284 /* features depends on the SASL client implementation that is selected 285 /* with \fBsmtp_sasl_type\fR. 286 /* .PP 287 /* Available in Postfix version 2.2 and later: 288 /* .IP "\fBsmtp_sasl_mechanism_filter (empty)\fR" 289 /* If non-empty, a Postfix SMTP client filter for the remote SMTP 290 /* server's list of offered SASL mechanisms. 291 /* .PP 292 /* Available in Postfix version 2.3 and later: 293 /* .IP "\fBsmtp_sender_dependent_authentication (no)\fR" 294 /* Enable sender-dependent authentication in the Postfix SMTP client; this is 295 /* available only with SASL authentication, and disables SMTP connection 296 /* caching to ensure that mail from different senders will use the 297 /* appropriate credentials. 298 /* .IP "\fBsmtp_sasl_path (empty)\fR" 299 /* Implementation-specific information that the Postfix SMTP client 300 /* passes through to 301 /* the SASL plug-in implementation that is selected with 302 /* \fBsmtp_sasl_type\fR. 303 /* .IP "\fBsmtp_sasl_type (cyrus)\fR" 304 /* The SASL plug-in type that the Postfix SMTP client should use 305 /* for authentication. 306 /* .PP 307 /* Available in Postfix version 2.5 and later: 308 /* .IP "\fBsmtp_sasl_auth_cache_name (empty)\fR" 309 /* An optional table to prevent repeated SASL authentication 310 /* failures with the same remote SMTP server hostname, username and 311 /* password. 312 /* .IP "\fBsmtp_sasl_auth_cache_time (90d)\fR" 313 /* The maximal age of an smtp_sasl_auth_cache_name entry before it 314 /* is removed. 315 /* .IP "\fBsmtp_sasl_auth_soft_bounce (yes)\fR" 316 /* When a remote SMTP server rejects a SASL authentication request 317 /* with a 535 reply code, defer mail delivery instead of returning 318 /* mail as undeliverable. 319 /* .PP 320 /* Available in Postfix version 2.9 and later: 321 /* .IP "\fBsmtp_send_dummy_mail_auth (no)\fR" 322 /* Whether or not to append the "AUTH=<>" option to the MAIL 323 /* FROM command in SASL-authenticated SMTP sessions. 324 /* STARTTLS SUPPORT CONTROLS 325 /* .ad 326 /* .fi 327 /* Detailed information about STARTTLS configuration may be found 328 /* in the TLS_README document. 329 /* .IP "\fBsmtp_tls_security_level (empty)\fR" 330 /* The default SMTP TLS security level for the Postfix SMTP client; 331 /* when a non-empty value is specified, this overrides the obsolete 332 /* parameters smtp_use_tls, smtp_enforce_tls, and smtp_tls_enforce_peername. 333 /* .IP "\fBsmtp_sasl_tls_security_options ($smtp_sasl_security_options)\fR" 334 /* The SASL authentication security options that the Postfix SMTP 335 /* client uses for TLS encrypted SMTP sessions. 336 /* .IP "\fBsmtp_starttls_timeout (300s)\fR" 337 /* Time limit for Postfix SMTP client write and read operations 338 /* during TLS startup and shutdown handshake procedures. 339 /* .IP "\fBsmtp_tls_CAfile (empty)\fR" 340 /* A file containing CA certificates of root CAs trusted to sign 341 /* either remote SMTP server certificates or intermediate CA certificates. 342 /* .IP "\fBsmtp_tls_CApath (empty)\fR" 343 /* Directory with PEM format certificate authority certificates 344 /* that the Postfix SMTP client uses to verify a remote SMTP server 345 /* certificate. 346 /* .IP "\fBsmtp_tls_cert_file (empty)\fR" 347 /* File with the Postfix SMTP client RSA certificate in PEM format. 348 /* .IP "\fBsmtp_tls_mandatory_ciphers (medium)\fR" 349 /* The minimum TLS cipher grade that the Postfix SMTP client will 350 /* use with 351 /* mandatory TLS encryption. 352 /* .IP "\fBsmtp_tls_exclude_ciphers (empty)\fR" 353 /* List of ciphers or cipher types to exclude from the Postfix 354 /* SMTP client cipher 355 /* list at all TLS security levels. 356 /* .IP "\fBsmtp_tls_mandatory_exclude_ciphers (empty)\fR" 357 /* Additional list of ciphers or cipher types to exclude from the 358 /* Postfix SMTP client cipher list at mandatory TLS security levels. 359 /* .IP "\fBsmtp_tls_dcert_file (empty)\fR" 360 /* File with the Postfix SMTP client DSA certificate in PEM format. 361 /* .IP "\fBsmtp_tls_dkey_file ($smtp_tls_dcert_file)\fR" 362 /* File with the Postfix SMTP client DSA private key in PEM format. 363 /* .IP "\fBsmtp_tls_key_file ($smtp_tls_cert_file)\fR" 364 /* File with the Postfix SMTP client RSA private key in PEM format. 365 /* .IP "\fBsmtp_tls_loglevel (0)\fR" 366 /* Enable additional Postfix SMTP client logging of TLS activity. 367 /* .IP "\fBsmtp_tls_note_starttls_offer (no)\fR" 368 /* Log the hostname of a remote SMTP server that offers STARTTLS, 369 /* when TLS is not already enabled for that server. 370 /* .IP "\fBsmtp_tls_policy_maps (empty)\fR" 371 /* Optional lookup tables with the Postfix SMTP client TLS security 372 /* policy by next-hop destination; when a non-empty value is specified, 373 /* this overrides the obsolete smtp_tls_per_site parameter. 374 /* .IP "\fBsmtp_tls_mandatory_protocols (!SSLv2)\fR" 375 /* List of SSL/TLS protocols that the Postfix SMTP client will use with 376 /* mandatory TLS encryption. 377 /* .IP "\fBsmtp_tls_scert_verifydepth (9)\fR" 378 /* The verification depth for remote SMTP server certificates. 379 /* .IP "\fBsmtp_tls_secure_cert_match (nexthop, dot-nexthop)\fR" 380 /* How the Postfix SMTP client verifies the server certificate 381 /* peername for the 382 /* "secure" TLS security level. 383 /* .IP "\fBsmtp_tls_session_cache_database (empty)\fR" 384 /* Name of the file containing the optional Postfix SMTP client 385 /* TLS session cache. 386 /* .IP "\fBsmtp_tls_session_cache_timeout (3600s)\fR" 387 /* The expiration time of Postfix SMTP client TLS session cache 388 /* information. 389 /* .IP "\fBsmtp_tls_verify_cert_match (hostname)\fR" 390 /* How the Postfix SMTP client verifies the server certificate 391 /* peername for the 392 /* "verify" TLS security level. 393 /* .IP "\fBtls_daemon_random_bytes (32)\fR" 394 /* The number of pseudo-random bytes that an \fBsmtp\fR(8) or \fBsmtpd\fR(8) 395 /* process requests from the \fBtlsmgr\fR(8) server in order to seed its 396 /* internal pseudo random number generator (PRNG). 397 /* .IP "\fBtls_high_cipherlist (ALL:!EXPORT:!LOW:!MEDIUM:+RC4:@STRENGTH)\fR" 398 /* The OpenSSL cipherlist for "HIGH" grade ciphers. 399 /* .IP "\fBtls_medium_cipherlist (ALL:!EXPORT:!LOW:+RC4:@STRENGTH)\fR" 400 /* The OpenSSL cipherlist for "MEDIUM" or higher grade ciphers. 401 /* .IP "\fBtls_low_cipherlist (ALL:!EXPORT:+RC4:@STRENGTH)\fR" 402 /* The OpenSSL cipherlist for "LOW" or higher grade ciphers. 403 /* .IP "\fBtls_export_cipherlist (ALL:+RC4:@STRENGTH)\fR" 404 /* The OpenSSL cipherlist for "EXPORT" or higher grade ciphers. 405 /* .IP "\fBtls_null_cipherlist (eNULL:!aNULL)\fR" 406 /* The OpenSSL cipherlist for "NULL" grade ciphers that provide 407 /* authentication without encryption. 408 /* .PP 409 /* Available in Postfix version 2.4 and later: 410 /* .IP "\fBsmtp_sasl_tls_verified_security_options ($smtp_sasl_tls_security_options)\fR" 411 /* The SASL authentication security options that the Postfix SMTP 412 /* client uses for TLS encrypted SMTP sessions with a verified server 413 /* certificate. 414 /* .PP 415 /* Available in Postfix version 2.5 and later: 416 /* .IP "\fBsmtp_tls_fingerprint_cert_match (empty)\fR" 417 /* List of acceptable remote SMTP server certificate fingerprints for 418 /* the "fingerprint" TLS security level (\fBsmtp_tls_security_level\fR = 419 /* fingerprint). 420 /* .IP "\fBsmtp_tls_fingerprint_digest (md5)\fR" 421 /* The message digest algorithm used to construct remote SMTP server 422 /* certificate fingerprints. 423 /* .PP 424 /* Available in Postfix version 2.6 and later: 425 /* .IP "\fBsmtp_tls_protocols (!SSLv2)\fR" 426 /* List of TLS protocols that the Postfix SMTP client will exclude or 427 /* include with opportunistic TLS encryption. 428 /* .IP "\fBsmtp_tls_ciphers (export)\fR" 429 /* The minimum TLS cipher grade that the Postfix SMTP client 430 /* will use with opportunistic TLS encryption. 431 /* .IP "\fBsmtp_tls_eccert_file (empty)\fR" 432 /* File with the Postfix SMTP client ECDSA certificate in PEM format. 433 /* .IP "\fBsmtp_tls_eckey_file ($smtp_tls_eccert_file)\fR" 434 /* File with the Postfix SMTP client ECDSA private key in PEM format. 435 /* .PP 436 /* Available in Postfix version 2.7 and later: 437 /* .IP "\fBsmtp_tls_block_early_mail_reply (no)\fR" 438 /* Try to detect a mail hijacking attack based on a TLS protocol 439 /* vulnerability (CVE-2009-3555), where an attacker prepends malicious 440 /* HELO, MAIL, RCPT, DATA commands to a Postfix SMTP client TLS session. 441 /* .PP 442 /* Available in Postfix version 2.8 and later: 443 /* .IP "\fBtls_disable_workarounds (see 'postconf -d' output)\fR" 444 /* List or bit-mask of OpenSSL bug work-arounds to disable. 445 /* OBSOLETE STARTTLS CONTROLS 446 /* .ad 447 /* .fi 448 /* The following configuration parameters exist for compatibility 449 /* with Postfix versions before 2.3. Support for these will 450 /* be removed in a future release. 451 /* .IP "\fBsmtp_use_tls (no)\fR" 452 /* Opportunistic mode: use TLS when a remote SMTP server announces 453 /* STARTTLS support, otherwise send the mail in the clear. 454 /* .IP "\fBsmtp_enforce_tls (no)\fR" 455 /* Enforcement mode: require that remote SMTP servers use TLS 456 /* encryption, and never send mail in the clear. 457 /* .IP "\fBsmtp_tls_enforce_peername (yes)\fR" 458 /* With mandatory TLS encryption, require that the remote SMTP 459 /* server hostname matches the information in the remote SMTP server 460 /* certificate. 461 /* .IP "\fBsmtp_tls_per_site (empty)\fR" 462 /* Optional lookup tables with the Postfix SMTP client TLS usage 463 /* policy by next-hop destination and by remote SMTP server hostname. 464 /* .IP "\fBsmtp_tls_cipherlist (empty)\fR" 465 /* Obsolete Postfix < 2.3 control for the Postfix SMTP client TLS 466 /* cipher list. 467 /* RESOURCE AND RATE CONTROLS 468 /* .ad 469 /* .fi 470 /* .IP "\fBsmtp_destination_concurrency_limit ($default_destination_concurrency_limit)\fR" 471 /* The maximal number of parallel deliveries to the same destination 472 /* via the smtp message delivery transport. 473 /* .IP "\fBsmtp_destination_recipient_limit ($default_destination_recipient_limit)\fR" 474 /* The maximal number of recipients per message for the smtp 475 /* message delivery transport. 476 /* .IP "\fBsmtp_connect_timeout (30s)\fR" 477 /* The Postfix SMTP client time limit for completing a TCP connection, or 478 /* zero (use the operating system built-in time limit). 479 /* .IP "\fBsmtp_helo_timeout (300s)\fR" 480 /* The Postfix SMTP client time limit for sending the HELO or EHLO command, 481 /* and for receiving the initial remote SMTP server response. 482 /* .IP "\fBlmtp_lhlo_timeout (300s)\fR" 483 /* The Postfix LMTP client time limit for sending the LHLO command, 484 /* and for receiving the initial remote LMTP server response. 485 /* .IP "\fBsmtp_xforward_timeout (300s)\fR" 486 /* The Postfix SMTP client time limit for sending the XFORWARD command, 487 /* and for receiving the remote SMTP server response. 488 /* .IP "\fBsmtp_mail_timeout (300s)\fR" 489 /* The Postfix SMTP client time limit for sending the MAIL FROM command, 490 /* and for receiving the remote SMTP server response. 491 /* .IP "\fBsmtp_rcpt_timeout (300s)\fR" 492 /* The Postfix SMTP client time limit for sending the SMTP RCPT TO 493 /* command, and for receiving the remote SMTP server response. 494 /* .IP "\fBsmtp_data_init_timeout (120s)\fR" 495 /* The Postfix SMTP client time limit for sending the SMTP DATA command, 496 /* and for receiving the remote SMTP server response. 497 /* .IP "\fBsmtp_data_xfer_timeout (180s)\fR" 498 /* The Postfix SMTP client time limit for sending the SMTP message content. 499 /* .IP "\fBsmtp_data_done_timeout (600s)\fR" 500 /* The Postfix SMTP client time limit for sending the SMTP ".", and 501 /* for receiving the remote SMTP server response. 502 /* .IP "\fBsmtp_quit_timeout (300s)\fR" 503 /* The Postfix SMTP client time limit for sending the QUIT command, 504 /* and for receiving the remote SMTP server response. 505 /* .PP 506 /* Available in Postfix version 2.1 and later: 507 /* .IP "\fBsmtp_mx_address_limit (5)\fR" 508 /* The maximal number of MX (mail exchanger) IP addresses that can 509 /* result from Postfix SMTP client mail exchanger lookups, or zero (no 510 /* limit). 511 /* .IP "\fBsmtp_mx_session_limit (2)\fR" 512 /* The maximal number of SMTP sessions per delivery request before 513 /* the Postfix SMTP client 514 /* gives up or delivers to a fall-back relay host, or zero (no 515 /* limit). 516 /* .IP "\fBsmtp_rset_timeout (20s)\fR" 517 /* The Postfix SMTP client time limit for sending the RSET command, 518 /* and for receiving the remote SMTP server response. 519 /* .PP 520 /* Available in Postfix version 2.2 and earlier: 521 /* .IP "\fBlmtp_cache_connection (yes)\fR" 522 /* Keep Postfix LMTP client connections open for up to $max_idle 523 /* seconds. 524 /* .PP 525 /* Available in Postfix version 2.2 and later: 526 /* .IP "\fBsmtp_connection_cache_destinations (empty)\fR" 527 /* Permanently enable SMTP connection caching for the specified 528 /* destinations. 529 /* .IP "\fBsmtp_connection_cache_on_demand (yes)\fR" 530 /* Temporarily enable SMTP connection caching while a destination 531 /* has a high volume of mail in the active queue. 532 /* .IP "\fBsmtp_connection_reuse_time_limit (300s)\fR" 533 /* The amount of time during which Postfix will use an SMTP 534 /* connection repeatedly. 535 /* .IP "\fBsmtp_connection_cache_time_limit (2s)\fR" 536 /* When SMTP connection caching is enabled, the amount of time that 537 /* an unused SMTP client socket is kept open before it is closed. 538 /* .PP 539 /* Available in Postfix version 2.3 and later: 540 /* .IP "\fBconnection_cache_protocol_timeout (5s)\fR" 541 /* Time limit for connection cache connect, send or receive 542 /* operations. 543 /* .PP 544 /* Available in Postfix version 2.9 and later: 545 /* .IP "\fBsmtp_per_record_deadline (no)\fR" 546 /* Change the behavior of the smtp_*_timeout time limits, from a 547 /* time limit per read or write system call, to a time limit to send 548 /* or receive a complete record (an SMTP command line, SMTP response 549 /* line, SMTP message content line, or TLS protocol message). 550 /* TROUBLE SHOOTING CONTROLS 551 /* .ad 552 /* .fi 553 /* .IP "\fBdebug_peer_level (2)\fR" 554 /* The increment in verbose logging level when a remote client or 555 /* server matches a pattern in the debug_peer_list parameter. 556 /* .IP "\fBdebug_peer_list (empty)\fR" 557 /* Optional list of remote client or server hostname or network 558 /* address patterns that cause the verbose logging level to increase 559 /* by the amount specified in $debug_peer_level. 560 /* .IP "\fBerror_notice_recipient (postmaster)\fR" 561 /* The recipient of postmaster notifications about mail delivery 562 /* problems that are caused by policy, resource, software or protocol 563 /* errors. 564 /* .IP "\fBinternal_mail_filter_classes (empty)\fR" 565 /* What categories of Postfix-generated mail are subject to 566 /* before-queue content inspection by non_smtpd_milters, header_checks 567 /* and body_checks. 568 /* .IP "\fBnotify_classes (resource, software)\fR" 569 /* The list of error classes that are reported to the postmaster. 570 /* MISCELLANEOUS CONTROLS 571 /* .ad 572 /* .fi 573 /* .IP "\fBbest_mx_transport (empty)\fR" 574 /* Where the Postfix SMTP client should deliver mail when it detects 575 /* a "mail loops back to myself" error condition. 576 /* .IP "\fBconfig_directory (see 'postconf -d' output)\fR" 577 /* The default location of the Postfix main.cf and master.cf 578 /* configuration files. 579 /* .IP "\fBdaemon_timeout (18000s)\fR" 580 /* How much time a Postfix daemon process may take to handle a 581 /* request before it is terminated by a built-in watchdog timer. 582 /* .IP "\fBdelay_logging_resolution_limit (2)\fR" 583 /* The maximal number of digits after the decimal point when logging 584 /* sub-second delay values. 585 /* .IP "\fBdisable_dns_lookups (no)\fR" 586 /* Disable DNS lookups in the Postfix SMTP and LMTP clients. 587 /* .IP "\fBinet_interfaces (all)\fR" 588 /* The network interface addresses that this mail system receives 589 /* mail on. 590 /* .IP "\fBinet_protocols (all)\fR" 591 /* The Internet protocols Postfix will attempt to use when making 592 /* or accepting connections. 593 /* .IP "\fBipc_timeout (3600s)\fR" 594 /* The time limit for sending or receiving information over an internal 595 /* communication channel. 596 /* .IP "\fBlmtp_assume_final (no)\fR" 597 /* When a remote LMTP server announces no DSN support, assume that 598 /* the 599 /* server performs final delivery, and send "delivered" delivery status 600 /* notifications instead of "relayed". 601 /* .IP "\fBlmtp_tcp_port (24)\fR" 602 /* The default TCP port that the Postfix LMTP client connects to. 603 /* .IP "\fBmax_idle (100s)\fR" 604 /* The maximum amount of time that an idle Postfix daemon process waits 605 /* for an incoming connection before terminating voluntarily. 606 /* .IP "\fBmax_use (100)\fR" 607 /* The maximal number of incoming connections that a Postfix daemon 608 /* process will service before terminating voluntarily. 609 /* .IP "\fBprocess_id (read-only)\fR" 610 /* The process ID of a Postfix command or daemon process. 611 /* .IP "\fBprocess_name (read-only)\fR" 612 /* The process name of a Postfix command or daemon process. 613 /* .IP "\fBproxy_interfaces (empty)\fR" 614 /* The network interface addresses that this mail system receives mail 615 /* on by way of a proxy or network address translation unit. 616 /* .IP "\fBsmtp_address_preference (any)\fR" 617 /* The address type ("ipv6", "ipv4" or "any") that the Postfix 618 /* SMTP client will try first, when a destination has IPv6 and IPv4 619 /* addresses with equal MX preference. 620 /* .IP "\fBsmtp_bind_address (empty)\fR" 621 /* An optional numerical network address that the Postfix SMTP client 622 /* should bind to when making an IPv4 connection. 623 /* .IP "\fBsmtp_bind_address6 (empty)\fR" 624 /* An optional numerical network address that the Postfix SMTP client 625 /* should bind to when making an IPv6 connection. 626 /* .IP "\fBsmtp_helo_name ($myhostname)\fR" 627 /* The hostname to send in the SMTP EHLO or HELO command. 628 /* .IP "\fBlmtp_lhlo_name ($myhostname)\fR" 629 /* The hostname to send in the LMTP LHLO command. 630 /* .IP "\fBsmtp_host_lookup (dns)\fR" 631 /* What mechanisms the Postfix SMTP client uses to look up a host's IP 632 /* address. 633 /* .IP "\fBsmtp_randomize_addresses (yes)\fR" 634 /* Randomize the order of equal-preference MX host addresses. 635 /* .IP "\fBsyslog_facility (mail)\fR" 636 /* The syslog facility of Postfix logging. 637 /* .IP "\fBsyslog_name (see 'postconf -d' output)\fR" 638 /* The mail system name that is prepended to the process name in syslog 639 /* records, so that "smtpd" becomes, for example, "postfix/smtpd". 640 /* .PP 641 /* Available with Postfix 2.2 and earlier: 642 /* .IP "\fBfallback_relay (empty)\fR" 643 /* Optional list of relay hosts for SMTP destinations that can't be 644 /* found or that are unreachable. 645 /* .PP 646 /* Available with Postfix 2.3 and later: 647 /* .IP "\fBsmtp_fallback_relay ($fallback_relay)\fR" 648 /* Optional list of relay hosts for SMTP destinations that can't be 649 /* found or that are unreachable. 650 /* SEE ALSO 651 /* generic(5), output address rewriting 652 /* header_checks(5), message header content inspection 653 /* body_checks(5), body parts content inspection 654 /* qmgr(8), queue manager 655 /* bounce(8), delivery status reports 656 /* scache(8), connection cache server 657 /* postconf(5), configuration parameters 658 /* master(5), generic daemon options 659 /* master(8), process manager 660 /* tlsmgr(8), TLS session and PRNG management 661 /* syslogd(8), system logging 662 /* README FILES 663 /* .ad 664 /* .fi 665 /* Use "\fBpostconf readme_directory\fR" or 666 /* "\fBpostconf html_directory\fR" to locate this information. 667 /* .na 668 /* .nf 669 /* SASL_README, Postfix SASL howto 670 /* TLS_README, Postfix STARTTLS howto 671 /* LICENSE 672 /* .ad 673 /* .fi 674 /* The Secure Mailer license must be distributed with this software. 675 /* AUTHOR(S) 676 /* Wietse Venema 677 /* IBM T.J. Watson Research 678 /* P.O. Box 704 679 /* Yorktown Heights, NY 10598, USA 680 /* 681 /* Command pipelining in cooperation with: 682 /* Jon Ribbens 683 /* Oaktree Internet Solutions Ltd., 684 /* Internet House, 685 /* Canal Basin, 686 /* Coventry, 687 /* CV1 4LY, United Kingdom. 688 /* 689 /* SASL support originally by: 690 /* Till Franke 691 /* SuSE Rhein/Main AG 692 /* 65760 Eschborn, Germany 693 /* 694 /* TLS support originally by: 695 /* Lutz Jaenicke 696 /* BTU Cottbus 697 /* Allgemeine Elektrotechnik 698 /* Universitaetsplatz 3-4 699 /* D-03044 Cottbus, Germany 700 /* 701 /* Revised TLS and SMTP connection cache support by: 702 /* Victor Duchovni 703 /* Morgan Stanley 704 /*--*/ 705 706 /* System library. */ 707 708 #include <sys_defs.h> 709 #include <unistd.h> 710 #include <stdlib.h> 711 #include <string.h> 712 #include <fcntl.h> 713 #include <dict.h> 714 #include <stringops.h> 715 716 /* Utility library. */ 717 718 #include <msg.h> 719 #include <mymalloc.h> 720 #include <name_mask.h> 721 #include <name_code.h> 722 723 /* Global library. */ 724 725 #include <deliver_request.h> 726 #include <mail_params.h> 727 #include <mail_version.h> 728 #include <mail_conf.h> 729 #include <debug_peer.h> 730 #include <flush_clnt.h> 731 #include <scache.h> 732 #include <string_list.h> 733 #include <maps.h> 734 #include <ext_prop.h> 735 736 /* DNS library. */ 737 738 #include <dns.h> 739 740 /* Single server skeleton. */ 741 742 #include <mail_server.h> 743 744 /* Application-specific. */ 745 746 #include "smtp.h" 747 #include "smtp_sasl.h" 748 749 /* 750 * Tunable parameters. These have compiled-in defaults that can be overruled 751 * by settings in the global Postfix configuration file. 752 */ 753 int var_smtp_conn_tmout; 754 int var_smtp_helo_tmout; 755 int var_smtp_xfwd_tmout; 756 int var_smtp_mail_tmout; 757 int var_smtp_rcpt_tmout; 758 int var_smtp_data0_tmout; 759 int var_smtp_data1_tmout; 760 int var_smtp_data2_tmout; 761 int var_smtp_rset_tmout; 762 int var_smtp_quit_tmout; 763 char *var_inet_interfaces; 764 char *var_notify_classes; 765 int var_smtp_skip_5xx_greeting; 766 int var_ign_mx_lookup_err; 767 int var_skip_quit_resp; 768 char *var_fallback_relay; 769 char *var_bestmx_transp; 770 char *var_error_rcpt; 771 int var_smtp_always_ehlo; 772 int var_smtp_never_ehlo; 773 char *var_smtp_sasl_opts; 774 char *var_smtp_sasl_path; 775 char *var_smtp_sasl_passwd; 776 bool var_smtp_sasl_enable; 777 char *var_smtp_sasl_mechs; 778 char *var_smtp_sasl_type; 779 char *var_smtp_bind_addr; 780 char *var_smtp_bind_addr6; 781 bool var_smtp_rand_addr; 782 int var_smtp_pix_thresh; 783 int var_smtp_pix_delay; 784 int var_smtp_line_limit; 785 char *var_smtp_helo_name; 786 char *var_smtp_host_lookup; 787 bool var_smtp_quote_821_env; 788 bool var_smtp_defer_mxaddr; 789 bool var_smtp_send_xforward; 790 int var_smtp_mxaddr_limit; 791 int var_smtp_mxsess_limit; 792 int var_smtp_cache_conn; 793 int var_smtp_reuse_time; 794 char *var_smtp_cache_dest; 795 char *var_scache_service; /* You can now leave this here. */ 796 bool var_smtp_cache_demand; 797 char *var_smtp_ehlo_dis_words; 798 char *var_smtp_ehlo_dis_maps; 799 char *var_smtp_addr_pref; 800 801 char *var_smtp_tls_level; 802 bool var_smtp_use_tls; 803 bool var_smtp_enforce_tls; 804 char *var_smtp_tls_per_site; 805 char *var_smtp_tls_policy; 806 807 #ifdef USE_TLS 808 char *var_smtp_sasl_tls_opts; 809 char *var_smtp_sasl_tlsv_opts; 810 int var_smtp_starttls_tmout; 811 char *var_smtp_tls_CAfile; 812 char *var_smtp_tls_CApath; 813 char *var_smtp_tls_cert_file; 814 char *var_smtp_tls_mand_ciph; 815 char *var_smtp_tls_excl_ciph; 816 char *var_smtp_tls_mand_excl; 817 char *var_smtp_tls_dcert_file; 818 char *var_smtp_tls_dkey_file; 819 bool var_smtp_tls_enforce_peername; 820 char *var_smtp_tls_key_file; 821 char *var_smtp_tls_loglevel; 822 bool var_smtp_tls_note_starttls_offer; 823 char *var_smtp_tls_mand_proto; 824 char *var_smtp_tls_sec_cmatch; 825 int var_smtp_tls_scert_vd; 826 char *var_smtp_tls_vfy_cmatch; 827 char *var_smtp_tls_fpt_cmatch; 828 char *var_smtp_tls_fpt_dgst; 829 char *var_smtp_tls_proto; 830 char *var_smtp_tls_ciph; 831 char *var_smtp_tls_eccert_file; 832 char *var_smtp_tls_eckey_file; 833 bool var_smtp_tls_blk_early_mail_reply; 834 835 #endif 836 837 char *var_smtp_generic_maps; 838 char *var_prop_extension; 839 bool var_smtp_sender_auth; 840 char *var_lmtp_tcp_port; 841 int var_scache_proto_tmout; 842 bool var_smtp_cname_overr; 843 char *var_smtp_pix_bug_words; 844 char *var_smtp_pix_bug_maps; 845 char *var_cyrus_conf_path; 846 char *var_smtp_head_chks; 847 char *var_smtp_mime_chks; 848 char *var_smtp_nest_chks; 849 char *var_smtp_body_chks; 850 char *var_smtp_resp_filter; 851 bool var_lmtp_assume_final; 852 char *var_smtp_dns_res_opt; 853 bool var_smtp_rec_deadline; 854 bool var_smtp_dummy_mail_auth; 855 856 /* Special handling of 535 AUTH errors. */ 857 char *var_smtp_sasl_auth_cache_name; 858 int var_smtp_sasl_auth_cache_time; 859 bool var_smtp_sasl_auth_soft_bounce; 860 861 /* 862 * Global variables. 863 */ 864 int smtp_host_lookup_mask; 865 STRING_LIST *smtp_cache_dest; 866 SCACHE *smtp_scache; 867 MAPS *smtp_ehlo_dis_maps; 868 MAPS *smtp_generic_maps; 869 int smtp_ext_prop_mask; 870 unsigned smtp_dns_res_opt; 871 MAPS *smtp_pix_bug_maps; 872 HBC_CHECKS *smtp_header_checks; /* limited header checks */ 873 HBC_CHECKS *smtp_body_checks; /* limited body checks */ 874 875 #ifdef USE_TLS 876 877 /* 878 * OpenSSL client state (opaque handle) 879 */ 880 TLS_APPL_STATE *smtp_tls_ctx; 881 882 #endif 883 884 /* 885 * IPv6 preference. 886 */ 887 static int smtp_addr_pref; 888 889 /* deliver_message - deliver message with extreme prejudice */ 890 891 static int deliver_message(const char *service, DELIVER_REQUEST *request) 892 { 893 SMTP_STATE *state; 894 int result; 895 896 if (msg_verbose) 897 msg_info("deliver_message: from %s", request->sender); 898 899 /* 900 * Sanity checks. The smtp server is unprivileged and chrooted, so we can 901 * afford to distribute the data censoring code, instead of having it all 902 * in one place. 903 */ 904 if (request->nexthop[0] == 0) 905 msg_fatal("empty nexthop hostname"); 906 if (request->rcpt_list.len <= 0) 907 msg_fatal("recipient count: %d", request->rcpt_list.len); 908 909 /* 910 * Initialize. Bundle all information about the delivery request, so that 911 * we can produce understandable diagnostics when something goes wrong 912 * many levels below. The alternative would be to make everything global. 913 */ 914 state = smtp_state_alloc(); 915 state->request = request; 916 state->src = request->fp; 917 state->service = service; 918 state->misc_flags |= smtp_addr_pref; 919 SMTP_RCPT_INIT(state); 920 921 /* 922 * Establish an SMTP session and deliver this message to all requested 923 * recipients. At the end, notify the postmaster of any protocol errors. 924 * Optionally deliver mail locally when this machine is the best mail 925 * exchanger. 926 */ 927 result = smtp_connect(state); 928 929 /* 930 * Clean up. 931 */ 932 smtp_state_free(state); 933 934 return (result); 935 } 936 937 /* smtp_service - perform service for client */ 938 939 static void smtp_service(VSTREAM *client_stream, char *service, char **argv) 940 { 941 DELIVER_REQUEST *request; 942 int status; 943 944 /* 945 * Sanity check. This service takes no command-line arguments. 946 */ 947 if (argv[0]) 948 msg_fatal("unexpected command-line argument: %s", argv[0]); 949 950 /* 951 * This routine runs whenever a client connects to the UNIX-domain socket 952 * dedicated to remote SMTP delivery service. What we see below is a 953 * little protocol to (1) tell the queue manager that we are ready, (2) 954 * read a request from the queue manager, and (3) report the completion 955 * status of that request. All connection-management stuff is handled by 956 * the common code in single_server.c. 957 */ 958 if ((request = deliver_request_read(client_stream)) != 0) { 959 status = deliver_message(service, request); 960 deliver_request_done(client_stream, request, status); 961 } 962 } 963 964 /* post_init - post-jail initialization */ 965 966 static void post_init(char *unused_name, char **unused_argv) 967 { 968 static const NAME_MASK lookup_masks[] = { 969 SMTP_HOST_LOOKUP_DNS, SMTP_HOST_FLAG_DNS, 970 SMTP_HOST_LOOKUP_NATIVE, SMTP_HOST_FLAG_NATIVE, 971 0, 972 }; 973 static const NAME_MASK dns_res_opt_masks[] = { 974 SMTP_DNS_RES_OPT_DEFNAMES, RES_DEFNAMES, 975 SMTP_DNS_RES_OPT_DNSRCH, RES_DNSRCH, 976 0, 977 }; 978 979 /* 980 * Select hostname lookup mechanisms. 981 */ 982 if (var_disable_dns) 983 smtp_host_lookup_mask = SMTP_HOST_FLAG_NATIVE; 984 else 985 smtp_host_lookup_mask = name_mask(VAR_SMTP_HOST_LOOKUP, lookup_masks, 986 var_smtp_host_lookup); 987 if (msg_verbose) 988 msg_info("host name lookup methods: %s", 989 str_name_mask(VAR_SMTP_HOST_LOOKUP, lookup_masks, 990 smtp_host_lookup_mask)); 991 992 /* 993 * Session cache instance. 994 */ 995 if (*var_smtp_cache_dest || var_smtp_cache_demand) 996 #if 0 997 smtp_scache = scache_multi_create(); 998 #else 999 smtp_scache = scache_clnt_create(var_scache_service, 1000 var_scache_proto_tmout, 1001 var_ipc_idle_limit, 1002 var_ipc_ttl_limit); 1003 #endif 1004 1005 /* 1006 * Select DNS query flags. 1007 */ 1008 smtp_dns_res_opt = name_mask(VAR_SMTP_DNS_RES_OPT, dns_res_opt_masks, 1009 var_smtp_dns_res_opt); 1010 } 1011 1012 /* pre_init - pre-jail initialization */ 1013 1014 static void pre_init(char *unused_name, char **unused_argv) 1015 { 1016 int use_tls; 1017 static const NAME_CODE addr_pref_map[] = { 1018 INET_PROTO_NAME_IPV6, SMTP_MISC_FLAG_PREF_IPV6, 1019 INET_PROTO_NAME_IPV4, SMTP_MISC_FLAG_PREF_IPV4, 1020 INET_PROTO_NAME_ANY, 0, 1021 0, -1, 1022 }; 1023 1024 /* 1025 * Turn on per-peer debugging. 1026 */ 1027 debug_peer_init(); 1028 1029 /* 1030 * SASL initialization. 1031 */ 1032 if (var_smtp_sasl_enable) 1033 #ifdef USE_SASL_AUTH 1034 smtp_sasl_initialize(); 1035 #else 1036 msg_warn("%s is true, but SASL support is not compiled in", 1037 VAR_SMTP_SASL_ENABLE); 1038 #endif 1039 1040 if (*var_smtp_tls_level != 0) 1041 #ifdef USE_TLS 1042 switch (tls_level_lookup(var_smtp_tls_level)) { 1043 case TLS_LEV_SECURE: 1044 case TLS_LEV_VERIFY: 1045 case TLS_LEV_FPRINT: 1046 case TLS_LEV_ENCRYPT: 1047 var_smtp_use_tls = var_smtp_enforce_tls = 1; 1048 break; 1049 case TLS_LEV_MAY: 1050 var_smtp_use_tls = 1; 1051 var_smtp_enforce_tls = 0; 1052 break; 1053 case TLS_LEV_NONE: 1054 var_smtp_use_tls = var_smtp_enforce_tls = 0; 1055 break; 1056 default: 1057 /* tls_level_lookup() logs no warning. */ 1058 /* session_tls_init() assumes that var_smtp_tls_level is sane. */ 1059 msg_fatal("Invalid TLS level \"%s\"", var_smtp_tls_level); 1060 } 1061 #endif 1062 use_tls = (var_smtp_use_tls || var_smtp_enforce_tls); 1063 1064 /* 1065 * Initialize the TLS data before entering the chroot jail 1066 */ 1067 if (use_tls || var_smtp_tls_per_site[0] || var_smtp_tls_policy[0]) { 1068 #ifdef USE_TLS 1069 TLS_CLIENT_INIT_PROPS props; 1070 int using_smtp = (strcmp(var_procname, "smtp") == 0); 1071 1072 /* 1073 * We get stronger type safety and a cleaner interface by combining 1074 * the various parameters into a single tls_client_props structure. 1075 * 1076 * Large parameter lists are error-prone, so we emulate a language 1077 * feature that C does not have natively: named parameter lists. 1078 */ 1079 smtp_tls_ctx = 1080 TLS_CLIENT_INIT(&props, 1081 log_param = using_smtp ? 1082 VAR_SMTP_TLS_LOGLEVEL : VAR_LMTP_TLS_LOGLEVEL, 1083 log_level = var_smtp_tls_loglevel, 1084 verifydepth = var_smtp_tls_scert_vd, 1085 cache_type = using_smtp ? 1086 TLS_MGR_SCACHE_SMTP : TLS_MGR_SCACHE_LMTP, 1087 cert_file = var_smtp_tls_cert_file, 1088 key_file = var_smtp_tls_key_file, 1089 dcert_file = var_smtp_tls_dcert_file, 1090 dkey_file = var_smtp_tls_dkey_file, 1091 eccert_file = var_smtp_tls_eccert_file, 1092 eckey_file = var_smtp_tls_eckey_file, 1093 CAfile = var_smtp_tls_CAfile, 1094 CApath = var_smtp_tls_CApath, 1095 fpt_dgst = var_smtp_tls_fpt_dgst); 1096 smtp_tls_list_init(); 1097 #else 1098 msg_warn("TLS has been selected, but TLS support is not compiled in"); 1099 #endif 1100 } 1101 1102 /* 1103 * Flush client. 1104 */ 1105 flush_init(); 1106 1107 /* 1108 * Session cache domain list. 1109 */ 1110 if (*var_smtp_cache_dest) 1111 smtp_cache_dest = string_list_init(MATCH_FLAG_RETURN, var_smtp_cache_dest); 1112 1113 /* 1114 * EHLO keyword filter. 1115 */ 1116 if (*var_smtp_ehlo_dis_maps) 1117 smtp_ehlo_dis_maps = maps_create(VAR_SMTP_EHLO_DIS_MAPS, 1118 var_smtp_ehlo_dis_maps, 1119 DICT_FLAG_LOCK); 1120 1121 /* 1122 * PIX bug workarounds. 1123 */ 1124 if (*var_smtp_pix_bug_maps) 1125 smtp_pix_bug_maps = maps_create(VAR_SMTP_PIX_BUG_MAPS, 1126 var_smtp_pix_bug_maps, 1127 DICT_FLAG_LOCK); 1128 1129 /* 1130 * Generic maps. 1131 */ 1132 if (*var_prop_extension) 1133 smtp_ext_prop_mask = 1134 ext_prop_mask(VAR_PROP_EXTENSION, var_prop_extension); 1135 if (*var_smtp_generic_maps) 1136 smtp_generic_maps = 1137 maps_create(VAR_SMTP_GENERIC_MAPS, var_smtp_generic_maps, 1138 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX); 1139 1140 /* 1141 * Header/body checks. 1142 */ 1143 smtp_header_checks = hbc_header_checks_create( 1144 VAR_SMTP_HEAD_CHKS, var_smtp_head_chks, 1145 VAR_SMTP_MIME_CHKS, var_smtp_mime_chks, 1146 VAR_SMTP_NEST_CHKS, var_smtp_nest_chks, 1147 smtp_hbc_callbacks); 1148 smtp_body_checks = hbc_body_checks_create( 1149 VAR_SMTP_BODY_CHKS, var_smtp_body_chks, 1150 smtp_hbc_callbacks); 1151 1152 /* 1153 * Server reply filter. 1154 */ 1155 if (*var_smtp_resp_filter) 1156 smtp_chat_resp_filter = 1157 dict_open(var_smtp_resp_filter, O_RDONLY, 1158 DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX); 1159 1160 /* 1161 * Address family preference. 1162 */ 1163 if (*var_smtp_addr_pref) { 1164 smtp_addr_pref = name_code(addr_pref_map, NAME_CODE_FLAG_NONE, 1165 var_smtp_addr_pref); 1166 if (smtp_addr_pref < 0) 1167 msg_fatal("bad %s value: %s", VAR_SMTP_ADDR_PREF, var_smtp_addr_pref); 1168 } 1169 } 1170 1171 /* pre_accept - see if tables have changed */ 1172 1173 static void pre_accept(char *unused_name, char **unused_argv) 1174 { 1175 const char *table; 1176 1177 if ((table = dict_changed_name()) != 0) { 1178 msg_info("table %s has changed -- restarting", table); 1179 exit(0); 1180 } 1181 } 1182 1183 MAIL_VERSION_STAMP_DECLARE; 1184 1185 /* main - pass control to the single-threaded skeleton */ 1186 1187 int main(int argc, char **argv) 1188 { 1189 #include "smtp_params.c" 1190 #include "lmtp_params.c" 1191 int smtp_mode; 1192 1193 /* 1194 * Fingerprint executables and core dumps. 1195 */ 1196 MAIL_VERSION_STAMP_ALLOCATE; 1197 1198 /* 1199 * XXX At this point, var_procname etc. are not initialized. 1200 */ 1201 smtp_mode = (strcmp(sane_basename((VSTRING *) 0, argv[0]), "smtp") == 0); 1202 1203 /* 1204 * Initialize with the LMTP or SMTP parameter name space. 1205 */ 1206 single_server_main(argc, argv, smtp_service, 1207 MAIL_SERVER_TIME_TABLE, smtp_mode ? 1208 smtp_time_table : lmtp_time_table, 1209 MAIL_SERVER_INT_TABLE, smtp_mode ? 1210 smtp_int_table : lmtp_int_table, 1211 MAIL_SERVER_STR_TABLE, smtp_mode ? 1212 smtp_str_table : lmtp_str_table, 1213 MAIL_SERVER_BOOL_TABLE, smtp_mode ? 1214 smtp_bool_table : lmtp_bool_table, 1215 MAIL_SERVER_PRE_INIT, pre_init, 1216 MAIL_SERVER_POST_INIT, post_init, 1217 MAIL_SERVER_PRE_ACCEPT, pre_accept, 1218 0); 1219 } 1220