[exim-cvs] cvs commit: exim/exim-src/src malware.c spool_mbo…

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Tom Kistner
Ημερομηνία:  
Προς: exim-cvs
Αντικείμενο: [exim-cvs] cvs commit: exim/exim-src/src malware.c spool_mbox.c
tom 2005/06/06 19:49:35 BST

  Modified files:
    exim-src/src         malware.c spool_mbox.c 
  Log:
  Merged patched from Alex Miller: 1) Improve aveserver failure handling 2) Write proper mbox delimiter in .eml files. 3) add X-Envelope-Sender and X-Envelope-To headers to .eml file


  Revision  Changes    Path
  1.9       +37 -3     exim/exim-src/src/malware.c
  1.6       +44 -0     exim/exim-src/src/spool_mbox.c


  Index: malware.c
  ===================================================================
  RCS file: /home/cvs/exim/exim-src/src/malware.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- malware.c    24 May 2005 08:15:02 -0000    1.8
  +++ malware.c    6 Jun 2005 18:49:35 -0000    1.9
  @@ -1,4 +1,4 @@
  -/* $Cambridge: exim/exim-src/src/malware.c,v 1.8 2005/05/24 08:15:02 tom Exp $ */
  +/* $Cambridge: exim/exim-src/src/malware.c,v 1.9 2005/06/06 18:49:35 tom Exp $ */


   /*************************************************
   *     Exim - an Internet mail transport agent    *
  @@ -409,6 +409,7 @@
         uschar buf[32768];
         struct sockaddr_un server;
         int sock;
  +      int result;


         if ((kav_options = string_nextinlist(&av_scanner_work, &sep,
                                              kav_options_buffer,
  @@ -456,19 +457,52 @@
         }


         malware_name = NULL;
  +      result = 0;
         /* read response lines, find malware name and final response */
         while (recv_line(sock, buf, 32768) > 0) {
           debug_printf("aveserver: %s\n", buf);
  -        if (buf[0] == '2') break;
  -        if (Ustrncmp(buf,"322",3) == 0) {
  +        if (buf[0] == '2') {
  +    break;
  +  } else if (buf[0] == '5') {
  +          /* aveserver is having problems */
  +          log_write(0, LOG_MAIN|LOG_PANIC,
  +             "malware acl condition: unable to scan file %s/scan/%s/%s.eml (Responded: %s).",
  +       spool_directory, message_id, message_id, buf);
  +          result = DEFER;
  +    break;
  +  } else if (Ustrncmp(buf,"322",3) == 0) {
             uschar *p = Ustrchr(&buf[4],' ');
             *p = '\0';
             Ustrcpy(malware_name_buffer,&buf[4]);
             malware_name = malware_name_buffer;
  -        };
  +  };
  +      }
  +
  +      /* prepare our command */
  +      snprintf(CS buf, 32768, "quit\r\n");
  +
  +      /* and send it */
  +      if (send(sock, buf, Ustrlen(buf), 0) < 0) {
  +        close(sock);
  +        log_write(0, LOG_MAIN|LOG_PANIC,
  +             "malware acl condition: unable to write to aveserver UNIX socket (%s)", kav_options);
  +        return DEFER;
         }


  +      /* read aveserver's greeting and see if it is ready (2xx greeting) */
  +      recv_line(sock, buf, 32768);
  +
  +      if (buf[0] != '2') {
  +        /* aveserver is having problems */
  +        close(sock);
  +        log_write(0, LOG_MAIN|LOG_PANIC,
  +             "malware acl condition: unable to quit aveserver dialogue (Responded: %s).", ((buf[0] != 0) ? buf : (uschar *)"nothing") );
  +        return DEFER;
  +      };
  +
         close(sock);
  +
  +      if (result == DEFER) return DEFER;
       }
       /* "fsecure" scanner type ------------------------------------------------- */
       else if (strcmpic(scanner_name,US"fsecure") == 0) {


  Index: spool_mbox.c
  ===================================================================
  RCS file: /home/cvs/exim/exim-src/src/spool_mbox.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- spool_mbox.c    24 May 2005 08:15:02 -0000    1.5
  +++ spool_mbox.c    6 Jun 2005 18:49:35 -0000    1.6
  @@ -1,4 +1,4 @@
  -/* $Cambridge: exim/exim-src/src/spool_mbox.c,v 1.5 2005/05/24 08:15:02 tom Exp $ */
  +/* $Cambridge: exim/exim-src/src/spool_mbox.c,v 1.6 2005/06/06 18:49:35 tom Exp $ */


   /*************************************************
   *     Exim - an Internet mail transport agent    *
  @@ -36,6 +36,9 @@
     header_line *my_headerlist;
     struct stat statbuf;
     int i,j;
  +  uschar *mbox_delimiter;
  +  uschar *envelope_from;
  +  uschar *envelope_to;


     if (!spool_mbox_ok) {
       /* create scan directory, if not present */
  @@ -58,6 +61,47 @@
       if (mbox_file == NULL) {
         debug_printf("unable to open file for writing: %s\n", mbox_path);
         return NULL;
  +    };
  +
  +    /* Generate mailbox delimiter */
  +    mbox_delimiter = expand_string(US"From ${sender_address} ${tod_bsdinbox}\n");
  +    if (mbox_delimiter != NULL) {
  +      if (mbox_delimiter[0] != 0) {
  +        i = fwrite(mbox_delimiter, 1, Ustrlen(mbox_delimiter), mbox_file);
  +        if (i != Ustrlen(mbox_delimiter)) {
  +          debug_printf("error/short write on writing in: %s", mbox_path);
  +          fclose(mbox_file);
  +          return NULL;
  +        };
  +      };
  +    };
  +    /* Generate X-Envelope-From header */
  +    envelope_from = expand_string(US"${sender_address}");
  +    if (envelope_from != NULL) {
  +      if (envelope_from[0] != 0) {
  +        uschar *my_envelope_from;
  +        my_envelope_from = string_sprintf("X-Envelope-From: <%s>\n", envelope_from);
  +        i = fwrite(my_envelope_from, 1, Ustrlen(my_envelope_from), mbox_file);
  +        if (i != Ustrlen(my_envelope_from)) {
  +          debug_printf("error/short write on writing in: %s", mbox_path);
  +          fclose(mbox_file);
  +          return NULL;
  +        };
  +      };
  +    };
  +    /* Generate X-Envelope-To header */
  +    envelope_to = expand_string(US"${if def:received_for{$received_for}}");
  +    if (envelope_to != NULL) {
  +      if (envelope_to[0] != 0) {
  +        uschar *my_envelope_to;
  +        my_envelope_to = string_sprintf("X-Envelope-To: <%s>\n", envelope_to);
  +        i = fwrite(my_envelope_to, 1, Ustrlen(my_envelope_to), mbox_file);
  +        if (i != Ustrlen(my_envelope_to)) {
  +          debug_printf("error/short write on writing in: %s", mbox_path);
  +          fclose(mbox_file);
  +          return NULL;
  +        };
  +      };
       };


       /* write all header lines to mbox file */