Skip to content

Commit 60206e2

Browse files
committed
Work on using clamdscan for remote virus scanning
1 parent e2ee9ca commit 60206e2

File tree

5 files changed

+82
-6
lines changed

5 files changed

+82
-6
lines changed

Diff for: clamdscan-remote-wrapper.pl

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/local/bin/perl
2+
# Emulate the flags of clamdscan-stream-client
3+
4+
my $host;
5+
my $port = 3310;
6+
my $file = "-";
7+
while(@ARGV) {
8+
my $a = shift(@ARGV);
9+
if ($a eq "-d") {
10+
$host = shift(@ARGV);
11+
}
12+
elsif ($a eq "-p") {
13+
$port = shift(@ARGV);
14+
}
15+
elsif ($a eq "-" || $a !~ /^\-/) {
16+
# Input file
17+
$file = $a;
18+
}
19+
else {
20+
die "Unknown flag $a";
21+
}
22+
}
23+
24+
# Create a temporary config file
25+
my $cfile = "/tmp/clamdscan-remote-config-$$.conf";
26+
open(CONF, ">", $cfile);
27+
print CONF "TCPSocket $port\n";
28+
print CONF "TCPAddr $host\n";
29+
close(CONF);
30+
my $rv = system("clamdscan -c $cfile --fdpass --stream $file");
31+
unlink($cfile);
32+
exit($rv);
33+

Diff for: feature-mysql.pl

+16
Original file line numberDiff line numberDiff line change
@@ -2940,6 +2940,22 @@ sub delete_remote_mysql_module
29402940
unlink("$var_directory/module.infos.cache");
29412941
}
29422942

2943+
# get_remote_mysql_module(name)
2944+
# Returns a mysql module hash, looked up by hostname or socket file
2945+
sub get_remote_mysql_module
2946+
{
2947+
my ($name) = @_;
2948+
foreach my $mm (&list_remote_mysql_modules()) {
2949+
my $c = $mm->{'config'};
2950+
if ($c->{'sock'} && $name eq $c->{'sock'} ||
2951+
$c->{'host'} && $name eq $c->{'host'}.':'.($c->{'port'} || 3306) ||
2952+
$c->{'host'} && $name eq $c->{'host'}) {
2953+
return $mm;
2954+
}
2955+
}
2956+
return undef;
2957+
}
2958+
29432959
$done_feature_script{'mysql'} = 1;
29442960

29452961
1;

Diff for: feature-virus.pl

+24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sub check_depends_virus
88
sub init_virus
99
{
1010
$clam_wrapper_cmd = "$module_config_directory/clam-wrapper.pl";
11+
$clamdscan_remote_wrapper_cmd = "$module_config_directory/clamdscan-remote-wrapper.pl";
1112
}
1213

1314
# setup_virus(&domain)
@@ -330,6 +331,9 @@ sub get_domain_virus_scanner
330331
elsif ($rvs[0] eq &has_command("clamd-stream-client")) {
331332
$rv = "clamd-stream-client";
332333
}
334+
elsif ($rvs[0] eq $clamdscan_remote_wrapper_cmd) {
335+
$rv = "clamdscan-remote";
336+
}
333337
return $rv;
334338
}
335339
else {
@@ -358,11 +362,26 @@ sub save_domain_virus_scanner
358362
$prog = &has_command("clamd-stream-client");
359363
$prog .= &make_stream_client_args($config{'clamscan_host'});
360364
}
365+
elsif ($prog eq "clamdscan-remote") {
366+
$prog = $clamdscan_remote_wrapper_cmd;
367+
$prog .= &make_stream_client_args($config{'clamscan_host'});
368+
if (!-r $clamdscan_remote_wrapper_cmd) {
369+
&create_clamdscan_remote_wrapper_cmd();
370+
}
371+
}
361372
$clamrec[0]->{'action'} = "$clam_wrapper_cmd $prog";
362373
&procmail::modify_recipe($clamrec[0]);
363374
}
364375
}
365376

