From 9adabf8d8efffb166745c8bba2041e9856b20f01 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Mon, 16 Dec 2024 15:28:49 +0000 Subject: [PATCH] Cutthrough: logging of return_path --- src/src/deliver.c | 18 +++++++++--------- src/src/structs.h | 1 + src/src/verify.c | 6 +++++- test/confs/5400 | 2 +- test/log/5400 | 32 ++++++++++++++++---------------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/src/deliver.c b/src/src/deliver.c index 7e51048f2..cbf5268c2 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -77,7 +77,6 @@ static pardata *parlist = NULL; static struct pollfd *parpoll; static int return_count; static uschar *frozen_info = US""; -static const uschar * used_return_path = NULL; @@ -1172,8 +1171,8 @@ delivery; indeed, I did for some time, until this statement crashed. The case when it is not set is for a delivery to /dev/null which is optimised by not being run at all. */ -if (used_return_path && LOGGING(return_path_on_delivery)) - g = string_append(g, 3, US" P=<", used_return_path, US">"); +if (addr->return_path && LOGGING(return_path_on_delivery)) + g = string_append(g, 3, US" P=<", addr->return_path, US">"); if (msg) g = string_append(g, 2, US" ", msg); @@ -1406,8 +1405,8 @@ if (*queue_name) /* Return path may not be set if no delivery actually happened */ -if (used_return_path && LOGGING(return_path_on_delivery)) - g = string_append(g, 3, US" P=<", used_return_path, US">"); +if (addr->return_path && LOGGING(return_path_on_delivery)) + g = string_append(g, 3, US" P=<", addr->return_path, US">"); if (addr->router) g = string_append(g, 2, US" R=", addr->router->drinst.name); @@ -2175,7 +2174,7 @@ if (tp->return_path) /* For local deliveries, one at a time, the value used for logging can just be set directly, once and for all. */ -used_return_path = return_path; +addr->return_path = return_path; /* Sort out the uid, gid, and initgroups flag. If an error occurs, the message gets put into the address(es), and the expansions are unset, so we can just @@ -3957,7 +3956,7 @@ static address_item * par_wait(void) { int poffset, status; -address_item * addr, * addrlist; +address_item * addrlist; pid_t pid; set_process_info("delivering %s: waiting for a remote delivery subprocess " @@ -4167,7 +4166,7 @@ if ((status & 0xffff) != 0) if (msb != 0 || (code != SIGTERM && code != SIGKILL && code != SIGQUIT)) addrlist->special_action = SPECIAL_FREEZE; - for (addr = addrlist; addr; addr = addr->next) + for (address_item * addr = addrlist; addr; addr = addr->next) { addr->transport_return = DEFER; addr->message = msg; @@ -4186,7 +4185,8 @@ else if (!parlist[poffset].done) decrement the count of subprocesses, and return the address chain. */ transport_count = parlist[poffset].transport_count; -used_return_path = parlist[poffset].return_path; +for (address_item * addr = addrlist; addr; addr = addr->next) + addr->return_path = parlist[poffset].return_path; parlist[poffset].pid = 0; parcount--; return addrlist; diff --git a/src/src/structs.h b/src/src/structs.h index 4c74608b3..7a7f7a02c 100644 --- a/src/src/structs.h +++ b/src/src/structs.h @@ -550,6 +550,7 @@ typedef struct address_item { const uschar *suffix_v; /* variable part of above */ const uschar *domain; /* working domain (lower cased) */ + const uschar *return_path; /* mailfrom, for logging */ uschar *address_retry_key; /* retry key including full address */ uschar *domain_retry_key; /* retry key for domain only */ diff --git a/src/src/verify.c b/src/src/verify.c index 33929e023..08c3deb51 100644 --- a/src/src/verify.c +++ b/src/src/verify.c @@ -528,7 +528,11 @@ if (options & vopt_is_recipient) { from_address = sender_address; address_key = string_sprintf("%s/<%s>", addr->address, sender_address); - if (cutthrough.delivery) options |= vopt_callout_no_cache; + if (cutthrough.delivery) /* cutthrough previously req. */ + { + options |= vopt_callout_no_cache; /* in case called by verify= */ + addr->return_path = from_address; /* for cutthrough logging */ + } } else if (options & vopt_callout_recippmaster) { diff --git a/test/confs/5400 b/test/confs/5400 index 9693818b1..1906e819d 100644 --- a/test/confs/5400 +++ b/test/confs/5400 @@ -10,7 +10,7 @@ OPT= primary_hostname = myhost.test.ex -log_selector = +received_recipients +all_parents +log_selector = +received_recipients +all_parents +return_path_on_delivery queue_only # ----- Main settings ----- diff --git a/test/log/5400 b/test/log/5400 index 099075990..43873a680 100644 --- a/test/log/5400 +++ b/test/log/5400 @@ -1,59 +1,59 @@ **NOTE: The delivery lines in this file have been sorted. 1999-03-02 09:44:33 rcpt for userx@domain.com -1999-03-02 09:44:33 10HmaX-000000005vi-0000 >> userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmaX-000000005vi-0000 >> userx@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmaX-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com 1999-03-02 09:44:33 10HmaX-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userz@domain.com -1999-03-02 09:44:33 10HmaY-000000005vi-0000 >> userz@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmaY-000000005vi-0000 >> userz@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmaY-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userz@domain.com 1999-03-02 09:44:33 10HmaY-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for usery@domain.com 1999-03-02 09:44:33 rcpt for userx@domain.com -1999-03-02 09:44:33 10HmaZ-000000005vi-0000 >> userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" -1999-03-02 09:44:33 10HmaZ-000000005vi-0000 >> usery@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmaZ-000000005vi-0000 >> userx@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmaZ-000000005vi-0000 >> usery@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmaZ-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for usery@domain.com userx@domain.com 1999-03-02 09:44:33 10HmaZ-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain.com -1999-03-02 09:44:33 10HmbA-000000005vi-0000 >> userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbA-000000005vi-0000 >> userx@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbA-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com 1999-03-02 09:44:33 10HmbA-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for no@domain.com 1999-03-02 09:44:33 U=CALLER F= rejected RCPT 1999-03-02 09:44:33 rcpt for userx@domain.com 1999-03-02 09:44:33 10HmbB-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com -1999-03-02 09:44:33 10HmbB-000000005vi-0000 => userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbB-000000005vi-0000 => userx@domain.com P=<> R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbB-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain.com 1999-03-02 09:44:33 rcpt for no@domain.com 1999-03-02 09:44:33 U=CALLER F= rejected RCPT 1999-03-02 09:44:33 10HmbC-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com -1999-03-02 09:44:33 10HmbC-000000005vi-0000 => userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbC-000000005vi-0000 => userx@domain.com P=<> R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbC-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain.com 1999-03-02 09:44:33 rcpt for special_tpt@domain.com 1999-03-02 09:44:33 10HmbD-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com special_tpt@domain.com -1999-03-02 09:44:33 10HmbD-000000005vi-0000 => special_tpt@domain.com R=all T=smtp2 H=127.0.0.1 [127.0.0.1] C="250 OK" -1999-03-02 09:44:33 10HmbD-000000005vi-0000 => userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbD-000000005vi-0000 => special_tpt@domain.com P=<> R=all T=smtp2 H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbD-000000005vi-0000 => userx@domain.com P=<> R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbD-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain1.com 1999-03-02 09:44:33 rcpt for usery@domain2.com -1999-03-02 09:44:33 10HmbE-000000005vi-0000 >> usery@domain2.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" -1999-03-02 09:44:33 10HmbE-000000005vi-0000 >> userx@domain1.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbE-000000005vi-0000 >> usery@domain2.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbE-000000005vi-0000 >> userx@domain1.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbE-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain1.com usery@domain2.com 1999-03-02 09:44:33 10HmbE-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain.com 1999-03-02 09:44:33 rcpt for usery@special.com 1999-03-02 09:44:33 10HmbF-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com usery@special.com -1999-03-02 09:44:33 10HmbF-000000005vi-0000 => userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" -1999-03-02 09:44:33 10HmbF-000000005vi-0000 => usery@special.com R=all T=smtp H=ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4] C="250 OK" +1999-03-02 09:44:33 10HmbF-000000005vi-0000 => userx@domain.com P=<> R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbF-000000005vi-0000 => usery@special.com P=<> R=all T=smtp H=ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4] C="250 OK" 1999-03-02 09:44:33 10HmbF-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@localhost4.test.ex 1999-03-02 09:44:33 rcpt for usery@thishost.test.ex -1999-03-02 09:44:33 10HmbG-000000005vi-0000 >> usery@thishost.test.ex R=dns T=smtp H=localhost4.test.ex [127.0.0.1] C="250 OK" -1999-03-02 09:44:33 10HmbG-000000005vi-0000 >> userx@localhost4.test.ex R=dns T=smtp H=localhost4.test.ex [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbG-000000005vi-0000 >> usery@thishost.test.ex P= R=dns T=smtp H=localhost4.test.ex [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbG-000000005vi-0000 >> userx@localhost4.test.ex P= R=dns T=smtp H=localhost4.test.ex [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbG-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@localhost4.test.ex usery@thishost.test.ex 1999-03-02 09:44:33 10HmbG-000000005vi-0000 Completed 1999-03-02 09:44:33 rcpt for userx@domain.com -1999-03-02 09:44:33 10HmbH-000000005vi-0000 >> userx@domain.com R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" +1999-03-02 09:44:33 10HmbH-000000005vi-0000 >> userx@domain.com P= R=all T=smtp H=127.0.0.1 [127.0.0.1] C="250 OK" 1999-03-02 09:44:33 10HmbH-000000005vi-0000 <= CALLER@myhost.test.ex U=CALLER P=local-esmtp S=sss for userx@domain.com 1999-03-02 09:44:33 10HmbH-000000005vi-0000 Completed -- 2.30.2