I've made a patch against today's CVS to add an option to clamav-milter. Currently clamav-milter adds headers at the end of all the existing headers. This patch adds an option to clamav-milter:
-I --insert-headers which adds new headers at the top instead. This requires smfi_insheader, which is available as of sendmail 8.13 - I check for this in the patch. Can this patch be incorporated into the source? -- Matthew.van.Eerde (at) hbinc.com 805.964.4554 x902 Hispanic Business Inc./HireDiversity.com Software Engineer
diff -Nur cvs/clamav-devel/clamav-milter/clamav-milter.c clamav-devel/clamav-milter/clamav-milter.c --- cvs/clamav-devel/clamav-milter/clamav-milter.c 2006-01-23 02:38:00.000000000 -0800 +++ clamav-devel/clamav-milter/clamav-milter.c 2006-01-25 14:35:49.000000000 -0800 @@ -274,6 +274,7 @@ static void quit(void); static void broadcast(const char *mess); static int loadDatabase(void); +static int addheader(SMFICTX *ctx, char *headerf, char *headerv, int insertflag); #ifdef SESSION static pthread_mutex_t version_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -339,6 +340,10 @@ * Don't add X-Virus-Scanned to header. Patch * from Dirk Meyer <[EMAIL PROTECTED]> */ +static int insertflag = 0; /* + * Add headers at the top. + * Patch from Matthew van Eerde <[EMAIL PROTECTED]> + */ static int rejectmail = 1; /* * Send a 550 rejection when a virus is * found @@ -489,6 +494,7 @@ puts(_("\t--force-scan\t\t-f\tForce scan all messages (overrides (-o and -l).")); puts(_("\t--help\t\t\t-h\tThis message.")); puts(_("\t--headers\t\t-H\tInclude original message headers in the report.")); + puts(_("\t--insert-headers\t-I\tAdd headers at the top instead of the bottom.")); puts(_("\t--local\t\t\t-l\tScan messages sent from machines on our LAN.")); puts(_("\t--max-childen\t\t-m\tMaximum number of concurrent scans.")); puts(_("\t--outgoing\t\t-o\tScan outgoing messages from this machine.")); @@ -577,9 +583,9 @@ for(;;) { int opt_index = 0; #ifdef CL_DEBUG - const char *args = "a:AbB:c:CdDefF:lLm:M:nNop:PqQ:hHs:St:T:U:VwW:x:0:"; + const char *args = "a:AbB:c:CdDefF:hHi:IlLm:M:nNop:PqQ:hHs:St:T:U:VwW:x:0:"; #else - const char *args = "a:AbB:c:CdDefF:lLm:M:nNop:PqQ:hHs:St:T:U:VwW:0:"; + const char *args = "a:AbB:c:CdDefF:hHi:IlLm:M:nNop:PqQ:hHs:St:T:U:VwW:0:"; #endif static struct option long_options[] = { @@ -626,6 +632,9 @@ "help", 0, NULL, 'h' }, { + "insert-headers", 0, NULL, 'I' + }, + { "pidfile", 1, NULL, 'i' }, { @@ -749,6 +758,13 @@ case 'i': /* pidfile */ pidfile = optarg; break; + case 'I': /* add headers at the top */ +#ifndef SMFIR_INSHEADER + fprintf(stderr, "-I requires sendmail 8.13\n"); + return EX_USAGE; +#endif + insertflag++; + break; case 'l': /* scan mail from the lan */ lflag++; break; @@ -828,11 +844,7 @@ break; #endif default: -#ifdef CL_DEBUG - fprintf(stderr, "Usage: %s [-b] [-c FILE] [-F FILE] [--max-children=num] [-e] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-s SERVER] [-S] [-x#] [-U PATH] [-M#] socket-addr\n", argv[0]); -#else - fprintf(stderr, "Usage: %s [-b] [-c FILE] [-F FILE] [--max-children=num] [-e] [-l] [-o] [-p address] [-P] [-q] [-Q USER] [-s SERVER] [-S] [-U PATH] [-M#] socket-addr\n", argv[0]); -#endif + fprintf(stderr, "Usage:\n\t%s [options] socket-addr\n\t%s --help\n", argv[0], argv[0]); return EX_USAGE; } } @@ -2536,7 +2548,7 @@ sendmailId, streamMaxLength); } if(!nflag) - smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded")); + addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"), insertflag); return SMFIS_ACCEPT; /* clamfi_close will be called */ } @@ -2831,7 +2843,7 @@ /* sanity check failed - should issue warning */ strcpy(buf, _("Error determining host")); } - smfi_addheader(ctx, "X-Virus-Scanned", buf); + addheader(ctx, "X-Virus-Scanned", buf, insertflag); } /* @@ -2847,12 +2859,12 @@ syslog(LOG_NOTICE, _("%s: Message more than StreamMaxLength (%ld) bytes - not scanned"), sendmailId, streamMaxLength); if(!nflag) - smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded")); + addheader(ctx, "X-Virus-Status", _("Not Scanned - StreamMaxLength exceeded"), insertflag); clamfi_cleanup(ctx); /* not needed, but just to be safe */ return SMFIS_ACCEPT; } if(!nflag) - smfi_addheader(ctx, "X-Virus-Status", _("Not Scanned")); + addheader(ctx, "X-Virus-Status", _("Not Scanned"), insertflag); cli_warnmsg("%s: %s\n", sendmailId, mess); if(use_syslog) @@ -2882,7 +2894,7 @@ char buf[129]; snprintf(buf, sizeof(buf) - 1, "%s %s", _("Infected with"), virusname); - smfi_addheader(ctx, "X-Virus-Status", buf); + addheader(ctx, "X-Virus-Status", buf, insertflag); } if(use_syslog) { @@ -3067,7 +3079,7 @@ (strstr(virusname, "Phishing") != NULL)) { for(to = privdata->to; *to; to++) { smfi_delrcpt(ctx, *to); - smfi_addheader(ctx, "X-Original-To", *to); + addheader(ctx, "X-Original-To", *to, insertflag); free(*to); } free(privdata->to); @@ -3101,7 +3113,7 @@ if(quarantine) { for(to = privdata->to; *to; to++) { smfi_delrcpt(ctx, *to); - smfi_addheader(ctx, "X-Original-To", *to); + addheader(ctx, "X-Original-To", *to, insertflag); free(*to); } free(privdata->to); @@ -3148,7 +3160,7 @@ broadcast(mess); } else if(strstr(mess, "OK") == NULL) { if(!nflag) - smfi_addheader(ctx, "X-Virus-Status", _("Unknown")); + addheader(ctx, "X-Virus-Status", _("Unknown"), insertflag); if(use_syslog) syslog(LOG_ERR, _("%s: incorrect message \"%s\" from clamd"), sendmailId, @@ -3156,7 +3168,7 @@ rc = cl_error; } else { if(!nflag) - smfi_addheader(ctx, "X-Virus-Status", _("Clean")); + addheader(ctx, "X-Virus-Status", _("Clean"), insertflag); if(use_syslog && logClean) /* Include the sendmail queue ID in the log */ @@ -4353,13 +4365,13 @@ char subject[128]; if(privdata->subject) - smfi_addheader(ctx, "X-Original-Subject", privdata->subject); + addheader(ctx, "X-Original-Subject", privdata->subject, insertflag); snprintf(subject, sizeof(subject) - 1, _("[Virus] %s"), virusname); if(privdata->subject) smfi_chgheader(ctx, "Subject", 1, subject); else - smfi_addheader(ctx, "Subject", subject); + addheader(ctx, "Subject", subject, insertflag); } #if 0 @@ -5015,6 +5027,25 @@ return cl_statinidir(dbdir, &dbstat); } +/* + * Add or insert a header per preference + * Note insert requires sendmail 8.13 + */ +static int +addheader(SMFICTX *ctx, char *headerf, char *headerv, int insertflag) +{ + if(insertflag) { +#ifdef SMFIR_INSHEADER + return smfi_insheader(ctx, 0, headerf, headerv); +#else + /* Caller wants to insert, but we can't... */ + return MI_FAILURE; +#endif + } + + return smfi_addheader(ctx, headerf, headerv); +} + static void sigsegv(int sig) { diff -Nur cvs/clamav-devel/docs/man/clamav-milter.8 clamav-devel/docs/man/clamav-milter.8 --- cvs/clamav-devel/docs/man/clamav-milter.8 2005-12-16 05:32:14.000000000 -0800 +++ clamav-devel/docs/man/clamav-milter.8 2006-01-25 14:13:35.000000000 -0800 @@ -122,6 +122,13 @@ This option instructs clamav\-milter to refrain from adding this heading. .TP +\fB-I, \-\-insert-headers\fR +Usually clamav\-milter adds headers at the end of any existing headers. +This option instructs +clamav\-milter to add headers at the top. This requires a recent +version of libmilter that supports smfi_insheader \-\- +this was added in sendmail 8.13. +.TP \fB-N, \-\-noreject\fR When clamav\-milter processes an e-mail which contains a virus it rejects the e-mail by using the SMTP code 550 or 554 depending on the state machine.
_______________________________________________ http://lurker.clamav.net/list/clamav-devel.html