~ubuntu-branches/ubuntu/trusty/postfix/trusty-updates

« back to all changes in this revision

Viewing changes to src/smtp/smtp.c

Tags: upstream-2.3.1
ImportĀ upstreamĀ versionĀ 2.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/* NAME
3
3
/*      smtp 8
4
4
/* SUMMARY
5
 
/*      Postfix SMTP client
 
5
/*      Postfix SMTP+LMTP client
6
6
/* SYNOPSIS
7
7
/*      \fBsmtp\fR [generic Postfix daemon options]
8
8
/* DESCRIPTION
9
 
/*      The Postfix SMTP client processes message delivery requests from
 
9
/*      The Postfix SMTP+LMTP client implements the SMTP and LMTP mail
 
10
/*      delivery protocols. It processes message delivery requests from
10
11
/*      the queue manager. Each request specifies a queue file, a sender
11
12
/*      address, a domain or host to deliver to, and recipient information.
12
13
/*      This program expects to be run from the \fBmaster\fR(8) process
13
14
/*      manager.
14
15
/*
15
 
/*      The SMTP client updates the queue file and marks recipients
 
16
/*      The SMTP+LMTP client updates the queue file and marks recipients
16
17
/*      as finished, or it informs the queue manager that delivery should
17
18
/*      be tried again at a later time. Delivery status reports are sent
18
19
/*      to the \fBbounce\fR(8), \fBdefer\fR(8) or \fBtrace\fR(8) daemon as
19
20
/*      appropriate.
20
21
/*
21
 
/*      The SMTP client looks up a list of mail exchanger addresses for
 
22
/*      The SMTP+LMTP client looks up a list of mail exchanger addresses for
22
23
/*      the destination host, sorts the list by preference, and connects
23
24
/*      to each listed address until it finds a server that responds.
24
25
/*
25
26
/*      When a server is not reachable, or when mail delivery fails due
26
 
/*      to a recoverable error condition, the SMTP client will try to
 
27
/*      to a recoverable error condition, the SMTP+LMTP client will try to
27
28
/*      deliver the mail to an alternate host.
28
29
/*
29
30
/*      After a successful mail transaction, a connection may be saved
30
31
/*      to the \fBscache\fR(8) connection cache server, so that it
31
 
/*      may be used by any SMTP client for a subsequent transaction.
 
32
/*      may be used by any SMTP+LMTP client for a subsequent transaction.
32
33
/*
33
34
/*      By default, connection caching is enabled temporarily for
34
35
/*      destinations that have a high volume of mail in the active
35
36
/*      queue. Session caching can be enabled permanently for
36
37
/*      specific destinations.
 
38
/* SMTP DESTINATION SYNTAX
 
39
/* .ad
 
40
/* .fi
 
41
/*      SMTP destinations have the following form:
 
42
/* .IP \fIdomainname\fR
 
43
/* .IP \fIdomainname\fR:\fIport\fR
 
44
/*      Look up the mail exchangers for the specified domain, and
 
45
/*      connect to the specified port (default: \fBsmtp\fR).
 
46
/* .IP [\fIhostname\fR]
 
47
/* .IP [\fIhostname\fR]:\fIport\fR
 
48
/*      Look up the address(es) of the specified host, and connect to
 
49
/*      the specified port (default: \fBsmtp\fR).
 
50
/* .IP [\fIaddress\fR]
 
51
/* .IP [\fIaddress\fR]:\fIport\fR
 
52
/*      Connect to the host at the specified address, and connect
 
53
/*      to the specified port (default: \fBsmtp\fR). An IPv6 address
 
54
/*      must be formatted as [\fBipv6\fR:\fIaddress\fR].
 
55
/* LMTP DESTINATION SYNTAX
 
56
/* .ad
 
57
/* .fi
 
58
/*      LMTP destinations have the following form:
 
59
/* .IP \fBunix\fR:\fIpathname\fR
 
60
/*      Connect to the local UNIX-domain server that is bound to the specified
 
61
/*      \fIpathname\fR. If the process runs chrooted, an absolute pathname
 
62
/*      is interpreted relative to the Postfix queue directory.
 
63
/* .IP \fBinet\fR:\fIhostname\fR
 
64
/* .IP \fBinet\fB:\fIhostname\fR:\fIport\fR
 
65
/* .IP \fBinet\fR:[\fIaddress\fR]
 
66
/* .IP \fBinet\fR:[\fIaddress\fR]:\fIport\fR
 
67
/*      Connect to the specified TCP port on the specified local or
 
68
/*      remote host. If no port is specified, connect to the port defined as
 
69
/*      \fBlmtp\fR in \fBservices\fR(4).
 
70
/*      If no such service is found, the \fBlmtp_tcp_port\fR configuration
 
71
/*      parameter (default value of 24) will be used.
 
72
/*      An IPv6 address must be formatted as [\fBipv6\fR:\fIaddress\fR].
 
73
/* .PP
37
74
/* SECURITY
38
75
/* .ad
39
76
/* .fi
40
 
/*      The SMTP client is moderately security-sensitive. It talks to SMTP
41
 
/*      servers and to DNS servers on the network. The SMTP client can be
42
 
/*      run chrooted at fixed low privilege.
 
77
/*      The SMTP+LMTP client is moderately security-sensitive. It
 
78
/*      talks to SMTP or LMTP servers and to DNS servers on the
 
79
/*      network. The SMTP+LMTP client can be run chrooted at fixed
 
80
/*      low privilege.
43
81
/* STANDARDS
44
82
/*      RFC 821 (SMTP protocol)
45
83
/*      RFC 822 (ARPA Internet Text Messages)
46
84
/*      RFC 1651 (SMTP service extensions)
47
85
/*      RFC 1652 (8bit-MIME transport)
48
86
/*      RFC 1870 (Message Size Declaration)
 
87
/*      RFC 2033 (LMTP protocol)
 
88
/*      RFC 2034 (SMTP Enhanced Error Codes)
49
89
/*      RFC 2045 (MIME: Format of Internet Message Bodies)
50
90
/*      RFC 2046 (MIME: Media Types)
51
91
/*      RFC 2554 (AUTH command)
52
92
/*      RFC 2821 (SMTP protocol)
53
93
/*      RFC 2920 (SMTP Pipelining)
54
94
/*      RFC 3207 (STARTTLS command)
 
95
/*      RFC 3461 (SMTP DSN Extension)
 
96
/*      RFC 3463 (Enhanced Status Codes)
55
97
/* DIAGNOSTICS
56
98
/*      Problems and transactions are logged to \fBsyslogd\fR(8).
57
99
/*      Corrupted message files are marked so that the queue manager can
61
103
/*      the postmaster is notified of bounces, protocol problems, and of
62
104
/*      other trouble.
63
105
/* BUGS
64
 
/*      SMTP connection caching does not work with TLS. The necessary
 
106
/*      SMTP and LMTP connection caching does not work with TLS. The necessary
65
107
/*      support for TLS object passivation and re-activation does not
66
108
/*      exist without closing the session, which defeats the purpose.
67
109
/*
68
 
/*      SMTP connection caching assumes that SASL credentials are valid for
69
 
/*      all destinations that map onto the same IP address and TCP port.
 
110
/*      SMTP and LMTP connection caching assumes that SASL credentials
 
111
/*      are valid for all destinations that map onto the same IP
 
112
/*      address and TCP port.
70
113
/* CONFIGURATION PARAMETERS
71
114
/* .ad
72
115
/* .fi
 
116
/*      Before Postfix version 2.3, the LMTP client is a separate
 
117
/*      program that implements only a subset of the functionality
 
118
/*      available with SMTP: there is no support for TLS, and
 
119
/*      connections are cached in-process, making it ineffective
 
120
/*      when the client is used for multiple domains.
 
121
/*
 
122
/*      Most smtp_\fIxxx\fR configuration parameters have an
 
123
/*      lmtp_\fIxxx\fR "ghost" parameter for the equivalent LMTP
 
124
/*      feature. This document describes only those LMTP-related
 
125
/*      parameters that aren't simply "ghost" parameters.
 
126
/*
73
127
/*      Changes to \fBmain.cf\fR are picked up automatically, as \fBsmtp\fR(8)
74
128
/*      processes run for only a limited amount of time. Use the command
75
129
/*      "\fBpostfix reload\fR" to speed up a change.
85
139
/*      Always send EHLO at the start of an SMTP session.
86
140
/* .IP "\fBsmtp_never_send_ehlo (no)\fR"
87
141
/*      Never send EHLO at the start of an SMTP session.
88
 
/* .IP "\fBsmtp_cname_overrides_servername (yes)\fR"
89
 
/*      Allow DNS CNAME records to override the servername that the
90
 
/*      Postfix SMTP client uses for logging, SASL password lookup, TLS
91
 
/*      policy decisions, or TLS certificate verification.
92
142
/* .IP "\fBsmtp_defer_if_no_mx_address_found (no)\fR"
93
143
/*      Defer mail delivery when no MX record resolves to an IP address.
94
144
/* .IP "\fBsmtp_line_length_limit (990)\fR"
101
151
/* .IP "\fBsmtp_pix_workaround_threshold_time (500s)\fR"
102
152
/*      How long a message must be queued before the PIX firewall
103
153
/*      "<CR><LF>.<CR><LF>" bug workaround is turned
104
 
/*      on.
 
154
/*      on for delivery through firewalls with "smtp fixup" mode turned on.
105
155
/* .IP "\fBsmtp_quote_rfc821_envelope (yes)\fR"
106
156
/*      Quote addresses in SMTP MAIL FROM and RCPT TO commands as required
107
157
/*      by RFC 821.
119
169
/*      Available in Postfix version 2.2 and later:
120
170
/* .IP "\fBsmtp_discard_ehlo_keyword_address_maps (empty)\fR"
121
171
/*      Lookup tables, indexed by the remote SMTP server address, with
122
 
/*      case insensitive lists of EHLO keywords (pipelining, starttls,
123
 
/*      auth, etc.) that the SMTP client will ignore in the EHLO response
124
 
/*      from a remote SMTP server.
 
172
/*      case insensitive lists of EHLO keywords (pipelining, starttls, auth,
 
173
/*      etc.) that the Postfix SMTP client will ignore in the EHLO response from a
 
174
/*      remote SMTP server.
125
175
/* .IP "\fBsmtp_discard_ehlo_keywords (empty)\fR"
126
176
/*      A case insensitive list of EHLO keywords (pipelining, starttls,
127
 
/*      auth, etc.) that the SMTP client will ignore in the EHLO response
128
 
/*      from a remote SMTP server.
 
177
/*      auth, etc.) that the Postfix SMTP client will ignore in the EHLO
 
178
/*      response from a remote SMTP server.
129
179
/* .IP "\fBsmtp_generic_maps (empty)\fR"
130
180
/*      Optional lookup tables that perform address rewriting in the
131
181
/*      SMTP client, typically to transform a locally valid address into
132
182
/*      a globally valid address when sending mail across the Internet.
 
183
/* .PP
 
184
/*      Available in Postfix version 2.2.9 and later:
 
185
/* .IP "\fBsmtp_cname_overrides_servername (version dependent)\fR"
 
186
/*      Allow DNS CNAME records to override the servername that the
 
187
/*      Postfix SMTP client uses for logging, SASL password lookup, TLS
 
188
/*      policy decisions, or TLS certificate verification.
 
189
/* .PP
 
190
/*      Available in Postfix version 2.3 and later:
 
191
/* .IP "\fBlmtp_discard_lhlo_keyword_address_maps (empty)\fR"
 
192
/*      Lookup tables, indexed by the remote LMTP server address, with
 
193
/*      case insensitive lists of LHLO keywords (pipelining, starttls,
 
194
/*      auth, etc.) that the LMTP client will ignore in the LHLO response
 
195
/*      from a remote LMTP server.
 
196
/* .IP "\fBlmtp_discard_lhlo_keywords ($myhostname)\fR"
 
197
/*      A case insensitive list of LHLO keywords (pipelining, starttls,
 
198
/*      auth, etc.) that the LMTP client will ignore in the LHLO response
 
199
/*      from a remote LMTP server.
133
200
/* MIME PROCESSING CONTROLS
134
201
/* .ad
135
202
/* .fi
145
212
/* .fi
146
213
/*      Available in Postfix version 2.1 and later:
147
214
/* .IP "\fBsmtp_send_xforward_command (no)\fR"
148
 
/*      Send the non-standard XFORWARD command when the Postfix SMTP server EHLO
149
 
/*      response announces XFORWARD support.
 
215
/*      Send the non-standard XFORWARD command when the Postfix SMTP server
 
216
/*      EHLO response announces XFORWARD support.
150
217
/* SASL AUTHENTICATION CONTROLS
151
218
/* .ad
152
219
/* .fi
154
221
/*      Enable SASL authentication in the Postfix SMTP client.
155
222
/* .IP "\fBsmtp_sasl_password_maps (empty)\fR"
156
223
/*      Optional SMTP client lookup tables with one username:password entry
157
 
/*      per remote hostname or domain.
 
224
/*      per remote hostname or domain, or sender address when sender-dependent
 
225
/*      authentication is enabled.
158
226
/* .IP "\fBsmtp_sasl_security_options (noplaintext, noanonymous)\fR"
159
 
/*      What authentication mechanisms the Postfix SMTP client is allowed
160
 
/*      to use.
 
227
/*      SASL security options; as of Postfix 2.3 the list of available
 
228
/*      features depends on the SASL client implementation that is selected
 
229
/*      with \fBsmtp_sasl_type\fR.
161
230
/* .PP
162
231
/*      Available in Postfix version 2.2 and later:
163
232
/* .IP "\fBsmtp_sasl_mechanism_filter (empty)\fR"
164
233
/*      If non-empty, a Postfix SMTP client filter for the remote SMTP
165
234
/*      server's list of offered SASL mechanisms.
 
235
/* .PP
 
236
/*      Available in Postfix version 2.3 and later:
 
237
/* .IP "\fBsmtp_sender_dependent_authentication (no)\fR"
 
238
/*      Enable sender-dependent authentication in the Postfix SMTP client; this is
 
239
/*      available only with SASL authentication, and disables SMTP connection
 
240
/*      caching to ensure that mail from different senders will use the
 
241
/*      appropriate credentials.
 
242
/* .IP "\fBsmtp_sasl_path (empty)\fR"
 
243
/*      Implementation-specific information that is passed through to
 
244
/*      the SASL plug-in implementation that is selected with
 
245
/*      \fBsmtp_sasl_type\fR.
 
246
/* .IP "\fBsmtp_sasl_type (cyrus)\fR"
 
247
/*      The SASL plug-in type that the Postfix SMTP client should use
 
248
/*      for authentication.
166
249
/* STARTTLS SUPPORT CONTROLS
167
250
/* .ad
168
251
/* .fi
169
252
/*      Detailed information about STARTTLS configuration may be found
170
253
/*      in the TLS_README document.
171
 
/* .IP "\fBsmtp_use_tls (no)\fR"
172
 
/*      Opportunistic mode: use TLS when a remote SMTP server announces
173
 
/*      STARTTLS support, otherwise send the mail in the clear.
174
 
/* .IP "\fBsmtp_enforce_tls (no)\fR"
175
 
/*      Enforcement mode: require that remote SMTP servers use TLS
176
 
/*      encryption, and never send mail in the clear.
 
254
/* .IP "\fBsmtp_tls_security_level (empty)\fR"
 
255
/*      The default SMTP TLS security level for the Postfix SMTP client;
 
256
/*      when a non-empty value is specified, this overrides the obsolete
 
257
/*      parameters smtp_use_tls, smtp_enforce_tls, and smtp_tls_enforce_peername.
177
258
/* .IP "\fBsmtp_sasl_tls_security_options ($smtp_sasl_security_options)\fR"
178
259
/*      The SASL authentication security options that the Postfix SMTP
179
260
/*      client uses for TLS encrypted SMTP sessions.
189
270
/*      certificate.
190
271
/* .IP "\fBsmtp_tls_cert_file (empty)\fR"
191
272
/*      File with the Postfix SMTP client RSA certificate in PEM format.
192
 
/* .IP "\fBsmtp_tls_cipherlist (empty)\fR"
193
 
/*      Controls the Postfix SMTP client TLS cipher selection scheme.
 
273
/* .IP "\fBsmtp_tls_mandatory_ciphers (medium)\fR"
 
274
/*      The minimum TLS cipher grade that the Postfix SMTP client will
 
275
/*      use with
 
276
/*      mandatory TLS encryption.
 
277
/* .IP "\fBsmtp_tls_exclude_ciphers (empty)\fR"
 
278
/*      List of ciphers or cipher types to exclude from the Postfix
 
279
/*      SMTP client cipher
 
280
/*      list at all TLS security levels.
 
281
/* .IP "\fBsmtp_tls_mandatory_exclude_ciphers (empty)\fR"
 
282
/*      Additional list of ciphers or cipher types to exclude from the
 
283
/*      SMTP client cipher list at mandatory TLS security levels.
194
284
/* .IP "\fBsmtp_tls_dcert_file (empty)\fR"
195
285
/*      File with the Postfix SMTP client DSA certificate in PEM format.
196
286
/* .IP "\fBsmtp_tls_dkey_file ($smtp_tls_dcert_file)\fR"
197
287
/*      File with the Postfix SMTP client DSA private key in PEM format.
198
 
/* .IP "\fBsmtp_tls_enforce_peername (yes)\fR"
199
 
/*      When TLS encryption is enforced, require that the remote SMTP
200
 
/*      server hostname matches the information in the remote SMTP server
201
 
/*      certificate.
202
288
/* .IP "\fBsmtp_tls_key_file ($smtp_tls_cert_file)\fR"
203
289
/*      File with the Postfix SMTP client RSA private key in PEM format.
204
290
/* .IP "\fBsmtp_tls_loglevel (0)\fR"
206
292
/* .IP "\fBsmtp_tls_note_starttls_offer (no)\fR"
207
293
/*      Log the hostname of a remote SMTP server that offers STARTTLS,
208
294
/*      when TLS is not already enabled for that server.
209
 
/* .IP "\fBsmtp_tls_per_site (empty)\fR"
210
 
/*      Optional lookup tables with the Postfix SMTP client TLS usage
211
 
/*      policy by next-hop domain name and by remote SMTP server hostname.
 
295
/* .IP "\fBsmtp_tls_policy_maps (empty)\fR"
 
296
/*      Optional lookup tables with the Postfix SMTP client TLS security
 
297
/*      policy by next-hop destination; when a non-empty value is specified,
 
298
/*      this overrides the obsolete smtp_tls_per_site parameter.
 
299
/* .IP "\fBsmtp_tls_mandatory_protocols (SSLv3, TLSv1)\fR"
 
300
/*      List of TLS protocols that the Postfix SMTP client will use
 
301
/*      with mandatory TLS encryption.
212
302
/* .IP "\fBsmtp_tls_scert_verifydepth (5)\fR"
213
303
/*      The verification depth for remote SMTP server certificates.
 
304
/* .IP "\fBsmtp_tls_secure_cert_match (nexthop, dot-nexthop)\fR"
 
305
/*      The server certificate peername verification method for the
 
306
/*      "secure" TLS security level.
214
307
/* .IP "\fBsmtp_tls_session_cache_database (empty)\fR"
215
308
/*      Name of the file containing the optional Postfix SMTP client
216
309
/*      TLS session cache.
217
310
/* .IP "\fBsmtp_tls_session_cache_timeout (3600s)\fR"
218
311
/*      The expiration time of Postfix SMTP client TLS session cache
219
312
/*      information.
 
313
/* .IP "\fBsmtp_tls_verify_cert_match (hostname)\fR"
 
314
/*      The server certificate peername verification method for the
 
315
/*      "verify" TLS security level.
220
316
/* .IP "\fBtls_daemon_random_bytes (32)\fR"
221
317
/*      The number of pseudo-random bytes that an \fBsmtp\fR(8) or \fBsmtpd\fR(8)
222
318
/*      process requests from the \fBtlsmgr\fR(8) server in order to seed its
223
319
/*      internal pseudo random number generator (PRNG).
 
320
/* .IP "\fBtls_high_cipherlist (!EXPORT:!LOW:!MEDIUM:ALL:+RC4:@STRENGTH)\fR"
 
321
/*      The OpenSSL cipherlist for "HIGH" grade ciphers.
 
322
/* .IP "\fBtls_medium_cipherlist (!EXPORT:!LOW:ALL:+RC4:@STRENGTH)\fR"
 
323
/*      The OpenSSL cipherlist for "MEDIUM" or higher grade ciphers.
 
324
/* .IP "\fBtls_low_cipherlist (!EXPORT:ALL:+RC4:@STRENGTH)\fR"
 
325
/*      The OpenSSL cipherlist for "LOW" or higher grade ciphers.
 
326
/* .IP "\fBtls_export_cipherlist (ALL:+RC4:@STRENGTH)\fR"
 
327
/*      The OpenSSL cipherlist for "EXPORT" or higher grade ciphers.
 
328
/* .IP "\fBtls_null_cipherlist (!aNULL:eNULL+kRSA)\fR"
 
329
/*      The OpenSSL cipherlist for "NULL" grade ciphers that provide
 
330
/*      authentication without encryption.
 
331
/* .PP
 
332
/*      Available in Postfix version 2.4 and later:
 
333
/* .IP "\fBsmtp_sasl_tls_verified_security_options ($smtp_sasl_tls_security_options)\fR"
 
334
/*      The SASL authentication security options that the Postfix SMTP
 
335
/*      client uses for TLS encrypted SMTP sessions with a verified server
 
336
/*      certificate.
 
337
/* OBSOLETE STARTTLS CONTROLS
 
338
/* .ad
 
339
/* .fi
 
340
/*      The following configuration parameters exist for compatibility
 
341
/*      with Postfix versions before 2.3. Support for these will
 
342
/*      be removed in a future release.
 
343
/* .IP "\fBsmtp_use_tls (no)\fR"
 
344
/*      Opportunistic mode: use TLS when a remote SMTP server announces
 
345
/*      STARTTLS support, otherwise send the mail in the clear.
 
346
/* .IP "\fBsmtp_enforce_tls (no)\fR"
 
347
/*      Enforcement mode: require that remote SMTP servers use TLS
 
348
/*      encryption, and never send mail in the clear.
 
349
/* .IP "\fBsmtp_tls_enforce_peername (yes)\fR"
 
350
/*      With mandatory TLS encryption, require that the remote SMTP
 
351
/*      server hostname matches the information in the remote SMTP server
 
352
/*      certificate.
 
353
/* .IP "\fBsmtp_tls_per_site (empty)\fR"
 
354
/*      Optional lookup tables with the Postfix SMTP client TLS usage
 
355
/*      policy by next-hop destination and by remote SMTP server hostname.
 
356
/* .IP "\fBsmtp_tls_cipherlist (empty)\fR"
 
357
/*      Obsolete Postfix < 2.3 control for the Postfix SMTP client TLS
 
358
/*      cipher list.
224
359
/* RESOURCE AND RATE CONTROLS
225
360
/* .ad
226
361
/* .fi
236
371
/* .IP "\fBsmtp_helo_timeout (300s)\fR"
237
372
/*      The SMTP client time limit for sending the HELO or EHLO command,
238
373
/*      and for receiving the initial server response.
 
374
/* .IP "\fBlmtp_lhlo_timeout (300s)\fR"
 
375
/*      The LMTP client time limit for sending the LHLO command, and
 
376
/*      for receiving the initial server response.
239
377
/* .IP "\fBsmtp_xforward_timeout (300s)\fR"
240
378
/*      The SMTP client time limit for sending the XFORWARD command, and
241
379
/*      for receiving the server response.
258
396
/*      receiving the server response.
259
397
/* .PP
260
398
/*      Available in Postfix version 2.1 and later:
261
 
/* .IP "\fBsmtp_mx_address_limit (0)\fR"
 
399
/* .IP "\fBsmtp_mx_address_limit (5)\fR"
262
400
/*      The maximal number of MX (mail exchanger) IP addresses that can
263
401
/*      result from mail exchanger lookups, or zero (no limit).
264
402
/* .IP "\fBsmtp_mx_session_limit (2)\fR"
269
407
/*      The SMTP client time limit for sending the RSET command, and
270
408
/*      for receiving the server response.
271
409
/* .PP
 
410
/*      Available in Postfix version 2.2 and earlier:
 
411
/* .IP "\fBlmtp_cache_connection (yes)\fR"
 
412
/*      Keep Postfix LMTP client connections open for up to $max_idle
 
413
/*      seconds.
 
414
/* .PP
272
415
/*      Available in Postfix version 2.2 and later:
273
416
/* .IP "\fBsmtp_connection_cache_destinations (empty)\fR"
274
417
/*      Permanently enable SMTP connection caching for the specified
276
419
/* .IP "\fBsmtp_connection_cache_on_demand (yes)\fR"
277
420
/*      Temporarily enable SMTP connection caching while a destination
278
421
/*      has a high volume of mail in the active queue.
279
 
/* .IP "\fBsmtp_connection_cache_reuse_limit (10)\fR"
280
 
/*      When SMTP connection caching is enabled, the number of times that
281
 
/*      an SMTP session is reused before it is closed.
 
422
/* .IP "\fBsmtp_connection_reuse_time_limit (300s)\fR"
 
423
/*      The amount of time during which Postfix will use an SMTP
 
424
/*      connection repeatedly.
282
425
/* .IP "\fBsmtp_connection_cache_time_limit (2s)\fR"
283
426
/*      When SMTP connection caching is enabled, the amount of time that
284
427
/*      an unused SMTP client socket is kept open before it is closed.
 
428
/* .PP
 
429
/*      Available in Postfix version 2.3 and later:
 
430
/* .IP "\fBconnection_cache_protocol_timeout (5s)\fR"
 
431
/*      Time limit for connection cache connect, send or receive
 
432
/*      operations.
285
433
/* TROUBLE SHOOTING CONTROLS
286
434
/* .ad
287
435
/* .fi
296
444
/*      The recipient of postmaster notifications about mail delivery
297
445
/*      problems that are caused by policy, resource, software or protocol
298
446
/*      errors.
 
447
/* .IP "\fBinternal_mail_filter_classes (empty)\fR"
 
448
/*      What categories of Postfix-generated mail are subject to
 
449
/*      before-queue content inspection by non_smtpd_milters, header_checks
 
450
/*      and body_checks.
299
451
/* .IP "\fBnotify_classes (resource, software)\fR"
300
452
/*      The list of error classes that are reported to the postmaster.
301
453
/* MISCELLANEOUS CONTROLS
310
462
/* .IP "\fBdaemon_timeout (18000s)\fR"
311
463
/*      How much time a Postfix daemon process may take to handle a
312
464
/*      request before it is terminated by a built-in watchdog timer.
 
465
/* .IP "\fBdelay_logging_resolution_limit (2)\fR"
 
466
/*      The maximal number of digits after the decimal point when logging
 
467
/*      sub-second delay values.
313
468
/* .IP "\fBdisable_dns_lookups (no)\fR"
314
469
/*      Disable DNS lookups in the Postfix SMTP and LMTP clients.
315
 
/* .IP "\fBfallback_relay (empty)\fR"
316
 
/*      Optional list of relay hosts for SMTP destinations that can't be
317
 
/*      found or that are unreachable.
318
470
/* .IP "\fBinet_interfaces (all)\fR"
319
471
/*      The network interface addresses that this mail system receives
320
472
/*      mail on.
324
476
/* .IP "\fBipc_timeout (3600s)\fR"
325
477
/*      The time limit for sending or receiving information over an internal
326
478
/*      communication channel.
 
479
/* .IP "\fBlmtp_tcp_port (24)\fR"
 
480
/*      The default TCP port that the Postfix LMTP client connects to.
327
481
/* .IP "\fBmax_idle (100s)\fR"
328
482
/*      The maximum amount of time that an idle Postfix daemon process
329
483
/*      waits for the next service request before exiting.
338
492
/*      The network interface addresses that this mail system receives mail
339
493
/*      on by way of a proxy or network address translation unit.
340
494
/* .IP "\fBsmtp_bind_address (empty)\fR"
341
 
/*      An optional numerical network address that the SMTP client should
342
 
/*      bind to when making an IPv4 connection.
 
495
/*      An optional numerical network address that the Postfix SMTP client
 
496
/*      should bind to when making an IPv4 connection.
343
497
/* .IP "\fBsmtp_bind_address6 (empty)\fR"
344
 
/*      An optional numerical network address that the SMTP client should
345
 
/*      bind to when making an IPv6 connection.
 
498
/*      An optional numerical network address that the Postfix SMTP client
 
499
/*      should bind to when making an IPv6 connection.
346
500
/* .IP "\fBsmtp_helo_name ($myhostname)\fR"
347
501
/*      The hostname to send in the SMTP EHLO or HELO command.
 
502
/* .IP "\fBlmtp_lhlo_name ($myhostname)\fR"
 
503
/*      The hostname to send in the LMTP LHLO command.
348
504
/* .IP "\fBsmtp_host_lookup (dns)\fR"
349
 
/*      What mechanisms when the SMTP client uses to look up a host's IP
 
505
/*      What mechanisms when the Postfix SMTP client uses to look up a host's IP
350
506
/*      address.
351
507
/* .IP "\fBsmtp_randomize_addresses (yes)\fR"
352
508
/*      Randomize the order of equal-preference MX host addresses.
355
511
/* .IP "\fBsyslog_name (postfix)\fR"
356
512
/*      The mail system name that is prepended to the process name in syslog
357
513
/*      records, so that "smtpd" becomes, for example, "postfix/smtpd".
 
514
/* .PP
 
515
/*      Available with Postfix 2.2 and earlier:
 
516
/* .IP "\fBfallback_relay (empty)\fR"
 
517
/*      Optional list of relay hosts for SMTP destinations that can't be
 
518
/*      found or that are unreachable.
 
519
/* .PP
 
520
/*      Available with Postfix 2.3 and later:
 
521
/* .IP "\fBsmtp_fallback_relay ($fallback_relay)\fR"
 
522
/*      Optional list of relay hosts for SMTP destinations that can't be
 
523
/*      found or that are unreachable.
358
524
/* SEE ALSO
359
525
/*      qmgr(8), queue manager
360
526
/*      bounce(8), delivery status reports
391
557
/*      Coventry,
392
558
/*      CV1 4LY, United Kingdom.
393
559
/*
 
560
/*      SASL support originally by:
 
561
/*      Till Franke
 
562
/*      SuSE Rhein/Main AG
 
563
/*      65760 Eschborn, Germany
 
564
/*
394
565
/*      Connection caching in cooperation with:
395
566
/*      Victor Duchovni
396
567
/*      Morgan Stanley
411
582
#include <string.h>
412
583
#include <fcntl.h>
413
584
#include <dict.h>
 
585
#include <stringops.h>
414
586
 
415
587
/* Utility library. */
416
588
 
