1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
diff -Naur exim-4.50/src/deliver.c exim-4.50-patched/src/deliver.c
--- exim-4.50/src/deliver.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/deliver.c 2005-04-01 21:03:14.000000000 +0100
@@ -859,6 +859,11 @@
if ((log_extra_selector & LX_sender_on_delivery) != 0)
s = string_append(s, &size, &ptr, 3, US" F=<", sender_address, US">");
+
+ #ifdef EXPERIMENTAL_SRS
+ if(addr->p.srs_sender)
+ s = string_append(s, &size, &ptr, 3, US" SRS=<", addr->p.srs_sender, US">");
+ #endif
/* You might think that the return path must always be set for a successful
delivery; indeed, I did for some time, until this statement crashed. The case
@@ -1516,8 +1521,14 @@
/* Set up the return path from the errors or sender address. If the transport
has its own return path setting, expand it and replace the existing value. */
-return_path = (addr->p.errors_address != NULL)?
- addr->p.errors_address : sender_address;
+if(addr->p.errors_address != NULL)
+ return_path = addr->p.errors_address;
+#ifdef EXPERIMENTAL_SRS
+else if(addr->p.srs_sender != NULL)
+ return_path = addr->p.srs_sender;
+#endif
+else
+ return_path = sender_address;
if (tp->return_path != NULL)
{
@@ -3505,8 +3516,14 @@
/* Compute the return path, expanding a new one if required. The old one
must be set first, as it might be referred to in the expansion. */
- return_path = (addr->p.errors_address != NULL)?
- addr->p.errors_address : sender_address;
+ if(addr->p.errors_address != NULL)
+ return_path = addr->p.errors_address;
+#ifdef EXPERIMENTAL_SRS
+ else if(addr->p.srs_sender != NULL)
+ return_path = addr->p.srs_sender;
+#endif
+ else
+ return_path = sender_address;
if (tp->return_path != NULL)
{
diff -Naur exim-4.50/src/globals.c exim-4.50-patched/src/globals.c
--- exim-4.50/src/globals.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/globals.c 2005-04-01 19:03:23.000000000 +0100
@@ -279,6 +279,9 @@
NULL, /* errors_address */
NULL, /* extra_headers */
NULL, /* remove_headers */
+#ifdef EXPERIMENTAL_SRS
+ NULL, /* srs_sender */
+#endif
}
};
@@ -1031,10 +1034,16 @@
uschar *srs_config = NULL;
uschar *srs_db_address = NULL;
uschar *srs_db_key = NULL;
+int srs_hashlength = 6;
+int srs_hashmin = -1;
+int srs_maxage = 31;
uschar *srs_orig_recipient = NULL;
uschar *srs_orig_sender = NULL;
uschar *srs_recipient = NULL;
+uschar *srs_secrets = NULL;
uschar *srs_status = NULL;
+BOOL srs_usehash = TRUE;
+BOOL srs_usetimestamp = TRUE;
#endif
int string_datestamp_offset= -1;
BOOL strip_excess_angle_brackets = FALSE;
diff -Naur exim-4.50/src/globals.h exim-4.50-patched/src/globals.h
--- exim-4.50/src/globals.h 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/globals.h 2005-04-01 18:55:30.000000000 +0100
@@ -634,10 +634,16 @@
extern uschar *srs_config; /* SRS config secret:max age:hash length:use timestamp:use hash */
extern uschar *srs_db_address; /* SRS db address */
extern uschar *srs_db_key; /* SRS db key */
+extern int srs_hashlength; /* SRS hash length */
+extern int srs_hashmin; /* SRS minimum hash length */
+extern int srs_maxage; /* SRS max age */
extern uschar *srs_orig_sender; /* SRS original sender */
extern uschar *srs_orig_recipient; /* SRS original recipient */
extern uschar *srs_recipient; /* SRS recipient */
+extern uschar *srs_secrets; /* SRS secrets list */
extern uschar *srs_status; /* SRS staus */
+extern BOOL srs_usehash; /* SRS use hash flag */
+extern BOOL srs_usetimestamp; /* SRS use timestamp flag */
#endif
extern int string_datestamp_offset;/* After insertion by string_format */
extern BOOL strip_excess_angle_brackets; /* Surrounding route-addrs */
diff -Naur exim-4.50/src/readconf.c exim-4.50-patched/src/readconf.c
--- exim-4.50/src/readconf.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/readconf.c 2005-04-01 18:56:06.000000000 +0100
@@ -334,6 +334,12 @@
{ "spool_directory", opt_stringptr, &spool_directory },
#ifdef EXPERIMENTAL_SRS
{ "srs_config", opt_stringptr, &srs_config },
+ { "srs_hashlength", opt_int, &srs_hashlength },
+ { "srs_hashmin", opt_int, &srs_hashmin },
+ { "srs_maxage", opt_int, &srs_maxage },
+ { "srs_secrets", opt_stringptr, &srs_secrets },
+ { "srs_usehash", opt_bool, &srs_usehash },
+ { "srs_usetimestamp", opt_bool, &srs_usetimestamp },
#endif
{ "strip_excess_angle_brackets", opt_bool, &strip_excess_angle_brackets },
{ "strip_trailing_dot", opt_bool, &strip_trailing_dot },
diff -Naur exim-4.50/src/routers/redirect.c exim-4.50-patched/src/routers/redirect.c
--- exim-4.50/src/routers/redirect.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/routers/redirect.c 2005-04-02 01:31:32.000000000 +0100
@@ -108,8 +108,10 @@
(void *)offsetof(redirect_router_options_block, srs_alias) },
{ "srs_condition", opt_stringptr,
(void *)offsetof(redirect_router_options_block, srs_condition) },
- { "srs_db", opt_stringptr,
- (void *)offsetof(redirect_router_options_block, srs_db) },
+ { "srs_dbinsert", opt_stringptr,
+ (void *)offsetof(redirect_router_options_block, srs_dbinsert) },
+ { "srs_dbselect", opt_stringptr,
+ (void *)offsetof(redirect_router_options_block, srs_dbselect) },
#endif
{ "syntax_errors_text", opt_stringptr,
(void *)offsetof(redirect_router_options_block, syntax_errors_text) },
@@ -146,9 +148,10 @@
NULL, /* owngroups */
#ifdef EXPERIMENTAL_SRS
NULL, /* srs */
- NULL, /* srs_condition */
- NULL, /* srs_db */
NULL, /* srs_alias */
+ NULL, /* srs_condition */
+ NULL, /* srs_dbinsert */
+ NULL, /* srs_dbselect */
#endif
022, /* modemask */
RDO_REWRITE, /* bit_options */
@@ -517,6 +520,10 @@
addr_prop.extra_headers = NULL;
addr_prop.remove_headers = NULL;
+#ifdef EXPERIMENTAL_SRS
+addr_prop.srs_sender = NULL;
+#endif
+
/* When verifying and testing addresses, the "logwrite" command in filters
must be bypassed. */
@@ -543,8 +550,8 @@
}
#ifdef EXPERIMENTAL_SRS
- /* For reverse SRS, fill the srs_recipient expandsion variable,
- on failure, return decline/fail as relevant */
+ /* Perform SRS on recipient/return-path as required */
+
if(ob->srs != NULL)
{
BOOL usesrs = TRUE;
@@ -553,22 +560,78 @@
usesrs = expand_check_condition(ob->srs_condition, "srs_condition expansion failed", NULL);
if(usesrs)
- if(Ustrcmp(ob->srs, "reverse") == 0 || Ustrcmp(ob->srs, "reverseandforward") == 0)
+ {
+ int srs_action, n_srs;
+ uschar *res;
+ uschar *usedomain;
+
+ /* What are we doing? */
+ if(Ustrcmp(ob->srs, "forward") == 0)
+ srs_action = 1;
+ else if(Ustrcmp(ob->srs, "reverseandforward") == 0)
{
- uschar *res;
- int n_srs;
+ srs_action = 3;
+ if((ob->srs_dbinsert == NULL) ^ (ob->srs_dbselect == NULL))
+ return DEFER;
+ }
+ else if(Ustrcmp(ob->srs, "reverse") == 0)
+ srs_action = 2;
+
+ /* Reverse SRS */
+ if(srs_action & 2)
+ {
srs_orig_recipient = addr->address;
+
eximsrs_init();
- if(ob->srs_db)
- eximsrs_db_set(TRUE, ob->srs_db);
- if((n_srs = eximsrs_reverse(&res, addr->address)) != OK)
+ if(ob->srs_dbselect)
+ eximsrs_db_set(TRUE, ob->srs_dbselect);
+// Comment this out for now...
+// else
+// eximsrs_db_set(TRUE, NULL);
+
+ if((n_srs = eximsrs_reverse(&res, addr->address)) == OK)
+ {
+ srs_recipient = res;
+ DEBUG(D_any)
+ debug_printf("SRS (reverse): Recipient '%s' rewritten to '%s'\n", srs_orig_recipient, srs_recipient);
+ }
+
+ eximsrs_done();
+
+ if(n_srs != OK)
return n_srs;
- srs_recipient = res;
+ }
+
+ /* Forward SRS */
+ /* No point in actually performing SRS if we are just verifying a recipient */
+ if((srs_action & 1) && !verify && (sender_address ? sender_address[0] != 0 : FALSE))
+ {
+
+ srs_orig_sender = sender_address;
+ eximsrs_init();
+ if(ob->srs_dbinsert)
+ eximsrs_db_set(FALSE, ob->srs_dbinsert);
+// Comment this out for now...
+// else
+// eximsrs_db_set(FALSE, NULL);
+
+ if(ob->srs_alias != NULL ? (usedomain = expand_string(ob->srs_alias)) == NULL : 1)
+ usedomain = deliver_domain;
+
+ if((n_srs = eximsrs_forward(&res, sender_address, usedomain)) == OK)
+ {
+ addr_prop.srs_sender = res;
+ DEBUG(D_any)
+ debug_printf("SRS (forward): Sender '%s' rewritten to '%s'\n", srs_orig_sender, res);
+ }
+
eximsrs_done();
- DEBUG(D_any)
- debug_printf("SRS: Recipient '%s' rewritten to '%s'\n", srs_orig_recipient, srs_recipient);
+
+ if(n_srs != OK)
+ return n_srs;
}
+ }
}
#endif
@@ -795,39 +858,6 @@
(addr_prop.errors_address != NULL)? "\n" : "");
}
-#ifdef EXPERIMENTAL_SRS
- /* On successful redirection, check for SRS forwarding and adjust sender */
- if(ob->srs != NULL)
- {
- BOOL usesrs = TRUE;
-
- if(ob->srs_condition != NULL)
- usesrs = expand_check_condition(ob->srs_condition, "srs_condition expansion failed", NULL);
-
- if(usesrs)
- if((Ustrcmp(ob->srs, "forward") == 0 || Ustrcmp(ob->srs, "reverseandforward") == 0) && !verify)
- {
- uschar *res;
- uschar *usedomain;
- int n_srs;
-
- srs_orig_sender = sender_address;
- eximsrs_init();
- if(ob->srs_db)
- eximsrs_db_set(FALSE, ob->srs_db);
-
- if(ob->srs_alias != NULL ? (usedomain = expand_string(ob->srs_alias)) == NULL : 1)
- usedomain = deliver_domain;
-
- if((n_srs = eximsrs_forward(&res, sender_address, usedomain)) != OK)
- return n_srs;
- sender_address = res;
- DEBUG(D_any)
- debug_printf("SRS: Sender '%s' rewritten to '%s'\n", srs_orig_sender, sender_address);
- }
- }
-#endif
-
/* Control gets here only when the address has been completely handled. Put the
original address onto the succeed queue so that any retry items that get
attached to it get processed. */
diff -Naur exim-4.50/src/routers/redirect.h exim-4.50-patched/src/routers/redirect.h
--- exim-4.50/src/routers/redirect.h 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/routers/redirect.h 2005-04-02 01:22:45.000000000 +0100
@@ -35,9 +35,10 @@
#ifdef EXPERIMENTAL_SRS
uschar *srs;
- uschar *srs_condition;
- uschar *srs_db;
uschar *srs_alias;
+ uschar *srs_condition;
+ uschar *srs_dbinsert;
+ uschar *srs_dbselect;
#endif
int modemask;
diff -Naur exim-4.50/src/srs.c exim-4.50-patched/src/srs.c
--- exim-4.50/src/srs.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/srs.c 2005-04-01 22:33:39.000000000 +0100
@@ -1,11 +1,12 @@
-/* $Cambridge: exim/exim-src/src/srs.c,v 1.4 2005/02/17 11:58:26 ph10 Exp $ */
-
/*************************************************
* Exim - an Internet mail transport agent *
*************************************************/
/* SRS - Sender rewriting scheme support
- �2004 Miles Wilton <miles@mirtol.com>
+ (C)2004 Miles Wilton <miles@mirtol.com>
+
+ SRS Support Version: 1.0
+
License: GPL */
#include "exim.h"
@@ -24,72 +25,88 @@
int eximsrs_init()
{
- int co;
uschar *list = srs_config;
char secret_buf[SRS_MAX_SECRET_LENGTH];
char *secret;
char sbuf[4];
char *sbufp;
- int hashlen, maxage;
-
+ // Check if this instance of Exim has not initialized SRS
if(!srs)
{
- /* Check config */
- if(!srs_config)
+ int co = 0;
+ int hashlen, maxage;
+ BOOL usetimestamp, usehash;
+
+ /* Copy config vars */
+ hashlen = srs_hashlength;
+ maxage = srs_maxage;
+ usetimestamp = srs_usetimestamp;
+ usehash = srs_usehash;
+
+ /* Pass srs_config var (overrides new config vars) */
+ co = 0;
+ if(srs_config)
{
- log_write(0, LOG_MAIN | LOG_PANIC,
- "SRS Configuration Error");
- return DEFER;
+ secret = string_nextinlist(&list, &co, secret_buf, SRS_MAX_SECRET_LENGTH);
+
+ if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
+ maxage = atoi(sbuf);
+
+ if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
+ hashlen = atoi(sbuf);
+
+ if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
+ usetimestamp = atoi(sbuf);
+
+ if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
+ usehash = atoi(sbuf);
}
+
+ if(srs_hashmin == -1)
+ srs_hashmin = hashlen;
- /* Get config */
+ /* First secret specified in secrets? */
co = 0;
- if((secret = string_nextinlist(&list, &co, secret_buf,
- SRS_MAX_SECRET_LENGTH)) == NULL)
+ list = srs_secrets;
+ if(secret == NULL)
{
- log_write(0, LOG_MAIN | LOG_PANIC,
- "SRS Configuration Error: No secret specified");
- return DEFER;
+ if((secret = string_nextinlist(&list, &co, secret_buf, SRS_MAX_SECRET_LENGTH)) == NULL)
+ {
+ log_write(0, LOG_MAIN | LOG_PANIC,
+ "SRS Configuration Error: No secret specified");
+ return DEFER;
+ }
}
-
- if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) == NULL)
- maxage = 31;
- else
- maxage = atoi(sbuf);
+
+ /* Check config */
if(maxage < 0 || maxage > 365)
{
log_write(0, LOG_MAIN | LOG_PANIC,
"SRS Configuration Error: Invalid maximum timestamp age");
return DEFER;
}
-
- if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) == NULL)
- hashlen = 6;
- else
- hashlen = atoi(sbuf);
- if(hashlen < 1 || hashlen > 20)
+ if(hashlen < 1 || hashlen > 20 || srs_hashmin < 1 || srs_hashmin > 20)
{
log_write(0, LOG_MAIN | LOG_PANIC,
"SRS Configuration Error: Invalid hash length");
return DEFER;
}
-
if((srs = srs_open(secret, strnlen(secret, SRS_MAX_SECRET_LENGTH),
- maxage, hashlen, hashlen)) == NULL)
+ maxage, hashlen, srs_hashmin)) == NULL)
{
log_write(0, LOG_MAIN | LOG_PANIC,
"Failed to allocate SRS memory");
return DEFER;
}
+ srs_set_option(srs, SRS_OPTION_USETIMESTAMP, usetimestamp);
+ srs_set_option(srs, SRS_OPTION_USEHASH, usehash);
- if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
- srs_set_option(srs, SRS_OPTION_USETIMESTAMP, atoi(sbuf));
-
- if((sbufp = string_nextinlist(&list, &co, sbuf, sizeof(sbuf))) != NULL)
- srs_set_option(srs, SRS_OPTION_USEHASH, atoi(sbuf));
+ /* Extra secrets? */
+ while((secret = string_nextinlist(&list, &co, secret_buf, SRS_MAX_SECRET_LENGTH)) != NULL)
+ srs_add_secret(srs, secret, strnlen(secret, SRS_MAX_SECRET_LENGTH));
DEBUG(D_any)
debug_printf("SRS initialized\n");
@@ -151,11 +168,12 @@
int eximsrs_db_set(BOOL reverse, uschar *srs_db)
{
if(reverse)
- srs_db_reverse = string_copy(srs_db);
+ srs_db_reverse = (srs_db == NULL ? NULL : string_copy(srs_db));
else
- srs_db_forward = string_copy(srs_db);
+ srs_db_forward = (srs_db == NULL ? NULL : string_copy(srs_db));
- if(srs_set_db_functions(srs, eximsrs_db_insert, eximsrs_db_lookup) * SRS_RESULT_FAIL)
+ if(srs_set_db_functions(srs, (srs_db_forward ? eximsrs_db_insert : NULL),
+ (srs_db_reverse ? eximsrs_db_lookup : NULL)) & SRS_RESULT_FAIL)
return DEFER;
return OK;
@@ -167,9 +185,12 @@
uschar *res;
char buf[64];
+ if(!srs_db_forward)
+ return SRS_RESULT_DBERROR;
+
srs_db_address = string_copyn(data, data_len);
if(srs_generate_unique_id(srs, srs_db_address, buf, 64) & SRS_RESULT_FAIL)
- return DEFER;
+ return SRS_RESULT_DBERROR;
srs_db_key = string_copyn(buf, 16);
@@ -188,6 +209,9 @@
srs_result eximsrs_db_lookup(srs_t *srs, char *data, uint data_len, char *result, uint result_len)
{
uschar *res;
+
+ if(!srs_db_reverse)
+ return SRS_RESULT_DBERROR;
srs_db_key = string_copyn(data, data_len);
if((res = expand_string(srs_db_reverse)) == NULL)
diff -Naur exim-4.50/src/structs.h exim-4.50-patched/src/structs.h
--- exim-4.50/src/structs.h 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/structs.h 2005-04-01 18:55:45.000000000 +0100
@@ -469,6 +469,10 @@
uschar *errors_address; /* where to send errors (NULL => sender) */
header_line *extra_headers; /* additional headers */
uschar *remove_headers; /* list of those to remove */
+
+ #ifdef EXPERIMENTAL_SRS
+ uschar *srs_sender; /* Change return path when delivering */
+ #endif
} address_item_propagated;
/* Bits for the flags field below */
@@ -551,7 +555,7 @@
uschar *cipher; /* Cipher used for transport */
uschar *peerdn; /* DN of server's certificate */
#endif
-
+
uid_t uid; /* uid for transporting */
gid_t gid; /* gid for transporting */
diff -Naur exim-4.50/src/verify.c exim-4.50-patched/src/verify.c
--- exim-4.50/src/verify.c 2005-02-17 14:49:11.000000000 +0000
+++ exim-4.50-patched/src/verify.c 2005-04-01 22:34:52.000000000 +0100
@@ -1228,6 +1228,10 @@
addr_list = addr->next;
fprintf(f, "%s", CS addr->address);
+#ifdef EXPERIMENTAL_SRS
+ if(addr->p.srs_sender)
+ fprintf(f, " [srs = %s]", addr->p.srs_sender);
+#endif
while (p != NULL)
{
fprintf(f, "\n <-- %s", p->address);
|