samba3-vscan/antivir vscan-antivir.c,1.5,1.6

Rainer Link <[email protected]> Thu, 28 Jul 2005 10:15:10 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba3-vscan/antivir
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12787/antivir

Modified Files:
	vscan-antivir.c 
Log Message:
bugfix in kaspersky module
stream-lined vscan_close for all modules


Index: vscan-antivir.c
===================================================================
RCS file: /cvsroot/openantivirus/samba3-vscan/antivir/vscan-antivir.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- vscan-antivir.c	27 Jul 2005 18:35:33 -0000	1.5
+++ vscan-antivir.c	28 Jul 2005 10:15:07 -0000	1.6
@@ -321,60 +321,69 @@
 static int vscan_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
 {
 	pstring filepath;
-	int retval, rv, rc;
-	int sockfd;
+	SMB_STRUCT_STAT stat_buf;
+	int retval = 0, rv = 0, rc = 0, sockfd;
 	char client_ip[CLIENT_IP_SIZE];
 
 	/* First close the file */
 	retval = SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
 
-	if ( !vscan_config.common.scan_on_close ) {
-		DEBUG(3, ("samba-vscan - close: File '%s' not scanned as scan_on_close is not set\n", fsp->fsp_name));
-		return retval;
-	}
-
 
-	/* get the file name */
-	pstrcpy(filepath, fsp->conn->connectpath);
-	pstrcat(filepath, "/");
-	pstrcat(filepath, fsp->fsp_name);
-
-	/* Don't scan directorys */
-	if ( fsp->is_directory )
-	    return retval;
-
-
-	if ( !fsp->modified ) {
-		if ( vscan_config.common.verbose_file_logging )
-			vscan_syslog("INFO: file %s was not modified - not scanned", filepath);
-
-		return retval;
-	}
+        /* get the file name */
+        pstrcpy(filepath, fsp->conn->connectpath);
+        pstrcat(filepath, "/");
+        pstrcat(filepath, fsp->fsp_name);
 
-	/* dont' scan file which matches exclude regexp */
-	if ( fileregexp_skipscan(filepath) == VSCAN_FR_SKIP_SCAN ) {
-		if ( vscan_config.common.verbose_file_logging )
-			vscan_syslog("INFO: file '%s' not scanned as file is machted by exclude regexp", filepath);
-		return retval;
+        if ( !vscan_config.common.scan_on_close ) {
+                DEBUG(3, ("samba-vscan - close: File '%s' not scanned as scan_on_close is not set\n", fsp->fsp_name));
+        }
+        /* Don't scan directorys */
+        else if ( fsp->is_directory )
+		DEBUG(10, ("don't scan directory\n"));
+	/* Don't scan files which have not been modified */
+	else if ( !fsp->modified ) {
+                if ( vscan_config.common.verbose_file_logging ) 
+                        vscan_syslog("INFO: file %s was not modified - not scanned", filepath);
 	}
-
+        /* dont' scan file which matches exclude regexp */
+        else if ( fileregexp_skipscan(filepath) == VSCAN_FR_SKIP_SCAN ) {
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: file '%s' not scanned as file is machted by exclude regexp", filepath);
+        }
 	/* don't scan files which are in the list of exclude file types */
-	if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
-		if ( vscan_config.common.verbose_file_logging )
-			vscan_syslog("INFO: file '%s' not scanned as file type is on exclude list", filepath);
-		return retval;
+	else if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: File '%s' not scanned as file type is on exclude list", filepath);
 	}
-
-
-	sockfd = vscan_antivir_init();
-	if ( sockfd >= 0 ) {
-		safe_strcpy(client_ip, fsp->conn->client_address, CLIENT_IP_SIZE -1);
-		/* scan only file, do nothing */
-		rv = vscan_antivir_scanfile(sockfd, filepath, client_ip);
-		vscan_antivir_end(sockfd);
-		if ( rv == VSCAN_SCAN_VIRUS_FOUND ) {
-			/* alert was found */
-			rc = vscan_do_infected_file_action(handle, fsp->conn, filepath, vscan_config.common.quarantine_dir, vscan_config.common.quarantine_prefix, vscan_config.common.infected_file_action);
+	else if ( (SMB_VFS_NEXT_STAT(handle, handle->conn, fsp->fsp_name, &stat_buf)) != 0 ) {    /* an error occured */ 
+		if( errno == ENOENT) {
+			if ( vscan_config.common.verbose_file_logging )
+				vscan_syslog("INFO: File %s not found! Not scanned!", fsp->fsp_name);
+		} else {
+			vscan_syslog("ERROR: File %s not readable or an error occured", fsp->fsp_name);
+		}
+	}
+	else {
+		sockfd = vscan_antivir_init();
+		if ( sockfd >= 0 ) {
+			safe_strcpy(client_ip, fsp->conn->client_address, CLIENT_IP_SIZE -1);
+			/* scan only file, do nothing */
+			rv = vscan_antivir_scanfile(sockfd, filepath, client_ip);
+			vscan_antivir_end(sockfd);
+			if ( rv == VSCAN_SCAN_VIRUS_FOUND ) {
+				/* alert was found */
+				rc = vscan_do_infected_file_action(handle, fsp->conn, filepath, vscan_config.common.quarantine_dir, vscan_config.common.quarantine_prefix, vscan_config.common.infected_file_action);
+				/* add/update file, mark file as infected! */
+				lrufiles_add(filepath, stat_buf.st_mtime, True);
+			}
+			else if( rv == VSCAN_SCAN_OK ) {
+				/* add/update file, mark file as clean! */
+				lrufiles_add(filepath, stat_buf.st_mtime, False);
+			}
+			else {
+				/* to be save, delete file from lrufiles */
+				lrufiles_delete(filepath);
+			}
 		}
 	}
 	return retval;



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf