To stabilize the simscan 1.2 2006111001

* strsep bug in Solaris - Tom Collins
* virgin envelope patch - Ken Jones
* set exit code on errors - Jeremy Kister
* logging modifications plucked from simscan 1.2.3
* fix compile warning issues with long versus int - Jeremy Kister
* add pid to debug messages - Jeremy Kister
* log configured spam reject limit, not spamassassin's - Jeremy Kister
* band-aid simscanmk NFS timing issue on solaris - Tom Collins
* RFC2822 Received field compliance - Tullio Andreatta

* NOTE: this patch works on the ORIGINAL simscan-1.2 release, which is
* temporarily available at: http://jeremy.kister.net/tmp/simscan-1.2.tar.gz

#####################################################################

Common subdirectories: ../simscan-1.2.orig/cdb/CVS and cdb/CVS
Common subdirectories: ../simscan-1.2.orig/contrib/CVS and contrib/CVS
--- ../simscan-1.2.orig/simscan.c	2005-09-28 17:20:07.000000000 -0400
+++ simscan.c	2006-11-10 11:38:38.026005000 -0500
@@ -42,6 +42,7 @@
 #define EXIT_0     0  /* Success */
 #define EXIT_11   11  /* address too long */
 #define EXIT_400  71  /* temporary refusal to accept */
+#define EXIT_454  54  /* unable to read envelope or message */
 #define EXIT_500  31  /* permenent refusal to accept message SMTP: 5XX code */
 #define EXIT_MSG  82  /* exit with custom error message */ 
 
@@ -68,6 +69,9 @@
        91   Envelope format error.
 */
 
+#if HAVE_STRSEP!=1
+char *strsep (char **pp, char *delim);
+#endif
 
 #ifdef QUARANTINEDIR 
 void quarantine_msg(char *message_name);
@@ -194,6 +198,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
@@ -257,14 +265,14 @@
   format_dir(workdir);
 
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: starting: work dir: %s\n", workdir);  
+    fprintf(stderr, "simscan[%ld]: starting: work dir: %s\n", getppid(), workdir);  
   }
 
   /* create the working directory, allow group access too */
   if ( mkdir(workdir, 0750) == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error making work dir, exit 400, errno: %d\n",
-        errno);
+      fprintf(stderr, "simscan[%ld]: error making work dir, exit 400, errno: %d\n",
+        getppid(), errno);
     }
     _exit(EXIT_400);
   }
@@ -273,8 +281,8 @@
   if ( chdir(workdir) != 0 ) {
     if ( DebugFlag > 0 ) {
       fprintf(stderr, 
-        "simscan: error changing directory to workdir errno: %d\n",
-        errno);
+        "simscan[%ld]: error changing directory to workdir errno: %d\n",
+        getppid(), errno);
     }
     exit_clean(EXIT_400);
   }
@@ -283,8 +291,8 @@
   snprintf(message_name, sizeof(message_name), "msg.%s", unique_ext);
   if ( (fd=open(message_name, O_WRONLY|O_CREAT|O_TRUNC,0644)) ==- 1) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error opening msg file %s errnostr: %d\n", 
-        message_name, errno);
+      fprintf(stderr, "simscan[%ld]: error opening msg file %s errnostr: %d\n", 
+        getppid(), message_name, errno);
     }
     exit_clean(EXIT_400);
   }
@@ -293,7 +301,7 @@
   while( (ret = read(0, buffer, sizeof(buffer))) > 0 ) {
     if ( write(fd, buffer,ret) == -1 ) {
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: error writing msg error: %d\n", errno);
+        fprintf(stderr, "simscan[%ld]: error writing msg error: %d\n", getppid(), errno);
       }
       exit_clean(EXIT_400);
     }
@@ -302,7 +310,7 @@
   /* close the file */
   if ( close(fd) == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error closing email file errno: %d\n", errno);
+      fprintf(stderr, "simscan[%ld]: error closing email file errno: %d\n", getppid(), errno);
     }
     exit_clean(EXIT_400);
   }
@@ -313,7 +321,7 @@
   /* open the addr_name file */
   if ( (fd_per=open(addr_name, O_WRONLY|O_CREAT|O_TRUNC,0644)) ==- 1) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error opening addr name: %s\n", addr_name);
+      fprintf(stderr, "simscan[%ld]: error opening addr name: %s\n", getppid(), addr_name);
     }
     exit_clean(EXIT_400);
   }
@@ -341,6 +349,12 @@
     write(fd_per,addr_buff, tmpread);
   }
 