417
589
#include <msg.h>
418
590
#include <mymalloc.h>
419
591
#include <name_mask.h>
 
592
#include <name_code.h>
420
593
 
421
594
/* Global library. */
422
595
 
464
637
int     var_smtp_always_ehlo;
465
638
int     var_smtp_never_ehlo;
466
639
char   *var_smtp_sasl_opts;
 
640
char   *var_smtp_sasl_path;
467
641
char   *var_smtp_sasl_passwd;
468
642
bool    var_smtp_sasl_enable;
469
643
char   *var_smtp_sasl_mechs;
 
644
char   *var_smtp_sasl_type;
470
645
char   *var_smtp_bind_addr;
471
646
char   *var_smtp_bind_addr6;
472
647
bool    var_smtp_rand_addr;
481
656
int     var_smtp_mxaddr_limit;
482
657
int     var_smtp_mxsess_limit;
483
658
int     var_smtp_cache_conn;
484
 
int     var_smtp_reuse_limit;
 
659
int     var_smtp_reuse_time;
485
660
char   *var_smtp_cache_dest;
486
661
char   *var_scache_service;
487
662
bool    var_smtp_cache_demand;
488
663
char   *var_smtp_ehlo_dis_words;
489
664
char   *var_smtp_ehlo_dis_maps;
490
665
 
 
666
char   *var_smtp_tls_level;
491
667
bool    var_smtp_use_tls;
492
668
bool    var_smtp_enforce_tls;
493
669
char   *var_smtp_tls_per_site;
 
