Common subdirectories: ../simscan-1.4.0.orig/cdb/CVS and cdb/CVS
Common subdirectories: ../simscan-1.4.0.orig/contrib/CVS and contrib/CVS
--- ../simscan-1.4.0.orig/simscan.c	2007-10-29 09:15:05.000000000 -0500
+++ simscan.c	2007-11-12 13:47:14.086079000 -0500
@@ -45,7 +45,6 @@
 #define EXIT_400  71  /* temporary refusal to accept */
 #define EXIT_500  31  /* permenent refusal to accept message SMTP: 5XX code */
 #define EXIT_MSG  82  /* exit with custom error message */ 
-#define EXIT_54   54  /* Unable to read the message or envelope. */
 #define EXIT_91   91  /* Envelope format error. */
 
 
@@ -73,6 +72,9 @@
        91   Envelope format error.
 */
 
+#if HAVE_STRSEP!=1
+char *strsep (char **pp, char *delim);
+#endif
 
 #ifdef QUARANTINEDIR 
 void quarantine_msg(char *message_name);
@@ -84,9 +86,6 @@
 #define MAX_SPAMC_ARGS 20
 char *spamc_args[MAX_SPAMC_ARGS];
 
-/* --stdout is required for reading virus names */
-char *viri_args[] = { "clamdscan", "--stdout", NULL };
-
 /* Global work buffers */
 #define BUFFER_SIZE 2048
 char buffer[BUFFER_SIZE];
@@ -103,6 +102,9 @@
 char *replace(char *string, char *oldpiece, char *newpiece);
 int DebugFlag = 0;
 
+/* --stdout is required for reading virus names */
+char *viri_args[] = { "clamdscan", "--stdout", message_name, NULL };
+
 /* To/From address processing globals */
 #define MAX_RCPT_TO 255
 #define MAX_EMAIL 500
@@ -215,6 +217,10 @@
 #ifdef ENABLE_RECEIVED
 char runned_scanners[MAX_EMAIL]="";
 void add_run_scanner(char *key);
+struct tm *tm;
+static char monthname[12][4] = {
+ "Jan","Feb","Mar","Apr","May","Jun"
+,"Jul","Aug","Sep","Oct","Nov","Dec"};
 #endif
 
 #ifdef ENABLE_REGEX
@@ -238,6 +244,7 @@
  int ret;
  int fd_per;
  size_t tmpread;
+ size_t msgsize;
  char *tmpstr;
  int pim[2];
  int qstat;
@@ -312,7 +319,9 @@
   }
 
   /* read the email into the new file */
