X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=src%2Fsrc%2Fspf.c;h=ddbb938e473c9c959622d685e37514560db762a4;hb=b9d8b5586790946de2fef94e0b8c43d573a71090;hp=23c02be208286b1195606f21e5d73e8d4effc737;hpb=92f1b1705a69394b944ea16aafbdb9d1351b3b81;p=exim.git diff --git a/src/src/spf.c b/src/src/spf.c index 23c02be20..ddbb938e4 100644 --- a/src/src/spf.c +++ b/src/src/spf.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/spf.c,v 1.5 2005/05/25 20:07:55 tom Exp $ */ +/* $Cambridge: exim/src/src/spf.c,v 1.9 2009/11/11 10:08:02 nm4 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -13,6 +13,18 @@ #include "exim.h" #ifdef EXPERIMENTAL_SPF +/* must be kept in numeric order */ +static spf_result_id spf_result_id_list[] = { + { US"invalid", 0}, + { US"neutral", 1 }, + { US"pass", 2 }, + { US"fail", 3 }, + { US"softfail", 4 }, + { US"none", 5 }, + { US"err_temp", 6 }, + { US"err_perm", 7 } +}; + SPF_server_t *spf_server = NULL; SPF_request_t *spf_request = NULL; SPF_response_t *spf_response = NULL; @@ -23,7 +35,6 @@ SPF_response_t *spf_response_2mx = NULL; same host with the same HELO string) */ int spf_init(uschar *spf_helo_domain, uschar *spf_remote_addr) { - uschar *p; spf_server = SPF_server_new(SPF_DNS_CACHE, 0); @@ -32,16 +43,22 @@ int spf_init(uschar *spf_helo_domain, uschar *spf_remote_addr) { return 0; } + if (SPF_server_set_rec_dom(spf_server, CS primary_hostname)) { + debug_printf("spf: SPF_server_set_rec_dom() failed.\n"); + spf_server = NULL; + return 0; + } + spf_request = SPF_request_new(spf_server); - if (SPF_request_set_ipv4_str(spf_request, spf_remote_addr)) { + if (SPF_request_set_ipv4_str(spf_request, CS spf_remote_addr)) { debug_printf("spf: SPF_request_set_ipv4_str() failed.\n"); spf_server = NULL; spf_request = NULL; return 0; } - if (SPF_request_set_helo_dom(spf_request, spf_helo_domain)) { + if (SPF_request_set_helo_dom(spf_request, CS spf_helo_domain)) { debug_printf("spf: SPF_set_helo_dom() failed.\n"); spf_server = NULL; spf_request = NULL; @@ -56,7 +73,7 @@ int spf_init(uschar *spf_helo_domain, uschar *spf_remote_addr) { context (if any), retrieves the result, sets up expansion strings and evaluates the condition outcome. */ -int spf_process(uschar **listptr, uschar *spf_envelope_sender) { +int spf_process(uschar **listptr, uschar *spf_envelope_sender, int action) { int sep = 0; uschar *list = *listptr; uschar *spf_result_id; @@ -69,14 +86,17 @@ int spf_process(uschar **listptr, uschar *spf_envelope_sender) { goto SPF_EVALUATE; }; - if (SPF_request_set_env_from(spf_request, spf_envelope_sender)) { + if (SPF_request_set_env_from(spf_request, CS spf_envelope_sender)) { /* Invalid sender address. This should be a real rare occurence */ rc = SPF_RESULT_PERMERROR; goto SPF_EVALUATE; } /* get SPF result */ - SPF_request_query_mailfrom(spf_request, &spf_response); + if (action == SPF_PROCESS_FALLBACK) + SPF_request_query_fallback(spf_request, &spf_response, CS spf_guess); + else + SPF_request_query_mailfrom(spf_request, &spf_response); /* set up expansion items */ spf_header_comment = (uschar *)SPF_response_get_header_comment(spf_response); @@ -89,6 +109,10 @@ int spf_process(uschar **listptr, uschar *spf_envelope_sender) { /* We got a result. Now see if we should return OK or FAIL for it */ SPF_EVALUATE: debug_printf("SPF result is %s (%d)\n", SPF_strresult(rc), rc); + + if (action == SPF_PROCESS_GUESS && (!strcmp (SPF_strresult(rc), "none"))) + return spf_process(listptr, spf_envelope_sender, SPF_PROCESS_FALLBACK); + while ((spf_result_id = string_nextinlist(&list, &sep, spf_result_id_buffer, sizeof(spf_result_id_buffer))) != NULL) { @@ -112,4 +136,3 @@ int spf_process(uschar **listptr, uschar *spf_envelope_sender) { } #endif -