Import Upstream version 4.92
[hcoop/debian/exim4.git] / src / routers / rf_self_action.c
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8
9 #include "../exim.h"
10 #include "rf_functions.h"
11
12
13
14 /*************************************************
15 * Decode actions for self reference *
16 *************************************************/
17
18 /* This function is called from a number of routers on receiving
19 HOST_FOUND_LOCAL when looking up a supposedly remote host. The action is
20 controlled by a generic configuration option called "self" on each router,
21 which can be one of:
22
23 . freeze: Log the incident, freeze, and return DEFER
24
25 . defer: Log the incident and return DEFER
26
27 . fail: Fail the address
28
29 . send: Carry on with the delivery regardless -
30 this makes sense only if the SMTP
31 listener on this machine is a differently
32 configured MTA
33
34 . pass: The router passes; the address
35 gets passed to the next router, overriding
36 the setting of no_more
37
38 . reroute:<new-domain> Change the domain to the given domain
39 and return REROUTE so it gets passed back
40 to the routers.
41
42 . reroute:rewrite:<new-domain> The same, but headers containing the
43 old domain get rewritten.
44
45 These string values are interpreted earlier on, and passed into this function
46 as the values of "code" and "rewrite".
47
48 Arguments:
49 addr the address being routed
50 host the host that is local, with MX set (or -1 if MX not used)
51 code the action to be taken (one of the self_xxx enums)
52 rewrite TRUE if rewriting headers required for REROUTED
53 new new domain to be used for REROUTED
54 addr_new child chain for REROUTEED
55
56 Returns: DEFER, REROUTED, PASS, FAIL, or OK, according to the value of code.
57 */
58
59 int
60 rf_self_action(address_item *addr, host_item *host, int code, BOOL rewrite,
61 uschar *new, address_item **addr_new)
62 {
63 uschar * msg = host->mx >= 0
64 ? US"lowest numbered MX record points to local host"
65 : US"remote host address is the local host";
66
67 switch (code)
68 {
69 case self_freeze:
70
71 /* If there is no message id, this is happening during an address
72 verification, so give information about the address that is being verified,
73 and where it has come from. Otherwise, during message delivery, the normal
74 logging for the address will be sufficient. */
75
76 if (message_id[0] == 0)
77 if (sender_fullhost)
78 log_write(0, LOG_MAIN, "%s: %s (while verifying <%s> from host %s)",
79 msg, addr->domain, addr->address, sender_fullhost);
80 else
81 log_write(0, LOG_MAIN, "%s: %s (while routing <%s>)", msg,
82 addr->domain, addr->address);
83 else
84 log_write(0, LOG_MAIN, "%s: %s", msg, addr->domain);
85
86 addr->message = msg;
87 addr->special_action = SPECIAL_FREEZE;
88 return DEFER;
89
90 case self_defer:
91 addr->message = msg;
92 return DEFER;
93
94 case self_reroute:
95 DEBUG(D_route)
96 debug_printf("%s: %s: domain changed to %s\n", msg, addr->domain, new);
97 rf_change_domain(addr, new, rewrite, addr_new);
98 return REROUTED;
99
100 case self_send:
101 DEBUG(D_route)
102 debug_printf("%s: %s: configured to try delivery anyway\n", msg, addr->domain);
103 return OK;
104
105 case self_pass: /* This is soft failure; pass to next router */
106 DEBUG(D_route)
107 debug_printf("%s: %s: passed to next router (self = pass)\n", msg, addr->domain);
108 addr->message = msg;
109 addr->self_hostname = string_copy(host->name);
110 return PASS;
111
112 case self_fail:
113 DEBUG(D_route)
114 debug_printf("%s: %s: address failed (self = fail)\n", msg, addr->domain);
115 addr->message = msg;
116 setflag(addr, af_pass_message);
117 return FAIL;
118 }
119
120 return DEFER; /* paranoia */
121 }
122
123 /* End of rf_self_action.c */