377+
# create_clamdscan_remote_wrapper_cmd()
378+
# Create a command to call clamdscan with a remote target in the /etc dir
379+
sub create_clamdscan_remote_wrapper_cmd
380+
{
381+
&copy_source_dest("$module_root_directory/clamdscan-remote-wrapper.pl",
382+
$clamdscan_remote_wrapper_cmd);
383+
}
384+
366385
# get_global_virus_scanner()
367386
# Returns the virus scanning program used by all domains, and possibly also
368387
# the clamd hostname
@@ -415,6 +434,11 @@ sub test_virus_scanner
415434
# Set remote host
416435
$fullcmd .= &make_stream_client_args($host);
417436
}
437+
elsif ($cmd eq "clamdscan-remote") {
438+
# Use actual wrapper and set remote host
439+
$fullcmd = $clamdscan_remote_wrapper_cmd." ".
440+
&make_stream_client_args($host);
441+
}
418442
else {
419443
# Tell command to use stdin
420444
if ($cmd eq "clamdscan") {

Diff for: modify-spam.pl

+3-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ package virtual_server;
161161
elsif ($a eq "--spam-no-delete-level") {
162162
$spamlevel = 0;
163163
}
164-
elsif ($a =~ /^--use-(clamscan|clamdscan)$/) {
164+
elsif ($a =~ /^--use-(clamscan|clamdscan|clamd-stream-client|clamdscan-remote)$/) {
165165
$virus_scanner = $1;
166166
}
167167
elsif ($a eq "--spamtrap") {
@@ -288,7 +288,8 @@ sub usage
288288
print " [--trashclear-none |\n";
289289
print " --trashclear-days days\n";
290290
print " --trashclear-size bytes]\n";
291-
print " [--use-clamscan | --use-clamdscan]\n";
291+
print " [--use-clamscan | --use-clamdscan |\n";
292+
print " --use-clamd-stream-client | --use-clamdscan-remote]\n";
292293
print " [--spamtrap | --no-spamtrap]\n";
293294
print "\n";
294295
print "Warning - modifying the SpamAssassin or virus scanning client for\n";

Diff for: set-spam.pl

+6-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ package virtual_server;
6868
elsif ($a eq "--no-spamc-max" || $a eq "--no-spam-max") {
6969
$spam_max = 0;
7070
}
71-
elsif ($a =~ /^--use-(clamscan|clamdscan|clamd-stream-client)$/) {
71+
elsif ($a =~ /^--use-(clamscan|clamdscan|clamd-stream-client|clamdscan-remote)$/) {
7272
$virus_scanner = $1;
7373
}
7474
elsif ($a eq "--use-virus") {
@@ -144,8 +144,9 @@ package virtual_server;
144144
# Make sure the new virus scanner works
145145
if ($virus_scanner || $virus_host) {
146146
local ($cmd, @args) = &split_quoted_string($new_virus_scanner);
147-
&has_command($cmd) ||
148-
&usage("Virus scanning command $cmd does not exist");
147+
local $shcmd = $cmd eq "clamdscan-remote" ? "clamdscan" : $cmd;
148+
&has_command($shcmd) ||
149+
&usage("Virus scanning command $shcmd does not exist");
149150
if (!$clamd || $new_virus_scanner ne "clamdscan") {
150151
# Only test if we aren't enabling clamd anyway
151152
$err = &test_virus_scanner($new_virus_scanner, $new_virus_host);
@@ -260,7 +261,8 @@ sub usage
260261
print " [--spamc-host hostname | --no-spamc-host]\n";
261262
print " [--spam-max bytes | --no-spam-max]\n";
262263
print " [--use-clamscan | --use-clamdscan |\n";
263-
print " --use-clamd-stream-client | --use-virus command]\n";
264+
print " --use-clamd-stream-client | --use-clamdscan-remote |\n";
265+
print " --use-virus command]\n";
264266
print " [--clamd-host hostname]\n";
265267
if (&check_clamd_status() >= 0) {
266268
print " [--enable-clamd | --disable-clamd]\n";

0 commit comments

Comments
 (0)