TLS resumption: support Outlook hosts-behind-loadbalancer
[exim.git] / src / src / transports / smtp.h
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2020 - 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8
9 #define DELIVER_BUFFER_SIZE 4096
10
11 #define PENDING          256
12 #define PENDING_DEFER   (PENDING + DEFER)
13 #define PENDING_OK      (PENDING + OK)
14
15
16 #ifndef DISABLE_TLS
17 /* Flags structure for validity of TLS configuration */
18
19 typedef struct {
20   BOOL conn_certs:1;            /* certificates etc. loaded */
21   BOOL cabundle:1;              /* CA certificates loaded */
22   BOOL crl:1;                   /* CRL loaded */
23   BOOL pri_string:1;            /* cipher priority-string cache loaded */
24   BOOL dh:1;                    /* Diffie-Helman params loaded */
25   BOOL ecdh:1;                  /* EC Diffie-Helman params loaded */
26
27   BOOL ca_rdn_emulate:1;        /* do not advertise usable-cert list */
28   BOOL ocsp_hook:1;             /* need hshake callback on session */
29
30   void * libdata0;              /* library-dependent preloaded data */
31   void * libdata1;              /* library-dependent preloaded data */
32 } exim_tlslib_state;
33 #endif
34
35
36 /* Private structure for the private options and other private data. */
37
38 typedef struct {
39   uschar        *hosts;
40   uschar        *fallback_hosts;
41   host_item     *hostlist;
42   host_item     *fallback_hostlist;
43   uschar        *authenticated_sender;
44   uschar        *helo_data;
45   uschar        *interface;
46   uschar        *port;
47   uschar        *protocol;
48   uschar        *dscp;
49   uschar        *serialize_hosts;
50   uschar        *hosts_try_auth;
51   uschar        *hosts_require_alpn;
52   uschar        *hosts_require_auth;
53   uschar        *hosts_try_chunking;
54 #ifdef SUPPORT_DANE
55   uschar        *hosts_try_dane;
56   uschar        *hosts_require_dane;
57   uschar        *dane_require_tls_ciphers;
58 #endif
59   uschar        *hosts_try_fastopen;
60 #ifndef DISABLE_PRDR
61   uschar        *hosts_try_prdr;
62 #endif
63 #ifndef DISABLE_OCSP
64   uschar        *hosts_request_ocsp;
65   uschar        *hosts_require_ocsp;
66 #endif
67   uschar        *hosts_require_tls;
68   uschar        *hosts_avoid_tls;
69   uschar        *hosts_verify_avoid_tls;
70   uschar        *hosts_avoid_pipelining;
71 #ifndef DISABLE_PIPE_CONNECT
72   uschar        *hosts_pipe_connect;
73 #endif
74   uschar        *hosts_avoid_esmtp;
75 #ifndef DISABLE_TLS
76   uschar        *hosts_nopass_tls;
77   uschar        *hosts_noproxy_tls;
78 #endif
79   int           command_timeout;
80   int           connect_timeout;
81   int           data_timeout;
82   int           final_timeout;
83   int           size_addition;
84   int           hosts_max_try;
85   int           hosts_max_try_hardlimit;
86   int           message_linelength_limit;
87   BOOL          address_retry_include_sender;
88   BOOL          allow_localhost;
89   BOOL          authenticated_sender_force;
90   BOOL          gethostbyname;
91   BOOL          dns_qualify_single;
92   BOOL          dns_search_parents;
93   dnssec_domains dnssec;
94   BOOL          delay_after_cutoff;
95   BOOL          hosts_override;
96   BOOL          hosts_randomize;
97   BOOL          keepalive;
98   BOOL          lmtp_ignore_quota;
99   uschar        *expand_retry_include_ip_address;
100   BOOL          retry_include_ip_address;
101 #ifdef SUPPORT_SOCKS
102   uschar        *socks_proxy;
103 #endif
104 #ifndef DISABLE_TLS
105   uschar        *tls_alpn;
106   uschar        *tls_certificate;
107   uschar        *tls_crl;
108   uschar        *tls_privatekey;
109   uschar        *tls_require_ciphers;
110 # ifndef DISABLE_TLS_RESUME
111   uschar        *host_name_extract;
112   uschar        *tls_resumption_hosts;
113 # endif
114   const uschar  *tls_sni;
115   uschar        *tls_verify_certificates;
116   int           tls_dh_min_bits;
117   BOOL          tls_tempfail_tryclear;
118   uschar        *tls_verify_hosts;
119   uschar        *tls_try_verify_hosts;
120   uschar        *tls_verify_cert_hostnames;
121 #endif
122 #ifdef SUPPORT_I18N
123   uschar        *utf8_downconvert;
124 #endif
125 #ifndef DISABLE_DKIM
126   struct ob_dkim dkim;
127 #endif
128 #ifdef EXPERIMENTAL_ARC
129   uschar        *arc_sign;
130 #endif
131 #ifndef DISABLE_TLS
132   exim_tlslib_state tls_preload;
133 #endif
134 } smtp_transport_options_block;
135
136 #define SOB (smtp_transport_options_block *)
137
138
139 /* smtp connect context */
140 typedef struct {
141   uschar *              from_addr;
142   address_item *        addrlist;
143
144   smtp_connect_args     conn_args;
145   int                   port;
146
147   BOOL verify:1;
148   BOOL lmtp:1;
149   BOOL smtps:1;
150   BOOL ok:1;
151   BOOL setting_up:1;
152 #ifndef DISABLE_PIPE_CONNECT
153   BOOL early_pipe_ok:1;
154   BOOL early_pipe_active:1;
155 #endif
156   BOOL esmtp:1;
157   BOOL esmtp_sent:1;
158   BOOL pipelining_used:1;
159 #ifndef DISABLE_PRDR
160   BOOL prdr_active:1;
161 #endif
162 #ifdef SUPPORT_I18N
163   BOOL utf8_needed:1;
164 #endif
165   BOOL dsn_all_lasthop:1;
166 #if !defined(DISABLE_TLS) && defined(SUPPORT_DANE)
167   BOOL dane_required:1;
168 #endif
169 #ifndef DISABLE_PIPE_CONNECT
170   BOOL pending_BANNER:1;
171   BOOL pending_EHLO:1;
172 #endif
173   BOOL pending_MAIL:1;
174   BOOL pending_BDAT:1;
175   BOOL RCPT_452:1;
176   BOOL good_RCPT:1;
177 #ifdef EXPERIMENTAL_ESMTP_LIMITS
178   BOOL single_rcpt_domain:1;
179 #endif
180   BOOL completed_addr:1;
181   BOOL send_rset:1;
182   BOOL send_quit:1;
183   BOOL send_tlsclose:1;
184
185   unsigned      peer_offered;
186 #ifdef EXPERIMENTAL_ESMTP_LIMITS
187   unsigned      peer_limit_mail;
188   unsigned      peer_limit_rcpt;
189   unsigned      peer_limit_rcptdom;
190 #endif
191
192   unsigned      max_mail;
193   int           max_rcpt;
194   int           cmd_count;
195
196   unsigned      avoid_option;
197   uschar *      igquotstr;
198   uschar *      helo_data;
199 #ifdef EXPERIMENTAL_DSN_INFO
200   uschar *      smtp_greeting;
201   uschar *      helo_response;
202 #endif
203 #ifndef DISABLE_PIPE_CONNECT
204   /* Info about the EHLO response stored to / retrieved from cache.  When
205   operating early-pipe, we use the cached values.  For each of plaintext and
206   crypted we store bitmaps for ESMTP features and AUTH methods.  If the LIMITS
207   extension is built and usable them at least one of the limits values cached
208   is nonzero, and we use the values to constrain the connection. */
209   ehlo_resp_precis      ehlo_resp;
210 #endif
211
212   struct timeval        delivery_start;
213   address_item *        first_addr;
214   address_item *        next_addr;
215   address_item *        sync_addr;
216
217   client_conn_ctx       cctx;
218   smtp_inblock          inblock;
219   smtp_outblock         outblock;
220   uschar        buffer[DELIVER_BUFFER_SIZE];
221   uschar        inbuffer[4096];
222   uschar        outbuffer[4096];
223 } smtp_context;
224
225 extern int smtp_setup_conn(smtp_context *, BOOL);
226 extern int smtp_write_mail_and_rcpt_cmds(smtp_context *, int *);
227 extern int smtp_reap_early_pipe(smtp_context *, int *);
228
229
230 /* Data for reading the private options. */
231
232 extern optionlist smtp_transport_options[];
233 extern int smtp_transport_options_count;
234
235 /* Block containing default values. */
236
237 extern smtp_transport_options_block smtp_transport_option_defaults;
238
239 /* The main, init, and closedown entry points for the transport */
240
241 extern BOOL smtp_transport_entry(transport_instance *, address_item *);
242 extern void smtp_transport_init(transport_instance *);
243 extern void smtp_transport_closedown(transport_instance *);
244
245
246
247 #ifdef SUPPORT_SOCKS
248 extern int     socks_sock_connect(host_item *, int, int, uschar *,
249                  transport_instance *, int);
250 #endif
251
252 /* End of transports/smtp.h */