+  if(virgin == 1){
+    if( DebugFlag > 0){
+      fprintf(stderr, "simscan[%ld]: no envelope information, deferred exit\n", getppid());
+    }
+    exit_clean(EXIT_454);
+  }
 
   /* close the addr file */
   if ( close(fd_per) == -1 ) {
@@ -377,7 +391,7 @@
   /* break the email msg into mime parts */
   if ( run_ripmime() != 0 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: ripmime error\n");
+      fprintf(stderr, "simscan[%ld]: ripmime error\n", getppid());
     }
     exit_clean(EXIT_400);
   }
@@ -406,29 +420,29 @@
   ret = check_clam();
   switch ( ret ) {
     case -2: 
-      if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: clamdscan disabled\n"); }
+      if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: clamdscan disabled\n", getppid()); }
       break;
     case -1: 
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: fatal error executing clamdscan\n");
+        fprintf(stderr, "simscan[%ld]: fatal error executing clamdscan\n", getppid());
       }
       exit_clean(EXIT_400);
       break;
     case 1:
       FoundVirus=1;
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: clamdscan detected a virus\n");
+        fprintf(stderr, "simscan[%ld]: clamdscan detected a virus\n", getppid());
       }
       break;
     case 2:
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: fatal error executing clamdscan\n");
+        fprintf(stderr, "simscan[%ld]: fatal error executing clamdscan\n", getppid());
       }
       exit_clean(EXIT_400);
       break;
     default: 
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: normal clamdscan return code: %d\n", ret);
+        fprintf(stderr, "simscan[%ld]: normal clamdscan return code: %ld\n", getppid(), ret);
       }
       break;
   }
@@ -439,22 +453,22 @@
   switch(ret) {
     case 0:
       if ( DebugFlag > 0 ) {
-       fprintf(stderr, "simscan: trophie found no virus\n");
+       fprintf(stderr, "simscan[%ld]: trophie found no virus\n",getppid());
       }
       break;
     case 1:
       if ( DebugFlag > 0 ) {
-       fprintf(stderr, "simscan: trophie found virus\n");
+       fprintf(stderr, "simscan[%ld]: trophie found virus\n", getppid());
       }
       FoundVirus=1;
       break;
     case -1:
       /* disabled */
-      if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: trophie disabled\n"); }
+      if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: trophie disabled\n", getppid()); }
       break;
     default:
       if ( DebugFlag > 0 ) {
-       fprintf(stderr, "simscan: some temp. error occured with trophie\n");
+       fprintf(stderr, "simscan[%ld]: some temp. error occured with trophie\n");
       }
       exit_clean(EXIT_400);
   }
@@ -487,7 +501,7 @@
   /* 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);
+      fprintf(stderr, "simscan[%ld]: spam can not open file: %s\n", getppid(), message_name);
     }
     exit_clean(EXIT_400);
   }
@@ -495,7 +509,7 @@
   /* 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");
+      fprintf(stderr, "simscan[%ld]: spam could not fd_move\n", getppid());
     }
     exit_clean(EXIT_400);
   }
@@ -513,7 +527,7 @@
     /* spam detected, refuse message */
     case 1:
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: check_spam detected spam refuse message\n");
+        fprintf(stderr, "simscan[%ld]: check_spam detected spam refuse message\n", getppid());
       }
       close(fd);
 
@@ -525,7 +539,7 @@
 #ifdef ENABLE_DROPMSG
       log_message("SPAM DROPPED", VirusName, 1);
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: droping the message\n");
+        fprintf(stderr, "simscan[%ld]: droping the message\n", getppid());
       }
       exit_clean(EXIT_0);
       /* Drop the message, returning success to sender. */
@@ -548,7 +562,7 @@
       /* errors , return temporary error */
     default:
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: check_spam had an error ret: %d\n", ret);
+        fprintf(stderr, "simscan[%ld]: check_spam had an error ret: %d\n", getppid(), ret);
       }
       close(fd);
       exit_clean(EXIT_400); 
@@ -558,7 +572,7 @@
   /* re-open the file read only */
   if ( (fd = open(message_name, O_RDONLY)) == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: could not re-open file: %s\n", message_name);
+      fprintf(stderr, "simscan[%ld]: could not re-open file: %s\n", getppid(), message_name);
     }
     exit_clean(EXIT_400);
   }
@@ -566,7 +580,7 @@
   /* re-open the address read only */
   if ( (fd_per = open(addr_name, O_RDONLY)) == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: could not re-open address: %s\n", addr_name);
+      fprintf(stderr, "simscan[%ld]: could not re-open address: %s\n", getppid(), addr_name);
     }
     exit_clean(EXIT_400);
   }
