When the plugin was changed to use the qpsmtp transaction temp file, this broke the tmp_dir option. The patch below fixes this bug and allows the files to be scanned to be written outside ~smtpd/tmp.
--- qpsmtpd-0.32/plugins/virus/clamav 2006-02-26 06:22:16.000000000 -0600
+++ qpsmtpd/plugins/virus/clamav 2006-10-24 10:41:50.000000000 -0500
@@ -101,6 +101,7 @@ Please see the LICENSE file included wit
=cut
+use File::Temp qw(tempfile);
use strict;
use warnings;
@@ -136,22 +137,13 @@ sub register {
}
$self->{_max_size} ||= 512 * 1024;
- $self->{_spool_dir} ||= $self->spool_dir();
$self->{_back_compat} ||= ''; # make sure something is set
- unless ($self->{_spool_dir}) {
- $self->log(LOGERROR, "No spool dir configuration found");
- return undef;
- }
- unless (-d $self->{_spool_dir}) {
- $self->log(LOGERROR, "Spool dir $self->{_spool_dir} does not
exist");
- return undef;
- }
-
}
sub hook_data_post {
my ($self, $transaction) = @_;
+ my $filename;
if ($transaction->body_size > $self->{_max_size}) {
$self->log(LOGWARN, 'Mail too large to scan ('.
@@ -159,16 +151,35 @@ sub hook_data_post {
return (DECLINED);
}
- my $filename = $transaction->body_filename;
- unless (defined $filename) {
- $self->log(LOGWARN, "didn't get a filename");
- return DECLINED;
- }
- my $mode = (stat($self->{_spool_dir}))[2];
- if ( $mode & 07077 ) { # must be sharing spool directory with external
app
+ if (defined $self->{_spool_dir}) {
+ my $temp_fh;
+ ($temp_fh, $filename) = tempfile( 'clamavXXXXX', DIR =>
$self->{_spool_dir} );
+ chmod 0644, $filename;
+ if (! defined $temp_fh) {
+ $self->log(LOGERROR, "OUCH: undefined filehandle; NOT SCANNING");
+ return (DECLINED);
+ }
+ print $temp_fh "From ", $transaction->sender->format
+ . " " . gmtime(time) . "\n";
+ print $temp_fh $transaction->header->as_string;
+ print $temp_fh "\n";
+ $transaction->body_resetpos;
+ while (my $line = $transaction->body_getline) {
+ print $temp_fh $line;
+ }
+ seek($temp_fh, 0, 0);
+ } else {
+ $filename = $transaction->body_filename;
+ unless (defined $filename) {
+ $self->log(LOGWARN, "didn't get a filename");
+ return DECLINED;
+ }
+ my $mode = (stat($self->spool_dir()))[2];
+ if ( $mode & 07077 ) { # must be sharing spool directory with ext app
$self->log(LOGWARN,
"Changing permissions on file to permit scanner access");
chmod $mode, $filename;
+ }
}
# Now do the actual scanning!
@@ -181,6 +192,10 @@ sub hook_data_post {
my $result = ($? >> 8);
my $signal = ($? & 127);
+ if (defined $self->{_spool_dir}) {
+ unlink($filename);
+ }
+
chomp($output);
$output =~ s/^.* (.*) FOUND$/$1 /mg;
clamav.diff
Description: Binary data