+  msgsize = 0;
   while( (ret = read(0, buffer, sizeof(buffer))) > 0 ) {
+    msgsize += ret;
     if ( write(fd, buffer,ret) == -1 ) {
       if ( DebugFlag > 0 ) {
         fprintf(stderr, "simscan: error writing msg error: %d\n", errno);
@@ -380,6 +389,7 @@
            exit_clean(EXIT_91);
         }
         strncpy(MailFrom, &addr_buff[1], sizeof(MailFrom)-1);
+        lowerit(MailFrom);
         gotfrom = 1;
         if ( DebugFlag > 3 )
           fprintf(stderr, "simscan: F envelope is %s\n", MailFrom);
@@ -387,6 +397,7 @@
      if (addr_buff[0] == 'T') {
         if (MaxRcptTo<MAX_RCPT_TO) {
            strncpy(RcptTo[MaxRcptTo], &addr_buff[1], MAX_EMAIL-1);
+           lowerit(RcptTo[MaxRcptTo]);
            gotrcpt = 1;
            MaxRcptTo ++;
            if ( DebugFlag > 3 )
@@ -400,7 +411,7 @@
   if (tmpread <= 0 && errno != 0) {
      // error or unexpected EOF
      close (fd_per);
-     exit_clean(EXIT_54);
+     exit_clean(EXIT_454);
   }
 
 
@@ -433,12 +444,6 @@
   }
 #endif
 
-
-  /* get the mail from value 
-  memset(MailFrom,0,sizeof(MailFrom));
-  strncpy(MailFrom, &addr_buff[1], sizeof(MailFrom)-1);
-  */
-
 #ifdef ENABLE_PER_DOMAIN
   /* setup the per domain values for checking virus or spam */
   set_per_domain();
@@ -539,7 +544,84 @@
 
 #endif
 
+#ifdef ENABLE_SPAM
+if (msgsize >= 250000) {
+  if ( DebugFlag > 0 ) {
+    fprintf(stderr, "simscan: big file (%lu bytes); skipping SpamAssassin\n",
+      (unsigned long) msgsize);
+  }
+} else {
+  /* re-open the file read only */
+  if ( (fd = open(message_name, O_RDONLY)) == -1 ) {
+    if ( DebugFlag > 0 ) {
+      fprintf(stderr, "simscan: spam can not open file: %s\n", message_name);
+    }
+    exit_clean(EXIT_400);
+  }
 
+  /* set the standard input to be the new file */
+  if ( fd_move(0,fd)  == -1 ) {
+    if ( DebugFlag > 0 ) {
+      fprintf(stderr, "simscan: spam could not fd_move\n");
+    }
+    exit_clean(EXIT_400);
+  }
+
+  /* optionally check for spam with spamassassin */ 
+  snprintf(spam_message_name, sizeof(spam_message_name), "spamc.msg.%s", unique_ext);
+  ret = check_spam();
+  switch ( ret ) {
+    /* spamassassin not enabled for this domain */
+    case 2:
+      /* re-open the message file file read only */
+      /* do nothing, message_name gets openend in any case*/
+      break;
+
+    /* spam detected, refuse message */
+    case 1:
+      if ( DebugFlag > 0 ) {
+        fprintf(stderr, "simscan: check_spam detected spam refuse message\n");
+      }
+      close(fd);
+
+#ifdef QUARANTINEDIR
+      quarantine_msg(message_name);
+      /* put message in quarantine */
+#endif
+	      
+#ifdef ENABLE_DROPMSG
+      if ( DebugFlag > 0 ) {
+        fprintf(stderr, "simscan: droping the message\n");
+      }
+      exit_clean(EXIT_0);
+      /* Drop the message, returning success to sender. */
+#else			
+ #ifdef ENABLE_CUSTOM_SMTP_REJECT
+      snprintf(RejectMsg,sizeof(RejectMsg), 
+       "DYour email is considered spam (%.2f spam-hits)", SpamHits );
+      write(4,RejectMsg, strlen(RejectMsg));
+      exit_clean(EXIT_MSG);
+ #else
+      exit_clean(EXIT_500); 
+ #endif
+#endif
+      break;
+
+      /* spamassassin processed message and no spam detected */
+    case 0:
+      /* open the spam file read only */
+      strncpy(message_name,spam_message_name,BUFFER_SIZE);
+      break;
+      /* errors , return temporary error */
+    default:
+      if ( DebugFlag > 0 ) {
+        fprintf(stderr, "simscan: check_spam had an error ret: %d\n", ret);
+      }
+      close(fd);
+      exit_clean(EXIT_400); 
+  }
+}
+#endif
 
 #if (VIRUSSCANNER==1 || ENABLE_ATTACH==1) && DO_RIPMIME==1
   /* break the email msg into mime parts */
@@ -652,78 +734,6 @@
   }
 #endif
 
-#ifdef ENABLE_SPAM
-  /* re-open the file read only */
-  if ( (fd = open(message_name, O_RDONLY)) == -1 ) {
-    if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: spam can not open file: %s\n", message_name);
-    }
-    exit_clean(EXIT_400);
-  }
-
-  /* set the standard input to be the new file */
-  if ( fd_move(0,fd)  == -1 ) {
-    if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: spam could not fd_move\n");
-    }
-    exit_clean(EXIT_400);
-  }
-
-  /* optionally check for spam with spamassassin */ 
-  snprintf(spam_message_name, sizeof(spam_message_name), "spamc.msg.%s", unique_ext);
-  ret = check_spam();
-  switch ( ret ) {
-    /* spamassassin not enabled for this domain */
-    case 2:
-      /* re-open the message file file read only */
-      /* do nothing, message_name gets openend in any case*/
-      break;
-
-    /* spam detected, refuse message */
-    case 1:
-      if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: check_spam detected spam refuse message\n");
-      }
-      close(fd);
-
-#ifdef QUARANTINEDIR
-      quarantine_msg(message_name);
-      /* put message in quarantine */
-#endif
-	      
-#ifdef ENABLE_DROPMSG
-      if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: droping the message\n");
-      }
-      exit_clean(EXIT_0);
-      /* Drop the message, returning success to sender. */
-#else			
- #ifdef ENABLE_CUSTOM_SMTP_REJECT
-      snprintf(RejectMsg,sizeof(RejectMsg), 
-       "DYour email is considered spam (%.2f spam-hits)", SpamHits );
-      write(4,RejectMsg, strlen(RejectMsg));
-      exit_clean(EXIT_MSG);
- #else
-      exit_clean(EXIT_500); 
- #endif
-#endif
-      break;
-
-      /* spamassassin processed message and no spam detected */
-    case 0:
-      /* open the spam file read only */
-      strncpy(message_name,spam_message_name,BUFFER_SIZE);
-      break;
-      /* errors , return temporary error */
-    default:
-      if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: check_spam had an error ret: %d\n", ret);
-      }
-      close(fd);
-      exit_clean(EXIT_400); 
-  }
-#endif
-
   /* re-open the file read only */
   if ( (fd = open(message_name, O_RDONLY)) == -1 ) {
     if ( DebugFlag > 0 ) {
@@ -764,25 +774,27 @@
     case 0:
       close(pim[1]);
       dup2(pim[0],0);
-      execl(qmail_queue, qmail_queue, 0);
-      _exit(-1);
+      execl(qmail_queue, qmail_queue, NULL);
+      _exit(111);
   }
   close(pim[0]);
 
-  #ifdef ENABLE_RECEIVED
+#ifdef ENABLE_RECEIVED
   gettimeofday(&stop,(struct timezone *) 0);
   utime=SECS(stop)-SECS(start);
-  snprintf(buffer,sizeof(buffer),
-"Received: by simscan %s ppid: %d, pid: %d, t: %3.4fs\n         scanners:%s\n",
-    VERSION,getppid(),getpid(),utime,
-    strlen(runned_scanners) > 0 ? runned_scanners : "none");
+
+  tm = gmtime(&start.tv_sec);
+  snprintf(buffer,sizeof(buffer), "Received: (simscan %s ppid %ld pid %d t %.4fs)\n"
+    " (scanners: %s); %02d %s %04d %02d:%02d:%02d -0000\n",
+    VERSION, getppid(), getpid(), utime, runned_scanners[0] ? runned_scanners : "none",
+    tm->tm_mday,monthname[tm->tm_mon],tm->tm_year,tm->tm_hour,tm->tm_min,tm->tm_sec);
   if ( write(pim[1], buffer,strlen(buffer)) == -1 ) {
     if ( DebugFlag > 0 ) {
       fprintf(stderr, "simscan: error writing received line\n");
     }
     exit_clean(EXIT_400);
   }
-  #endif
+#endif
 
   /* write the message to qmail-queue */
   while( (ret = read(fd, buffer, sizeof(buffer))) > 0 ) {
@@ -1340,10 +1352,10 @@
   memset(buffer,0,sizeof(buffer));
   spamfs = fdopen(0,"r");
   while(fgets(buffer,sizeof(buffer)-1,spamfs) != NULL ) {
+    write(spam_fd, buffer,strlen(buffer));
     if ( InHeaders == 1 ) {
       is_spam(buffer);
     }
-    write(spam_fd, buffer,strlen(buffer));
     memset(buffer,0,sizeof(buffer));
   }
   close(spam_fd);
@@ -1362,11 +1374,13 @@
 #endif
 
 #ifdef SPAM_HITS
+  ReqHits = SPAM_HITS;
   if ( PerDomainHits==1 && ( SpamHits >= PDHits ) ) {
+    ReqHits = PDHits;
 #ifdef ENABLE_DROPMSG
     log_message("SPAM DROPPED", Subject, 1);
 #else
-    log_message("SPAM REJECT", Subject,1);
+     log_message("SPAM REJECT", Subject,1);
 #endif
     return(1);
   } else if ( PerDomainHits==0 && ( SpamHits >= SPAM_HITS ) ) {
@@ -1725,7 +1739,7 @@
       return(-1);
     }
   }
-  return(0);
+  return((n < sn) ? 0 : -1);
 }
 
 #ifdef ENABLE_PER_DOMAIN