@@ -574,12 +588,12 @@
   /* set the standard input to be the new file */
   if ( fd_move(1,fd_per)  == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: could not fd_move\n");
+      fprintf(stderr, "simscan[%ld]: could not fd_move\n", getppid());
     }
     exit_clean(EXIT_400);
   }
 
-  if ( DebugFlag > 0 ) fprintf(stderr, "simscan: done, execing qmail-queue\n");
+  if ( DebugFlag > 0 ) fprintf(stderr, "simscan[%ld]: done, execing qmail-queue\n", getppid());
 
   if ( pipe(pim) != 0 ) return(-1);
 
@@ -587,7 +601,7 @@
   switch(pid = vfork()) {
     case -1:
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: error forking qmail-queue\n");
+        fprintf(stderr, "simscan[%ld]: error forking qmail-queue\n", getppid());
       }
       close(pim[0]);
       close(pim[1]);
@@ -596,20 +610,22 @@
       close(pim[1]);
       dup2(pim[0],0);
       execl(qmail_queue, qmail_queue, 0);
-      _exit(-1);
+      _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");
+      fprintf(stderr, "simscan[%ld]: error writing received line\n", getppid());
     }
     exit_clean(EXIT_400);
   }
@@ -620,7 +636,7 @@
     if ( write(pim[1], buffer,ret) == -1 ) {
       if ( DebugFlag > 0 ) {
         fprintf(stderr, 
-          "simscan: error writing msg to qmail-queue error: %d\n", errno);
+          "simscan[%ld]: error writing msg to qmail-queue error: %d\n", getppid(), errno);
       }
       exit_clean(EXIT_400);
     }
@@ -631,14 +647,14 @@
   /* wait for qmail-queue to finish */
   if (waitpid(pid,&qstat, 0) == -1) { 
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error forking qmail-queue (back in simscan)\n");
+      fprintf(stderr, "simscan[%ld]: error forking qmail-queue (back in simscan)\n", getppid());
     }
     exit_clean(EXIT_400);
   }
 
   /* hand the email to the qmail-queue */
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: qmail-queue exited %d\n", WEXITSTATUS(qstat));
+    fprintf(stderr, "simscan[%ld]: qmail-queue exited %d\n", getppid(), WEXITSTATUS(qstat));
   }
 
   /* remove the working files */
@@ -684,7 +700,7 @@
   char tmpbuf[256];
   char *data;
   
-  if ( DebugFlag > 1 ) fprintf(stderr, "simscan: cdb looking up version %s\n", key);  
+  if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: cdb looking up version %s\n", getppid(), key);  
 
   snprintf(tmpbuf,sizeof(tmpbuf), "%s/simversions.cdb", CONTROLDIR);
   if ( (fd = open(tmpbuf, O_RDONLY)) == -1 ) {
@@ -702,8 +718,8 @@
   ret = read(fd,data,dlen);
   close(fd);
   snprintf(runned_scanners+strlen(runned_scanners),MAX_EMAIL-strlen(runned_scanners)," %s: %s",key,data);
-  if ( DebugFlag > 2 ) fprintf(stderr, "simscan: runned_scanners is %s\n", runned_scanners);  
-  if ( DebugFlag > 2 ) fprintf(stderr, "simscan: found %s\n", data);  
+  if ( DebugFlag > 2 ) fprintf(stderr, "simscan[%ld]: runned_scanners is %s\n", getppid(), runned_scanners);  
+  if ( DebugFlag > 2 ) fprintf(stderr, "simscan[%ld]: found %s\n", getppid(), data);  
 }
 #endif
 
@@ -762,7 +778,7 @@
 #endif
 
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: calling clamdscan\n");
+    fprintf(stderr, "simscan[%ld]: calling clamdscan\n", getppid());
   }
 
   if ( pipe(pim) != 0 ) return(-1);
@@ -892,14 +908,14 @@
   
   if ( (spam_fd=open(spam_message_name, O_RDWR|O_CREAT|O_TRUNC,0644)) ==- 1) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: check_spam could not open spam file: %s\n", 
-        spam_message_name);
+      fprintf(stderr, "simscan[%ld]: check_spam could not open spam file: %s\n", 
+        getppid(), spam_message_name);
     }
     return(-1);
   }
 
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: calling spamc\n");
+    fprintf(stderr, "simscan[%ld]: calling spamc\n", getppid());
   }
 
   tmpbuf = malloc(strlen(SPAMC_ARGS)+1);
