samba-vscan/clamav vscan-clamav.c,1.1.2.19,1.1.2.20

Rainer Link <[email protected]> Sun, 10 Apr 2005 15:48:41 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/clamav
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22532

Modified Files:
      Tag: VSCAN_0_3
	vscan-clamav.c 
Log Message:
some code re-org in vscan_close


Index: vscan-clamav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav.c,v
retrieving revision 1.1.2.19
retrieving revision 1.1.2.20
diff -u -d -r1.1.2.19 -r1.1.2.20
--- vscan-clamav.c	10 Apr 2005 15:22:50 -0000	1.1.2.19
+++ vscan-clamav.c	10 Apr 2005 15:48:39 -0000	1.1.2.20
@@ -389,7 +389,7 @@
 {
 	SMB_STRUCT_STAT stat_buf;
 	pstring filepath;
-        int retval, rv;
+        int retval = 0, rv = 0;
 	char client_ip[CLIENT_IP_SIZE];
 
         /* First close the file */
@@ -399,48 +399,37 @@
         retval = default_vfs_ops.close(fsp, fd);
 #endif
 
+        /* get the file name */
+        pstrcpy(filepath, fsp->conn->connectpath);
+        pstrcat(filepath, "/");
+        pstrcat(filepath, fsp->fsp_name);
+
         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 ) {
+        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);
 
-		return retval;
 	}
-
         /* dont' scan file which matches exclude regexp */
-        if ( fileregexp_skipscan(filepath) == VSCAN_FR_SKIP_SCAN ) {
+        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);
-                return retval;
         }
-
 	/* don't scan files which are in the list of exclude file types */
-	if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
+	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);
-		return retval;
 	}
-
-
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
-	if ( (SMB_VFS_NEXT_STAT(handle, handle->conn, fsp->fsp_name, &stat_buf)) != 0 ) {    /* an error occured */ 
+	else if ( (SMB_VFS_NEXT_STAT(handle, handle->conn, fsp->fsp_name, &stat_buf)) != 0 ) {    /* an error occured */ 
 #else
-	if ( (default_vfs_ops.stat(fsp->conn, fsp->fsp_name, &stat_buf)) != 0 ) {    /* an error occured */ 
+	else if ( (default_vfs_ops.stat(fsp->conn, fsp->fsp_name, &stat_buf)) != 0 ) {    /* an error occured */ 
 #endif
 		if( errno == ENOENT) {
 			if ( vscan_config.common.verbose_file_logging )
@@ -448,7 +437,7 @@
 		} else {
 			vscan_syslog("ERROR: File %s not readable or an error occured", fsp->fsp_name);
 		}
-		rv = 3;
+		rv = 3; /* FIXME: due to code re-org this should no longer be needed */
 	}
 	else {
 		safe_strcpy(client_ip, fsp->conn->client_address, CLIENT_IP_SIZE -1);
@@ -467,27 +456,26 @@
                 	vscan_clamav_end(sockfd);
 		}
 #endif	/* LIBCLAMAV */
-	}
 
-	if ( rv == VSCAN_SCAN_VIRUS_FOUND ) {
-		/* virus was found */
+		if ( rv == VSCAN_SCAN_VIRUS_FOUND ) {
+			/* virus was found */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
-		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);
+			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
-		vscan_do_infected_file_action(&default_vfs_ops, fsp->conn, filepath, vscan_config.common.quarantine_dir, vscan_config.common.quarantine_prefix, vscan_config.common.infected_file_action);
+			vscan_do_infected_file_action(&default_vfs_ops, fsp->conn, filepath, vscan_config.common.quarantine_dir, vscan_config.common.quarantine_prefix, vscan_config.common.infected_file_action);
 #endif
-		/* 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);
+			/* 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 email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click