MailScanner temporary files not deleted

MikeM michaelm12-asfbugzilla at aquaorange.net
Wed Jul 3 10:04:31 IST 2013


Hi,

Attached is a patch which helps to avoid the various temporary files 
left lying around by MailScanner in /tmp and 
/var/spool/MailScanner/incoming/SpamAssassin-Temp

They tend to be named:
     /tmp/tmp.XXXXXXXXXX
     /var/spool/MailScanner/incoming/SpamAssassin-Temp/tmp.XXXXXXXXXX
/var/spool/MailScanner/incoming/SpamAssassin-Temp/MailScanner.LastSpam.XXXXXX
/var/spool/MailScanner/incoming/SpamAssassin-Temp/MailScanner.XXXXXX

The patch also disables the mcafee (old not version 6) virus scanner (in 
etc/virus.scanners.conf) which should no longer be being used. By 
leaving it included the detection routines will increase your server's 
load unnecessarily if you have the McAfee v6 scanner installed.

Many thanks,
Mike

-------------- next part --------------
diff -ur MailScanner-4.84.5-3-orig/etc/virus.scanners.conf MailScanner/etc/virus.scanners.conf
--- MailScanner-4.84.5-3-orig/etc/virus.scanners.conf	2013-07-02 19:57:15.649957030 +0100
+++ MailScanner/etc/virus.scanners.conf	2013-07-02 20:24:54.927741681 +0100
@@ -36,7 +36,8 @@
 kaspersky-4.5	/opt/MailScanner/lib/kaspersky-wrapper	/opt/kav
 kaspersky	/opt/MailScanner/lib/kaspersky-wrapper	/opt/AVP
 kavdaemonclient	/opt/MailScanner/lib/kavdaemonclient-wrapper /usr/local
-mcafee		/opt/MailScanner/lib/mcafee-wrapper	/usr/local/uvscan
+##mcafee pre-verion6 should not be used. Not DAT updates anymore
+##mcafee		/opt/MailScanner/lib/mcafee-wrapper	/usr/local/uvscan
 mcafee6		/opt/MailScanner/lib/mcafee6-wrapper	/usr/local/uvscan
 # Now updated to handle nod32 2.01 and upwards
 #nod32-1.99	/opt/MailScanner/lib/nod32-wrapper	/usr/local/nod32
diff -ur MailScanner-4.84.5-3-orig/lib/bitdefender-wrapper MailScanner/lib/bitdefender-wrapper
--- MailScanner-4.84.5-3-orig/lib/bitdefender-wrapper	2011-08-20 13:20:04.000000000 +0100
+++ MailScanner/lib/bitdefender-wrapper	2013-07-02 18:57:17.205996644 +0100
@@ -55,13 +55,15 @@
 fi
 
 if [ "x$1" = "x-IsItInstalled" ]; then
+  rm -f $LogFile
   [ -x ${PackageDir}/$prog ] && exit 0
   exit 1
 fi
 
 umask 077
-rm -f $LogFile
+#rm -f $LogFile # We don't delete here, possible race condition. It's empty!
 ${PackageDir}/$prog --log=$LogFile $extras "$@" >/dev/null 2>&1
 cat $LogFile
 rm -f $LogFile
 exit 0
+
diff -ur MailScanner-4.84.5-3-orig/lib/clamav-wrapper MailScanner/lib/clamav-wrapper
--- MailScanner-4.84.5-3-orig/lib/clamav-wrapper	2011-08-20 13:32:02.000000000 +0100
+++ MailScanner/lib/clamav-wrapper	2013-07-02 19:06:32.353402229 +0100
@@ -52,7 +52,7 @@
 # You may want to check this script for bash-isms
 
 #TempDir="/tmp/clamav.$$"
-TempDir=$(mktemp) || { echo "$0: Cannot make name for temporary dir" >&2; exit 1; }
+TempDir=$(mktemp -d) || { echo "$0: Cannot make temporary dir" >&2; exit 1; }
 ClamUser="clamav"
 ClamGroup="clamav"
 
@@ -132,6 +132,7 @@
 fi
 
 if [ "x$1" = "x-IsItInstalled" ]; then
+  rm -rf ${TempDir} >/dev/null 2>&1
   [ -x $ClamScan ] && exit 0
   exit 1
 fi
@@ -140,32 +141,23 @@
 PATH=$PATH:/usr/ucb
 export PATH
 
-# Check if the tmpdir exists, if so delete so we start with a clean slate
-if [ -x "${TempDir}" ]; then
-	rm -rf ${TempDir} >/dev/null 2>&1
-fi
-
-# Make the Temp dir
-umask 0077
-mkdir "${TempDir}" >/dev/null 2>&1
-
 # In case we get interupted....
 trap "rm -rf ${TempDir}" EXIT
 
-if [ $? ]; then 
+if [ -d "${TempDir}" ]
   ExtraScanOptions="$ExtraScanOptions --tempdir=${TempDir}"
   # If we are root chown it to the clamav user/group
   if [ `whoami` = "root" ]; then
     chown ${ClamUser}:${ClamGroup} "${TempDir}"
   fi
