xref: /netbsd-src/external/ibm-public/postfix/dist/src/smtp/smtp.h (revision b8ecfcfef0e343ad71faea7a54fb5fcb42ad4e27)
1 /*	$NetBSD: smtp.h,v 1.1.1.4 2014/07/06 19:27:55 tron Exp $	*/
2 
3 /*++
4 /* NAME
5 /*	smtp 3h
6 /* SUMMARY
7 /*	smtp client program
8 /* SYNOPSIS
9 /*	#include "smtp.h"
10 /* DESCRIPTION
11 /* .nf
12 
13  /*
14   * System library.
15   */
16 #include <string.h>
17 
18  /*
19   * Utility library.
20   */
21 #include <vstream.h>
22 #include <vstring.h>
23 #include <argv.h>
24 #include <htable.h>
25 #include <dict.h>
26 
27  /*
28   * Global library.
29   */
30 #include <deliver_request.h>
31 #include <scache.h>
32 #include <string_list.h>
33 #include <maps.h>
34 #include <tok822.h>
35 #include <dsn_buf.h>
36 #include <header_body_checks.h>
37 
38  /*
39   * Postfix TLS library.
40   */
41 #include <tls.h>
42 
43  /*
44   * Global iterator support. This is updated by the connection-management
45   * loop, and contains dynamic context that appears in lookup keys for SASL
46   * passwords, TLS policy, cached SMTP connections, and cached TLS session
47   * keys.
48   *
49   * For consistency and maintainability, context that is used in more than one
50   * lookup key is formatted with smtp_key_format().
51   */
52 typedef struct SMTP_ITERATOR {
53     /* Public members. */
54     VSTRING *request_nexthop;		/* request nexhop or empty */
55     VSTRING *dest;			/* current nexthop */
56     VSTRING *host;			/* hostname or empty */
57     VSTRING *addr;			/* printable address or empty */
58     unsigned port;			/* network byte order or null */
59     struct DNS_RR *rr;			/* DNS resource record or null */
60     struct DNS_RR *mx;			/* DNS resource record or null */
61     /* Private members. */
62     VSTRING *saved_dest;		/* saved current nexthop */
63     struct SMTP_STATE *parent;		/* parent linkage */
64 } SMTP_ITERATOR;
65 
66 #define SMTP_ITER_INIT(iter, _dest, _host, _addr, _port, state) do { \
67 	vstring_strcpy((iter)->dest, (_dest)); \
68 	vstring_strcpy((iter)->host, (_host)); \
69 	vstring_strcpy((iter)->addr, (_addr)); \
70 	(iter)->port = (_port); \
71 	(iter)->mx = (iter)->rr = 0; \
72 	vstring_strcpy((iter)->saved_dest, ""); \
73 	(iter)->parent = (state); \
74     } while (0)
75 
76 #define SMTP_ITER_CLOBBER(iter, _dest, _host, _addr) do { \
77 	vstring_strcpy((iter)->dest, (_dest)); \
78 	vstring_strcpy((iter)->host, (_host)); \
79 	vstring_strcpy((iter)->addr, (_addr)); \
80     } while (0)
81 
82 #define SMTP_ITER_SAVE_DEST(iter) do { \
83 	vstring_strcpy((iter)->saved_dest, STR((iter)->dest)); \
84     } while (0)
85 
86 #define SMTP_ITER_RESTORE_DEST(iter) do { \
87 	vstring_strcpy((iter)->dest, STR((iter)->saved_dest)); \
88     } while (0)
89 
90  /*
91   * TLS Policy support.
92   */
93 #ifdef USE_TLS
94 
95 typedef struct SMTP_TLS_POLICY {
96     int     level;			/* TLS enforcement level */
97     char   *protocols;			/* Acceptable SSL protocols */
98     char   *grade;			/* Cipher grade: "export", ... */
99     VSTRING *exclusions;		/* Excluded SSL ciphers */
100     ARGV   *matchargv;			/* Cert match patterns */
101     DSN_BUF *why;			/* Lookup error status */
102     TLS_DANE *dane;			/* DANE TLSA digests */
103 } SMTP_TLS_POLICY;
104 
105  /*
106   * smtp_tls_policy.c
107   */
108 extern void smtp_tls_list_init(void);
109 extern int smtp_tls_policy_cache_query(DSN_BUF *, SMTP_TLS_POLICY *, SMTP_ITERATOR *);
110 extern void smtp_tls_policy_cache_flush(void);
111 
112  /*
113   * Macros must use distinct names for local temporary variables, otherwise
114   * there will be bugs due to shadowing. This happened when an earlier
115   * version of smtp_tls_policy_dummy() invoked smtp_tls_policy_init(), but it
116   * could also happen without macro nesting.
117   *
118   * General principle: use all or part of the macro name in each temporary
119   * variable name. Then, append suffixes to the names if needed.
120   */
121 #define smtp_tls_policy_dummy(t) do { \
122 	SMTP_TLS_POLICY *_tls_policy_dummy_tmp = (t); \
123 	smtp_tls_policy_init(_tls_policy_dummy_tmp, (DSN_BUF *) 0); \
124 	_tls_policy_dummy_tmp->level = TLS_LEV_NONE; \
125     } while (0)
126 
127  /* This macro is not part of the module external interface. */
128 #define smtp_tls_policy_init(t, w) do { \
129 	SMTP_TLS_POLICY *_tls_policy_init_tmp = (t); \
130 	_tls_policy_init_tmp->protocols = 0; \
131 	_tls_policy_init_tmp->grade = 0; \
132 	_tls_policy_init_tmp->exclusions = 0; \
133 	_tls_policy_init_tmp->matchargv = 0; \
134 	_tls_policy_init_tmp->why = (w); \
135 	_tls_policy_init_tmp->dane = 0; \
136     } while (0)
137 
138 #endif
139 
140  /*
141   * State information associated with each SMTP delivery request.
142   * Session-specific state is stored separately.
143   */
144 typedef struct SMTP_STATE {
145     int     misc_flags;			/* processing flags, see below */
146     VSTREAM *src;			/* queue file stream */
147     const char *service;		/* transport name */
148     DELIVER_REQUEST *request;		/* envelope info, offsets */
149     struct SMTP_SESSION *session;	/* network connection */
150     int     status;			/* delivery status */
151     ssize_t space_left;			/* output length control */
152 
153     /*
154      * Global iterator.
155      */
156     SMTP_ITERATOR iterator[1];		/* Usage: state->iterator->member */
157 
158     /*
159      * Global iterator.
160      */
161 #ifdef USE_TLS
162     SMTP_TLS_POLICY tls[1];		/* Usage: state->tls->member */
163 #endif
164 
165     /*
166      * Connection cache support.
167      */
168     HTABLE *cache_used;			/* cached addresses that were used */
169     VSTRING *dest_label;		/* cached logical/physical binding */
170     VSTRING *dest_prop;			/* binding properties, passivated */
171     VSTRING *endp_label;		/* cached session physical endpoint */
172     VSTRING *endp_prop;			/* endpoint properties, passivated */
173 
174     /*
175      * Flags and counters to control the handling of mail delivery errors.
176      * There is some redundancy for sanity checking. At the end of an SMTP
177      * session all recipients should be marked one way or the other.
178      */
179     int     rcpt_left;			/* recipients left over */
180     int     rcpt_drop;			/* recipients marked as drop */
181     int     rcpt_keep;			/* recipients marked as keep */
182 
183     /*
184      * DSN Support introduced major bloat in error processing.
185      */
186     DSN_BUF *why;			/* on-the-fly formatting buffer */
187 } SMTP_STATE;
188 
189  /*
190   * TODO: use the new SMTP_ITER name space.
191   */
192 #define SET_NEXTHOP_STATE(state, nexthop) { \
193 	vstring_strcpy((state)->iterator->request_nexthop, nexthop); \
194     }
195 
196 #define FREE_NEXTHOP_STATE(state) { \
197 	STR((state)->iterator->request_nexthop)[0] = 0; \
198     }
199 
200 #define HAVE_NEXTHOP_STATE(state) (STR((state)->iterator->request_nexthop)[0] != 0)
201 
202 
203  /*
204   * Server features.
205   */
206 #define SMTP_FEATURE_ESMTP		(1<<0)
207 #define SMTP_FEATURE_8BITMIME		(1<<1)
208 #define SMTP_FEATURE_PIPELINING		(1<<2)
209 #define SMTP_FEATURE_SIZE		(1<<3)
210 #define SMTP_FEATURE_STARTTLS		(1<<4)
211 #define SMTP_FEATURE_AUTH		(1<<5)
212 #define SMTP_FEATURE_XFORWARD_NAME	(1<<7)
213 #define SMTP_FEATURE_XFORWARD_ADDR	(1<<8)
214 #define SMTP_FEATURE_XFORWARD_PROTO	(1<<9)
215 #define SMTP_FEATURE_XFORWARD_HELO	(1<<10)
216 #define SMTP_FEATURE_XFORWARD_DOMAIN	(1<<11)
217 #define SMTP_FEATURE_BEST_MX		(1<<12)	/* for next-hop or fall-back */
218 #define SMTP_FEATURE_RSET_REJECTED	(1<<13)	/* RSET probe rejected */
219 #define SMTP_FEATURE_FROM_CACHE		(1<<14)	/* cached connection */
220 #define SMTP_FEATURE_DSN		(1<<15)	/* DSN supported */
221 #define SMTP_FEATURE_PIX_NO_ESMTP	(1<<16)	/* PIX smtp fixup mode */
222 #define SMTP_FEATURE_PIX_DELAY_DOTCRLF	(1<<17)	/* PIX smtp fixup mode */
223 #define SMTP_FEATURE_XFORWARD_PORT	(1<<18)
224 #define SMTP_FEATURE_EARLY_TLS_MAIL_REPLY (1<<19)	/* CVE-2009-3555 */
225 #define SMTP_FEATURE_XFORWARD_IDENT	(1<<20)
226 
227  /*
228   * Features that passivate under the endpoint.
229   */
230 #define SMTP_FEATURE_ENDPOINT_MASK \
231 	(~(SMTP_FEATURE_BEST_MX | SMTP_FEATURE_RSET_REJECTED \
232 	| SMTP_FEATURE_FROM_CACHE))
233 
234  /*
235   * Features that passivate under the logical destination.
236   */
237 #define SMTP_FEATURE_DESTINATION_MASK (SMTP_FEATURE_BEST_MX)
238 
239  /*
240   * Misc flags.
241   */
242 #define SMTP_MISC_FLAG_LOOP_DETECT	(1<<0)
243 #define	SMTP_MISC_FLAG_IN_STARTTLS	(1<<1)
244 #define SMTP_MISC_FLAG_FIRST_NEXTHOP	(1<<2)
245 #define SMTP_MISC_FLAG_FINAL_NEXTHOP	(1<<3)
246 #define SMTP_MISC_FLAG_FINAL_SERVER	(1<<4)
247 #define SMTP_MISC_FLAG_CONN_LOAD	(1<<5)
248 #define SMTP_MISC_FLAG_CONN_STORE	(1<<6)
249 #define SMTP_MISC_FLAG_COMPLETE_SESSION	(1<<7)
250 #define SMTP_MISC_FLAG_PREF_IPV6	(1<<8)
251 #define SMTP_MISC_FLAG_PREF_IPV4	(1<<9)
252 
253 #define SMTP_MISC_FLAG_CONN_CACHE_MASK \
254 	(SMTP_MISC_FLAG_CONN_LOAD | SMTP_MISC_FLAG_CONN_STORE)
255 
256  /*
257   * smtp.c
258   */
259 #define SMTP_HAS_DSN(why)	(STR((why)->status)[0] != 0)
260 #define SMTP_HAS_SOFT_DSN(why)	(STR((why)->status)[0] == '4')
261 #define SMTP_HAS_HARD_DSN(why)	(STR((why)->status)[0] == '5')
262 #define SMTP_HAS_LOOP_DSN(why) \
263     (SMTP_HAS_DSN(why) && strcmp(STR((why)->status) + 1, ".4.6") == 0)
264 
265 #define SMTP_SET_SOFT_DSN(why)	(STR((why)->status)[0] = '4')
266 #define SMTP_SET_HARD_DSN(why)	(STR((why)->status)[0] = '5')
267 
268 extern int smtp_host_lookup_mask;	/* host lookup methods to use */
269 
270 #define SMTP_HOST_FLAG_DNS	(1<<0)
271 #define SMTP_HOST_FLAG_NATIVE	(1<<1)
272 
273 extern int smtp_dns_support;		/* dns support level */
274 
275 #define SMTP_DNS_INVALID	(-1)	/* smtp_dns_support_level = <bogus> */
276 #define SMTP_DNS_DISABLED	0	/* smtp_dns_support_level = disabled */
277 #define SMTP_DNS_ENABLED	1	/* smtp_dns_support_level = enabled */
278 #define SMTP_DNS_DNSSEC		2	/* smtp_dns_support_level = dnssec */
279 
280 extern SCACHE *smtp_scache;		/* connection cache instance */
281 extern STRING_LIST *smtp_cache_dest;	/* cached destinations */
282 
283 extern MAPS *smtp_ehlo_dis_maps;	/* ehlo keyword filter */
284 
285 extern MAPS *smtp_pix_bug_maps;		/* PIX workarounds */
286 
287 extern MAPS *smtp_generic_maps;		/* make internal address valid */
288 extern int smtp_ext_prop_mask;		/* address externsion propagation */
289 extern unsigned smtp_dns_res_opt;	/* DNS query flags */
290 
291 #ifdef USE_TLS
292 
293 extern TLS_APPL_STATE *smtp_tls_ctx;	/* client-side TLS engine */
294 
295 #endif
296 
297 extern HBC_CHECKS *smtp_header_checks;	/* limited header checks */
298 extern HBC_CHECKS *smtp_body_checks;	/* limited body checks */
299 
300  /*
301   * smtp_session.c
302   */
303 
304 typedef struct SMTP_SESSION {
305     VSTREAM *stream;			/* network connection */
306     SMTP_ITERATOR *iterator;		/* dest, host, addr, port */
307     char   *namaddr;			/* mail exchanger */
308     char   *helo;			/* helo response */
309     unsigned port;			/* network byte order */
310     char   *namaddrport;		/* mail exchanger, incl. port */
311 
312     VSTRING *buffer;			/* I/O buffer */
313     VSTRING *scratch;			/* scratch buffer */
314     VSTRING *scratch2;			/* scratch buffer */
315 
316     int     features;			/* server features */
317     off_t   size_limit;			/* server limit or unknown */
318 
319     ARGV   *history;			/* transaction log */
320     int     error_mask;			/* error classes */
321     struct MIME_STATE *mime_state;	/* mime state machine */
322 
323     int     send_proto_helo;		/* XFORWARD support */
324 
325     time_t  expire_time;		/* session reuse expiration time */
326     int     reuse_count;		/* # of times reused (for logging) */
327     int     dead;			/* No further I/O allowed */
328 
329 #ifdef USE_SASL_AUTH
330     char   *sasl_mechanism_list;	/* server mechanism list */
331     char   *sasl_username;		/* client username */
332     char   *sasl_passwd;		/* client password */
333     struct XSASL_CLIENT *sasl_client;	/* SASL internal state */
334     VSTRING *sasl_reply;		/* client response */
335 #endif
336 
337     /*
338      * TLS related state, don't forget to initialize in session_tls_init()!
339      */
340 #ifdef USE_TLS
341     TLS_SESS_STATE *tls_context;	/* TLS library session state */
342     char   *tls_nexthop;		/* Nexthop domain for cert checks */
343     int     tls_retry_plain;		/* Try plain when TLS handshake fails */
344     SMTP_TLS_POLICY *tls;		/* TEMPORARY */
345 #endif
346 
347     SMTP_STATE *state;			/* back link */
348 } SMTP_SESSION;
349 
350 extern SMTP_SESSION *smtp_session_alloc(VSTREAM *, SMTP_ITERATOR *, time_t, int);
351 extern void smtp_session_new_stream(SMTP_SESSION *, VSTREAM *, time_t, int);
352 extern int smtp_sess_plaintext_ok(SMTP_ITERATOR *, int);
353 extern void smtp_session_free(SMTP_SESSION *);
354 extern int smtp_session_passivate(SMTP_SESSION *, VSTRING *, VSTRING *);
355 extern SMTP_SESSION *smtp_session_activate(int, SMTP_ITERATOR *, VSTRING *, VSTRING *);
356 
357  /*
358   * What's in a name?
359   */
360 #define SMTP_HNAME(rr) (var_smtp_cname_overr ? (rr)->rname : (rr)->qname)
361 
362  /*
363   * smtp_connect.c
364   */
365 extern int smtp_connect(SMTP_STATE *);
366 
367  /*
368   * smtp_proto.c
369   */
370 extern int smtp_helo(SMTP_STATE *);
371 extern int smtp_xfer(SMTP_STATE *);
372 extern int smtp_rset(SMTP_STATE *);
373 extern int smtp_quit(SMTP_STATE *);
374 
375 extern HBC_CALL_BACKS smtp_hbc_callbacks[];
376 
377  /*
378   * A connection is re-usable if session->expire_time is > 0 and the
379   * expiration time has not been reached.  This is subtle because the timer
380   * can expire between sending a command and receiving the reply for that
381   * command.
382   *
383   * But wait, there is more! When SMTP command pipelining is enabled, there are
384   * two protocol loops that execute at very different times: one loop that
385   * generates commands, and one loop that receives replies to those commands.
386   * These will be called "sender loop" and "receiver loop", respectively. At
387   * well-defined protocol synchronization points, the sender loop pauses to
388   * let the receiver loop catch up.
389   *
390   * When we choose to reuse a connection, both the sender and receiver protocol
391   * loops end with "." (mail delivery) or "RSET" (address probe). When we
392   * choose not to reuse, both the sender and receiver protocol loops end with
393   * "QUIT". The problem is that we must make the same protocol choices in
394   * both the sender and receiver loops, even though those loops may execute
395   * at completely different times.
396   *
397   * We "freeze" the choice in the sender loop, just before we generate "." or
398   * "RSET". The reader loop leaves the connection cachable even if the timer
399   * expires by the time the response arrives. The connection cleanup code
400   * will call smtp_quit() for connections with an expired cache expiration
401   * timer.
402   *
403   * We could have made the programmer's life a lot simpler by not making a
404   * choice at all, and always leaving it up to the connection cleanup code to
405   * call smtp_quit() for connections with an expired cache expiration timer.
406   *
407   * As a general principle, neither the sender loop nor the receiver loop must
408   * modify the connection caching state, if that can affect the receiver
409   * state machine for not-yet processed replies to already-generated
410   * commands. This restriction does not apply when we have to exit the
411   * protocol loops prematurely due to e.g., timeout or connection loss, so
412   * that those pending replies will never be received.
413   *
414   * But wait, there is even more! Only the first good connection for a specific
415   * destination may be cached under both the next-hop destination name and
416   * the server address; connections to alternate servers must be cached under
417   * the server address alone. This means we must distinguish between bad
418   * connections and other reasons why connections cannot be cached.
419   */
420 #define THIS_SESSION_IS_CACHED \
421 	(!THIS_SESSION_IS_DEAD && session->expire_time > 0)
422 
423 #define THIS_SESSION_IS_EXPIRED \
424 	(THIS_SESSION_IS_CACHED \
425 	    && (session->expire_time < vstream_ftime(session->stream) \
426 		|| (var_smtp_reuse_count > 0 \
427 		    && session->reuse_count >= var_smtp_reuse_count)))
428 
429 #define THIS_SESSION_IS_BAD \
430 	(!THIS_SESSION_IS_DEAD && session->expire_time < 0)
431 
432 #define THIS_SESSION_IS_DEAD \
433 	(session->dead != 0)
434 
435  /* Bring the bad news. */
436 
437 #define DONT_CACHE_THIS_SESSION \
438 	(session->expire_time = 0)
439 
440 #define DONT_CACHE_BAD_SESSION \
441 	(session->expire_time = -1)
442 
443 #define DONT_USE_DEAD_SESSION \
444 	(session->dead = 1)
445 
446  /* Initialization. */
447 
448 #define USE_NEWBORN_SESSION \
449 	(session->dead = 0)
450 
451 #define CACHE_THIS_SESSION_UNTIL(when) \
452 	(session->expire_time = (when))
453 
454  /*
455   * Encapsulate the following so that we don't expose details of of
456   * connection management and error handling to the SMTP protocol engine.
457   */
458 #define RETRY_AS_PLAINTEXT do { \
459 	session->tls_retry_plain = 1; \
460 	state->misc_flags &= ~SMTP_MISC_FLAG_FINAL_SERVER; \
461     } while (0)
462 
463  /*
464   * smtp_chat.c
465   */
466 typedef struct SMTP_RESP {		/* server response */
467     int     code;			/* SMTP code */
468     const char *dsn;			/* enhanced status */
469     char   *str;			/* full reply */
470     VSTRING *dsn_buf;			/* status buffer */
471     VSTRING *str_buf;			/* reply buffer */
472 } SMTP_RESP;
473 
474 extern void PRINTFLIKE(2, 3) smtp_chat_cmd(SMTP_SESSION *, const char *,...);
475 extern DICT *smtp_chat_resp_filter;
476 extern SMTP_RESP *smtp_chat_resp(SMTP_SESSION *);
477 extern void smtp_chat_init(SMTP_SESSION *);
478 extern void smtp_chat_reset(SMTP_SESSION *);
479 extern void smtp_chat_notify(SMTP_SESSION *);
480 
481 #define SMTP_RESP_FAKE(resp, _dsn) \
482     ((resp)->code = 0, \
483      (resp)->dsn = (_dsn), \
484      (resp)->str = DSN_BY_LOCAL_MTA, \
485      (resp))
486 
487 #define DSN_BY_LOCAL_MTA	((char *) 0)	/* DSN issued by local MTA */
488 
489  /*
490   * These operations implement a redundant mark-and-sweep algorithm that
491   * explicitly accounts for the fate of every recipient. The interface is
492   * documented in smtp_rcpt.c, which also implements the sweeping. The
493   * smtp_trouble.c module does most of the marking after failure.
494   *
495   * When a delivery fails or succeeds, take one of the following actions:
496   *
497   * - Mark the recipient as KEEP (deliver to alternate MTA) and do not update
498   * the delivery request status.
499   *
500   * - Mark the recipient as DROP (remove from delivery request), log whether
501   * delivery succeeded or failed, delete the recipient from the queue file
502   * and/or update defer or bounce logfiles, and update the delivery request
503   * status.
504   *
505   * At the end of a delivery attempt, all recipients must be marked one way or
506   * the other. Failure to do so will trigger a panic.
507   */
508 #define SMTP_RCPT_STATE_KEEP	1	/* send to backup host */
509 #define SMTP_RCPT_STATE_DROP	2	/* remove from request */
510 #define SMTP_RCPT_INIT(state) do { \
511 	    (state)->rcpt_drop = (state)->rcpt_keep = 0; \
512 	    (state)->rcpt_left = state->request->rcpt_list.len; \
513 	} while (0)
514 
515 #define SMTP_RCPT_DROP(state, rcpt) do { \
516 	    (rcpt)->u.status = SMTP_RCPT_STATE_DROP; (state)->rcpt_drop++; \
517 	} while (0)
518 
519 #define SMTP_RCPT_KEEP(state, rcpt) do { \
520 	    (rcpt)->u.status = SMTP_RCPT_STATE_KEEP; (state)->rcpt_keep++; \
521 	} while (0)
522 
523 #define SMTP_RCPT_ISMARKED(rcpt) ((rcpt)->u.status != 0)
524 
525 #define SMTP_RCPT_LEFT(state) (state)->rcpt_left
526 
527 extern void smtp_rcpt_cleanup(SMTP_STATE *);
528 extern void smtp_rcpt_done(SMTP_STATE *, SMTP_RESP *, RECIPIENT *);
529 
530  /*
531   * smtp_trouble.c
532   */
533 extern int smtp_sess_fail(SMTP_STATE *);
534 extern int PRINTFLIKE(4, 5) smtp_site_fail(SMTP_STATE *, const char *,
535 				             SMTP_RESP *, const char *,...);
536 extern int PRINTFLIKE(4, 5) smtp_mesg_fail(SMTP_STATE *, const char *,
537 				             SMTP_RESP *, const char *,...);
538 extern void PRINTFLIKE(5, 6) smtp_rcpt_fail(SMTP_STATE *, RECIPIENT *,
539 					          const char *, SMTP_RESP *,
540 					            const char *,...);
541 extern int smtp_stream_except(SMTP_STATE *, int, const char *);
542 
543  /*
544   * smtp_unalias.c
545   */
546 extern const char *smtp_unalias_name(const char *);
547 extern VSTRING *smtp_unalias_addr(VSTRING *, const char *);
548 
549  /*
550   * smtp_state.c
551   */
552 extern SMTP_STATE *smtp_state_alloc(void);
553 extern void smtp_state_free(SMTP_STATE *);
554 
555  /*
556   * smtp_map11.c
557   */
558 extern int smtp_map11_external(VSTRING *, MAPS *, int);
559 extern int smtp_map11_tree(TOK822 *, MAPS *, int);
560 extern int smtp_map11_internal(VSTRING *, MAPS *, int);
561 
562  /*
563   * smtp_key.c
564   */
565 char   *smtp_key_prefix(VSTRING *, const char *, SMTP_ITERATOR *, int);
566 
567 #define SMTP_KEY_FLAG_SERVICE		(1<<0)	/* service name */
568 #define SMTP_KEY_FLAG_SENDER		(1<<1)	/* sender address */
569 #define SMTP_KEY_FLAG_REQ_NEXTHOP	(1<<2)	/* request nexthop */
570 #define SMTP_KEY_FLAG_NEXTHOP		(1<<3)	/* current nexthop */
571 #define SMTP_KEY_FLAG_HOSTNAME		(1<<4)	/* remote host name */
572 #define SMTP_KEY_FLAG_ADDR		(1<<5)	/* remote address */
573 #define SMTP_KEY_FLAG_PORT		(1<<6)	/* remote port */
574 
575 #define SMTP_KEY_MASK_ALL \
576 	(SMTP_KEY_FLAG_SERVICE | SMTP_KEY_FLAG_SENDER | \
577 	SMTP_KEY_FLAG_REQ_NEXTHOP | \
578 	SMTP_KEY_FLAG_NEXTHOP | SMTP_KEY_FLAG_HOSTNAME | \
579 	SMTP_KEY_FLAG_ADDR | SMTP_KEY_FLAG_PORT)
580 
581  /*
582   * Conditional lookup-key flags for cached connections that may be
583   * SASL-authenticated with a per-{sender, nexthop, or hostname} credential.
584   * Each bit corresponds to one type of smtp_sasl_password_file lookup key,
585   * and is turned on only when the corresponding main.cf parameter is turned
586   * on.
587   */
588 #define COND_SASL_SMTP_KEY_FLAG_SENDER \
589 	((var_smtp_sender_auth && *var_smtp_sasl_passwd) ? \
590 	    SMTP_KEY_FLAG_SENDER : 0)
591 
592 #define COND_SASL_SMTP_KEY_FLAG_NEXTHOP \
593 	(*var_smtp_sasl_passwd ? SMTP_KEY_FLAG_NEXTHOP : 0)
594 
595 #define COND_SASL_SMTP_KEY_FLAG_HOSTNAME \
596 	(*var_smtp_sasl_passwd ? SMTP_KEY_FLAG_HOSTNAME : 0)
597 
598  /*
599   * Connection-cache destination lookup key. The SENDER attribute is a proxy
600   * for sender-dependent SASL credentials (or absence thereof), and prevents
601   * false connection sharing when different SASL credentials may be required
602   * for different deliveries to the same domain and port. The SERVICE
603   * attribute is a proxy for all request-independent configuration details.
604   */
605 #define SMTP_KEY_MASK_SCACHE_DEST_LABEL \
606 	(SMTP_KEY_FLAG_SERVICE | COND_SASL_SMTP_KEY_FLAG_SENDER \
607 	| SMTP_KEY_FLAG_REQ_NEXTHOP)
608 
609  /*
610   * Connection-cache endpoint lookup key. The SENDER, NEXTHOP, and HOSTNAME
611   * attributes are proxies for SASL credentials (or absence thereof), and
612   * prevent false connection sharing when different SASL credentials may be
613   * required for different deliveries to the same IP address and port.
614   */
615 #define SMTP_KEY_MASK_SCACHE_ENDP_LABEL \
616 	(SMTP_KEY_FLAG_SERVICE | COND_SASL_SMTP_KEY_FLAG_SENDER \
617 	| COND_SASL_SMTP_KEY_FLAG_NEXTHOP | COND_SASL_SMTP_KEY_FLAG_HOSTNAME \
618 	| SMTP_KEY_FLAG_ADDR | SMTP_KEY_FLAG_PORT)
619 
620  /*
621   * Silly little macros.
622   */
623 #define STR(s) vstring_str(s)
624 #define LEN(s) VSTRING_LEN(s)
625 
626 extern int smtp_mode;
627 
628 #define SMTP_X(x) (smtp_mode ? VAR_SMTP_##x : VAR_LMTP_##x)
629 #define X_SMTP(x) (smtp_mode ? x##_SMTP : x##_LMTP)
630 
631 /* LICENSE
632 /* .ad
633 /* .fi
634 /*	The Secure Mailer license must be distributed with this software.
635 /* AUTHOR(S)
636 /*	Wietse Venema
637 /*	IBM T.J. Watson Research
638 /*	P.O. Box 704
639 /*	Yorktown Heights, NY 10598, USA
640 /*
641 /*	TLS support originally by:
642 /*	Lutz Jaenicke
643 /*	BTU Cottbus
644 /*	Allgemeine Elektrotechnik
645 /*	Universitaetsplatz 3-4
646 /*	D-03044 Cottbus, Germany
647 /*
648 /*	Victor Duchovni
649 /*	Morgan Stanley
650 /*--*/
651