From: Jeremy Harris Date: Tue, 13 Aug 2019 21:33:50 +0000 (+0100) Subject: SPF: split library init from per-connection init X-Git-Tag: exim-4.93-RC0~101 X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=commitdiff_plain;h=73ec116f6e17189e5a8b284ec9a4433a581adefc SPF: split library init from per-connection init --- diff --git a/src/src/daemon.c b/src/src/daemon.c index 21ce2f03e..1ef28a156 100644 --- a/src/src/daemon.c +++ b/src/src/daemon.c @@ -1744,6 +1744,9 @@ dns_pattern_init(); #ifdef WITH_CONTENT_SCAN malware_init(); #endif +#ifdef SUPPORT_SPF +spf_init(); +#endif /* Close the log so it can be renamed and moved. In the few cases below where this long-running process writes to the log (always exceptional conditions), it diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c index 24978c86c..257c33de1 100644 --- a/src/src/smtp_in.c +++ b/src/src/smtp_in.c @@ -4191,7 +4191,7 @@ while (done <= 0) #ifdef SUPPORT_SPF /* set up SPF context */ - spf_init(sender_helo_name, sender_host_address); + spf_conn_init(sender_helo_name, sender_host_address); #endif /* Apply an ACL check if one is defined; afterwards, recheck diff --git a/src/src/spf.c b/src/src/spf.c index 8b7bf4bc9..1aa68f181 100644 --- a/src/src/spf.c +++ b/src/src/spf.c @@ -133,25 +133,18 @@ return spf_dns_server; -/* spf_init sets up a context that can be re-used for several - messages on the same SMTP connection (that come from the - same host with the same HELO string). -XXX the spf_server layer could usefully be separately init'd -given that it sets up a dns cache. -Return: Boolean success */ +/* Construct the SPF library stack. + Return: Boolean success. +*/ BOOL -spf_init(uschar *spf_helo_domain, uschar *spf_remote_addr) +spf_init(void) { -int debug = 0; SPF_dns_server_t * dc; +int debug = 0; -DEBUG(D_receive) - { - debug_printf("spf_init: %s %s\n", spf_helo_domain, spf_remote_addr); - debug = 1; - } +DEBUG(D_receive) debug = 1; /* We insert our own DNS access layer rather than letting the spf library do it, so that our dns access path is used for debug tracing and for the @@ -172,6 +165,24 @@ if (!(spf_server = SPF_server_new_dns(dc, debug))) DEBUG(D_receive) debug_printf("spf: SPF_server_new() failed.\n"); return FALSE; } +return TRUE; +} + + +/* Set up a context that can be re-used for several + messages on the same SMTP connection (that come from the + same host with the same HELO string). + +Return: Boolean success +*/ + +BOOL +spf_conn_init(uschar * spf_helo_domain, uschar * spf_remote_addr) +{ +DEBUG(D_receive) + debug_printf("spf_conn_init: %s %s\n", spf_helo_domain, spf_remote_addr); + +if (!spf_server && !spf_init()) return FALSE; if (SPF_server_set_rec_dom(spf_server, CS primary_hostname)) { diff --git a/src/src/spf.h b/src/src/spf.h index a0779f87c..1c87669f4 100644 --- a/src/src/spf.h +++ b/src/src/spf.h @@ -25,7 +25,8 @@ typedef struct spf_result_id { } spf_result_id; /* prototypes */ -BOOL spf_init(uschar *,uschar *); +BOOL spf_init(void); +BOOL spf_conn_init(uschar *, uschar *); int spf_process(const uschar **, uschar *, int); #define SPF_PROCESS_NORMAL 0 diff --git a/test/stderr/0275 b/test/stderr/0275 index 4b60d4e3f..a10784724 100644 --- a/test/stderr/0275 +++ b/test/stderr/0275 @@ -361,7 +361,7 @@ test in helo_lookup_domains? no (end of list) sender_fullhost = (test) [127.0.0.1] sender_rcvhost = [127.0.0.1] (helo=test) set_process_info: pppp handling incoming connection from (test) [127.0.0.1] -spf_init: test 127.0.0.1 +spf_conn_init: test 127.0.0.1 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 diff --git a/test/stderr/0303 b/test/stderr/0303 index 02b811307..f4efb6a8c 100644 --- a/test/stderr/0303 +++ b/test/stderr/0303 @@ -68,7 +68,7 @@ SMTP<< EHLO [V4NET.2.3.4] sender_fullhost = ([V4NET.2.3.4]) [V4NET.2.3.4] sender_rcvhost = [V4NET.2.3.4] set_process_info: pppp handling incoming connection from ([V4NET.2.3.4]) [V4NET.2.3.4] -spf_init: [V4NET.2.3.4] V4NET.2.3.4 +spf_conn_init: [V4NET.2.3.4] V4NET.2.3.4 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 @@ -146,7 +146,7 @@ SMTP<< EHLO [V4NET.2.3.4] sender_fullhost = host.name.tld [V4NET.2.3.4] sender_rcvhost = host.name.tld ([V4NET.2.3.4]) set_process_info: pppp handling incoming connection from host.name.tld [V4NET.2.3.4] -spf_init: [V4NET.2.3.4] V4NET.2.3.4 +spf_conn_init: [V4NET.2.3.4] V4NET.2.3.4 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 diff --git a/test/stderr/0371 b/test/stderr/0371 index d31d61580..105e589f0 100644 --- a/test/stderr/0371 +++ b/test/stderr/0371 @@ -35,7 +35,7 @@ something in helo_lookup_domains? no (end of list) sender_fullhost = (something) [V4NET.0.0.0] sender_rcvhost = [V4NET.0.0.0] (helo=something) set_process_info: pppp handling incoming connection from (something) [V4NET.0.0.0] -spf_init: something V4NET.0.0.0 +spf_conn_init: something V4NET.0.0.0 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 diff --git a/test/stderr/0433 b/test/stderr/0433 index d0f69f0cb..df91b7031 100644 --- a/test/stderr/0433 +++ b/test/stderr/0433 @@ -14,6 +14,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -31,6 +34,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 port 1226 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 port 1226 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -49,6 +55,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on [127.0.0.1]:1228 port 1225 (IPv4) port 1226 (IPv4) set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on [127.0.0.1]:1228 port 1225 (IPv4) port 1226 (IPv4) +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -67,6 +76,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 port 1226 [127.0.0.1]:1228 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 port 1226 [127.0.0.1]:1228 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -86,6 +98,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on [127.0.0.1]:1228 port 1227 (IPv4) set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on [127.0.0.1]:1228 port 1227 (IPv4) +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -105,5 +120,8 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 port 1226 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 port 1226 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... diff --git a/test/stderr/0438 b/test/stderr/0438 index f44d7bb76..a9db0031b 100644 --- a/test/stderr/0438 +++ b/test/stderr/0438 @@ -16,6 +16,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -34,5 +37,8 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... diff --git a/test/stderr/0479 b/test/stderr/0479 index 4f73548c1..1ec4bce8a 100644 --- a/test/stderr/0479 +++ b/test/stderr/0479 @@ -27,7 +27,7 @@ SMTP<< helo [1.2.3.4] sender_fullhost = ([1.2.3.4]) [1.2.3.4] sender_rcvhost = [1.2.3.4] set_process_info: pppp handling incoming connection from ([1.2.3.4]) [1.2.3.4] -spf_init: [1.2.3.4] 1.2.3.4 +spf_conn_init: [1.2.3.4] 1.2.3.4 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 diff --git a/test/stderr/0487 b/test/stderr/0487 index 97acc460a..5aa280068 100644 --- a/test/stderr/0487 +++ b/test/stderr/0487 @@ -19,7 +19,7 @@ LOG: smtp_connection MAIN SMTP>> 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000 smtp_setup_msg entered SMTP<< ehlo x.y -spf_init: x.y NULL +spf_conn_init: x.y NULL SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1 diff --git a/test/stderr/1007 b/test/stderr/1007 index ad5f748f9..80051cd19 100644 --- a/test/stderr/1007 +++ b/test/stderr/1007 @@ -15,6 +15,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -34,6 +37,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -54,6 +60,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) [127.0.0.1]:1228 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) [127.0.0.1]:1228 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -74,6 +83,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) [127.0.0.1]:1228 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv6 and IPv4) [127.0.0.1]:1228 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -91,6 +103,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on [ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6]:{1225,1226} set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on [ip6:ip6:ip6:ip6:ip6:ip6:ip6:ip6]:{1225,1226} +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -111,6 +126,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1227 (IPv6 and IPv4) [127.0.0.1]:1228 set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1227 (IPv6 and IPv4) [127.0.0.1]:1228 +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -132,6 +150,9 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on [127.0.0.1]:{1227,1225} set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on [127.0.0.1]:{1227,1225} +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... Exim version x.yz .... @@ -152,5 +173,8 @@ changed uid/gid: running as a daemon LOG: MAIN exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv4) set_process_info: pppp daemon(x.yz): no queue runs, listening for SMTP on port 1225 (IPv6 and IPv4) port 1226 (IPv4) +SPF_dns_exim_new +spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} +spf_compile.c:1210 Debug: Compiling record v=spf1 daemon running with uid=EXIM_UID gid=EXIM_GID euid=EXIM_UID egid=EXIM_GID Listening... diff --git a/test/stderr/3400 b/test/stderr/3400 index c5d7c2787..bb77c58ab 100644 --- a/test/stderr/3400 +++ b/test/stderr/3400 @@ -432,7 +432,7 @@ testing.testing in helo_lookup_domains? no (end of list) sender_fullhost = (testing.testing) [10.0.0.5] sender_rcvhost = [10.0.0.5] (helo=testing.testing ident=CALLER) set_process_info: pppp handling incoming connection from (testing.testing) [10.0.0.5] U=CALLER -spf_init: testing.testing 10.0.0.5 +spf_conn_init: testing.testing 10.0.0.5 SPF_dns_exim_new spf_compile.c:523 Debug: Parsing macro starting at Please%_see%_http://www.openspf.org/Why?id=%{S}&ip=%{C}&receiver=%{R} spf_compile.c:1210 Debug: Compiling record v=spf1