@@ -925,7 +941,7 @@
   spamc_args[i] = NULL;
 
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: calling %s ", SPAMC);
+    fprintf(stderr, "simscan[%ld]: calling %s ", getppid(), SPAMC);
     i=0;
     while(spamc_args[i] != NULL){
       fprintf(stderr, " %s", spamc_args[i]);
@@ -983,16 +999,30 @@
 #endif
 
 #ifdef SPAM_HITS
-  if ( PerDomainHits==1 && ( SpamHits > PDHits ) ) {
+  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);
+#endif
     return(1);
-  } else if ( PerDomainHits==0 && ( SpamHits > SPAM_HITS ) ) {
+  } else if ( PerDomainHits==0 && ( SpamHits >= SPAM_HITS ) ) {
+#ifdef ENABLE_DROPMSG
+    log_message("SPAM DROPPED", Subject, 1);
+#else
     log_message("SPAM REJECT", Subject,1);
+#endif
     return(1);
   }
 
-  if (SpamHits >= 5) {
-    log_message("SPAM PASS", Subject,1);
+  if (SpamHits >= SPAM_HITS) {
+#ifdef ENABLE_DROPMSG
+    log_message("SPAM DROPPED", Subject, 1);
+#else
+    log_message("SPAM REJECT", Subject,1);
+#endif
   } else {
     log_message("CLEAN", Subject,1);
   }
@@ -1002,7 +1032,7 @@
  #ifdef ENABLE_PER_DOMAIN
     if ( PerDomainSpamPassthru == 1) {
       if (( IsSpam == 1.0 ) && (DebugFlag > 0)){	    
-        fprintf(stderr, "simscan: delivering spam because spam-passthru is defined in this domain\n");
+        fprintf(stderr, "simscan[%ld]: delivering spam because spam-passthru is defined in this domain\n", getppid());
       }	
       log_message("PASSTHRU", Subject,1);
       return(0);
@@ -1153,14 +1183,14 @@
   strncat(quarantinefile, "/", sizeof(quarantinefile)-1);
   strncat(quarantinefile, message_name, sizeof(quarantinefile)-1);
   
-  fprintf(stderr, "simscan: Putting the message in quarantine: %s\n", 
-    quarantinefile);
+  fprintf(stderr, "simscan[%ld]: Putting the message in quarantine: %s\n", 
+    getppid(), quarantinefile);
   
   if ((fd_destino=open(quarantinefile, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
     if ( DebugFlag > 0 ) {
       fprintf(stderr, 
-        "simscan: error opening quarantine file %s errnostr: %d\n", 
-        message_name, errno);
+        "simscan[%ld]: error opening quarantine file %s errnostr: %ld\n", 
+        getppid(), message_name, errno);
     }
     return;
   }
@@ -1169,7 +1199,7 @@
   while ((ret = read(fd_origem, buffer, sizeof(buffer))) > 0) {
     if (write(fd_destino, buffer, ret) == -1) {
       if (DebugFlag > 0) {
-        fprintf(stderr, "simscan: error writing msg error: %d\n", errno);
+        fprintf(stderr, "simscan[%ld]: error writing msg error: %ld\n", getppid(), errno);
       }
       return;
     }
@@ -1177,20 +1207,20 @@
   
   if (close(fd_origem) == -1) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error closing original mail file errno: %d\n", 
-        errno);
+      fprintf(stderr, "simscan[%ld]: error closing original mail file errno: %ld\n", 
+        getppid(), errno);
     }
     return;
   }
   
   if ( close(fd_destino) == -1 ) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: error closing quarantine file errno: %d\n", 
-        errno);
+      fprintf(stderr, "simscan[%ld]: error closing quarantine file errno: %ld\n", 
+        getppid(), errno);
     }
     return;
   } else {
-    fprintf(stderr, "simscan: Message recorded in quarantine successful\n");
+    fprintf(stderr, "simscan[%ld]: Message recorded in quarantine successful\n", getppid());
   }
   return;
 }
@@ -1204,7 +1234,7 @@
 {
   remove_files(workdir);
   if ( DebugFlag > 0 ) {
-    fprintf(stderr, "simscan: exit error code: %d\n", error_code); 
+    fprintf(stderr, "simscan[%ld]: exit error code: %d\n", getppid(), error_code); 
   }
   _exit(error_code);
 }
@@ -1251,10 +1281,10 @@
  char *found;
   
   MaxAttach = 0;
