(1) Typo in redirect router; (2) Update version number; (3) Update
[exim.git] / src / src / routers / ipliteral.c
1 /* $Cambridge: exim/src/src/routers/ipliteral.c,v 1.3 2005/01/04 10:00:44 ph10 Exp $ */
2
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
6
7 /* Copyright (c) University of Cambridge 1995 - 2005 */
8 /* See the file NOTICE for conditions of use and distribution. */
9
10
11 #include "../exim.h"
12 #include "rf_functions.h"
13 #include "ipliteral.h"
14
15
16 /* Options specific to the ipliteral router. Because some compilers do not like
17 empty declarations ("undefined" in the Standard) we put in a dummy value. */
18
19 optionlist ipliteral_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 ipliteral_router_options_count =
27 sizeof(ipliteral_router_options)/sizeof(optionlist);
28
29 /* Default private options block for the ipliteral router. Again, a dummy
30 value is present to keep some compilers happy. */
31
32 ipliteral_router_options_block ipliteral_router_option_defaults = { 0 };
33
34
35
36 /*************************************************
37 * Initialization entry point *
38 *************************************************/
39
40 /* Called for each instance, after its options have been read, to enable
41 consistency checks to be done, or anything else that needs to be set up. */
42
43 void
44 ipliteral_router_init(router_instance *rblock)
45 {
46 /*
47 ipliteral_router_options_block *ob =
48 (ipliteral_router_options_block *)(rblock->options_block);
49 */
50 rblock = rblock;
51 }
52
53
54
55 /*************************************************
56 * Main entry point *
57 *************************************************/
58
59 /* See local README for interface details. This router returns:
60
61 DECLINE
62 . the domain is not in the form of an IP literal
63
64 DEFER
65 . verifying the errors address caused a deferment or a big disaster such
66 as an expansion failure (rf_get_errors_address)
67 . expanding a headers_{add,remove} string caused a deferment or another
68 expansion error (rf_get_munge_headers)
69 . a problem in rf_get_transport: no transport when one is needed;
70 failed to expand dynamic transport; failed to find dynamic transport
71 . failure to expand or find a uid/gid (rf_get_ugid via rf_queue_add)
72 . self = "freeze", self = "defer"
73
74 PASS
75 . self = "pass"
76
77 REROUTED
78 . self = "reroute"
79
80 FAIL
81 . self = "fail"
82
83 OK
84 added address to addr_local or addr_remote, as appropriate for the
85 type of transport; this includes the self="send" case.
86 */
87
88 int
89 ipliteral_router_entry(
90 router_instance *rblock, /* data for this instantiation */
91 address_item *addr, /* address we are working on */
92 struct passwd *pw, /* passwd entry after check_local_user */
93 BOOL verify, /* TRUE when verifying */
94 address_item **addr_local, /* add it to this if it's local */
95 address_item **addr_remote, /* add it to this if it's remote */
96 address_item **addr_new, /* put new addresses on here */
97 address_item **addr_succeed) /* put old address here on success */
98 {
99 /*
100 ipliteral_router_options_block *ob =
101 (ipliteral_router_options_block *)(rblock->options_block);
102 */
103 host_item *h;
104 uschar *domain = addr->domain;
105 int len = Ustrlen(domain);
106 int rc;
107
108 addr_new = addr_new; /* Keep picky compilers happy */
109 addr_succeed = addr_succeed;
110
111 DEBUG(D_route) debug_printf("%s router called for %s: domain = %s\n",
112 rblock->name, addr->address, addr->domain);
113
114 /* Check that the domain is an IP address enclosed in square brackets. If
115 not, the router declines. Otherwise route to the single IP address, setting the
116 host name to "(unnamed)". */
117
118 if (domain[0] != '[' || domain[len-1] != ']') return DECLINE;
119 domain[len-1] = 0; /* temporarily */
120
121 if (!string_is_ip_address(domain+1, NULL))
122 {
123 domain[len-1] = ']';
124 return DECLINE;
125 }
126
127 /* It seems unlikely that ignore_target_hosts will be used with this router,
128 but if it is set, it should probably work. */
129
130 if (verify_check_this_host(&(rblock->ignore_target_hosts), NULL, domain,
131 domain + 1, NULL) == OK)
132 {
133 DEBUG(D_route)
134 debug_printf("%s is in ignore_target_hosts\n", domain+1);
135 addr->message = US"IP literal host explicitly ignored";
136 domain[len-1] = ']';
137 return DECLINE;
138 }
139
140 /* Set up a host item */
141
142 h = store_get(sizeof(host_item));
143
144 h->next = NULL;
145 h->address = string_copy(domain+1);
146 h->port = PORT_NONE;
147 domain[len-1] = ']'; /* restore */
148 h->name = string_copy(domain);
149 h->mx = MX_NONE;
150 h->status = hstatus_unknown;
151 h->why = hwhy_unknown;
152 h->last_try = 0;
153
154 /* Determine whether the host is the local host, and if so, take action
155 according to the configuration. */
156
157 if (host_scan_for_local_hosts(h, &h, NULL) == HOST_FOUND_LOCAL)
158 {
159 int rc = rf_self_action(addr, h, rblock->self_code, rblock->self_rewrite,
160 rblock->self, addr_new);
161 if (rc != OK) return rc;
162 }
163
164 /* Address is routed to this host */
165
166 addr->host_list = h;
167
168 /* Set up the errors address, if any. */
169
170 rc = rf_get_errors_address(addr, rblock, verify, &(addr->p.errors_address));
171 if (rc != OK) return rc;
172
173 /* Set up the additional and removeable headers for this address. */
174
175 rc = rf_get_munge_headers(addr, rblock, &(addr->p.extra_headers),
176 &(addr->p.remove_headers));
177 if (rc != OK) return rc;
178
179 /* Fill in the transport, queue the address for local or remote delivery, and
180 yield success. For local delivery, of course, the IP address won't be used. If
181 just verifying, there need not be a transport, in which case it doesn't matter
182 which queue we put the address on. This is all now handled by the route_queue()
183 function. */
184
185 if (!rf_get_transport(rblock->transport_name, &(rblock->transport),
186 addr, rblock->name, NULL))
187 return DEFER;
188
189 addr->transport = rblock->transport;
190
191 return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)?
192 OK : DEFER;
193 }
194
195 /* End of routers/ipliteral.c */