Discussion:
MailScanner temporary files not deleted
MikeM
2013-07-03 09:04:31 UTC
Permalink
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);
Stephen Cox
2013-07-09 06:28:13 UTC
Permalink
On Wed, Jul 3, 2013 at 11:04 AM, MikeM <
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
Mike,

Thank you for the patch. Can you please open a pull request on github.

Regards,
Stephen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.mailscanner.info/pipermail/mailscanner/attachments/20130709/cb7190d1/attachment.html
Mark Sapiro
2013-07-10 02:43:19 UTC
Permalink
Post by Stephen Cox
On Wed, Jul 3, 2013 at 11:04 AM, MikeM
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
Mike,
Thank you for the patch. Can you please open a pull request on github.
Regards,
Stephen
Patches for this issue were committed in GitHub a year ago. See
<https://github.com/MailScanner/MailScanner/commit/3765b8b20e3d6166734fc923a1d00ea04918f2da>.
--
Mark Sapiro <mark at msapiro.net> The highway is for gamblers,
San Francisco Bay Area, California better use your sense - B. Dylan
MikeM
2013-07-15 11:09:08 UTC
Permalink
Hi,

Please note that the commit below does not include all the changes from
my patch.

Regards,
Mike
Post by Mark Sapiro
Post by Stephen Cox
On Wed, Jul 3, 2013 at 11:04 AM, MikeM
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
Mike,
Thank you for the patch. Can you please open a pull request on github.
Regards,
Stephen
Patches for this issue were committed in GitHub a year ago. See
<https://github.com/MailScanner/MailScanner/commit/3765b8b20e3d6166734fc923a1d00ea04918f2da>.
Mark Sapiro
2013-07-16 21:41:53 UTC
Permalink
Post by MikeM
Hi,
Please note that the commit below does not include all the changes from
my patch.
That's true, but there were several other commits on this issue around
that time. See the May 29 and June 4 commits at
<https://github.com/MailScanner/MailScanner/commits/master>, or better
yet, can you look at

<https://github.com/MailScanner/MailScanner/blob/master/mailscanner/lib/bitdefender-wrapper>
<https://github.com/MailScanner/MailScanner/blob/master/mailscanner/lib/clamav-wrapper>
<https://github.com/MailScanner/MailScanner/blob/master/mailscanner/lib/kaspersky-wrapper>
<https://github.com/MailScanner/MailScanner/blob/master/mailscanner/bin/MailScanner/CustomFunctions/Ruleset-from-Function.pm>

and see what if anything is missing from those? As far as I can tell,
those have fixed this issue for me and the only parts of your patch that
are new are the patches to MailScanner/etc/virus.scanners.conf and
MailScanner/CustomFunctions/LastSpam.pm.

The LastSpam.pm file doesn't even exist in my 4.84.5-3 installation.

I think it would still be appropriate to create a patch for only those
things which are still not addressed in the master at
<https://github.com/MailScanner/MailScanner> and open a pull request.
--
Mark Sapiro <mark at msapiro.net> The highway is for gamblers,
San Francisco Bay Area, California better use your sense - B. Dylan
Loading...