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