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