Harmonised TLS library version reporting.
[exim.git] / src / src / routers / rf_get_errors_address.c
CommitLineData
0a49a7a4 1/* $Cambridge: exim/src/src/routers/rf_get_errors_address.c,v 1.8 2009/11/16 19:50:38 nm4 Exp $ */
0756eb3c
PH
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
0a49a7a4 7/* Copyright (c) University of Cambridge 1995 - 2009 */
0756eb3c
PH
8/* See the file NOTICE for conditions of use and distribution. */
9
10#include "../exim.h"
11#include "rf_functions.h"
12
13
14/*************************************************
15* Get errors address for a router *
16*************************************************/
17
18/* This function is called by routers to sort out the errors address for a
19particular address. If there is a setting in the router block, then expand and
20verify it, and if it works, use it. Otherwise use any setting that is in the
21address itself. This might be NULL, meaning unset (the message's sender is then
22used). Verification isn't done when the original address is just being
23verified, as otherwise there might be routing loops if someone sets up a silly
24configuration.
25
26Arguments:
27 addr the input address
28 rblock the router instance
fd6de02e 29 verify v_none / v_recipient / v_sender / v_expn
0756eb3c
PH
30 errors_to point the errors address here
31
32Returns: OK if no problem
33 DEFER if verifying the address caused a deferment
34 or a big disaster (e.g. expansion failure)
35*/
36
37int
38rf_get_errors_address(address_item *addr, router_instance *rblock,
fd6de02e 39 int verify, uschar **errors_to)
0756eb3c
PH
40{
41uschar *s;
42
43*errors_to = addr->p.errors_address;
44if (rblock->errors_to == NULL) return OK;
45
46s = expand_string(rblock->errors_to);
47
48if (s == NULL)
49 {
50 if (expand_string_forcedfail)
51 {
52 DEBUG(D_route)
53 debug_printf("forced expansion failure - ignoring errors_to\n");
54 return OK;
55 }
56 addr->message = string_sprintf("%s router failed to expand \"%s\": %s",
57 rblock->name, rblock->errors_to, expand_string_message);
58 return DEFER;
59 }
60
61/* If the errors_to address is empty, it means "ignore errors" */
62
63if (*s == 0)
64 {
65 setflag(addr, af_ignore_error); /* For locally detected errors */
66 *errors_to = US""; /* Return path for SMTP */
67 return OK;
68 }
69
70/* If we are already verifying, do not check the errors address, in order to
71save effort (but we do verify when testing an address). When we do verify, set
72the sender address to null, because that's what it will be when sending an
73error message, and there are now configuration options that control the running
74of routers by checking the sender address. When testing an address, there may
75not be a sender address. We also need to save and restore the expansion values
76associated with an address. */
77
fd6de02e 78if (verify != v_none)
0756eb3c
PH
79 {
80 *errors_to = s;
81 DEBUG(D_route)
82 debug_printf("skipped verify errors_to address: already verifying\n");
83 }
84else
85 {
86 BOOL save_address_test_mode = address_test_mode;
87 int save1 = 0;
88 int i;
89 uschar ***p;
90 uschar *address_expansions_save[ADDRESS_EXPANSIONS_COUNT];
91 address_item *snew = deliver_make_addr(s, FALSE);
92
93 if (sender_address != NULL)
94 {
95 save1 = sender_address[0];
96 sender_address[0] = 0;
97 }
98
99 for (i = 0, p = address_expansions; *p != NULL;)
100 address_expansions_save[i++] = **p++;
101 address_test_mode = FALSE;
102
58de37c5
PH
103 /* NOTE: the address is verified as a recipient, not a sender. This is
104 perhaps confusing. It isn't immediately obvious what to do: we want to have
105 some confidence that we can deliver to the address, in which case it will be
106 a recipient, but on the other hand, it will be passed on in SMTP deliveries
107 as a sender. However, I think on balance recipient is right because sender
108 verification is really about the *incoming* sender of the message.
109
110 If this code is changed, note that you must set vopt_fake_sender instead of
111 vopt_is_recipient, as otherwise sender_address may be altered because
112 verify_address() thinks it is dealing with *the* sender of the message. */
113
0756eb3c
PH
114 DEBUG(D_route|D_verify)
115 debug_printf("------ Verifying errors address %s ------\n", s);
58de37c5
PH
116 if (verify_address(snew, NULL,
117 vopt_is_recipient /* vopt_fake_sender is the alternative */
118 | vopt_qualify, -1, -1, -1, NULL, NULL, NULL) == OK)
119 *errors_to = snew->address;
0756eb3c
PH
120 DEBUG(D_route|D_verify)
121 debug_printf("------ End verifying errors address %s ------\n", s);
122
123 address_test_mode = save_address_test_mode;
124 for (i = 0, p = address_expansions; *p != NULL;)
125 **p++ = address_expansions_save[i++];
126
127 if (sender_address != NULL) sender_address[0] = save1;
128 }
129
130return OK;
131}
132
133/* End of rf_get_errors_address.c */