This patch is to implement fail safe feature for mailfront plugin clamav. Giam Teck Choon http://choon.net/ --- mailfront-1.12/plugin-clamav.c.original 2009-08-06 23:38:08.000000000 +0800 +++ mailfront-1.12/plugin-clamav.c 2009-08-07 00:51:22.000000000 +0800 @@ -48,6 +48,7 @@ ibuf netin; obuf netout; struct stat st; + const char* clamav_failsafe = session_getenv("CLAMAV_FAILSAFE"); if ((hostname = session_getenv("CLAMAV_HOST")) != 0 || (hostname = session_getenv("CLAMD_HOST")) != 0) { @@ -81,8 +82,14 @@ || (send_timeout = strtoul(tmp, (char**)&tmp, 10)) == 0 || *tmp != 0) send_timeout = timeout; - if ((ip_count = resolve_ipv4name_n(hostname, ips, MAX_IPS)) <= 0) - return &resp_no_hostname; + if ((ip_count = resolve_ipv4name_n(hostname, ips, MAX_IPS)) <= 0) { + if (clamav_failsafe == 0) + return &resp_no_hostname; + else { + warn1("ClamAV scanning skipped: Could not resolve virus scanner hostname"); + return 0; + } + } gettimeofday(&tv, 0); offset = (tv.tv_sec ^ tv.tv_usec) % ip_count; @@ -128,7 +135,12 @@ close(sock); } } - return &resp_no_scan; + if (clamav_failsafe == 0) + return &resp_no_scan; + else { + warn1("ClamAV scanning skipped: Could not virus scan message"); + return 0; + } } struct plugin plugin = { --- mailfront-1.12/plugin-clamav.html.original 2009-08-07 00:53:09.000000000 +0800 +++ mailfront-1.12/plugin-clamav.html 2009-08-07 00:58:04.000000000 +0800 @@ -20,6 +20,12 @@
+
$CLAMAV_FAILSAFE
+
The default behaviour of the plugin is to defer any SMTP delivery if the +clamav service is not available including authorized users, at the risk of +emails being finally rejected if the problem is not fixed. To let any mail +pass in such a case set this environment variable.
+
$CLAMAV_CONNECT_TIMEOUT
The maximum amount of time to wait for a response when connecting to a ClamAV scanner, in milliseconds. (defaults to $CLAMAV_TIMEOUT below)