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