670
char   *var_smtp_tls_policy;
 
671
 
494
672
#ifdef USE_TLS
 
673
char   *var_smtp_sasl_tls_opts;
 
674
char   *var_smtp_sasl_tlsv_opts;
495
675
int     var_smtp_starttls_tmout;
496
 
char   *var_smtp_sasl_tls_opts;
 
676
char   *var_smtp_tls_CAfile;
 
677
char   *var_smtp_tls_CApath;
 
678
char   *var_smtp_tls_cert_file;
 
679
char   *var_smtp_tls_mand_ciph;
 
680
char   *var_smtp_tls_excl_ciph;
 
681
char   *var_smtp_tls_mand_excl;
 
682
char   *var_smtp_tls_dcert_file;
 
683
char   *var_smtp_tls_dkey_file;
497
684
bool    var_smtp_tls_enforce_peername;
 
685
char   *var_smtp_tls_key_file;
 
686
int     var_smtp_tls_loglevel;
 
687
bool    var_smtp_tls_note_starttls_offer;
 
688
char   *var_smtp_tls_mand_proto;
 
689
char   *var_smtp_tls_sec_cmatch;
498
690
int     var_smtp_tls_scert_vd;
499
 
bool    var_smtp_tls_note_starttls_offer;
 
691
char   *var_smtp_tls_vfy_cmatch;
 
