spamassassin-clamav: Initial version of role
This commit is contained in:
parent
8cea9f7e5f
commit
757553ef89
4 changed files with 146 additions and 0 deletions
115
roles/spamassassin-clamav/files/ClamAV.pm
Normal file
115
roles/spamassassin-clamav/files/ClamAV.pm
Normal file
|
@ -0,0 +1,115 @@
|
|||
|
||||
=head1 NAME
|
||||
|
||||
ClamAV - ClamAV anti-virus check
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
loadplugin Mail::SpamAssassin::Plugin::ClamAV
|
||||
|
||||
full CLAMAV eval:check_clamav()
|
||||
score CLAMAV 5
|
||||
|
||||
add_header all Virus _CLAMAV_
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This plugin sends the mail to locally running ClamAV daemon for virus
|
||||
detection.
|
||||
|
||||
=cut
|
||||
|
||||
package Mail::SpamAssassin::Plugin::ClamAV;
|
||||
|
||||
use Mail::SpamAssassin::Plugin;
|
||||
use Mail::SpamAssassin::Logger;
|
||||
|
||||
use IO::Socket::UNIX;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use vars qw(@ISA);
|
||||
@ISA = qw(Mail::SpamAssassin::Plugin);
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $mailsa = shift;
|
||||
|
||||
$class = ref($class) || $class;
|
||||
my $self = $class->SUPER::new($mailsa);
|
||||
bless ($self, $class);
|
||||
|
||||
dbg("ClamAV: Registering ClamAV plugin rules");
|
||||
$self->register_eval_rule("check_clamav");
|
||||
|
||||
$self->set_config($mailsa->{conf});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub set_config {
|
||||
my ($self, $conf) = @_;
|
||||
my @cmds;
|
||||
|
||||
=head1 ADMINISTRATOR SETTINGS
|
||||
|
||||
=over
|
||||
|
||||
=item clamav_socket STRING (default: /var/run/clamav/clamd.sock)
|
||||
|
||||
Full path to locally running ClamAV daemon socket.
|
||||
|
||||
=cut
|
||||
|
||||
push (@cmds, {
|
||||
setting => "clamav_socket",
|
||||
is_admin => 1,
|
||||
default => "/var/run/clamav/clamd.sock",
|
||||
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
|
||||
});
|
||||
|
||||
$conf->{parser}->register_commands(\@cmds);
|
||||
|
||||
}
|
||||
|
||||
sub check_clamav {
|
||||
my ($self, $permsg, $fulltext) = @_;
|
||||
|
||||
my $socket = IO::Socket::UNIX->new(
|
||||
Type => SOCK_STREAM,
|
||||
Peer => Mail::SpamAssassin::Util::untaint_file_path($permsg->{conf}->{clamav_socket})
|
||||
) or do {
|
||||
$permsg->set_tag("CLAMAV", "Error");
|
||||
info("ClamAV: Failed to connect socket, skipping virus check");
|
||||
return;
|
||||
};
|
||||
|
||||
$socket->send("nINSTREAM\n");
|
||||
$socket->send(pack("N", length($$fulltext)));
|
||||
$socket->send($$fulltext);
|
||||
$socket->send(pack("N", 0));
|
||||
|
||||
my $result = $socket->getline();
|
||||
if ($result =~ /^stream: (.+) FOUND/i) {
|
||||
info("ClamAV: Found virus " . $1);
|
||||
$permsg->set_tag("CLAMAV", $1);
|
||||
my $rulename = $permsg->get_current_eval_rule_name();
|
||||
$permsg->{conf}->{descriptions}->{$rulename} = "Found virus " . $1;
|
||||
$result = 1;
|
||||
} elsif ($result =~ /^(.*) ERROR/i) {
|
||||
$permsg->set_tag("CLAMAV", "Error");
|
||||
info("ClamAV: Error in scanning: " . $1);
|
||||
$result = 0;
|
||||
} else {
|
||||
$permsg->set_tag("CLAMAV", "Clean");
|
||||
dbg("ClamAV: Message clean");
|
||||
$result = 0;
|
||||
}
|
||||
|
||||
$socket->send("QUIT\n");
|
||||
close $socket;
|
||||
return $result;
|
||||
}
|
||||
|
||||
1;
|
8
roles/spamassassin-clamav/files/clamav.cf
Normal file
8
roles/spamassassin-clamav/files/clamav.cf
Normal file
|
@ -0,0 +1,8 @@
|
|||
loadplugin Mail::SpamAssassin::Plugin::ClamAV ClamAV.pm
|
||||
|
||||
full CLAMAV eval:check_clamav()
|
||||
score CLAMAV 5
|
||||
|
||||
add_header all Virus _CLAMAV_
|
||||
|
||||
clamav_socket /run/clamd.scan/clamd.sock
|
4
roles/spamassassin-clamav/meta/main.yml
Normal file
4
roles/spamassassin-clamav/meta/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
|
||||
dependencies:
|
||||
- {role: clamav}
|
19
roles/spamassassin-clamav/tasks/main.yml
Normal file
19
roles/spamassassin-clamav/tasks/main.yml
Normal file
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
|
||||
- name: copy clamav plugin
|
||||
copy:
|
||||
src: ClamAV.pm
|
||||
dest: /etc/mail/spamassassin/ClamAV.pm
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: "{{ ansible_wheel }}"
|
||||
notify: restart spamassassin
|
||||
|
||||
- name: create spamassassin config
|
||||
copy:
|
||||
src: clamav.cf
|
||||
dest: /etc/mail/spamassassin/clamav.cf
|
||||
mode: 0644
|
||||
owner: root
|
||||
group: "{{ ansible_wheel }}"
|
||||
notify: restart spamassassin
|
Loading…
Add table
Reference in a new issue