-  if ( DebugFlag > 3 ) fprintf(stderr, "simscan: add_attach called with %s\n", list);  
+  if ( DebugFlag > 3 ) fprintf(stderr, "simscan[%ld]: add_attach called with %s\n", getppid(), list);  
   while( ( found = strsep(&list,":") ) != NULL) {
       strncpy(bk_attachments[MaxAttach], found, strlen(found));
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: %s is attachment number %d\n", bk_attachments[MaxAttach], MaxAttach);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: %s is attachment number %ld\n", getppid(), bk_attachments[MaxAttach], MaxAttach);  
       ++MaxAttach;
   }
 }
@@ -1292,7 +1322,7 @@
     }
 
     for(i=0;i<MaxAttach;++i) {
-      if ( DebugFlag > 2 ) fprintf(stderr, "simscan: checking attachment %s against %s\n", mydirent->d_name, bk_attachments[i] );  
+      if ( DebugFlag > 2 ) fprintf(stderr, "simscan[%ld]: checking attachment %s against %s\n", getppid(), mydirent->d_name, bk_attachments[i] );  
       lowerit(mydirent->d_name); 
       if ( str_rstr(mydirent->d_name,bk_attachments[i]) == 0 ) {
         strncpy(AttachName, mydirent->d_name, sizeof(AttachName)-1); 
@@ -1349,7 +1379,7 @@
  char *parm;
  char *val;
   
-  if ( DebugFlag > 1 ) fprintf(stderr, "simscan: cdb looking up %s\n", key);  
+  if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: cdb looking up %s\n", getppid(), key);  
 
   snprintf(tmpbuf,sizeof(tmpbuf), "%s/simcontrol.cdb", CONTROLDIR);
   if ( (fd = open(tmpbuf, O_RDONLY)) == -1 ) {
@@ -1367,12 +1397,12 @@
   ret = read(fd,data,dlen);
   close(fd);
   
-  if ( DebugFlag > 1 ) fprintf(stderr, "simscan: cdb for %s found %s\n", key, data);  
+  if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: cdb for %s found %s\n", getppid(), key, data);  
 
   parm = strsep(&data, PER_DOMAIN_TOKENS);
   if ( parm != NULL ) val = strsep(&data, PER_DOMAIN_TOKENS);
   while ( parm != NULL && val != NULL) {
-    if ( DebugFlag > 1 ) fprintf(stderr, "simscan: pelookup %s = %s\n", parm,val);  
+    if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: pelookup %s = %s\n", getppid(), parm,val);  
     if ( strcasecmp(parm,"clam") == 0 ) {
       if ( strcasecmp(val, "yes") == 0 ) {
         PerDomainClam = 1; 
@@ -1387,12 +1417,12 @@
       }
     } else if ( strcasecmp(parm,"qmailqueue") == 0 ) {
       qmail_queue = strdup(val);
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: qmailqueue = %s\n", val);
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: qmailqueue = %s\n", getppid(), val);
 
 #ifdef ENABLE_SPAM
     } else if ( strcasecmp(parm,"spamuser") == 0 ) {
       strncpy(spamuser,val,BUFFER_SIZE);
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: spamuser = %s\n", spamuser);
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: spamuser = %s\n", getppid(), spamuser);
 #endif
 
     } else if ( strcasecmp(parm,"trophie") == 0 ) {
@@ -1401,22 +1431,22 @@
       } else if ( strcasecmp(val, "no") == 0 ) {
         PerDomainTrophie = 0; 
       }
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: trophie = %s/%d\n", val,PerDomainTrophie);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: trophie = %s/%d\n", getppid(), val,PerDomainTrophie);  
 #ifdef ENABLE_REGEX
     } else if ( strcasecmp(parm,"regex") == 0 ) {
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: regex flag %s = %s\n", parm, val);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: regex flag %s = %s\n", getppid(), parm, val);  
       init_regex(val);
 #endif
 #ifdef ENABLE_ATTACH
     } else if ( strcasecmp(parm,"attach") == 0 ) {
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: attachment flag %s = %s\n", parm, val);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: attachment flag %s = %s\n", getppid(), parm, val);  
       add_attach(val);
 #endif
 #ifdef SPAM_HITS
     } else if ( strcasecmp(parm,"spam_hits") == 0 ) {
       PerDomainHits = 1;
       PDHits = atof(val);
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: Per Domain Hits set to : %f\n", PDHits);
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: Per Domain Hits set to : %f\n", getppid(), PDHits);
 #endif
 #ifdef ENABLE_SPAM_PASSTHRU
     } else if ( strcasecmp(parm,"spam_passthru") == 0) {
@@ -1425,10 +1455,10 @@
       } else if ( strcasecmp(val, "no") == 0 ) {
         PerDomainSpamPassthru = 0;
       }
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: spampassthru = %s/%d\n", val,PerDomainSpamPassthru);
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: spampassthru = %s/%ld\n", getppid(), val,PerDomainSpamPassthru);
 #endif   
     } else {
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: unimplemented flag %s = %s\n", parm, val);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: unimplemented flag %s = %s\n", getppid(), parm, val);  
     }
     parm = strsep(&data, PER_DOMAIN_TOKENS);
     if ( parm != NULL ) val = strsep(&data, PER_DOMAIN_TOKENS);