692
int     var_tls_daemon_rand_bytes;
 
693
 
500
694
#endif
501
695
 
502
696
char   *var_smtp_generic_maps;
503
697
char   *var_prop_extension;
 
698
bool    var_smtp_sender_auth;
 
699
char   *var_lmtp_tcp_port;
 
700
int     var_scache_proto_tmout;
504
701
bool    var_smtp_cname_overr;
505
702
 
506
703
 /*
507
 
  * Global variables. smtp_errno is set by the address lookup routines and by
508
 
  * the connection management routines.
 
704
  * Global variables.
509
705
  */
510
 
int     smtp_errno;
511
706
int     smtp_host_lookup_mask;
512
707
STRING_LIST *smtp_cache_dest;
513
708
SCACHE *smtp_scache;
629
824
        smtp_scache = scache_multi_create();
630
825
#else
631
826
        smtp_scache = scache_clnt_create(var_scache_service,
 
827
                                         var_scache_proto_tmout,
632
828
                                         var_ipc_idle_limit,
633
829
                                         var_ipc_ttl_limit);
634
830
#endif
638
834
 
639
835
static void pre_init(char *unused_name, char **unused_argv)
640
836
{
 
837
    int     use_tls;
641
838
 
642
839
    /*
643
840
     * Turn on per-peer debugging.
655
852
                 VAR_SMTP_SASL_ENABLE);
656
853
#endif
657
854
 
 
855
    if (*var_smtp_tls_level)
 
856
        use_tls = tls_level_lookup(var_smtp_tls_level) > TLS_LEV_NONE;
 
857
    else
 
858
        use_tls = var_smtp_enforce_tls || var_smtp_use_tls;
 
859
 
658
860
    /*
659
861
     * Initialize the TLS data before entering the chroot jail
660
862
     */
661
 
    if (var_smtp_use_tls || var_smtp_enforce_tls || var_smtp_tls_per_site[0]) {
 
863
    if (use_tls || var_smtp_tls_per_site[0] || var_smtp_tls_policy[0]) {
662
864
#ifdef USE_TLS
663
 
        smtp_tls_ctx = tls_client_init(var_smtp_tls_scert_vd);
 
865
        tls_client_init_props props;
 
866
 
 
867
        /*
 
868
         * We get stronger type safety and a cleaner interface by combining
 
869
         * the various parameters into a single tls_client_props structure.
 
870
         */
 
871
        props.log_level = var_smtp_tls_loglevel;
 
872
        props.verifydepth = var_smtp_tls_scert_vd;
 
873
        props.cache_type = strcmp(var_procname, "smtp") == 0 ?
 
874
            TLS_MGR_SCACHE_SMTP : TLS_MGR_SCACHE_LMTP;
 
875
        props.cert_file = var_smtp_tls_cert_file;
 
876
        props.key_file = var_smtp_tls_key_file;
 
877
        props.dcert_file = var_smtp_tls_dcert_file;
 
878
        props.dkey_file = var_smtp_tls_dkey_file;
 
879
        props.CAfile = var_smtp_tls_CAfile;
 
880
        props.CApath = var_smtp_tls_CApath;
 
881
 
 
882
        smtp_tls_ctx = tls_client_init(&props);
664
883
        smtp_tls_list_init();
665
884
#else
666
885
        msg_warn("TLS has been selected, but TLS support is not compiled in");
695
914
    if (*var_smtp_generic_maps)
696
915
        smtp_generic_maps =
697
916
            maps_create(VAR_SMTP_GENERIC_MAPS, var_smtp_generic_maps,
698
 
                        DICT_FLAG_LOCK);
 
917
                        DICT_FLAG_LOCK | DICT_FLAG_FOLD_FIX);
699
918
}
700
919
 
701
920
/* pre_accept - see if tables have changed */
710
929
    }
