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 + (C)2004 Miles Wilton + + 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);