X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/ef546e788203ac3881abe2ddb17f3e24f6524d15..62ebdc13d2e889666221bc18d6fed022554daf64:/src/src/spf.c diff --git a/src/src/spf.c b/src/src/spf.c index 3e121678c..3d83f07ba 100644 --- a/src/src/spf.c +++ b/src/src/spf.c @@ -3,9 +3,10 @@ *************************************************/ /* SPF support. + Copyright (c) The Exim Maintainers 2015 - 2022 Copyright (c) Tom Kistner 2004 - 2014 License: GPL - Copyright (c) The Exim Maintainers 2015 - 2020 + SPDX-License-Identifier: GPL-2.0-or-later */ /* Code for calling spf checks via libspf-alt. Called from acl.c. */ @@ -34,15 +35,17 @@ SPF_response_t *spf_response_2mx = NULL; SPF_dns_rr_t * spf_nxdomain = NULL; -void -spf_lib_version_report(FILE * fp) +gstring * +spf_lib_version_report(gstring * g) { int maj, min, patch; + SPF_get_lib_version(&maj, &min, &patch); -fprintf(fp, "Library version: spf2: Compile: %d.%d.%d\n", +g = string_fmt_append(g, "Library version: spf2: Compile: %d.%d.%d\n", SPF_LIB_VERSION_MAJOR, SPF_LIB_VERSION_MINOR, SPF_LIB_VERSION_PATCH); -fprintf(fp, " Runtime: %d.%d.%d\n", +g = string_fmt_append(g, " Runtime: %d.%d.%d\n", maj, min, patch); +return g; } @@ -80,6 +83,7 @@ if (rr_type == T_SPF) HDEBUG(D_host_lookup) debug_printf("faking NO_DATA for SPF RR(99) lookup\n"); srr.herrno = NO_DATA; SPF_dns_rr_dup(&spfrr, &srr); + store_free_dns_answer(dnsa); return spfrr; } @@ -100,6 +104,7 @@ for (dns_record * rr = dns_next_rr(dnsa, &dnss, RESET_ANSWERS); rr; if (found == 0) { SPF_dns_rr_dup(&spfrr, &srr); + store_free_dns_answer(dnsa); return spfrr; } @@ -171,6 +176,7 @@ if (!(srr.num_rr = found)) /* spfrr->rr must have been malloc()d for this */ SPF_dns_rr_dup(&spfrr, &srr); +store_free_dns_answer(dnsa); return spfrr; } @@ -199,7 +205,7 @@ spf_nxdomain = SPF_dns_rr_new_init(spf_dns_server, "", ns_t_any, 24 * 60 * 60, HOST_NOT_FOUND); if (!spf_nxdomain) { - free(spf_dns_server); + store_free(spf_dns_server); return NULL; } @@ -248,7 +254,7 @@ if (!(spf_server = SPF_server_new_dns(dc, debug))) if (!(s = expand_string(spf_smtp_comment_template))) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "expansion of spf_smtp_comment_template failed"); -SPF_server_set_explanation(spf_server, s, &spf_response); +SPF_server_set_explanation(spf_server, CCS s, &spf_response); if (SPF_response_errcode(spf_response) != SPF_E_SUCCESS) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "%s", SPF_strerror(SPF_response_errcode(spf_response))); @@ -395,16 +401,31 @@ gstring * authres_spf(gstring * g) { uschar * s; -if (!spf_result) return g; +if (spf_result) + { + int start = 0; /* Compiler quietening */ + DEBUG(D_acl) start = gstring_length(g); -g = string_append(g, 2, US";\n\tspf=", spf_result); -if (spf_result_guessed) - g = string_cat(g, US" (best guess record for domain)"); + g = string_append(g, 2, US";\n\tspf=", spf_result); + if (spf_result_guessed) + g = string_cat(g, US" (best guess record for domain)"); -s = expand_string(US"$sender_address_domain"); -return s && *s - ? string_append(g, 2, US" smtp.mailfrom=", s) - : string_cat(g, US" smtp.mailfrom=<>"); + s = expand_string(US"$sender_address_domain"); + if (s && *s) + g = string_append(g, 2, US" smtp.mailfrom=", s); + else + { + s = sender_helo_name; + g = s && *s + ? string_append(g, 2, US" smtp.helo=", s) + : string_cat(g, US" smtp.mailfrom=<>"); + } + DEBUG(D_acl) debug_printf("SPF:\tauthres '%.*s'\n", + gstring_length(g) - start - 3, g->s + start + 3); + } +else + DEBUG(D_acl) debug_printf("SPF:\tno authres\n"); +return g; }