From 89c18c181ddacb178888285fc9c5793a7d9ed5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Wed, 6 Nov 2002 10:54:41 +0000 Subject: [PATCH] clamav plugin git-svn-id: https://svn.perl.org/qpsmtpd/trunk@97 958fd67b-6ff1-0310-b445-bb7760255be9 --- Changes | 4 ++++ plugins/clamav | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 plugins/clamav diff --git a/Changes b/Changes index dbc30cc..d15630a 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,10 @@ 0.12 - 2002/10/17 + clamav plugin, thanks to Matt Sergeant, matt@sergeant.org. + Enabling this might require you to increase your memory limits in + the run file. http://www.clamav.org/ + Better error messages when a plugin fails Remove some debug messages in the log diff --git a/plugins/clamav b/plugins/clamav new file mode 100644 index 0000000..f5bfeea --- /dev/null +++ b/plugins/clamav @@ -0,0 +1,52 @@ +#!/usr/bin/perl -w +# Clam-AV plugin. + +use File::Temp qw(tempfile); + +sub register { + my ($self, $qp) = @_; + $self->register_hook("data_post", "clam_scan"); +} + +sub clam_scan { + my ($self, $transaction) = @_; + + my ($temp_fh, $filename) = tempfile(); + print $temp_fh $transaction->header->as_string; + print $temp_fh "\n"; + while (my $line = $transaction->body_getline) { + print $temp_fh $line; + } + seek($temp_fh, 0, 0); + + # Now do the actual scanning! + my $cmd = "/usr/local/bin/clamscan --stdout -i --max-recursion=50 --disable-summary $filename 2>&1"; + $self->log(1, "Running: $cmd"); + my $output = `$cmd`; + + my $result = ($? >> 8); + my $signal = ($? & 127); + + unlink($filename); + chomp($output); + + $output =~ s/^.* (.*) FOUND$/$1 /mg; + + $self->log(1, "clamscan results: $output"); + + if ($signal) { + $self->log(1, "clamscan exited with signal: $signal"); + return (DECLINED); + } + if ($result == 1) { + $self->log(1, "Virus(es) found"); + # return (DENY, "Virus Found: $output"); + $transaction->header->add('X-Virus-Found', 'Yes'); + $transaction->header->add('X-Virus-Details', $output); + } + elsif ($result) { + $self->log(1, "ClamAV error: $result\n"); + } + $transaction->header->add('X-Virus-Checked', 'Checked'); + return (DECLINED); +}