[exim-dev] DCC update patch

Top Page
Delete this message
Reply to this message
Author: Wolfgang Breyha
Date:  
To: exim-dev
Subject: [exim-dev] DCC update patch
Hi!

I've update my experimental DCC code currently found in the CVS. I did a diff
against the current CVS. Can someone apply it for me, please?

It patches exim-src/src/dcc.h, exim-src/src/dcc.c and
exim-doc/doc-txt/experimental-spec.txt.

Regards, Wolfgang Breyha
--
Wolfgang Breyha <wbreyha@???> | http://www.blafasel.at/
Vienna University Computer Center | Austria

diff -urN exim-src/src/dcc.c exim-src-dcc/src/dcc.c
--- exim-src/src/dcc.c    2009-06-30 20:25:03.000000000 +0200
+++ exim-src-dcc/src/dcc.c    2009-09-03 12:34:17.000000000 +0200
@@ -1,10 +1,8 @@
-/* $Cambridge: exim/exim-src/src/dcc.c,v 1.2 2009/06/30 18:25:03 tom Exp $ */
-
 /*************************************************
 *     Exim - an Internet mail transport agent    *
 *************************************************/


-/* Copyright (c) Wolfgang Breyha 2005-2008
+/* Copyright (c) Wolfgang Breyha 2005-2009
* Vienna University Computer Center
* wbreyha@???
* See the file NOTICE for conditions of use and distribution.
@@ -58,15 +56,16 @@
int dcc_sock;
uschar dcc_buffer[32600];
uschar *dcc_daemon_ip = US"";
- int dcc_daemon_port = 6276;
+ int dcc_daemon_port = 6276;
uschar *dcc_request = US"header";
uschar *dcc_default_ip_option = US"127.0.0.1";
uschar *dcc_ip_option = US"";
uschar *dcc_helo_option = US"localhost";
uschar *dcc_reject_message = US"Rejected by DCC";
+ uschar *xtra_hdrs = NULL;

/* from local_scan */
- int i, j, k, c, retval, sockfd, servlen, resp, rcpt_count, portnr, line;
+ int i, j, k, c, retval, sockfd, servlen, resp, portnr, line;
struct sockaddr_un serv_addr;
struct sockaddr_in serv_addr_in;
struct hostent *ipaddress;
@@ -82,9 +81,9 @@
uschar message_subdir[2];
struct header_line *dcchdr;
struct recipient_item *dcc_rcpt = recipients_list;
- int some;
uschar *dcc_acl_options;
uschar dcc_acl_options_buffer[10];
+ uschar dcc_xtra_hdrs[1024];

int offset, result;
uschar *p,*q;
@@ -123,7 +122,7 @@
};

   sep = 0;
-
+ 
   /* if we scanned this message last time, just return */
   if ( dcc_ok )
       return dcc_rc;
