X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/c58b88df956cd5f2b2febc6c447d8549928b454b..805e5aabc6e28e536153862bcef7268f84108fd7:/src/src/malware.c diff --git a/src/src/malware.c b/src/src/malware.c index a790b284b..7e3c587c9 100644 --- a/src/src/malware.c +++ b/src/src/malware.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/malware.c,v 1.11 2005/07/01 10:49:02 ph10 Exp $ */ +/* $Cambridge: exim/src/src/malware.c,v 1.14 2006/02/22 14:46:44 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -199,7 +199,7 @@ int malware(uschar **listptr) { /* prepare variables */ drweb_cmd = htonl(DRWEBD_SCAN_CMD); drweb_flags = htonl(DRWEBD_RETURN_VIRUSES | DRWEBD_IS_MAIL); - snprintf(CS scanrequest, 1024,CS"%s/scan/%s/%s.eml", + (void)string_format(scanrequest, 1024,CS"%s/scan/%s/%s.eml", spool_directory, message_id, message_id); /* calc file size */ @@ -287,7 +287,7 @@ int malware(uschar **listptr) { /* prepare variables */ drweb_cmd = htonl(DRWEBD_SCAN_CMD); drweb_flags = htonl(DRWEBD_RETURN_VIRUSES | DRWEBD_IS_MAIL); - snprintf(CS scanrequest, 1024,CS"%s/scan/%s/%s.eml", spool_directory, message_id, message_id); + (void)string_format(scanrequest, 1024,CS"%s/scan/%s/%s.eml", spool_directory, message_id, message_id); drweb_slen = htonl(Ustrlen(scanrequest)); /* send scan request */ @@ -446,7 +446,7 @@ int malware(uschar **listptr) { }; /* prepare our command */ - snprintf(CS buf, 32768, "SCAN bPQRSTUW %s/scan/%s/%s.eml\r\n", spool_directory, message_id, message_id); + (void)string_format(buf, 32768, "SCAN bPQRSTUW %s/scan/%s/%s.eml\r\n", spool_directory, message_id, message_id); /* and send it */ if (send(sock, buf, Ustrlen(buf), 0) < 0) { @@ -479,7 +479,7 @@ int malware(uschar **listptr) { } /* prepare our command */ - snprintf(CS buf, 32768, "quit\r\n"); + (void)string_format(buf, 32768, "quit\r\n"); /* and send it */ if (send(sock, buf, Ustrlen(buf), 0) < 0) { @@ -571,7 +571,7 @@ int malware(uschar **listptr) { }; /* pass the mailfile to fsecure */ - snprintf(CS file_name,1024,"SCAN\t%s/scan/%s/%s.eml\n", spool_directory, message_id, message_id); + (void)string_format(file_name,1024,"SCAN\t%s/scan/%s/%s.eml\n", spool_directory, message_id, message_id); /* debug_printf("send scan %s",file_name); */ if (write(sock, file_name, Ustrlen(file_name)) < 0) { (void)close(sock); @@ -661,7 +661,7 @@ int malware(uschar **listptr) { /* get current date and time, build scan request */ time(&t); strftime(CS tmpbuf, sizeof(tmpbuf), "<0>%d %b %H:%M:%S:%%s/scan/%%s", localtime(&t)); - snprintf(CS scanrequest, 1024,CS tmpbuf, spool_directory, message_id); + (void)string_format(scanrequest, 1024,CS tmpbuf, spool_directory, message_id); /* send scan request */ if (send(sock, scanrequest, Ustrlen(scanrequest)+1, 0) < 0) { @@ -854,8 +854,8 @@ int malware(uschar **listptr) { }; /* prepare scanner call */ - snprintf(CS file_name,1024,"%s/scan/%s", spool_directory, message_id); - snprintf(CS commandline,1024, CS cmdline_scanner,file_name); + (void)string_format(file_name,1024,"%s/scan/%s", spool_directory, message_id); + (void)string_format(commandline,1024, CS cmdline_scanner,file_name); /* redirect STDERR too */ Ustrcat(commandline," 2>&1"); @@ -872,8 +872,8 @@ int malware(uschar **listptr) { return DEFER; }; - snprintf(CS file_name,1024,"%s/scan/%s/%s_scanner_output", spool_directory, message_id, message_id); - scanner_record = fopen(CS file_name,"wb"); + (void)string_format(file_name,1024,"%s/scan/%s/%s_scanner_output", spool_directory, message_id, message_id); + scanner_record = modefopen(file_name,"wb",SPOOL_MODE); if (scanner_record == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, @@ -964,7 +964,7 @@ int malware(uschar **listptr) { } /* pass the scan directory to sophie */ - snprintf(CS file_name,1024,"%s/scan/%s", spool_directory, message_id); + (void)string_format(file_name,1024,"%s/scan/%s", spool_directory, message_id); if (write(sock, file_name, Ustrlen(file_name)) < 0) { (void)close(sock); log_write(0, LOG_MAIN|LOG_PANIC, @@ -1079,7 +1079,7 @@ int malware(uschar **listptr) { /* Pass the string to ClamAV (7 = "SCAN \n" + \0) */ - snprintf(CS file_name,1024,"SCAN %s/scan/%s\n", spool_directory, message_id); + (void)string_format(file_name,1024,"SCAN %s/scan/%s\n", spool_directory, message_id); if (send(sock, file_name, Ustrlen(file_name), 0) < 0) { (void)close(sock); @@ -1141,7 +1141,7 @@ int malware(uschar **listptr) { return DEFER; } - snprintf(CS scanrequest, 1024,CS"%s/scan/%s/%s.eml", + (void)string_format(scanrequest, 1024,CS"%s/scan/%s/%s.eml", spool_directory, message_id, message_id); /* calc file size */ @@ -1218,7 +1218,7 @@ int malware(uschar **listptr) { /* Pass the string to ClamAV (7 = "SCAN \n" + \0) */ - snprintf(CS file_name,1024,"SCAN %s/scan/%s\n", spool_directory, message_id); + (void)string_format(file_name,1024,"SCAN %s/scan/%s\n", spool_directory, message_id); if (send(sock, file_name, Ustrlen(file_name), 0) < 0) { (void)close(sock); @@ -1265,6 +1265,10 @@ int malware(uschar **listptr) { return DEFER; } + /* strip newline at the end */ + p = av_buffer + Ustrlen(av_buffer) - 1; + if( *p == '\n' ) *p = '\0'; + /* colon in returned output? */ if((p = Ustrrchr(av_buffer,':')) == NULL) { log_write(0, LOG_MAIN|LOG_PANIC, @@ -1273,13 +1277,10 @@ int malware(uschar **listptr) { return DEFER; } - /* strip filename strip CR at the end */ + /* strip filename */ ++p; while (*p == ' ') ++p; vname = p; - p = vname + Ustrlen(vname) - 1; - if( *p == '\n' ) *p = '\0'; - if ((p = Ustrstr(vname, "FOUND"))!=NULL) { *p=0; for (--p;p>vname && *p<=32;p--) *p=0;