@@ -1461,25 +1491,25 @@
   int i,keyIndex=0;
 
   *localtmp='\0';
-  if ( DebugFlag > 1 ) fprintf(stderr, "simscan: pelookup: called with %s\n", email);  
+  if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: pelookup: called with %s\n", getppid(), email);  
 
   /* first we lookup the domain */
   
   for(tmpstr = email; tmpstr!=NULL && *tmpstr!='@' && keyIndex < MAX_EMAIL; ++tmpstr ){++keyIndex;}
   if (*tmpstr != '@') {
-    if ( DebugFlag > 1 ) fprintf(stderr, "simscan: WARN: no domain part found! %s\n", email);  
+    if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: WARN: no domain part found! %s\n", getppid(), email);  
     *domain='\0';
   } else {
     keyIndex++;
     strncpy(domain,email+keyIndex,sizeof(domain)-keyIndex-1); 
-    if ( DebugFlag > 1 ) fprintf(stderr, "simscan: pelookup: domain is %s\n", domain);  
+    if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: pelookup: domain is %s\n", getppid(), domain);  
     per_domain_lookup( domain ); 
   }
  
   strncpy(local,email, sizeof(local)); 
   for(l_ptr=local; l_ptr!=NULL && *l_ptr!='@' && *l_ptr!='\0'; ++l_ptr );
   *l_ptr='\0';
-  if ( DebugFlag > 1 ) fprintf(stderr, "simscan: pelookup: local part is %s\n", local);  
+  if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: pelookup: local part is %s\n", getppid(), local);  
 
   /* then we check if the local part is an extended address (bla-ext)
    * we have to fill an array, as per_domain_lookup uses strtok again
@@ -1487,7 +1517,7 @@
   l_ptr = local;
   keyIndex=0;
   while( (lpart = strsep(&l_ptr,MAIL_EXT_TOKENS) )!= NULL && keyIndex < MAX_RCPT_TO) {
-    if ( DebugFlag > 2 ) fprintf(stderr, "simscan: lpart: local part is *%s*\n", localtmp);
+    if ( DebugFlag > 2 ) fprintf(stderr, "simscan[%ld]: lpart: local part is *%s*\n", getppid(),localtmp);
     strncat(localtmp,lpart,MAX_EMAIL-strlen(localtmp)-strlen(lpart)-1);
     sprintf(toScan[keyIndex], "%s@%s", localtmp,domain);
     strncat(localtmp,"-",MAX_EMAIL-strlen(localtmp)-2);
@@ -1558,7 +1588,7 @@
        if ( tmpstr == NULL ) {
          if ( DebugFlag > 1 ) {
            fprintf(stderr,
-           "simscan: neither hits= or score= in X-Spam-Status header\n");
+           "simscan[%ld]: neither hits= or score= in X-Spam-Status header\n", getppid());
          }
          return(0);
        }
@@ -1569,7 +1599,7 @@
     if ( tmpstr == NULL ) {
        if ( DebugFlag > 1 ) {
          fprintf(stderr,
-           "simscan: neither hits= or score= in X-Spam-Status header\n");
+           "simscan[%ld]: neither hits= or score= in X-Spam-Status header\n", getppid());
        }
     }
     memset(hits,0,sizeof(hits));
@@ -1578,15 +1608,6 @@
     }
     SpamHits = atof(hits);
 
-    if ( (tmpstr = strstr(spambuf, "required=")) != NULL ) {
-      tmpstr+=9;
-      memset(hits,0,sizeof(hits));
-      for(l=0;l<9 && *tmpstr!=' '; ++l, ++tmpstr) {
-        hits[l] = *tmpstr;
-      }
-      ReqHits = atof(hits);
-    }
-
   }
   return(0);
 }
@@ -1610,19 +1631,19 @@
   int match=0;
 
   for (i=0;i<numRegex;i++){
-      if ( DebugFlag > 1 ) { fprintf(stderr, "simscan: compiling regex %d (%s)\n", i,regexs[i]);  }
+      if ( DebugFlag > 1 ) { fprintf(stderr, "simscan[%ld]: compiling regex %ld (%s)\n", getppid(), i,regexs[i]);  }
       comp_regexs[i]=pcre_compile(regexs[i], 0, &error, &erroffset, NULL);    
       if (comp_regexs[i] == NULL){
-        if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: error compiling regex %d (%s): %s\n", i,regexs[i],error);  }
+        if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: error compiling regex %ld (%s): %s\n", getppid(),i,regexs[i],error);  }
       }
   }
   
-  if ( DebugFlag > 1 ) { fprintf(stderr, "simscan: regex opening message file %s\n", message_name);  }
+  if ( DebugFlag > 1 ) { fprintf(stderr, "simscan[%ld]: regex opening message file %s\n", getppid(), message_name);  }
   if ( (regex_fd=fopen(message_name, "r")) == NULL ) {
-    if ( DebugFlag > 1 ) { fprintf(stderr, "simscan: regex error opening message file %s\n", message_name);  }
+    if ( DebugFlag > 1 ) { fprintf(stderr, "simscan[%ld]: regex error opening message file %s\n", getppid(), message_name);  }
     retvalue=1;
   } else {
-    if ( DebugFlag > 1 ) { fprintf(stderr, "simscan: regex reading message\n");  }
+    if ( DebugFlag > 1 ) { fprintf(stderr, "simscan[%ld]: regex reading message\n", getppid());  }
     while(!feof(regex_fd) && !match){
       /* read line and match it */
       fgets(line, MAX_REGEX_LINE, regex_fd);