@@ -173,15 +172,15 @@
     /* Do we have a sender_host_address or is it NULL? */
     if(sender_host_address){
       /* check if it is an ipv6 address */
-      if(Ustrchr(sender_host_address, ':')){
+//      if(Ustrchr(sender_host_address, ':')){
         /* This is an IPv6 address
          * For the moment we will not use it, but use 127.0.0.1 instead */
-        DEBUG(D_acl)
-          debug_printf("IPv6 address!\n");
-        Ustrncpy(client_ip, dcc_default_ip_option, sizeof(client_ip)-1);
-      } else {
+//        DEBUG(D_acl)
+//          debug_printf("IPv6 address!\n");
+//        Ustrncpy(client_ip, dcc_default_ip_option, sizeof(client_ip)-1);
+//      } else {
         Ustrncpy(client_ip, sender_host_address, sizeof(client_ip)-1);
-      }
+//      }
     } else {
       /* sender_host_address is NULL which means it comes from localhost */
       Ustrncpy(client_ip, dcc_default_ip_option, sizeof(client_ip)-1);
@@ -199,7 +198,6 @@


/* initialize the other variables */
dcchdr = header_list;
- rcpt_count = 0;
/* we set the default return value to DEFER */
retval = DEFER;

@@ -380,10 +378,8 @@
    ******************************************************************/


   line = 1;    /* we start at the first line of the output */
-  rcpt_count = 0; /* initializing the recipients counter */
   j = 0;       /* will be used as index for the recipients list */
   k = 0;       /* initializing the index of the X-DCC header: xhdr[k] */
-  some = 0;


   /* Let's read from the socket until there's nothing left to read */
   bzero(recvbuf, sizeof(recvbuf));
@@ -399,7 +395,7 @@
        * then increment the line counter */
       if(recvbuf[i] == '\n') {
         line++;
-      }
+      } 
       else {
         /* The first character of the first line is the
          * overall response. If there's another character
@@ -412,48 +408,55 @@
               DEBUG(D_acl)
                 debug_printf("Overall result = A\treturning OK\n");
               Ustrcpy(dcc_return_text, "Mail accepted by DCC");
+              dcc_result = "A";
               retval = OK;
-            }
+            } 
             else if(recvbuf[i] == 'R') {
               DEBUG(D_acl)
                 debug_printf("Overall result = R\treturning FAIL\n");
+              dcc_result = "R";
               retval = FAIL;
               if(sender_host_name) {
                 log_write(0, LOG_MAIN, "H=%s [%s] F=<%s>: rejected by DCC", sender_host_name, sender_host_address, sender_address);
-              }
+              } 
               else {
                 log_write(0, LOG_MAIN, "H=[%s] F=<%s>: rejected by DCC", sender_host_address, sender_address);
               }
               Ustrncpy(dcc_return_text, dcc_reject_message, Ustrlen(dcc_reject_message) + 1);
-            }
+            } 
             else if(recvbuf[i] == 'S') {
               DEBUG(D_acl)
                 debug_printf("Overall result  = S\treturning OK\n");
               Ustrcpy(dcc_return_text, "Not all recipients accepted by DCC");
-              some = 1;
+              /* Since we're in an ACL we want a global result
+               * so we accept for all */
+              dcc_result = "A";
               retval = OK;
-            }
+            } 
             else if(recvbuf[i] == 'G') {
               DEBUG(D_acl)
                 debug_printf("Overall result  = G\treturning FAIL\n");
               Ustrcpy(dcc_return_text, "Greylisted by DCC");
-              retval = DEFER;
-            }
+              dcc_result = "G";
+              retval = FAIL;
+            } 
             else if(recvbuf[i] == 'T') {
               DEBUG(D_acl)
                 debug_printf("Overall result = T\treturning DEFER\n");
               retval = DEFER;
               log_write(0,LOG_MAIN,"Temporary error with DCC: %s\n", recvbuf);
               Ustrcpy(dcc_return_text, "Temporary error with DCC");
-            }
+              dcc_result = "T";
+            } 
             else {
               DEBUG(D_acl)
                 debug_printf("Overall result = something else\treturning DEFER\n");
               retval = DEFER;
               log_write(0,LOG_MAIN,"Unknown DCC response: %s\n", recvbuf);
               Ustrcpy(dcc_return_text, "Unknown DCC response");
+              dcc_result = "T";
             }
-          }
+          } 
           else {
           /* We're on the first line but not on the first character,
            * there must be something wrong. */
@@ -461,52 +464,26 @@
               debug_printf("Line = %d but i = %d != 0  character is %c - This is wrong!\n", line, i, recvbuf[i]);
               log_write(0,LOG_MAIN,"Wrong header from DCC, output is %s\n", recvbuf);
           }
-        }
+        } 
         else if(line == 2) {
           /* On the second line we get a list of
-           * answer for each recipient */
-           /* We only need to copy the list of recipients if we
-            * accept the mail i.e. if retval is LOCAL_SCAN_ACCEPT */
-// I don't care about results "SOME" since we're in the DATA stage. So we've a global result
-          if(some) {
-            if(j > recipients_count - 1) {
-              DEBUG(D_acl)
-                debug_printf("More recipients returned than sent!\nSent %d recipients, got %d in return.\n", recipients_count, j);
-            }
-            else {
-              if(recvbuf[i] == 'A') {
-                DEBUG(D_acl)
-                  debug_printf("Accepted recipient: %c - %s\n", recvbuf[i], recipients_list[j].address);
-//                Ustrcpy(dcc_rcpt[rcpt_count].address, recipients_list[j].address);
-                rcpt_count++;
-              }
-              else {
-                DEBUG(D_acl)
-                  debug_printf("Rejected recipient: %c - %s\n", recvbuf[i], recipients_list[j].address);
-              }
-              j++;
-            }
-          }
-          else {
-            DEBUG(D_acl)
-              debug_printf("result was not SOME, so we take the overall result\n");
-          }
-        }
+           * answer for each recipient. We don't care about
+           * it because we're in an acl and so just take the
+           * global result. */
+        } 
         else if(line > 2) {
           /* The third and following lines is the X-DCC header,
            * so we store it in xhdr. */
           /* check if we don't get more than what we can handle */
           if(k < sizeof(xhdr)) { /* xhdr has a length of 120 */
-//            DEBUG(D_acl)
-//              debug_printf("Writing X-DCC header: k = %d recvbuf[%d] = %c\n", k, i, recvbuf[i]);
             xhdr[k] = recvbuf[i];
             k++;
-          }
+          } 
           else {
             DEBUG(D_acl)
               debug_printf("We got more output than we can store in the X-DCC header. Truncating at 120 characters.\n");
           }
