diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-07-06 17:36:26 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-07-06 17:36:26 -0400 |
commit | 2f3a279f68dcf8c1566d82419fc7257e162ee345 (patch) | |
tree | 6d906880657a3f68fb2c19cc5db8fb4b0bca50a9 /IkiWiki/Plugin | |
parent | 788c1e9eca84093b01d312e4d9f8e736ecc61ea9 (diff) |
add virus checking to attachments plugin
Diffstat (limited to 'IkiWiki/Plugin')
-rw-r--r-- | IkiWiki/Plugin/attachment.pm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index 2bb86b78d..cb762e453 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -333,6 +333,44 @@ sub match_mimetype ($$;@) { #{{{ } } #}}} +sub match_virusfree ($$;@) { #{{{ + shift; + my $wanted=shift; + + my %params=@_; + if (! exists $params{file}) { + return IkiWiki::FailReason->new("no file specified"); + } + + if (! exists $IkiWiki::config{virus_checker} || + ! length $IkiWiki::config{virus_checker}) { + return IkiWiki::FailReason->new("no virus_checker configured"); + } + + # The file needs to be fed into the virus checker on stdin, + # because the file is not world-readable, and if clamdscan is + # used, clamd would fail to read it. + eval q{use IPC::Open2}; + error($@) if $@; + open (IN, "<", $params{file}) || return IkiWiki::FailReason->new("failed to read file"); + binmode(IN); + my $sigpipe=0; + $SIG{PIPE} = sub { $sigpipe=1 }; + my $pid=open2(\*CHECKER_OUT, "<&IN", $IkiWiki::config{virus_checker}); + my $reason=<CHECKER_OUT>; + chomp $reason; + 1 while (<CHECKER_OUT>); + close(CHECKER_OUT); + waitpid $pid, 0; + $SIG{PIPE}="DEFAULT"; + if ($sigpipe || $?) { + return IkiWiki::FailReason->new("file seems to contain a virus ($reason)"); + } + else { + return IkiWiki::SuccessReason->new("file seems virusfree ($reason)"); + } +} #}}} + sub match_ispage ($$;@) { #{{{ my $filename=shift; |