@@ -1631,13 +1652,13 @@
           if (comp_regexs[i] != NULL){
             rc=pcre_exec(comp_regexs[i], NULL, line, strlen(line), 0, 0, NULL,0);
             if (rc >= 0){
-              if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: regex match %d (%s) matches %s\n", i, regexs[i],line);  };
+              if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: regex match %ld (%s) matches %s\n", getppid(), i, regexs[i],line);  };
               match=1;
               retvalue=2;
-              snprintf(VirusName,BUFFER_SIZE,"#%d",i);
+              snprintf(VirusName,BUFFER_SIZE,"#%ld",i);
             } else if (rc < -1){
               /* -1 means no match, but all other errors are ``strange'' */
-              if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: regex %d (%s) error %d\n", i, regexs[i],rc);  };
+              if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: regex %ld (%s) error %ld\n", getppid(),i, regexs[i],rc);  };
             }
           }
         }
@@ -1645,7 +1666,7 @@
     }
   }
   
-  if ( DebugFlag > 0 ) { fprintf(stderr, "simscan: regex freeing memory\n");  };
+  if ( DebugFlag > 0 ) { fprintf(stderr, "simscan[%ld]: regex freeing memory\n", getppid());  };
   for (i=0;i<numRegex;i++){
     pcre_free(comp_regexs[i]);
   }
@@ -1660,10 +1681,10 @@
 void init_regex (char *list) {
   int len=0;
   char *found;
-  if ( DebugFlag > 3 ) fprintf(stderr, "simscan: init_regex called with %s\n", list);  
+  if ( DebugFlag > 3 ) fprintf(stderr, "simscan[%ld]: init_regex called with %s\n", getppid(), list);  
   while( ( found = strsep(&list,":") ) != NULL) {
       strncpy(regexs[numRegex], found, strlen(found));
-      if ( DebugFlag > 1 ) fprintf(stderr, "simscan: regex %d is %s\n", numRegex,regexs[numRegex]);  
+      if ( DebugFlag > 1 ) fprintf(stderr, "simscan[%ld]: regex %ld is %s\n", getppid(),numRegex,regexs[numRegex]);  
       ++numRegex;
   }
 }
@@ -1691,7 +1712,7 @@
 #endif
       
   if ( DebugFlag > 1 ) {
-    fprintf(stderr, "simscan: trophie starting!\n");  
+    fprintf(stderr, "simscan[%ld]: trophie starting!\n", getppid());  
   }
 
   /* Create socket */
