| 1 |
#!perl -w |
| 2 |
|
| 3 |
=head1 NAME |
| 4 |
|
| 5 |
bitdefender -- BitDefender Linux Edition antivirus plugin for qpsmtpd |
| 6 |
|
| 7 |
=head1 DESCRIPTION |
| 8 |
|
| 9 |
This plugin scans incoming mail with the BitDefender Linux Edition scanner, |
| 10 |
and can at your option reject or flag infected messages. |
| 11 |
|
| 12 |
=head1 CONFIGURATION |
| 13 |
|
| 14 |
=over 4 |
| 15 |
|
| 16 |
=item B<bitdefender_location> |
| 17 |
|
| 18 |
Full path to the BitDefender binary and all signature files; defaults to |
| 19 |
/opt/bdc/bdc. |
| 20 |
|
| 21 |
=item B<deny_viruses> |
| 22 |
|
| 23 |
Whether the scanner will automatically delete messages which have viruses. |
| 24 |
Takes either 'yes' or 'no' (defaults to 'yes'). |
| 25 |
|
| 26 |
=item B<max_size> |
| 27 |
|
| 28 |
Maximum size in kilobytes for messages which will be scanned; defaults to 128k; |
| 29 |
|
| 30 |
=back |
| 31 |
|
| 32 |
=head1 DEPENDENCIES |
| 33 |
|
| 34 |
=over 4 |
| 35 |
|
| 36 |
=item B<BitDefender> |
| 37 |
|
| 38 |
The BitDefender Linux Edition is available to use, free of charge, from |
| 39 |
this link: |
| 40 |
|
| 41 |
<http://www.bitdefender.com/bd/site/products.php?p_id=16> |
| 42 |
|
| 43 |
Please read the documentation for configuring automatic updates of the |
| 44 |
virus profiles. |
| 45 |
|
| 46 |
=back |
| 47 |
|
| 48 |
=head1 AUTHOR |
| 49 |
|
| 50 |
John Peacock <[email protected]> |
| 51 |
|
| 52 |
=head1 COPYRIGHT AND LICENSE |
| 53 |
|
| 54 |
Copyright (c) 2004 John Peacock |
| 55 |
|
| 56 |
Based lightly on the clamav plugin |
| 57 |
|
| 58 |
This plugin is licensed under the same terms as the qpsmtpd package itself. |
| 59 |
Please see the LICENSE file included with qpsmtpd for details. |
| 60 |
|
| 61 |
=cut |
| 62 |
|
| 63 |
use strict; |
| 64 |
use warnings; |
| 65 |
|
| 66 |
use File::Path; |
| 67 |
use Qpsmtpd::Constants; |
| 68 |
|
| 69 |
sub register { |
| 70 |
my ($self, $qp, @args) = @_; |
| 71 |
|
| 72 |
while (@args) { |
| 73 |
$self->{"_bitd"}->{pop @args} = pop @args; |
| 74 |
} |
| 75 |
$self->{"_bitd"}->{"bitdefender_location"} ||= "/opt/bdc/bdc"; |
| 76 |
$self->{"_bitd"}->{"deny_viruses"} ||= "yes"; |
| 77 |
$self->{"_bitd"}->{"max_size"} ||= 128; |
| 78 |
$self->{"_bitd"}->{"max_size"} *= 1024; |
| 79 |
} |
| 80 |
|
| 81 |
sub hook_data_post { |
| 82 |
my ($self, $transaction) = @_; |
| 83 |
|
| 84 |
if ($transaction->data_size > $self->{"_bitd"}->{"max_size"}) { |
| 85 |
$self->log(LOGWARN, |
| 86 |
'Mail too large to scan (' |
| 87 |
. $transaction->data_size . " vs " |
| 88 |
. $self->{"_bitd"}->{"max_size"} . ")" |
| 89 |
); |
| 90 |
return (DECLINED); |
| 91 |
} |
| 92 |
|
| 93 |
# Ignore non-multipart emails |
| 94 |
my $content_type = $transaction->header->get('Content-Type'); |
| 95 |
$content_type =~ s/\s/ /g if defined $content_type; |
| 96 |
unless ( $content_type |
| 97 |
&& $content_type =~ m!\bmultipart/.*\bboundary="?([^"]+)!i) |
| 98 |
{ |
| 99 |
$self->log(LOGERROR, "non-multipart mail - skipping"); |
| 100 |
return DECLINED; |
| 101 |
} |
| 102 |
|
| 103 |
my $filename = $transaction->body_filename; |
| 104 |
unless (defined $filename) { |
| 105 |
$self->log(LOGERROR, "didn't get a filename"); |
| 106 |
return DECLINED; |
| 107 |
} |
| 108 |
|
| 109 |
# Now do the actual scanning! |
| 110 |
open my $bdc, "-|", |
| 111 |
$self->{"_bitd"}->{"bitdefender_location"} |
| 112 |
. " --mail --all --arc $filename"; |
| 113 |
|
| 114 |
my $output; |
| 115 |
while (<$bdc>) { |
| 116 |
if (/infected: (.+)$/) { |
| 117 |
$output = $1; |
| 118 |
last; |
| 119 |
} |
| 120 |
} |
| 121 |
close $bdc; |
| 122 |
|
| 123 |
if ($output) { |
| 124 |
$self->log(LOGINFO, "Virus(es) found: $output"); |
| 125 |
if ($self->{"_bitd"}->{"deny_viruses"} eq "yes") { |
| 126 |
return (DENY, "Virus Found: $output"); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
return (DECLINED); |
| 131 |
} |
| 132 |
|