[exim-dev] [PATCH] Allow a message to be set from accept in …

Góra strony
Delete this message
Reply to this message
Autor: Simon Arlott
Data:  
Dla: exim-dev
Temat: [exim-dev] [PATCH] Allow a message to be set from accept in DATA ACL
Details here: http://simon.arlott.org/sw/exim/data-accept-message/

There is a WishList entry for changing all the OK responses, but this one is fairly simple to do and more likely to be used by connecting MTAs (at least by Exim and Sendmail with the right logging options set).

Afaict there are no side effects from this patch.

--
Simon Arlott
Only in exim-4.62+data-accept-message: build-Linux-i386
diff -U4 -r exim-4.62/src/acl.c exim-4.62+data-accept-message/src/acl.c
--- exim-4.62/src/acl.c    2006-04-28 11:32:22.000000000 +0100
+++ exim-4.62+data-accept-message/src/acl.c    2006-07-23 10:42:21.000000000 +0100
@@ -2987,8 +2987,9 @@
 If there isn't a log message set, we make it the same as the user message. */


 if (((rc == FAIL_DROP)? FAIL : rc) == msgcond[verb] ||
     (verb == ACL_DISCARD && rc == OK) ||
+    (where == ACL_WHERE_DATA && rc == OK) ||
     (where == ACL_WHERE_QUIT))
   {
   uschar *expmessage;


@@ -3003,17 +3004,25 @@
if (verb == ACL_WARN) *log_msgptr = *user_msgptr = NULL;

   if (user_message != NULL)
     {
-    acl_verify_message = old_user_msgptr;
+    /* If the verb is "accept" or "require" in the DATA ACL, the previous
+    message should not be used as the acl_verify_message. */
+
+    if (where == ACL_WHERE_DATA && rc == OK)
+      acl_verify_message = NULL;
+    else
+      acl_verify_message = old_user_msgptr;
+
     expmessage = expand_string(user_message);
     if (expmessage == NULL)
       {
       if (!expand_string_forcedfail)
         log_write(0, LOG_MAIN|LOG_PANIC, "failed to expand ACL message \"%s\": %s",
           user_message, expand_string_message);
       }
     else if (expmessage[0] != 0) *user_msgptr = expmessage;
+    else *user_msgptr = NULL;
     }


   if (log_message != NULL)
     {
@@ -3187,8 +3196,9 @@
 int fd = -1;
 acl_block *acl = NULL;
 uschar *acl_name = US"inline ACL";
 uschar *ss;
+BOOL require_message = FALSE;


/* Catch configuration loops */

if (level > 20)
@@ -3309,9 +3319,11 @@
int cond;
int basic_errno = 0;
BOOL endpass_seen = FALSE;

- *log_msgptr = *user_msgptr = NULL;
+ *log_msgptr = NULL;
+ /* If a "require" verb returned a message (only set when processing a DATA ACL), don't reset it. */
+ if (!require_message) *user_msgptr = NULL;
acl_temp_details = FALSE;

   if (where == ACL_WHERE_QUIT &&
       acl->verb != ACL_ACCEPT &&
@@ -3420,8 +3432,10 @@
     break;


     case ACL_REQUIRE:
     if (cond != OK) return cond;
+    /* If this is a DATA ACL, the message needs to be preserved. */
+    if (where == ACL_WHERE_DATA) require_message = (*user_msgptr != NULL ? TRUE : FALSE);
     break;


     case ACL_WARN:
     if (cond == OK)
@@ -3447,8 +3461,9 @@


/* We have reached the end of the ACL. This is an implicit DENY. */

HDEBUG(D_acl) debug_printf("end of %s: implicit DENY\n", acl_name);
+if (require_message) *user_msgptr = NULL;
return FAIL;
}


diff -U4 -r exim-4.62/src/receive.c exim-4.62+data-accept-message/src/receive.c
--- exim-4.62/src/receive.c    2006-04-28 11:32:22.000000000 +0100
+++ exim-4.62+data-accept-message/src/receive.c    2006-07-23 09:24:15.000000000 +0100
@@ -1278,8 +1278,9 @@


/* Final message to give to SMTP caller */

uschar *smtp_reply = NULL;
+uschar *user_msg = NULL;

/* Working header pointers */

 header_line *h, *next;
@@ -2929,9 +2930,9 @@
     them. */


     if (acl_smtp_data != NULL && recipients_count > 0)
       {
-      uschar *user_msg, *log_msg;
+      uschar *log_msg;
       rc = acl_check(ACL_WHERE_DATA, NULL, acl_smtp_data, &user_msg, &log_msg);
       add_acl_headers(US"DATA");
       if (rc == DISCARD)
         {
@@ -3484,8 +3485,10 @@
       {
       if (fake_response != OK)
         smtp_respond(fake_response == DEFER ? 450 : 550,
                      TRUE, fake_response_text);
+      else if (user_msg != NULL)
+        smtp_printf("250 OK id=%s %s\r\n", message_id, user_msg);
       else
         smtp_printf("250 OK id=%s\r\n", message_id);
       if (host_checking)
         fprintf(stdout,