@@ -1713,7 +1734,7 @@
   strncat(command, "\n", sizeof(command)-1);
 
   if ( DebugFlag > 1 ) {
-    fprintf(stderr, "simscan: sending command [%s]\n",command);  
+    fprintf(stderr, "simscan[%ld]: sending command [%s]\n",getppid(),command);  
   }
 
   if (retvalue == 0 && write(sock, command, strlen(command)) < 0 ) {
@@ -1728,31 +1749,31 @@
     if (buffer[0] == '1') {
       strncpy(VirusName,buffer+2,sizeof(VirusName)); 
       if ( DebugFlag > 0 ) {
-        fprintf(stderr, "simscan: trophie, virus found [%s]\n",VirusName);  
+        fprintf(stderr, "simscan[%ld]: trophie, virus found [%s]\n",getppid(),VirusName);  
       }
       retvalue=1;
     } else if (!strncmp(buffer, "-1", 2)) {
-      if ( DebugFlag > 0 ) fprintf(stderr, "simscan: trophie, error scanning file!\n"); 
+      if ( DebugFlag > 0 ) fprintf(stderr, "simscan[%ld]: trophie, error scanning file!\n",getppid()); 
       retvalue=5;
     } else if (!strncmp(buffer, "-2", 2)) {
-      if ( DebugFlag > 0 ) fprintf(stderr, "simscan: trophie, error scanning file!\n"); 
+      if ( DebugFlag > 0 ) fprintf(stderr, "simscan[%ld]: trophie, error scanning file!\n",getppid()); 
       retvalue=5;
     } else {
       if ( DebugFlag > 1 ) {
-        fprintf(stderr, "simscan: trophie, file clean\n");  
+        fprintf(stderr, "simscan[%ld]: trophie, file clean\n",getppid());  
       }
       retvalue=0;
     }
   } else if (retvalue == 0) {
     if ( DebugFlag > 0 ) {
-      fprintf(stderr, "simscan: trophie, error reading from socket\n");  
+      fprintf(stderr, "simscan[%ld]: trophie, error reading from socket\n",getppid());  
     }
     retvalue=4;
   }
   
   close(sock);
   if ( DebugFlag > 1 ) {
-    fprintf(stderr, "simscan: trophie ending, retvalue = %d\n", retvalue);  
+    fprintf(stderr, "simscan[%ld]: trophie ending, retvalue = %ld\n", getppid(), retvalue);  
   }
 
 #ifdef ENABLE_RECEIVED
@@ -1835,11 +1856,11 @@
   utime=SECS(stop)-SECS(start);
 
   if ( spam == 1 ) {
-    fprintf(stderr, "simscan:[%d]:%s (%.2f/%.2f):%s:%3.4f:%s:%s:%s",
+    fprintf(stderr, "simscan:[%ld]:%s (%.2f/%.2f):%s:%3.4f:%s:%s:%s",
       getppid(), state, SpamHits, ReqHits, subject, utime, 
       getenv("TCPREMOTEIP"), MailFrom, RcptTo[0]);
   } else {
-    fprintf(stderr, "simscan:[%d]:%s:%s:%3.4f:%s:%s:%s",
+    fprintf(stderr, "simscan:[%ld]:%s:%s:%3.4f:%s:%s:%s",
       getppid(),state, subject,utime,getenv("TCPREMOTEIP"),MailFrom,RcptTo[0]);
   }
 
--- ../simscan-1.2.orig/simscanmk.c	2005-09-27 14:14:58.000000000 -0400
+++ simscanmk.c	2006-11-10 11:36:02.230000000 -0500
@@ -72,10 +72,12 @@
   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();
+  int xcode = make_cdb();
+  if (xcode != 0) exit(xcode);
 #ifdef ENABLE_RECEIVED
   }
 #endif
@@ -369,6 +371,7 @@
  static char input[MAX_LINE];
  uint32 h;
 
+ sleep(0); /* some NFS timing crazyness on solaris jk 20061108 */
 
   if ( (fs = fopen(ClearFile,"r")) == NULL) {
     printf("Not building simcontrol.cdb file. No %s/simcontrol text file\n",
@@ -454,7 +457,7 @@
   snprintf(ClearFile, sizeof(ClearFile), "%s/simcontrol", CONTROLDIR);
   snprintf(CdbFile, sizeof(CdbFile), "%s/simcontrol.cdb", CONTROLDIR);
 
-  snprintf(CdbTmpFile, sizeof(CdbTmpFile), "%s/ss.cdb.tmp.%d", 
+  snprintf(CdbTmpFile, sizeof(CdbTmpFile), "%s/ss.cdb.tmp.%ld", 
     CONTROLDIR, getpid());
 
   errflag = 0;
