~ubuntu-branches/ubuntu/raring/clamav/raring

« back to all changes in this revision

Viewing changes to unit_tests/check_clamd.sh

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Gran
  • Date: 2008-09-05 17:25:34 UTC
  • mfrom: (0.35.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080905172534-yi3f8fkye1o7u1r3
* New upstream version (closes: #497662, #497773)
  - lots of new options for clamd.conf
  - fixes CVEs CVE-2008-3912, CVE-2008-3913, CVE-2008-3914, and
    CVE-2008-1389
* No longer supports --unzip option, so typo is gone (closes: #496276)
* Translations:
  - sv (thanks Martin Bagge <brother@bsnet.se>) (closes: #491760)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh 
 
2
#set -x
 
3
killclamd() {
 
4
        test -f /tmp/clamd-test.pid || return
 
5
        pid=`cat /tmp/clamd-test.pid`
 
6
        kill -0 $pid && kill $pid
 
7
        pippo=0
 
8
        while test -f /tmp/clamd-test.pid; do
 
9
                sleep 1
 
10
                pippo=`expr $pippo + 1`
 
11
                if test $pippo -gt 9; then
 
12
                        kill -KILL $pid
 
13
                        rm /tmp/clamd-test.pid
 
14
                fi
 
15
        done
 
16
}
 
17
die() {
 
18
        killclamd
 
19
        rm -rf test-db test-clamd-viraction.conf test-clamd.log test-clamd-heur-pred.conf clamd-test.socket
 
20
        exit $1
 
21
}
 
22
run_clamd_test() {
 
23
        conf_file=$1
 
24
        shift
 
25
        rm -f clamdscan.log
 
26
        ../clamd/clamd -c $conf_file || { echo "Failed to start clamd!" >&2; die 1;}
 
27
        ../clamdscan/clamdscan --version --config-file $conf_file 2>&1|grep "^ClamAV" >/dev/null || { echo "clamdscan can't get version of clamd!" >&2; die 2;}
 
28
        ../clamdscan/clamdscan --quiet --config-file $conf_file $* --log=clamdscan.log
 
29
        if test $? = 2; then 
 
30
                echo "Failed to run clamdscan!" >&2;
 
31
                die 3;  
 
32
        fi
 
33
        killclamd
 
34
}
 
35
 
 
36
run_clamd_fdpass_test() {
 
37
        conf_file=$1
 
38
        shift
 
39
        rm -f clamdscan.log
 
40
        ../clamd/clamd -c $conf_file || { echo "Failed to start clamd!" >&2; die 1;}
 
41
        ../clamdscan/clamdscan --quiet --fdpass --config-file $conf_file - <$1 --log=clamdscan.log
 
42
        if test $? = 2; then
 
43
                echo "Failed to run clamdscan!" >&2;
 
44
                die 3;
 
45
        fi
 
46
        killclamd
 
47
}
 
48
 
 
49
mkdir -p test-db
 
50
cat <<EOF >test-db/test.hdb
 
51
aa15bcf478d165efd2065190eb473bcb:544:ClamAV-Test-File
 
52
EOF
 
53
cp $srcdir/input/daily.ftm test-db/
 
54
cp $srcdir/input/daily.pdb test-db/
 
55
 
 
56
# Test that all testfiles are detected
 
57
FILES=../test/clam*
 
58
run_clamd_test $srcdir/test-clamd.conf $FILES
 
59
NFILES=`ls -1 $FILES | wc -l`
 
60
NINFECTED=`grep "Infected files" clamdscan.log | cut -f2 -d:|sed -e 's/ //g'`
 
61
if test "$NFILES" -ne "0$NINFECTED"; then
 
62
        echo "clamd did not detect all testfiles correctly!" >&2;
 
63
        grep OK clamdscan.log >&2;
 
64
        die 4;
 
65
fi
 
66
 
 
67
# Test VirusEvent feature
 
68
cat <$srcdir/test-clamd.conf >test-clamd-viraction.conf
 
69
echo "VirusEvent `pwd`/$srcdir/virusaction-test.sh `pwd` \"Virus found: %v\"" >>test-clamd-viraction.conf
 
70
rm -f test-clamd.log
 
71
run_clamd_test test-clamd-viraction.conf ../test/clam.exe
 
72
grep "Virus found: ClamAV-Test-File.UNOFFICIAL" test-clamd.log >/dev/null 2>/dev/null; 
 
73
if test ! $? ; then
 
74
        echo "Virusaction test failed!" 
 
75
        cat test-clamd.log
 
76
        die 5;
 
77
fi
 
78
 
 
79
# Test HeuristicScanPrecedence feature
 
80
cat <$srcdir/test-clamd.conf >test-clamd-heur-pred.conf
 
81
run_clamd_test test-clamd-heur-pred.conf clam-phish-exe
 
82
grep "ClamAV-Test-File" clamdscan.log >/dev/null 2>/dev/null;
 
83
if test ! $?; then
 
84
        echo "HeuristicScanPrecedence off test failed!" >&2;
 
85
        cat clamdscan.log;
 
86
        die 6;
 
87
fi
 
88
echo "HeuristicScanPrecedence yes" >>test-clamd-heur-pred.conf
 
89
run_clamd_test test-clamd-heur-pred.conf clam-phish-exe
 
90
grep "Phishing.Heuristics.Email.SpoofedDomain" clamdscan.log >/dev/null 2>/dev/null;
 
91
if test ! $?; then
 
92
        echo "HeuristicScanPrecedence on test failed!" >&2;
 
93
        cat clamdscan.log;
 
94
        die 6;
 
95
fi
 
96
 
 
97
if grep "^#define HAVE_FD_PASSING 1" ../clamav-config.h >/dev/null; then
 
98
        run_clamd_fdpass_test $srcdir/test-clamd.conf ../test/clam.exe
 
99
        grep "ClamAV-Test-File" clamdscan.log >/dev/null 2>/dev/null;
 
100
        if test ! $?; then
 
101
                echo "FDpassing test failed!" >&2;
 
102
                cat clamdscan.log;
 
103
                die 7;
 
104
        fi
 
105
else
 
106
        echo "No FD passing support, skipping test"
 
107
fi
 
108
die 0;