File: clamav-wrapper

package info (click to toggle)
mailscanner 4.79.11-2.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,820 kB
  • ctags: 1,309
  • sloc: perl: 25,655; sh: 2,666; xml: 624; makefile: 242
file content (179 lines) | stat: -rwxr-xr-x 6,253 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/sh

# clamav-wrapper --	invoke ClamAV for use with mailscanner
#
# Adrian Bridgett <adrian@smop.co.uk>, 14/12/01
#
#   MailScanner - SMTP E-Mail Virus Scanner
#   Copyright (C) 2001  Julian Field
#
#   $Id: clamav-wrapper 4538 2008-09-05 08:55:18Z sysjkf $
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#   The author, Julian Field, can be contacted by email at
#      Jules@JulianField.net
#   or by paper mail at
#      Julian Field
#      Dept of Electronics & Computer Science
#      University of Southampton
#      Southampton
#      SO17 1BJ
#      United Kingdom
#
#
# Modifications by Kevin Spicer <kevin@kevinspicer.co.uk> to get
# external unpackers working correctly.  9 Nov 2003
# Removed --unzip from ScanOptions, as its already in ExtraScanOptions
# (Clam usually uses own unzipper, -unzip just allows it to use external
# program so should be in ExtraScanOptions as it could cause a failure)
# Separate all unpackers and add missing ones.
# Add tmpdir (and check for it) in MailScanner incoming dir 
# (to take advantage of ramdisk) - needed by external unpacker

######  IF YOU ARE RUNNING MAILSCANNER AS ROOT ######
# You need to set the following in MailScanner.conf so that external 
# unpackers can be used...
#   Incoming Work Group = clamav
#   Incoming Work Permissions = 0640

# You may want to check this script for bash-isms

TempDir=$(tempfile) || { echo "$0: Cannot make name for temporary dir" >&2; exit 1;  }
ClamUser="clamav"
ClamGroup="clamav"

ScanOptions=""
ExtraScanOptions=""

# Extra options we try to pass to clam but we handle it failing
# For each option there are two alternatives...
# --option   # if the required program is in the PATH
# --option=/path/to/program  # If its in a non standard location
# If you use the second option make sure you set the correct path in each case

# Note that clam internally supports Zip, Gzip and Rar (v2.0) files,
# so for these the extra options are just a fallback should the internal 
# unpacker fail (the internal unzipper should also support .jar files).

# Common external unpackers you probably have installed (hence 
# enabled by default)
# Uncomment ONE of the following lines if you have unzip installed
#ExtraScanOptions="$ExtraScanOptions --unzip"  
#ExtraScanOptions="$ExtraScanOptions --unzip=/path/to/unzip" 

# Uncomment ONE of the following lines if you have unzip installed
# And want to be able to use it to scan jar files should the internal
# unzipper fail
#ExtraScanOptions="$ExtraScanOptions --jar"  
#ExtraScanOptions="$ExtraScanOptions --jar=/path/to/unzip" 

# Uncomment ONE of the following lines if you have tar installed 
#ExtraScanOptions="$ExtraScanOptions --tar"  
#ExtraScanOptions="$ExtraScanOptions --tar=/path/to/tar" 

# Uncomment ONE of the following lines if you have tar installed 
# AND it is GNU tar with gzip support
#ExtraScanOptions="$ExtraScanOptions --tgz"  
#ExtraScanOptions="$ExtraScanOptions --tgz=/path/to/tar" 

# Uncomment ONE of the following lines if you have tar installed and
# want to scan debian .deb packages
# Must be GNU tar with gzip support
#ExtraScanOptions="$ExtraScanOptions --deb"  
#ExtraScanOptions="$ExtraScanOptions --deb=/path/to/tar" 

# LESS COMMON unpackers, which probably aren't installed by default
# (hence disabled)
# Uncomment ONE of the following lines if you have unrar installed
#ExtraScanOptions="$ExtraScanOptions --unrar"  
#ExtraScanOptions="$ExtraScanOptions --unrar=/path/to/unrar" 

# Uncomment ONE of the following lines if you have unarj installed
#ExtraScanOptions="$ExtraScanOptions --unarj"  
#ExtraScanOptions="$ExtraScanOptions --unarj=/path/to/unarj" 

# Uncomment ONE of the following lines if you have unace installed
#ExtraScanOptions="$ExtraScanOptions --unace"  
#ExtraScanOptions="$ExtraScanOptions --unace=/path/to/unace" 

# Uncomment ONE of the following lines if you have lha installed
#ExtraScanOptions="$ExtraScanOptions --lha"  
#ExtraScanOptions="$ExtraScanOptions --lha=/path/to/lha" 

# Uncomment ONE of the following lines if you have zoo installed
#ExtraScanOptions="$ExtraScanOptions --zoo"  
#ExtraScanOptions="$ExtraScanOptions --zoo=/path/to/unzoo" 

# Now increase the allowed expansion size of zip files
# Removed in ClamAV 0.93: ExtraScanOptions="$ExtraScanOptions --max-ratio=500"

# Uncomment next line if you need to disable Clam's DoS protection
#ExtraScanOptions="--max-files=0 --max-space=0 --max-recursion=0 $ExtraScanOptions"

ClamScan=$1/bin/clamscan
shift

if [ ! -x $ClamScan ]; then
  ClamScan=/usr/bin/clamscan
fi

if [ "x$1" = "x-IsItInstalled" ]; then
  [ -x $ClamScan ] && exit 0
  exit 1
fi

# Add this for Solaris users so they can find whoami
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 
  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

$ClamScan $ExtraScanOptions $ScanOptions "$@"

retval=$?

#Clean up the temp directory
if [ -x "${TempDir}" ]; then
	rm -rf ${TempDir}
fi
trap '' EXIT

if [ "$retval" = "40" ]; then
  # Clam complained we passed an illegal command-line option
	# (As this calls without external unpackers the temp dir isn't used)
  exec $ClamScan $ScanOptions "$@"
else
  exit $retval
fi