-        }
+        } 
         else {
           /* Wrong line number. There must be a problem with the output. */
           DEBUG(D_acl)
@@ -525,46 +502,38 @@


   /* Now let's sum up what we've got. */
   DEBUG(D_acl)
-    debug_printf("\n--------------------------\nOverall result = %d\nNumber of recipients accepted: %d\nX-DCC header: %s\nReturn message: %s\n", retval, rcpt_count, xhdr, dcc_return_text);
-
-  /* If some recipients were rejected, then rcpt_count is
-   * less than the original recipients_count.
-   * Then reconstruct the recipients list for those accepted
-   * recipients only. */
-  if((rcpt_count == 0) & (retval == OK)) { /* There should be at least 1 recipient; but who knows... */
-    DEBUG(D_acl)
-      debug_printf("List of accepted recipients is 0!\n");
-    retval = FAIL;
-  }
-  else {
-/*  if(rcpt_count < recipients_count) {
-    recipients_count=0;
-    for(i=0; i < rcpt_count; i++){
-      DEBUG(D_acl)
-        debug_printf("Adding the new recipient: %s\n", dcc_rcpt[i].address);
-      receive_add_recipient(dcc_rcpt[i].address, -1);
-    } */
-    retval = OK;
-  }
+    debug_printf("\n--------------------------\nOverall result = %d\nX-DCC header: %sReturn message: %s\ndcc_result: %s\n", retval, xhdr, dcc_return_text, dcc_result);


   /* We only add the X-DCC header if it starts with X-DCC */
   if(!(Ustrncmp(xhdr, "X-DCC", 5))){
     dcc_header = xhdr;
     if(dcc_direct_add_header) {
       header_add(' ' , "%s", xhdr);
-  /* since the MIME ACL already writes the .eml file to disk without DCC Header we've to earase it */
+  /* since the MIME ACL already writes the .eml file to disk without DCC Header we've to erase it */
       unspool_mbox();
     }
-  }
+  } 
   else {
     DEBUG(D_acl)
       debug_printf("Wrong format of the X-DCC header: %s\n", xhdr);
   }


+  /* check if we should add additional headers passed in acl_m_dcc_add_header */
+  if(dcc_direct_add_header) {
+    if (((xtra_hdrs = expand_string("$acl_m_dcc_add_header")) != NULL) && (xtra_hdrs[0] != '\0')) {
+      Ustrncpy(dcc_xtra_hdrs, xtra_hdrs, sizeof(dcc_xtra_hdrs) - 2);
+      if (dcc_xtra_hdrs[Ustrlen(dcc_xtra_hdrs)-1] != '\n')
+    Ustrcat(dcc_xtra_hdrs, "\n");
+      header_add(' ', "%s", dcc_xtra_hdrs);
+      DEBUG(D_acl)
+        debug_printf("adding additional headers in $acl_m_dcc_add_header: %s", dcc_xtra_hdrs);
+    }
+  }
+
   dcc_ok = 1;
   /* Now return to exim main process */
   DEBUG(D_acl)
-    debug_printf("Before returning to exim main process:\nreturn_text = %s - retval = %d\n", dcc_return_text, retval);
+    debug_printf("Before returning to exim main process:\nreturn_text = %s - retval = %d\ndcc_result = %s\n", dcc_return_text, retval, dcc_result);


   (void)fclose(data_file);
   return retval;
diff -urN exim-doc/doc-txt/experimental-spec.txt exim-doc-dcc/doc-txt/experimental-spec.txt
--- exim-doc/doc-txt/experimental-spec.txt    2009-06-11 16:07:57.000000000 +0200
+++ exim-doc-dcc/doc-txt/experimental-spec.txt    2009-09-03 13:02:02.000000000 +0200
@@ -463,6 +463,56 @@
 in your Local/Makefile.



+DCC Support
+--------------------------------------------------------------
+
+*) Building exim
+
+In order to build exim with DCC support add
+EXPERIMENTAL_DCC=yes
+to your Makefile. (Re-)build/install exim. exim -d should show
+EXPERIMENTAL_DCC under "Support for".
+
+*) Configuration
+
+In the main section of exim.cf add at least
+dccifd_address = /usr/local/dcc/var/dccifd
+or
+dccifd_address = <ip> <port>
+
+In the DATA ACL you can use the new condition
+        dcc = *
+
+After that "dcc_header" contains the X-DCC-Header.
+
+*** WARNING: return codes changed from previous releases!
+
+Returnvalues are:
+fail for overall "R", "G" from dccifd
+defer for overall "T" from dccifd
+accept for overall "A", "S" from dccifd
+
+dcc = */defer_ok works as for spamd.
+
+dcc_result contains the overall result from DCC answer
+
+usually you'll use
+defer   !dcc = *
+to greylist with DCC.
+if
+dcc_direct_add_header = true
+is set, then the dcc header will be added "in deep" and if the spool file was
+already written it gets removed. This forces exim to write it again if needed.
+This helps to get the DCC Header through to eg. SpamAssassin.
+
+if you want to pass even more headers in the middle of the DATA stage you can
+use
+$acl_m_dcc_add_header
+to add information from eg. ClamAV.
+
+Be carefull. Header syntax is not checked and added "as is".
+
+
 --------------------------------------------------------------
 End of file
 --------------------------------------------------------------