@@ -1970,7 +1984,7 @@
  char *tmpstr;
  char hits[10];
 
-  if ( spambuf[0] == '\n' || spambuf[1] == '\n' ) {
+  if ( spambuf[0] == '\n' ) {
     InHeaders = 0;
     return(0);
   }
@@ -1979,7 +1993,7 @@
     IsSpam = 1;
 
   /* still in the headers get Subject */ 
-  } else if ( strncmp(spambuf, "Subject:", 8 ) == 0 ) {
+  } else if ( strncmp(spambuf, "Subject: ", 9 ) == 0 ) {
     
     strncpy(Subject, &spambuf[9], sizeof(Subject)-1);
 
@@ -2014,12 +2028,7 @@
     } else {
        tmpstr+=5;
     }
-    if ( tmpstr == NULL ) {
-       if ( DebugFlag > 1 ) {
-         fprintf(stderr,
-           "simscan: neither hits= or score= in X-Spam-Status header\n");
-       }
-    }
+
     memset(hits,0,sizeof(hits));
     for(l=0;l<9 && *tmpstr!=' '; ++l, ++tmpstr) {
       hits[l] = *tmpstr;
--- ../simscan-1.4.0.orig/simscanmk.c	2006-10-10 19:15:17.000000000 -0400
+++ simscanmk.c	2007-11-12 13:49:54.894937000 -0500
@@ -72,11 +72,11 @@
   get_options(argc,argv);
 #ifdef ENABLE_RECEIVED
   if (buildversions){
-    make_version_cdb();
+    int xcode = make_version_cdb();
+    if (xcode != 0) exit(xcode);
   } else {
-#endif
-  make_cdb();
-#ifdef ENABLE_RECEIVED
+    int xcode = make_cdb();
+    if (xcode != 0) exit(xcode);
   }
 #endif
   exit(0);
@@ -369,6 +369,7 @@
  static char input[MAX_LINE];
  uint32 h;
 
+ sleep(0); /* some NFS timing crazyness on solaris TC/jk 20061108  */
 
   if ( (fs = fopen(ClearFile,"r")) == NULL) {
     printf("Not building simcontrol.cdb file. No %s/simcontrol text file\n",
