Use compressed form of ipv6 in $sender_host_address under -bh. Bug 3027
[exim.git] / src / src / structs.h
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2023 */
6 /* Copyright (c) University of Cambridge 1995 - 2018 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
9
10
11 /* Definitions of various structures. In addition, those that are visible for
12 the compilation of local_scan() are defined in local_scan.h. These are
13
14   header_line
15   optionlist
16   recipient_item
17
18 For those declared here, we have to pre-declare some because of mutually
19 recursive definitions in the auths, routers, and transports blocks. */
20
21 struct address_item;
22 struct auth_info;
23 struct driver_info;
24 struct director_info;
25 struct smtp_inblock;
26 struct smtp_outblock;
27 struct transport_info;
28 struct router_info;
29
30 /* Growable-string */
31 typedef struct gstring {
32   int   size;           /* Current capacity of string memory */
33   int   ptr;            /* Offset at which to append further chars */
34   uschar * s;           /* The string memory */
35 } gstring;
36
37 /* Structure for remembering macros for the configuration file */
38
39 typedef struct macro_item {
40   struct  macro_item * next;
41   BOOL          command_line;
42   unsigned      namelen;
43   unsigned      replen;
44   const uschar * name;
45   const uschar * replacement;
46 } macro_item;
47
48 /* Structure for bit tables for debugging and logging */
49
50 typedef struct bit_table {
51   uschar *name;
52   int bit;
53 } bit_table;
54
55 /* Block for holding a uid and gid, possibly unset, and an initgroups flag. */
56
57 typedef struct ugid_block {
58   uid_t   uid;
59   gid_t   gid;
60   BOOL    uid_set;
61   BOOL    gid_set;
62   BOOL    initgroups;
63 } ugid_block;
64
65 typedef enum {  CHUNKING_NOT_OFFERED = -1,
66                 CHUNKING_OFFERED,
67                 CHUNKING_ACTIVE,
68                 CHUNKING_LAST} chunking_state_t;
69
70 typedef enum {  TFO_NOT_USED = 0,
71                 TFO_ATTEMPTED_NODATA,
72                 TFO_ATTEMPTED_DATA,
73                 TFO_USED_NODATA,
74                 TFO_USED_DATA } tfo_state_t;
75
76 /* Structure for holding information about a host for use mainly by routers,
77 but also used when checking lists of hosts and when transporting. Looking up
78 host addresses is done using this structure. */
79
80 typedef enum {DS_UNK=-1, DS_NO, DS_YES} dnssec_status_t;
81
82 typedef struct host_item {
83   struct host_item *next;
84   const uschar *name;           /* Host name */
85 #ifndef DISABLE_TLS
86   const uschar *certname;       /* Name used for certificate checks */
87 #endif
88   const uschar *address;        /* IP address in text form */
89   int     port;                 /* port value in host order (if SRV lookup) */
90   int     mx;                   /* MX value if found via MX records */
91   int     sort_key;             /* MX*1000 plus random "fraction" */
92   int     status;               /* Usable, unusable, or unknown */
93   int     why;                  /* Why host is unusable */
94   int     last_try;             /* Time of last try if known */
95   dnssec_status_t dnssec;
96 } host_item;
97
98 /* Chain of rewrite rules, read from the rewrite config, or parsed from the
99 rewrite_headers field of a transport. */
100
101 typedef struct rewrite_rule {
102   struct rewrite_rule *next;
103   int     flags;
104   uschar *key;
105   uschar *replacement;
106 } rewrite_rule;
107
108 /* This structure is used to pass back configuration data from the smtp
109 transport to the outside world. It is used during callback processing. If ever
110 another remote transport were implemented, it could use the same structure. */
111
112 typedef struct transport_feedback {
113   uschar *interface;
114   uschar *port;
115   uschar *protocol;
116   uschar *hosts;
117   uschar *helo_data;
118   BOOL   hosts_override;
119   BOOL   hosts_randomize;
120   BOOL   gethostbyname;
121   BOOL   qualify_single;
122   BOOL   search_parents;
123 } transport_feedback;
124
125 /* Routers, transports, and authenticators have similar data blocks. Each
126 driver that is compiled into the code is represented by a xxx_info block; the
127 active drivers are represented by a chain of xxx_instance blocks. To make it
128 possible to use the same code for reading the configuration files for all
129 three, the layout of the start of the blocks is kept the same, and represented
130 by the generic structures driver_info and driver_instance. */
131
132 typedef struct driver_instance {
133   struct driver_instance *next;
134   uschar *name;                   /* Instance name */
135   struct driver_info *info;       /* Points to info for this driver */
136   void   *options_block;          /* Pointer to private options */
137
138   uschar *driver_name;            /* All start with this generic option */
139   const uschar *srcfile;          /* and config source info for errors */
140   int     srcline;
141 } driver_instance;
142
143 typedef struct driver_info {
144   uschar *driver_name;            /* Name of driver */
145
146   optionlist *options;            /* Table of private options names */
147   int    *options_count;          /* -> Number of entries in table */
148   void   *options_block;          /* Points to default private block */
149   int     options_len;            /* Length of same in bytes */
150   void  (*init)(                  /* Initialization entry point */
151     struct driver_instance *);
152 } driver_info;
153
154
155 /* Structure for holding information about the configured transports. Some
156 of the generally accessible options are set from the configuration file; others
157 are set by transport initialization, since they can only be set for certain
158 transports. They need to be generally accessible, however, as they are used by
159 the main transport code. */
160
161 typedef struct transport_instance {
162   struct transport_instance *next;
163   uschar *name;                   /* Instance name */
164   struct transport_info *info;    /* Info for this driver */
165   void *options_block;            /* Pointer to private options */
166   uschar *driver_name;            /* Must be first */
167   const uschar *srcfile;
168   int     srcline;
169
170   int   (*setup)(                 /* Setup entry point */
171     struct transport_instance *,
172     struct address_item *,
173     struct transport_feedback *,  /* For passing back config data */
174     uid_t,                        /* The uid that will be used */
175     gid_t,                        /* The gid that will be used */
176     uschar **);                   /* For an error message */
177                                   /**************************************/
178   int     batch_max;              /* )                                  */
179   uschar *batch_id;               /* )                                  */
180   uschar *home_dir;               /* ) Used only for local transports   */
181   uschar *current_dir;            /* )                                  */
182                                   /**************************************/
183   uschar *expand_multi_domain;    /* )                                  */
184   BOOL    multi_domain;           /* )                                  */
185   BOOL    overrides_hosts;        /* ) Used only for remote transports  */
186   uschar *max_addresses;          /* )                                  */
187   int     connection_max_messages;/* )                                  */
188                                   /**************************************/
189   BOOL    deliver_as_creator;     /* Used only by pipe at present */
190   BOOL    disable_logging;        /* For very weird requirements */
191   BOOL    initgroups;             /* Initialize groups when setting uid */
192   BOOL    uid_set;                /* uid is set */
193   BOOL    gid_set;                /* gid is set */
194   uid_t   uid;
195   gid_t   gid;
196   uschar *expand_uid;             /* Variable uid */
197   uschar *expand_gid;             /* Variable gid */
198   uschar *warn_message;           /* Used only by appendfile at present */
199   uschar *shadow;                 /* Name of shadow transport */
200   uschar *shadow_condition;       /* Condition for running it */
201   uschar *filter_command;         /* For on-the-fly-filtering */
202   uschar *add_headers;            /* Add these headers */
203   uschar *remove_headers;         /* Remove these headers */
204   uschar *return_path;            /* Overriding (rewriting) return path */
205   uschar *debug_string;           /* Debugging output */
206   uschar *max_parallel;           /* Number of concurrent instances */
207   uschar *message_size_limit;     /* Biggest message this transport handles */
208   uschar *headers_rewrite;        /* Rules for rewriting headers */
209   rewrite_rule *rewrite_rules;    /* Parsed rewriting rules */
210   int     rewrite_existflags;     /* Bits showing which headers are rewritten */
211   int     filter_timeout;         /* For transport filter timing */
212   BOOL    body_only;              /* Deliver only the body */
213   BOOL    delivery_date_add;      /* Add Delivery-Date header */
214   BOOL    envelope_to_add;        /* Add Envelope-To header */
215   BOOL    headers_only;           /* Deliver only the headers */
216   BOOL    rcpt_include_affixes;   /* TRUE to retain affixes in RCPT commands */
217   BOOL    return_path_add;        /* Add Return-Path header */
218   BOOL    return_output;          /* TRUE if output should always be returned */
219   BOOL    return_fail_output;     /* ditto, but only on failure */
220   BOOL    log_output;             /* Similarly for logging */
221   BOOL    log_fail_output;
222   BOOL    log_defer_output;
223   BOOL    retry_use_local_part;   /* Defaults true for local, false for remote */
224 #ifndef DISABLE_EVENT
225   uschar  *event_action;          /* String to expand on notable events */
226 #endif
227 } transport_instance;
228
229
230 /* Structure for holding information about a type of transport. The first six
231 fields must match driver_info above. */
232
233 typedef struct transport_info {
234   uschar *driver_name;            /* Driver name */
235   optionlist *options;            /* Table of private options names */
236   int    *options_count;          /* -> Number of entries in table */
237   void   *options_block;          /* Points to default private block */
238   int     options_len;            /* Length of same in bytes */
239   void (*init)(                   /* Initialization function */
240     struct transport_instance *);
241 /****/
242   BOOL (*code)(                   /* Main entry point */
243     transport_instance *,
244     struct address_item *);
245   void (*tidyup)(                 /* Tidyup function */
246     struct transport_instance *);
247   void  (*closedown)(             /* For closing down a passed channel */
248     struct transport_instance *);
249   BOOL    local;                  /* TRUE for local transports */
250 } transport_info;
251
252
253 /* smtp transport datachunk callback */
254
255 #define tc_reap_prev    BIT(0)  /* Flags: reap previous SMTP cmd responses */
256 #define tc_chunk_last   BIT(1)  /* annotate chunk SMTP cmd as LAST */
257
258 struct transport_context;
259 typedef int (*tpt_chunk_cmd_cb)(struct transport_context *, unsigned, unsigned);
260
261 /* Structure for information about a delivery-in-progress */
262
263 typedef struct transport_context {
264   union {                       /* discriminated by option topt_output_string */
265     int                   fd;   /* file descriptor to write message to */
266     gstring *             msg;  /* allocated string with written message */
267   } u;
268   transport_instance    * tblock;               /* transport */
269   struct address_item   * addr;
270   uschar                * check_string;         /* string replacement */
271   uschar                * escape_string;
272   int                     options;              /* output processing topt_* */
273
274   /* items below only used with option topt_use_bdat */
275   tpt_chunk_cmd_cb        chunk_cb;             /* per-datachunk callback */
276   void                  * smtp_context;
277 } transport_ctx;
278
279
280
281 typedef struct {
282   uschar *request;
283   uschar *require;
284 } dnssec_domains;
285
286 /* Structure for holding information about the configured routers. */
287
288 typedef struct router_instance {
289   struct router_instance *next;
290   uschar *name;
291   struct router_info *info;
292   void   *options_block;          /* Pointer to private options */
293   uschar *driver_name;            /* Must be first */
294   const uschar *srcfile;
295   int     srcline;
296
297   uschar *address_data;           /* Arbitrary data */
298 #ifdef EXPERIMENTAL_BRIGHTMAIL
299   uschar *bmi_rule;               /* Brightmail AntiSpam rule checking */
300 #endif
301   uschar *cannot_route_message;   /* Used when routing fails */
302   uschar *condition;              /* General condition */
303   uschar *current_directory;      /* For use during delivery */
304   uschar *debug_string;           /* Debugging output */
305   uschar *domains;                /* Specific domains */
306   uschar *errors_to;              /* Errors address */
307   uschar *expand_gid;             /* Expanded gid string */
308   uschar *expand_uid;             /* Expanded uid string */
309   uschar *expand_more;            /* Expanded more string */
310   uschar *expand_unseen;          /* Expanded unseen string */
311   uschar *extra_headers;          /* Additional headers */
312   uschar *fallback_hosts;         /* For remote transports (text list) */
313   uschar *home_directory;         /* For use during delivery */
314   uschar *ignore_target_hosts;    /* Target hosts to ignore */
315   uschar *local_parts;            /* Specific local parts */
316   uschar *pass_router_name;       /* Router for passed address */
317   uschar *prefix;                 /* Address prefix */
318   uschar *redirect_router_name;   /* Router for generated address */
319   uschar *remove_headers;         /* Removed headers */
320   uschar *require_files;          /* File checks before router is run */
321   uschar *router_home_directory;  /* For use while routing */
322   uschar *self;                   /* Text option for handling self reference */
323   uschar *senders;                /* Specific senders */
324   uschar *suffix;                 /* Address suffix */
325   uschar *translate_ip_address;   /* IP address translation fudgery */
326   uschar *transport_name;         /* Transport name */
327
328   BOOL    address_test;           /* Use this router when testing addresses */
329 #ifdef EXPERIMENTAL_BRIGHTMAIL
330   BOOL    bmi_deliver_alternate;  /* TRUE => BMI said that message should be delivered to alternate location */
331   BOOL    bmi_deliver_default;    /* TRUE => BMI said that message should be delivered to default location */
332   BOOL    bmi_dont_deliver;       /* TRUE => BMI said that message should not be delivered at all */
333 #endif
334   BOOL    expn;                   /* Use this router when processing EXPN */
335   BOOL    caseful_local_part;     /* TRUE => don't lowercase */
336   BOOL    check_local_user;       /* TRUE => check local user */
337   BOOL    disable_logging;        /* For very weird requirements */
338   BOOL    fail_verify_recipient;  /* Fail verify if recipient match this router */
339   BOOL    fail_verify_sender;     /* Fail verify if sender match this router */
340   BOOL    gid_set;                /* Flag to indicate gid is set */
341   BOOL    initgroups;             /* TRUE if initgroups is required */
342   BOOL    log_as_local;           /* TRUE logs as a local delivery */
343   BOOL    more;                   /* If FALSE, do no more if this one fails */
344   BOOL    pass_on_timeout;        /* Treat timeout DEFERs as fails */
345   BOOL    prefix_optional;        /* Just what it says */
346   BOOL    repeat_use;             /* If FALSE, skip if ancestor used it */
347   BOOL    retry_use_local_part;   /* Just what it says */
348   BOOL    same_domain_copy_routing; /* TRUE => copy routing for same domain */
349   BOOL    self_rewrite;           /* TRUE to rewrite headers if making local */
350   uschar *set;                    /* Variable = value to set; list */
351   BOOL    suffix_optional;        /* As it says */
352   BOOL    verify_only;            /* Skip this router if not verifying */
353   BOOL    verify_recipient;       /* Use this router when verifying a recipient*/
354   BOOL    verify_sender;          /* Use this router when verifying a sender */
355   BOOL    uid_set;                /* Flag to indicate uid is set */
356   BOOL    unseen;                 /* If TRUE carry on, even after success */
357   BOOL    dsn_lasthop;            /* If TRUE, this router is a DSN endpoint */
358
359   int     self_code;              /* Encoded version of "self" */
360   uid_t   uid;                    /* Fixed uid value */
361   gid_t   gid;                    /* Fixed gid value */
362
363   host_item *fallback_hostlist;   /* For remote transport (block chain) */
364   transport_instance *transport;  /* Transport block (when found) */
365   struct router_instance *pass_router; /* Actual router for passed address */
366   struct router_instance *redirect_router; /* Actual router for generated address */
367
368   dnssec_domains dnssec;
369 } router_instance;
370
371
372 /* Structure for holding information about a type of router. The first six
373 fields must match driver_info above. */
374
375 typedef struct router_info {
376   uschar *driver_name;
377   optionlist *options;            /* Table of private options names */
378   int    *options_count;          /* -> Number of entries in table */
379   void   *options_block;          /* Points to default private block */
380   int     options_len;            /* Length of same in bytes */
381   void (*init)(                   /* Initialization function */
382     struct router_instance *);
383 /****/
384   int (*code)(                    /* Main entry point */
385     router_instance *,
386     struct address_item *,
387     struct passwd *,
388     int,
389     struct address_item **,
390     struct address_item **,
391     struct address_item **,
392     struct address_item **);
393   void (*tidyup)(                 /* Tidyup function */
394     struct router_instance *);
395   int     ri_flags;               /* Descriptive flags */
396 } router_info;
397
398
399 /* Structure for holding information about a lookup type. */
400
401 #include "lookupapi.h"
402
403
404 /* Structure for holding information about the configured authentication
405 mechanisms */
406
407 typedef struct auth_instance {
408   struct auth_instance *next;
409   uschar *name;                   /* Exim instance name */
410   struct auth_info *info;         /* Pointer to driver info block */
411   void   *options_block;          /* Pointer to private options */
412   uschar *driver_name;            /* Must be first */
413   const uschar *srcfile;
414   int     srcline;
415
416   uschar *advertise_condition;    /* Are we going to advertise this?*/
417   uschar *client_condition;       /* Should the client try this? */
418   uschar *public_name;            /* Advertised name */
419   uschar *set_id;                 /* String to set when server as authenticated id */
420   uschar *set_client_id;          /* String to set when client as client_authenticated id */
421   uschar *mail_auth_condition;    /* Condition for AUTH on MAIL command */
422   uschar *server_debug_string;    /* Debugging output */
423   uschar *server_condition;       /* Authorization condition */
424   BOOL    client;                 /* TRUE if client option(s) set */
425   BOOL    server;                 /* TRUE if server options(s) set */
426   BOOL    advertised;             /* Set TRUE when advertised */
427 } auth_instance;
428
429
430 /* Structure for holding information about an authentication mechanism. The
431 first six fields must match driver_info above. */
432
433 typedef struct auth_info {
434   uschar *driver_name;            /* e.g. "condition" */
435   optionlist *options;            /* Table of private options names */
436   int    *options_count;          /* -> Number of entries in table */
437   void   *options_block;          /* Points to default private block */
438   int     options_len;            /* Length of same in bytes */
439   void (*init)(                   /* initialization function */
440     struct auth_instance *);
441 /****/
442   int (*servercode)(              /* server function */
443     auth_instance *,              /* the instance data */
444     uschar *);                    /* rest of AUTH command */
445   int (*clientcode)(              /* client function */
446     struct auth_instance *,
447     void *,                       /* smtp conn, with socket, output and input buffers */
448     int,                          /* command timeout */
449     uschar *,                     /* buffer for reading response */
450     int);                         /* sizeof buffer */
451   gstring * (*version_report)(    /* diagnostic version reporting */
452     gstring *);                   /* string to append to */
453   void (*macros_create)(void);    /* feature-macro creation */
454 } auth_info;
455
456
457 /* Structure for holding a single IP address and port; used for the chain of
458 addresses and ports for the local host. Make the char string large enough to
459 hold an IPv6 address. */
460
461 typedef struct ip_address_item {
462   struct ip_address_item *next;
463   int    port;
464   BOOL   v6_include_v4;            /* Used in the daemon */
465   uschar address[46];
466   uschar * log;                    /* portion of "listening on" log line */
467 } ip_address_item;
468
469 /* Structure for chaining together arbitrary strings. */
470
471 typedef struct string_item {
472   struct string_item *  next;
473   uschar *              text;
474 } string_item;
475
476 /* Information about a soft delivery failure, for use when calculating
477 retry information. It's separate from the address block, because there
478 can be a chain of them for SMTP deliveries where multiple IP addresses
479 can be tried. */
480
481 typedef struct retry_item {
482   struct retry_item *next;        /* for chaining */
483   const uschar *key;              /* string identifying host/address/message */
484   int     basic_errno;            /* error code for this destination */
485   int     more_errno;             /* additional error information */
486   uschar *message;                /* local error message */
487   int     flags;                  /* see below */
488 } retry_item;
489
490 /* Retry data flags */
491
492 #define rf_delete   0x0001        /* retry info is to be deleted */
493 #define rf_host     0x0002        /* retry info is for a remote host */
494 #define rf_message  0x0004        /* retry info is for a host+message */
495
496 /* Information about a constructed message that is to be sent using the
497 autoreply transport. This is pointed to from the address block. */
498
499 typedef struct reply_item {
500   uschar *from;                   /* ) */
501   uschar *reply_to;               /* ) */
502   uschar *to;                     /* ) */
503   uschar *cc;                     /* ) specific header fields */
504   uschar *bcc;                    /* ) */
505   uschar *subject;                /* ) */
506   uschar *headers;                /* misc other headers, concatenated */
507   uschar *text;                   /* text string body */
508   uschar *file;                   /* file body */
509   BOOL    file_expand;            /* expand the body */
510   int     expand_forbid;          /* expansion lockout flags */
511   uschar *logfile;                /* file to keep a log in */
512   uschar *oncelog;                /* file to keep records in for once only */
513   time_t  once_repeat;            /* time to repeat "once only" */
514   BOOL    return_message;         /* send back the original message */
515 } reply_item;
516
517
518 /* The address_item structure contains many fields which are used at various
519 times while delivering a message. Some are used only for remote deliveries;
520 some only for local. A particular set of fields is copied whenever a child
521 address is created. For convenience, we keep those fields in a separate
522 sub-structure so they can be copied in one go. This also means I won't forget
523 to edit the various copying places when new to-be-copied fields are added. */
524
525 typedef struct address_item_propagated {
526   uschar *address_data;           /* arbitrary data to keep with the address */
527   uschar *domain_data;            /* from "domains" lookup */
528   uschar *localpart_data;         /* from "local_parts" lookup */
529   const uschar *errors_address;         /* where to send errors (NULL => sender) */
530   header_line *extra_headers;     /* additional headers */
531   uschar *remove_headers;         /* list of those to remove */
532   void   *variables;              /* router-vasriables */
533
534   BOOL    ignore_error:1;         /* ignore delivery error */
535 #ifdef SUPPORT_I18N
536   BOOL    utf8_msg:1;             /* requires SMTPUTF8 processing */
537   BOOL    utf8_downcvt:1;         /* mandatory downconvert on delivery */
538   BOOL    utf8_downcvt_maybe:1;   /* optional downconvert on delivery */
539 #endif
540 } address_item_propagated;
541
542
543 /* The main address structure. Note that fields that are to be copied to
544 generated addresses should be put in the address_item_propagated structure (see
545 above) rather than directly into the address_item structure. */
546
547 typedef struct address_item {
548   struct address_item *next;      /* for chaining addresses */
549   struct address_item *parent;    /* parent address */
550   struct address_item *first;     /* points to first after group delivery */
551   struct address_item *dupof;     /* points to address this is a duplicate of */
552
553   router_instance *start_router;  /* generated address starts here */
554   router_instance *router;        /* the router that routed */
555   transport_instance *transport;  /* the transport to use */
556
557   host_item *host_list;           /* host data for the transport */
558   host_item *host_used;           /* host that took delivery or failed hard */
559   host_item *fallback_hosts;      /* to try if delivery defers */
560
561   reply_item *reply;              /* data for autoreply */
562   retry_item *retries;            /* chain of retry information */
563
564   const uschar *address;                /* address being delivered or routed */
565   uschar *unique;                 /* used for disambiguating */
566   const uschar *cc_local_part;    /* caseful local part */
567   const uschar *lc_local_part;    /* lowercased local part */
568   const uschar *local_part;       /* points to cc or lc version */
569   const uschar *prefix;           /* stripped prefix of local part */
570   const uschar *prefix_v;         /*  variable part of above */
571   const uschar *suffix;           /* stripped suffix of local part */
572   const uschar *suffix_v;         /*  variable part of above */
573   const uschar *domain;           /* working domain (lower cased) */
574
575   uschar *address_retry_key;      /* retry key including full address */
576   uschar *domain_retry_key;       /* retry key for domain only */
577
578   uschar *current_dir;            /* current directory for transporting */
579   uschar *home_dir;               /* home directory for transporting */
580   uschar *message;                /* error message */
581   uschar *user_message;           /* error message that can be sent over SMTP
582                                      or quoted in bounce message */
583   const uschar *onetime_parent;         /* saved original parent for onetime */
584   uschar **pipe_expandn;          /* numeric expansions for pipe from filter */
585   uschar *return_filename;        /* name of return file */
586   uschar *self_hostname;          /* after self=pass */
587   uschar *shadow_message;         /* info about shadow transporting */
588
589   uid_t   uid;                    /* uid for transporting */
590   gid_t   gid;                    /* gid for transporting */
591
592 #ifndef DISABLE_TLS
593   const uschar *tlsver;           /* version used for transport */
594   uschar *cipher;                 /* Cipher used for transport */
595   void   *ourcert;                /* Certificate offered to peer, binary */
596   void   *peercert;               /* Certificate from peer, binary */
597   uschar *peerdn;                 /* DN of server's certificate */
598   int    ocsp;                    /* OCSP status of peer cert */
599 #endif
600
601 #ifdef EXPERIMENTAL_DSN_INFO
602   const uschar *smtp_greeting;    /* peer self-identification */
603   const uschar *helo_response;    /* peer message */
604 #endif
605
606   uschar *authenticator;          /* auth driver name used by transport */
607   uschar *auth_id;                /* auth "login" name used by transport */
608   uschar *auth_sndr;              /* AUTH arg to SMTP MAIL, used by transport */
609
610   uschar *dsn_orcpt;              /* DSN orcpt value */
611   int     dsn_flags;              /* DSN flags */
612   int     dsn_aware;              /* DSN aware flag */
613
614 #ifndef DISABLE_DKIM
615   const uschar * dkim_used;       /* DKIM info, or NULL */
616 #endif
617                                   /* flags */
618   struct {
619     BOOL af_allow_file:1;               /* allow file in generated address */
620     BOOL af_allow_pipe:1;               /* allow pipe in generated address */
621     BOOL af_allow_reply:1;              /* allow autoreply in generated address */
622     BOOL af_dr_retry_exists:1;          /* router retry record exists */
623     BOOL af_expand_pipe:1;              /* expand pipe arguments */
624     BOOL af_file:1;                     /* file delivery; always with pfr */
625     BOOL af_gid_set:1;                  /* gid field is set */
626     BOOL af_home_expanded:1;            /* home_dir is already expanded */
627     BOOL af_initgroups:1;               /* use initgroups() for local transporting */
628     BOOL af_local_host_removed:1;       /* local host was backup */
629     BOOL af_lt_retry_exists:1;          /* local transport retry exists */
630     BOOL af_pfr:1;                      /* pipe or file or reply delivery */
631     BOOL af_retry_skipped:1;            /* true if retry caused some skipping */
632     BOOL af_retry_timedout:1;           /* true if retry timed out */
633     BOOL af_uid_set:1;                  /* uid field is set */
634     BOOL af_hide_child:1;               /* hide child in bounce/defer msgs */
635     BOOL af_sverify_told:1;             /* sender verify failure notified */
636     BOOL af_verify_pmfail:1;            /* verify failure was postmaster callout */
637     BOOL af_verify_nsfail:1;            /* verify failure was null sender callout */
638     BOOL af_homonym:1;                  /* an ancestor has same address */
639     BOOL af_verify_routed:1;            /* for cached sender verify: routed OK */
640     BOOL af_verify_callout:1;           /* for cached sender verify: callout was specified */
641     BOOL af_include_affixes:1;          /* delivered with affixes in RCPT */
642     BOOL af_new_conn:1;                 /* delivered on an fresh TCP conn */
643     BOOL af_cont_conn:1;                /* delivered (with new MAIL cmd) on an existing TCP conn */
644     BOOL af_cert_verified:1;            /* delivered with verified TLS cert */
645     BOOL af_pass_message:1;             /* pass message in bounces */
646     BOOL af_bad_reply:1;                /* filter could not generate autoreply */
647     BOOL af_tcp_fastopen_conn:1;        /* delivery connection used TCP Fast Open */
648     BOOL af_tcp_fastopen:1;             /* delivery usefully used TCP Fast Open */
649     BOOL af_tcp_fastopen_data:1;        /* delivery sent SMTP commands on TCP Fast Open */
650     BOOL af_pipelining:1;               /* delivery used (traditional) pipelining */
651 #ifndef DISABLE_PIPE_CONNECT
652     BOOL af_early_pipe:1;               /* delivery used connect-time pipelining */
653 #endif
654 #ifndef DISABLE_PRDR
655     BOOL af_prdr_used:1;                /* delivery used SMTP PRDR */
656 #endif
657     BOOL af_chunking_used:1;            /* delivery used SMTP CHUNKING */
658     BOOL af_force_command:1;            /* force_command in pipe transport */
659 #ifdef SUPPORT_DANE
660     BOOL af_dane_verified:1;            /* TLS cert verify done with DANE */
661 #endif
662 #ifdef SUPPORT_I18N
663     BOOL af_utf8_downcvt:1;             /* downconvert was done for delivery */
664 #endif
665 #ifndef DISABLE_TLS_RESUME
666     BOOL af_tls_resume:1;               /* TLS used a resumed session */
667 #endif
668   } flags;
669
670   unsigned int domain_cache[(MAX_NAMED_LIST * 2)/32];
671   unsigned int localpart_cache[(MAX_NAMED_LIST * 2)/32];
672   int     mode;                   /* mode for local transporting to a file */
673   int     basic_errno;            /* status after failure */
674   int     more_errno;             /* additional error information */
675   struct timeval delivery_time;   /* time taken to do delivery/attempt */
676
677   unsigned short child_count;     /* number of child addresses */
678   short int return_file;          /* fileno of return data file */
679   short int special_action;       /* ( used when when deferred or failed */
680                                   /* (  also  */
681                                   /* ( contains = or - when successful SMTP delivered */
682                                   /* (  also  */
683                                   /* ( contains verify rc in sender verify cache */
684   short int transport_return;     /* result of delivery attempt */
685   address_item_propagated prop;   /* fields that are propagated to children */
686 } address_item;
687
688 /* The table of header names consists of items of this type */
689
690 typedef struct {
691   uschar *name;
692   int     len;
693   BOOL    allow_resent;
694   int     htype;
695 } header_name;
696
697 /* Chain of information about errors (e.g. bad addresses) */
698
699 typedef struct error_block {
700   struct error_block *next;
701   const uschar *text1;
702   uschar *text2;
703 } error_block;
704
705 /* Chain of file names when processing the queue */
706
707 typedef struct queue_filename {
708   struct queue_filename *next;
709   uschar dir_uschar;
710   uschar text[1];
711 } queue_filename;
712
713 /* Chain of items of retry information, read from the retry config. */
714
715 typedef struct retry_rule {
716   struct retry_rule *next;
717   int    rule;
718   int    timeout;
719   int    p1;
720   int    p2;
721 } retry_rule;
722
723 typedef struct retry_config {
724   struct retry_config *next;
725   uschar *pattern;
726   int     basic_errno;
727   int     more_errno;
728   uschar *senders;
729   retry_rule *rules;
730 } retry_config;
731
732 /* Structure for each node in a tree, of which there are various kinds */
733
734 typedef struct tree_node {
735   struct tree_node *left;         /* pointer to left child */
736   struct tree_node *right;        /* pointer to right child */
737   union
738     {
739     void  *ptr;                   /* pointer to data */
740     int val;                      /* or integer data */
741     } data;
742   uschar  balance;                /* balancing factor */
743   uschar  name[1];                /* node name - variable length */
744 } tree_node;
745
746 /* Structure for holding time-limited data such as DNS returns.
747 We use this rather than extending tree_node to avoid wasting
748 space for most tree use (variables...) at the cost of complexity
749 for the lookups cache.
750 We also store any options used for the lookup. */
751
752 typedef struct expiring_data {
753   time_t        expiry;         /* if nonzero, data invalid after this time */
754   const uschar * opts;          /* options, or NULL */
755   union
756     {
757     void  *     ptr;            /* pointer to data */
758     int         val;            /* or integer data */
759     } data;
760 } expiring_data;
761
762 /* Structure for holding the handle and the cached last lookup for searches.
763 This block is pointed to by the tree entry for the file. The file can get
764 closed if too many are opened at once. There is a LRU chain for deciding which
765 to close. */
766
767 typedef struct search_cache {
768   void   *handle;                 /* lookup handle, or NULL if closed */
769   int search_type;                /* search type */
770   tree_node *up;                  /* LRU up pointer */
771   tree_node *down;                /* LRU down pointer */
772   tree_node *item_cache;          /* tree of cached results */
773 } search_cache;
774
775 /* Structure for holding a partially decoded DNS record; the name has been
776 uncompressed, but the data pointer is into the raw data. */
777
778 typedef struct {
779   uschar        name[DNS_MAXNAME];      /* domain name */
780   int           type;                   /* record type */
781   unsigned short ttl;                   /* time-to-live, seconds */
782   int           size;                   /* size of data */
783   const uschar *data;                   /* pointer to data */
784 } dns_record;
785
786 /* Structure for holding the result of a DNS query.  A touch over
787 64k big, so take care to release as soon as possible. */
788
789 typedef struct {
790   int     answerlen;              /* length of the answer */
791   uschar  answer[NS_MAXMSG];      /* the answer itself */
792 } dns_answer;
793
794 /* Structure for holding the intermediate data while scanning a DNS answer
795 block. */
796
797 typedef struct {
798   int            rrcount;         /* count of RRs in the answer */
799   const uschar *aptr;             /* pointer in the answer while scanning */
800   dns_record     srr;             /* data from current record in scan */
801 } dns_scan;
802
803 /* Structure for holding a chain of IP addresses that are extracted from
804 an A, AAAA, or A6 record. For the first two, there is only ever one address,
805 but the chaining feature of A6 allows for several addresses to be realized from
806 a single initial A6 record. The structure defines the address field of length
807 1. In use, a suitable sized block is obtained to hold the complete textual
808 address. */
809
810 typedef struct dns_address {
811   struct dns_address *next;
812   uschar  address[1];
813 } dns_address;
814
815 /* Structure used for holding intermediate data during MD5 computations. */
816
817 typedef struct md5 {
818   unsigned int length;
819   unsigned int abcd[4];
820   }
821 md5;
822
823 /* Structure used for holding intermediate data during SHA-1 computations. */
824
825 typedef struct sha1 {
826   unsigned int H[5];
827   unsigned int length;
828 } sha1;
829
830 /* Information for making an smtp connection */
831 typedef struct {
832   transport_instance *  tblock;
833   void *                ob;     /* smtp_transport_options_block * */
834   host_item *           host;
835   int                   host_af;
836   uschar *              interface;
837
838   int                   sock;   /* used for a bound but not connected socket */
839   uschar *              sending_ip_address;     /* used for TLS resumption */
840   const uschar *        host_lbserver;          /* ditto, for server-behind LB */
841   BOOL                  have_lbserver:1;        /* host_lbserver is valid */
842
843 #ifdef SUPPORT_DANE
844   BOOL dane:1;                  /* connection must do dane */
845   dns_answer            tlsa_dnsa;      /* strictly, this should use tainted mem */
846 #endif
847 } smtp_connect_args;
848
849 /* A client-initiated connection. If TLS, the second element is non-NULL */
850 typedef struct {
851   int   sock;
852   void * tls_ctx;
853 } client_conn_ctx;
854
855
856 /* Structure used to hold incoming packets of SMTP responses for a specific
857 socket. The packets which may contain multiple lines (and in some cases,
858 multiple responses). */
859
860 typedef struct smtp_inblock {
861   client_conn_ctx * cctx;         /* the connection */
862   int     buffersize;             /* the size of the buffer */
863   uschar *ptr;                    /* current position in the buffer */
864   uschar *ptrend;                 /* end of data in the buffer */
865   uschar *buffer;                 /* the buffer itself */
866 } smtp_inblock;
867
868 /* Structure used to hold buffered outgoing packets of SMTP commands for a
869 specific socket. The packets which may contain multiple lines when pipelining
870 is in use. */
871
872 typedef struct smtp_outblock {
873   client_conn_ctx * cctx;         /* the connection */
874   int     cmd_count;              /* count of buffered commands */
875   int     buffersize;             /* the size of the buffer */
876   BOOL    authenticating;         /* TRUE when authenticating */
877   uschar *ptr;                    /* current position in the buffer */
878   uschar *buffer;                 /* the buffer itself */
879
880   smtp_connect_args * conn_args;  /* to make connection, if not yet made */
881 } smtp_outblock;
882
883 /* Structure to hold information about the source of redirection information */
884
885 typedef struct redirect_block {
886   uschar *string;                 /* file name or string */
887   uid_t  *owners;                 /* allowed file owners */
888   gid_t  *owngroups;              /* allowed file groups */
889   struct passwd *pw;              /* possible owner if not NULL */
890   int     modemask;               /* forbidden bits */
891   BOOL    isfile;                 /* TRUE if string is a file name */
892   BOOL    check_owner;            /* TRUE, FALSE, or TRUE_UNSET */
893   BOOL    check_group;            /* TRUE, FALSE, or TRUE_UNSET */
894 } redirect_block;
895
896 /* Structure for passing arguments to check_host() */
897
898 typedef struct check_host_block {
899   const uschar *host_name;
900   const uschar *host_address;
901   const uschar *host_ipv4;
902   mcs_flags     flags;
903 } check_host_block;
904
905 /* Structure for remembering lookup data when caching the result of
906 a lookup in a named list. */
907
908 typedef struct namedlist_cacheblock {
909   struct namedlist_cacheblock *next;
910   uschar *key;
911   uschar *data;
912 } namedlist_cacheblock;
913
914 /* Structure for holding data for an entry in a named list */
915
916 typedef struct namedlist_block {
917   const uschar *string;                 /* the list string */
918   namedlist_cacheblock *cache_data;     /* cached domain_data or localpart_data */
919   short         number;                 /* the number of the list for caching */
920   BOOL          hide;                   /* -bP does not display value */
921 } namedlist_block;
922
923 /* Structures for Access Control Lists */
924
925 typedef struct acl_condition_block {
926   struct acl_condition_block *  next;
927   uschar *                      arg;
928   int                           type;
929   union {
930     BOOL        negated;
931     uschar *    varname;
932   } u;
933 } acl_condition_block;
934
935 typedef struct acl_block {
936   struct acl_block *    next;
937   acl_condition_block * condition;
938   int                   verb;
939   int                   srcline;
940   const uschar *        srcfile;
941 } acl_block;
942
943 /* smtp transport calc outbound_ip */
944 typedef BOOL (*oicf) (uschar *message_id, void *data);
945
946 /* DKIM information for transport */
947 struct ob_dkim {
948   uschar *dkim_domain;
949   uschar *dkim_identity;
950   uschar *dkim_private_key;
951   uschar *dkim_selector;
952   uschar *dkim_canon;
953   uschar *dkim_sign_headers;
954   uschar *dkim_strict;
955   uschar *dkim_hash;
956   uschar *dkim_timestamps;
957   BOOL    dot_stuffed;
958   BOOL    force_bodyhash;
959 #ifdef EXPERIMENTAL_ARC
960   uschar *arc_signspec;
961 #endif
962 };
963
964
965 /* per-queue-runner info */
966 typedef struct qrunner {
967   struct qrunner * next;        /* list sorted by next tick */
968
969   uschar *      name;           /* NULL for the default queue */
970   unsigned      interval;       /* tick rate, seconds. Zero for a one-time run */
971   time_t        next_tick;      /* next run should, or should have, start(ed) */
972   unsigned      run_max;        /* concurrent queue runner limit */
973   unsigned      run_count;      /* current runners */
974
975   BOOL queue_run_force :1;
976   BOOL deliver_force_thaw :1;
977   BOOL queue_run_first_delivery :1;
978   BOOL queue_run_local :1;
979   BOOL queue_2stage :1;
980 } qrunner;
981
982 /* End of structs.h */