From 6ce1e9aab1d11fdc929605afdece4d4a17198d89 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sun, 6 Jan 2013 17:34:01 +0000 Subject: [PATCH] Prune recipients with PRDR acl results before writing spool file. --- src/src/receive.c | 142 +++++++++++++++--------------------- test/log/5500 | 4 + test/mail/5500.userx | 7 ++ test/mail/5500.userz | 7 ++ test/scripts/5500-PRDR/5500 | 4 +- test/stderr/5500 | 2 + test/stdout/5500 | 47 ++++++++++++ 7 files changed, 129 insertions(+), 84 deletions(-) create mode 100644 test/log/5500 create mode 100644 test/mail/5500.userx create mode 100644 test/mail/5500.userz create mode 100644 test/stderr/5500 create mode 100644 test/stdout/5500 diff --git a/src/src/receive.c b/src/src/receive.c index b4a368afe..6abf7900c 100644 --- a/src/src/receive.c +++ b/src/src/receive.c @@ -3228,13 +3228,17 @@ else #endif /* WITH_CONTENT_SCAN */ #ifdef EXPERIMENTAL_PRDR - unsigned int c; if (prdr_requested && recipients_count > 0 && acl_smtp_data_prdr != NULL ) { + unsigned int c; + int all_pass = OK; + int all_fail = FAIL; + smtp_printf("353 PRDR content analysis beginning\r\n"); /* Loop through recipients, responses must be in same order received */ for (c = 0; recipients_count > c; c++) { + uschar * code; DEBUG(D_receive) debug_printf("PRDR processing recipient %s (%d of %d)\n", recipients_list[c].address, c+1, recipients_count); @@ -3244,16 +3248,61 @@ else recipients_list[c].prdr_user_msg = user_msg ? string_sprintf("%s: %s", recipients_list[c].address, user_msg) : NULL; - //add_acl_headers(US"PRDR"); - //if (rc == DISCARD) - // { - // blackholed_by = US"PRDR ACL"; - // if (smtp_handle_acl_fail(ACL_WHERE_PRDR, rc, user_msg, log_msg) != 0) - // smtp_yield = FALSE; - // smtp_reply = US""; - // message_id[0] = 0; - // } + + /* If any recipient rejected content, then indicate it in final message */ + all_pass |= rc; + /* If all recipients rejected, indicate in final message */ + all_fail &= rc; + + switch (rc) + { + case OK: + case DISCARD: + code = US"250"; + if (user_msg != NULL) + smtp_user_msg(code, user_msg); + else + smtp_printf("250 OK PRDR accepted for %s\r\n", + recipients_list[c].address); + /* Decrement the counter _after_ removing the address * + * so that it points to the previous good one or zero * + * if result is to blackhole. */ + if (rc == DISCARD) + receive_remove_recipient(recipients_list[c--].address); + break; + + case DEFER: + code = US"450"; + if (user_msg != NULL) + smtp_user_msg(code, user_msg); + else + smtp_user_msg(code, string_sprintf( + "%s temporarily refuses the content", + recipients_list[c].address)); + receive_remove_recipient(recipients_list[c--].address); + break; + + default: + code = US"550"; + if (user_msg != NULL) + smtp_user_msg(code, user_msg); + else + smtp_user_msg(code, string_sprintf( + "%s refuses the content", + recipients_list[c].address)); + receive_remove_recipient(recipients_list[c--].address); + break; + } } + /* Set up final message */ + smtp_reply = string_sprintf("%s id=%s message %s", + all_fail == FAIL ? US"550" : US"250", + message_id, + all_fail == FAIL + ? US"rejected for all recipients" + : all_pass == OK + ? US"accepted" + : US"accepted for some recipients"); } /* Kinda ugly, but turns the next if into an else-if */ else @@ -3960,79 +4009,6 @@ if (smtp_input) { if (smtp_reply == NULL) { - #ifdef EXPERIMENTAL_PRDR - unsigned int c; - int prdr_rc; - int all_pass = OK; - int all_fail = FAIL; - if (prdr_requested && recipients_count > 0) - { - uschar *code; - uschar *user_msg; - for (c = 0; recipients_count > c; c++) - { - prdr_rc = recipients_list[c].prdr_rc; - user_msg = recipients_list[c].prdr_user_msg; - - /* If any recipient rejected content, then indicate it in final message */ - all_pass |= prdr_rc; - /* If all recipients rejected, indicate in final message */ - all_fail &= prdr_rc; - /* Non PRDR code path will have already rejected the message, but * - * we had to defer that action, then detect and display it here. */ - DEBUG(D_receive) - debug_printf("PRDR response processing for recipient %s (%d of %d)\n", - recipients_list[c].address, c+1, recipients_count); - switch (prdr_rc) - { - case OK: - case DISCARD: - code = US"250"; - if (user_msg != NULL) - smtp_user_msg(code, user_msg); - else - smtp_printf("250 OK PRDR accepted for %s\r\n", - recipients_list[c].address); - /* Decrement the counter _after_ removing the address * - * so that it points to the previous good one or zero * - * if result is to blackhole. */ - if (prdr_rc == DISCARD) - receive_remove_recipient(recipients_list[c--].address); - break; - - case DEFER: - code = US"450"; - if (user_msg != NULL) - smtp_user_msg(code, user_msg); - else - smtp_user_msg(code, string_sprintf( - "%s temporarily refuses the content", - recipients_list[c].address)); - receive_remove_recipient(recipients_list[c--].address); - break; - - default: - code = US"550"; - if (user_msg != NULL) - smtp_user_msg(code, user_msg); - else - smtp_user_msg(code, string_sprintf( - "%s refuses the content", - recipients_list[c].address)); - receive_remove_recipient(recipients_list[c--].address); - break; - } - } - /* Print final message */ - code = (all_fail == FAIL) ? US"550" : US"250"; - user_msg = string_sprintf("id=%s message %s", message_id, - ((all_fail == FAIL) ? US"rejected for all recipients" : - (all_pass == OK) ? US"accepted" : - US"accepted for some recipients") ); - smtp_user_msg(code, user_msg); - } - else - #endif if (fake_response != OK) smtp_respond((fake_response == DEFER)? US"450" : US"550", 3, TRUE, fake_response_text); diff --git a/test/log/5500 b/test/log/5500 new file mode 100644 index 000000000..50a822edd --- /dev/null +++ b/test/log/5500 @@ -0,0 +1,4 @@ +1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port 1225 +1999-03-02 09:44:33 10HmaX-0005vi-00 => userx R=r0 T=t1 +1999-03-02 09:44:33 10HmaX-0005vi-00 => userz R=r0 T=t1 +1999-03-02 09:44:33 10HmaX-0005vi-00 Completed diff --git a/test/mail/5500.userx b/test/mail/5500.userx new file mode 100644 index 000000000..723eae8ee --- /dev/null +++ b/test/mail/5500.userx @@ -0,0 +1,7 @@ +From MAILER-DAEMON Tue Mar 02 09:44:33 1999 +Received: from [127.0.0.1] (helo=rhu.barb) + by myhost.test.ex with esmtp (Exim x.yz) + id 10HmaX-0005vi-00; Tue, 2 Mar 1999 09:44:33 +0000 +Sender: sender@some.where + + diff --git a/test/mail/5500.userz b/test/mail/5500.userz new file mode 100644 index 000000000..723eae8ee --- /dev/null +++ b/test/mail/5500.userz @@ -0,0 +1,7 @@ +From MAILER-DAEMON Tue Mar 02 09:44:33 1999 +Received: from [127.0.0.1] (helo=rhu.barb) + by myhost.test.ex with esmtp (Exim x.yz) + id 10HmaX-0005vi-00; Tue, 2 Mar 1999 09:44:33 +0000 +Sender: sender@some.where + + diff --git a/test/scripts/5500-PRDR/5500 b/test/scripts/5500-PRDR/5500 index d7d76c67c..c9477a1c6 100644 --- a/test/scripts/5500-PRDR/5500 +++ b/test/scripts/5500-PRDR/5500 @@ -2,7 +2,7 @@ need_ipv4 # # usery should be rejected, x & z accepted, all after data per PRDR spec -exim -DSERVER=server -d -bd -oX PORT_D +exim -DSERVER=server -bd -oX PORT_D **** client 127.0.0.1 PORT_D ??? 220 @@ -33,3 +33,5 @@ Sender: sender@some.where quit ??? 221 **** +sleep 1 +killdaemon diff --git a/test/stderr/5500 b/test/stderr/5500 new file mode 100644 index 000000000..045fadc9b --- /dev/null +++ b/test/stderr/5500 @@ -0,0 +1,2 @@ + +******** SERVER ******** diff --git a/test/stdout/5500 b/test/stdout/5500 new file mode 100644 index 000000000..c45586301 --- /dev/null +++ b/test/stdout/5500 @@ -0,0 +1,47 @@ +Connecting to 127.0.0.1 port 1225 ... connected +??? 220 +<<< 220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000 +>>> ehlo rhu.barb +??? 250- +<<< 250-myhost.test.ex Hello rhu.barb [127.0.0.1] +??? 250- +<<< 250-SIZE 52428800 +??? 250- +<<< 250-8BITMIME +??? 250- +<<< 250-PIPELINING +??? 250-PRDR +<<< 250-PRDR +??? 250 +<<< 250 HELP +>>> mail from:<> PRDR +??? 250 +<<< 250 OK, PRDR Requested +>>> rcpt to: +??? 250 +<<< 250 Accepted +>>> rcpt to: +??? 250 +<<< 250 Accepted +>>> rcpt to: +??? 250 +<<< 250 Accepted +>>> data +??? 354 +<<< 354 Enter message, ending with "." on a line by itself +>>> Sender: sender@some.where +>>> . +??? 353 +<<< 353 PRDR content analysis beginning +??? 250 +<<< 250 OK PRDR accepted for userx@test.ex +??? 550 +<<< 550 usery@test.ex refuses the content +??? 250 +<<< 250 OK PRDR accepted for userz@test.ex +??? 250 +<<< 250 id=10HmaX-0005vi-00 message accepted for some recipients +>>> quit +??? 221 +<<< 221 myhost.test.ex closing connection +End of script -- 2.25.1