- fi
+fi
 
 $ClamScan $ExtraScanOptions $ScanOptions "$@"
 
 retval=$?
 
 #Clean up the temp directory
-if [ -x "${TempDir}" ]; then
+if [ -e "${TempDir}" ]; then
 	rm -rf ${TempDir}
 fi
 trap '' EXIT
diff -ur MailScanner-4.84.5-3-orig/lib/kaspersky-wrapper MailScanner/lib/kaspersky-wrapper
--- MailScanner-4.84.5-3-orig/lib/kaspersky-wrapper	2011-08-20 13:32:02.000000000 +0100
+++ MailScanner/lib/kaspersky-wrapper	2013-07-02 19:18:04.057323885 +0100
@@ -45,11 +45,12 @@
   Report=$(mktemp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
   ScanOptions="-xp -i0" # Don't report progress, don't attempt to clean
   if [ "x$1" = "x-IsItInstalled" ]; then
+    rm -f ${Report}
     exit 0
   fi
 
   Args=`echo "$@" | sed -e 's/ -I/ -i/g; s/^-I/-i/g; s/-- / /g;'`
-  rm -f $Report
+  #rm -f $Report ##Don't delete - possible race condition. Already empty.
   # 29/09/05 JKF Removed -j3 on advice from Kaspersky users
   ${PackageDir}/$Scanner $ScanOptions -o$Report -q "$@"
   cat $Report
@@ -64,11 +65,12 @@
   Report=$(mktemp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
   ScanOptions="-xp -i0" # Don't report progress, don't attempt to clean
   if [ "x$1" = "x-IsItInstalled" ]; then
+    rm -f ${Report}
     exit 0
   fi
 
   Args=`echo "$@" | sed -e 's/ -I/ -i/g; s/^-I/-i/g; s/-- / /g;'`
-  rm -f $Report
+  #rm -f $Report ##Don't delete - possible race condition. Already empty.
   # 29/09/05 JKF Removed -j3 on advice from Kaspersky users
   ${PackageDir}/$Scanner $ScanOptions -o$Report -q "$@"
   cat $Report
@@ -83,11 +85,12 @@
   Report=$(mktemp) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
   ScanOptions="-xp -i0" # Don't report progress, don't attempt to clean
   if [ "x$1" = "x-IsItInstalled" ]; then
+    rm -f ${Report}
     exit 0
   fi
 
   Args=`echo "$@" | sed -e 's/ -I/ -i/g; s/^-I/-i/g; s/-- / /g;'`
-  rm -f $Report
+  #rm -f $Report ##Don't delete - possible race condition. Already empty.
   # 29/09/05 JKF Removed -j3 on advice from Kaspersky users
   ${PackageDir}/$Scanner $ScanOptions -o$Report -q "$@"
   cat $Report
diff -ur MailScanner-4.84.5-3-orig/lib/MailScanner/CustomFunctions/LastSpam.pm MailScanner/lib/MailScanner/CustomFunctions/LastSpam.pm
--- MailScanner-4.84.5-3-orig/lib/MailScanner/CustomFunctions/LastSpam.pm	2011-08-20 13:24:49.000000000 +0100
+++ MailScanner/lib/MailScanner/CustomFunctions/LastSpam.pm	2013-07-02 20:17:34.388358859 +0100
@@ -32,7 +32,7 @@
 my $Debug = 0; # Set to 1 to enable debug output to STDERR
 #my $tmpfilename = "/tmp/MailScanner.LastSpam.$$.conf"; # Temp MS.conf file
 # Temp MS.conf file
-my($tmpfh, $tmpfilename) = tempfile("MailScanner.LastSpam.XXXXXX", TMPDIR => 1, UNLINK => 0);
+my($tmpfh, $tmpfilename) = tempfile("MailScanner.LastSpam.XXXXXX", TMPDIR => 1, UNLINK => 1);
 my %modtime = (); # Time domain list magic word file was last changed
 my %filename = (); # Map Config option to magic word file
 my %magicwords = {}; # Map Config option --> domains --> magic words
diff -ur MailScanner-4.84.5-3-orig/lib/MailScanner/CustomFunctions/Ruleset-from-Function.pm MailScanner/lib/MailScanner/CustomFunctions/Ruleset-from-Function.pm
--- MailScanner-4.84.5-3-orig/lib/MailScanner/CustomFunctions/Ruleset-from-Function.pm	2011-08-20 13:25:42.000000000 +0100
+++ MailScanner/lib/MailScanner/CustomFunctions/Ruleset-from-Function.pm	2013-07-02 20:19:01.571397055 +0100
@@ -31,7 +31,7 @@
 
 my $Debug = 0; # Set to 1 to enable debug output to STDERR
 #my $tmpfilename = "/tmp/MailScanner.$$.conf"; # Temp MS.conf file
-my($tmpfh, $tmpfilename) = tempfile("MailScanner.XXXXXX", TMPDIR => 1, UNLINK => 0);
+my($tmpfh, $tmpfilename) = tempfile("MailScanner.XXXXXX", TMPDIR => 1, UNLINK => 1);
 
 
 


More information about the MailScanner mailing list