Background: I'm administering a couple of mail servers and after the MyDoom outbreak I took a deeper look into virus filtering. All my users on Windows have local virus scanners, but the more viruses I stop on the server, the less support requests I get...
I looked at Amavis and other solutions, but I'm uncomfortable with such beasts. I was looking for something easier to set up. I discovered the existence of reformime a few days ago, and it looked like the -X option was what I needed to call ClamAV safely from maildrop, except that there's no easy way to signal that a virus has been found. Here's what my patch does: if the external program terminates with a nonzero exit status, reformime terminates and returns (program exit status + 20).
This is what I put into /etc/courier/maildroprc:
# log delivered emails for debugging purposes
logfile ./maildrop.log
exception {
`/usr/bin/reformime -X /usr/bin/clamdscan --disable-summary -`
if ($RETURNCODE == 21)
{
log "Virus found!"
to "./Maildir/.Virus"
}
}This is the log generated by an infected email:
courierlocal: id=X,from=<Y>,addr=<Z>: stream: OK
courierlocal: id=X,from=<Y>,addr=<Z>: stream: Worm.Dumaru.Y.enc FOUND
courierlocal: id=X,from=<Y>,addr=<Z>: reformime: /usr/bin/clamdscan exited with status 1.
courierlocal: id=X,from=<Y>,addr=<Z>,size=21594,success: Message delivered.
Please, apply. If you are uncomfortable with changing the current behaviour of the -X option, I would suggesti adding a new option for this purpose, let's say -Z.
--
Ciao,
Flavio Stanchina
Trento - Italydiff -ur courier-0.42.2-10/debian/changelog courier-0.42.2-10flavio/debian/changelog
--- courier-0.42.2-10/debian/changelog 2004-02-09 16:11:08.000000000 +0100
+++ courier-0.42.2-10flavio/debian/changelog 2004-02-09 16:16:40.000000000 +0100
@@ -1,3 +1,9 @@
+courier (0.42.2-10flavio) experimental; urgency=low
+
+ * reformime: -X returns the exit code of the launched program.
+
+ -- Flavio Stanchina <[EMAIL PROTECTED]> Mon, 9 Feb 2004 22:15:45 +0100
+
courier (0.42.2-10) unstable; urgency=low
* updated French translation of debconf templates (Closes: #213816,
diff -ur courier-0.42.2-10/rfc2045/reformime.1
courier-0.42.2-10flavio/rfc2045/reformime.1
--- courier-0.42.2-10/rfc2045/reformime.1 2003-04-21 22:56:15.000000000 +0200
+++ courier-0.42.2-10flavio/rfc2045/reformime.1 2004-02-09 16:52:39.000000000 +0100
@@ -208,6 +208,10 @@
\fBreformime\fR's liking. If the \fB-s\fR option is
not specified, the program runs once
for every MIME section in the message.
+.B "EXPERIMENTAL:"
+If the external program terminates with a nonzero exit status,
+\fBreformime\fR terminates and returns
+(program exit status + 20).
.sp
.RS
.B "Note:"
diff -ur courier-0.42.2-10/rfc2045/reformime.c
courier-0.42.2-10flavio/rfc2045/reformime.c
--- courier-0.42.2-10/rfc2045/reformime.c 2003-03-07 01:47:30.000000000 +0100
+++ courier-0.42.2-10flavio/rfc2045/reformime.c 2004-02-09 16:43:34.000000000 +0100
@@ -615,6 +615,16 @@
while ((p2=wait(&waitstat)) != pid && p2 != -1)
;
free(f);
+
+ if ((p2 == pid) && WIFEXITED(waitstat))
+ {
+ if (WEXITSTATUS(waitstat) != 0)
+ {
+ fprintf(stderr, "reformime: %s exited with status %d.\n",
+ argv[0], WEXITSTATUS(waitstat));
+ exit(WEXITSTATUS(waitstat) + 20);
+ }
+ }
}
static void extract_section(struct rfc2045 *top_rfcp, const char *mimesection,
