SPDX: license tags (mostly by guesswork)
[exim.git] / src / src / routers / accept.c
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 /* SPDX-License-Identifier: GPL-2.0-only */
9
10
11 #include "../exim.h"
12 #include "rf_functions.h"
13 #include "accept.h"
14
15
16 /* Options specific to the accept router. Because some compilers do not like
17 empty declarations ("undefined" in the Standard) we put in a dummy value. */
18
19 optionlist accept_router_options[] = {
20   { "", opt_hidden, {NULL} }
21 };
22
23 /* Size of the options list. An extern variable has to be used so that its
24 address can appear in the tables drtables.c. */
25
26 int accept_router_options_count =
27   sizeof(accept_router_options)/sizeof(optionlist);
28
29 /* Default private options block for the accept router. Again, a dummy
30 value is used. */
31
32 accept_router_options_block accept_router_option_defaults = {
33   NULL        /* dummy */
34 };
35
36
37 #ifdef MACRO_PREDEF
38
39 /* Dummy entries */
40 void accept_router_init(router_instance *rblock) {}
41 int accept_router_entry(router_instance *rblock, address_item *addr,
42   struct passwd *pw, int verify, address_item **addr_local,
43   address_item **addr_remote, address_item **addr_new,
44   address_item **addr_succeed) {return 0;}
45
46 #else   /*!MACRO_PREDEF*/
47
48
49
50 /*************************************************
51 *          Initialization entry point            *
52 *************************************************/
53
54 /* Called for each instance, after its options have been read, to enable
55 consistency checks to be done, or anything else that needs to be set up. */
56
57 void accept_router_init(router_instance *rblock)
58 {
59 /*
60 accept_router_options_block *ob =
61   (accept_router_options_block *)(rblock->options_block);
62 */
63
64 /* By default, log deliveries via this router as local deliveries. We can't
65 just leave it as TRUE_UNSET, because the global default is FALSE. */
66
67 if (rblock->log_as_local == TRUE_UNSET) rblock->log_as_local = TRUE;
68 }
69
70
71
72 /*************************************************
73 *              Main entry point                  *
74 *************************************************/
75
76 /* See local README for interface description. This router returns:
77
78 DEFER
79   . verifying the errors address caused a deferment or a big disaster such
80       as an expansion failure (rf_get_errors_address)
81   . expanding a headers_{add,remove} string caused a deferment or another
82       expansion error (rf_get_munge_headers)
83   . a problem in rf_get_transport: no transport when one is needed;
84     failed to expand dynamic transport; failed to find dynamic transport
85   . failure to expand or find a uid/gid (rf_get_ugid via rf_queue_add)
86
87 OK
88   added address to addr_local or addr_remote, as appropriate for the
89   type of transport
90 */
91
92 int accept_router_entry(
93   router_instance *rblock,        /* data for this instantiation */
94   address_item *addr,             /* address we are working on */
95   struct passwd *pw,              /* passwd entry after check_local_user */
96   int verify,                     /* v_none/v_recipient/v_sender/v_expn */
97   address_item **addr_local,      /* add it to this if it's local */
98   address_item **addr_remote,     /* add it to this if it's remote */
99   address_item **addr_new,        /* put new addresses on here */
100   address_item **addr_succeed)    /* put old address here on success */
101 {
102 /*
103 accept_router_options_block *ob =
104   (accept_router_options_block *)(rblock->options_block);
105 */
106 int rc;
107 uschar *errors_to;
108 uschar *remove_headers;
109 header_line *extra_headers;
110
111 DEBUG(D_route) debug_printf("%s router called for %s\n  domain = %s\n",
112   rblock->name, addr->address, addr->domain);
113
114 /* Set up the errors address, if any. */
115
116 rc = rf_get_errors_address(addr, rblock, verify, &errors_to);
117 if (rc != OK) return rc;
118
119 /* Set up the additional and removable headers for the address. */
120
121 rc = rf_get_munge_headers(addr, rblock, &extra_headers, &remove_headers);
122 if (rc != OK) return rc;
123
124 /* Set the transport and accept the address; update its errors address and
125 header munging. Initialization ensures that there is a transport except when
126 verifying. */
127
128 if (!rf_get_transport(rblock->transport_name, &(rblock->transport),
129   addr, rblock->name, NULL)) return DEFER;
130
131 addr->transport = rblock->transport;
132 addr->prop.errors_address = errors_to;
133 addr->prop.extra_headers = extra_headers;
134 addr->prop.remove_headers = remove_headers;
135
136 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)? OK : DEFER;
137 }
138
139 #endif  /*!MACRO_PREDEF*/
140 /* End of routers/accept.c */