711
930
}
712
931
 
713
 
/* pre_exit - pre-exit cleanup */
714
 
 
715
 
static void pre_exit(void)
716
 
{
717
 
#ifdef USE_SASL_AUTH
718
 
    if (var_smtp_sasl_enable)
719
 
        sasl_done();
720
 
#endif
721
 
}
722
 
 
723
932
/* main - pass control to the single-threaded skeleton */
724
933
 
725
934
int     main(int argc, char **argv)
726
935
{
727
 
    static CONFIG_STR_TABLE str_table[] = {
728
 
        VAR_NOTIFY_CLASSES, DEF_NOTIFY_CLASSES, &var_notify_classes, 0, 0,
729
 
        VAR_FALLBACK_RELAY, DEF_FALLBACK_RELAY, &var_fallback_relay, 0, 0,
730
 
        VAR_BESTMX_TRANSP, DEF_BESTMX_TRANSP, &var_bestmx_transp, 0, 0,
731
 
        VAR_ERROR_RCPT, DEF_ERROR_RCPT, &var_error_rcpt, 1, 0,
732
 
        VAR_SMTP_SASL_PASSWD, DEF_SMTP_SASL_PASSWD, &var_smtp_sasl_passwd, 0, 0,
733
 
        VAR_SMTP_SASL_OPTS, DEF_SMTP_SASL_OPTS, &var_smtp_sasl_opts, 0, 0,
734
 
#ifdef USE_TLS
735
 
        VAR_SMTP_SASL_TLS_OPTS, DEF_SMTP_SASL_TLS_OPTS, &var_smtp_sasl_tls_opts, 0, 0,
736
 
#endif
737
 
        VAR_SMTP_SASL_MECHS, DEF_SMTP_SASL_MECHS, &var_smtp_sasl_mechs, 0, 0,
738
 
        VAR_SMTP_BIND_ADDR, DEF_SMTP_BIND_ADDR, &var_smtp_bind_addr, 0, 0,
739
 
        VAR_SMTP_BIND_ADDR6, DEF_SMTP_BIND_ADDR6, &var_smtp_bind_addr6, 0, 0,
740
 
        VAR_SMTP_HELO_NAME, DEF_SMTP_HELO_NAME, &var_smtp_helo_name, 1, 0,
741
 
        VAR_SMTP_HOST_LOOKUP, DEF_SMTP_HOST_LOOKUP, &var_smtp_host_lookup, 1, 0,
742
 
        VAR_SMTP_CACHE_DEST, DEF_SMTP_CACHE_DEST, &var_smtp_cache_dest, 0, 0,
743
 
        VAR_SCACHE_SERVICE, DEF_SCACHE_SERVICE, &var_scache_service, 1, 0,
744
 
        VAR_SMTP_EHLO_DIS_WORDS, DEF_SMTP_EHLO_DIS_WORDS, &var_smtp_ehlo_dis_words, 0, 0,
745
 
        VAR_SMTP_EHLO_DIS_MAPS, DEF_SMTP_EHLO_DIS_MAPS, &var_smtp_ehlo_dis_maps, 0, 0,
746
 
        VAR_SMTP_TLS_PER_SITE, DEF_SMTP_TLS_PER_SITE, &var_smtp_tls_per_site, 0, 0,
747
 
        VAR_PROP_EXTENSION, DEF_PROP_EXTENSION, &var_prop_extension, 0, 0,
748
 
        VAR_SMTP_GENERIC_MAPS, DEF_SMTP_GENERIC_MAPS, &var_smtp_generic_maps, 0, 0,
749
 
        0,
750
 
    };
751
 
    static CONFIG_TIME_TABLE time_table[] = {
752
 
        VAR_SMTP_CONN_TMOUT, DEF_SMTP_CONN_TMOUT, &var_smtp_conn_tmout, 0, 0,
753
 
        VAR_SMTP_HELO_TMOUT, DEF_SMTP_HELO_TMOUT, &var_smtp_helo_tmout, 1, 0,
754
 
        VAR_SMTP_XFWD_TMOUT, DEF_SMTP_XFWD_TMOUT, &var_smtp_xfwd_tmout, 1, 0,
755
 
        VAR_SMTP_MAIL_TMOUT, DEF_SMTP_MAIL_TMOUT, &var_smtp_mail_tmout, 1, 0,
756
 
        VAR_SMTP_RCPT_TMOUT, DEF_SMTP_RCPT_TMOUT, &var_smtp_rcpt_tmout, 1, 0,
757
 
        VAR_SMTP_DATA0_TMOUT, DEF_SMTP_DATA0_TMOUT, &var_smtp_data0_tmout, 1, 0,
758
 
        VAR_SMTP_DATA1_TMOUT, DEF_SMTP_DATA1_TMOUT, &var_smtp_data1_tmout, 1, 0,
759
 
        VAR_SMTP_DATA2_TMOUT, DEF_SMTP_DATA2_TMOUT, &var_smtp_data2_tmout, 1, 0,
760
 
        VAR_SMTP_RSET_TMOUT, DEF_SMTP_RSET_TMOUT, &var_smtp_rset_tmout, 1, 0,
761
 
        VAR_SMTP_QUIT_TMOUT, DEF_SMTP_QUIT_TMOUT, &var_smtp_quit_tmout, 1, 0,
762
 
        VAR_SMTP_PIX_THRESH, DEF_SMTP_PIX_THRESH, &var_smtp_pix_thresh, 0, 0,
763
 
        VAR_SMTP_PIX_DELAY, DEF_SMTP_PIX_DELAY, &var_smtp_pix_delay, 1, 0,
764
 
        VAR_SMTP_CACHE_CONN, DEF_SMTP_CACHE_CONN, &var_smtp_cache_conn, 1, 0,
765
 
#ifdef USE_TLS
766
 
        VAR_SMTP_STARTTLS_TMOUT, DEF_SMTP_STARTTLS_TMOUT, &var_smtp_starttls_tmout, 1, 0,
767
 
#endif
768
 
        0,
769
 
    };
770
 
    static CONFIG_INT_TABLE int_table[] = {
771
 
        VAR_SMTP_LINE_LIMIT, DEF_SMTP_LINE_LIMIT, &var_smtp_line_limit, 0, 0,
772
 
        VAR_SMTP_MXADDR_LIMIT, DEF_SMTP_MXADDR_LIMIT, &var_smtp_mxaddr_limit, 0, 0,
773
 
        VAR_SMTP_MXSESS_LIMIT, DEF_SMTP_MXSESS_LIMIT, &var_smtp_mxsess_limit, 0, 0,
774
 
        VAR_SMTP_REUSE_LIMIT, DEF_SMTP_REUSE_LIMIT, &var_smtp_reuse_limit, 1, 0,
775
 
#ifdef USE_TLS
776
 
        VAR_SMTP_TLS_SCERT_VD, DEF_SMTP_TLS_SCERT_VD, &var_smtp_tls_scert_vd, 0, 0,
777
 
#endif
778
 
        0,
779
 
    };
780
 
    static CONFIG_BOOL_TABLE bool_table[] = {
781
 
        VAR_SMTP_SKIP_5XX, DEF_SMTP_SKIP_5XX, &var_smtp_skip_5xx_greeting,
782
 
        VAR_IGN_MX_LOOKUP_ERR, DEF_IGN_MX_LOOKUP_ERR, &var_ign_mx_lookup_err,
783
 
        VAR_SKIP_QUIT_RESP, DEF_SKIP_QUIT_RESP, &var_skip_quit_resp,
784
 
        VAR_SMTP_ALWAYS_EHLO, DEF_SMTP_ALWAYS_EHLO, &var_smtp_always_ehlo,
785
 
        VAR_SMTP_NEVER_EHLO, DEF_SMTP_NEVER_EHLO, &var_smtp_never_ehlo,
786
 
        VAR_SMTP_SASL_ENABLE, DEF_SMTP_SASL_ENABLE, &var_smtp_sasl_enable,
787
 
        VAR_SMTP_RAND_ADDR, DEF_SMTP_RAND_ADDR, &var_smtp_rand_addr,
788
 
        VAR_SMTP_QUOTE_821_ENV, DEF_SMTP_QUOTE_821_ENV, &var_smtp_quote_821_env,
789
 
        VAR_SMTP_DEFER_MXADDR, DEF_SMTP_DEFER_MXADDR, &var_smtp_defer_mxaddr,
790
 
        VAR_SMTP_SEND_XFORWARD, DEF_SMTP_SEND_XFORWARD, &var_smtp_send_xforward,
791
 
        VAR_SMTP_CACHE_DEMAND, DEF_SMTP_CACHE_DEMAND, &var_smtp_cache_demand,
792
 
        VAR_SMTP_USE_TLS, DEF_SMTP_USE_TLS, &var_smtp_use_tls,
793
 
        VAR_SMTP_ENFORCE_TLS, DEF_SMTP_ENFORCE_TLS, &var_smtp_enforce_tls,
794
 
#ifdef USE_TLS
795
 
        VAR_SMTP_TLS_ENFORCE_PN, DEF_SMTP_TLS_ENFORCE_PN, &var_smtp_tls_enforce_peername,
796
 
        VAR_SMTP_TLS_NOTEOFFER, DEF_SMTP_TLS_NOTEOFFER, &var_smtp_tls_note_starttls_offer,
797
 
#endif
798
 
        VAR_SMTP_CNAME_OVERR, DEF_SMTP_CNAME_OVERR, &var_smtp_cname_overr,
799
 
 
800
 
        0,
801
 
    };
802
 
 
 
936
#include "smtp_params.c"
 
937
#include "lmtp_params.c"
 
938
    int     smtp_mode;
 
939
 
 
940
    /*
 
941
     * XXX At this point, var_procname etc. are not initialized.
 
942
     */
 
943
    smtp_mode = (strcmp(sane_basename((VSTRING *) 0, argv[0]), "smtp") == 0);
 
944
 
 
945
    /*
 
946
     * Initialize with the LMTP or SMTP parameter name space.
 
947
     */
803
948
    single_server_main(argc, argv, smtp_service,
804
 
                       MAIL_SERVER_TIME_TABLE, time_table,
805
 
                       MAIL_SERVER_INT_TABLE, int_table,
806
 
                       MAIL_SERVER_STR_TABLE, str_table,
807
 
                       MAIL_SERVER_BOOL_TABLE, bool_table,
 
949
                       MAIL_SERVER_TIME_TABLE, smtp_mode ?
 
950
                       smtp_time_table : lmtp_time_table,
 
951
                       MAIL_SERVER_INT_TABLE, smtp_mode ?
 
952
                       smtp_int_table : lmtp_int_table,
 
953
                       MAIL_SERVER_STR_TABLE, smtp_mode ?
 
954
                       smtp_str_table : lmtp_str_table,
 
955
                       MAIL_SERVER_BOOL_TABLE, smtp_mode ?
 
956
                       smtp_bool_table : lmtp_bool_table,
808
957
                       MAIL_SERVER_PRE_INIT, pre_init,
809
958
                       MAIL_SERVER_POST_INIT, post_init,
810
959
                       MAIL_SERVER_PRE_ACCEPT, pre_accept,
811
 
                       MAIL_SERVER_EXIT, pre_exit,
812
960
                       0);
813
961
}