samba3-vscan/f-secure vscan-fsav.c,1.3,1.4

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/f-secure
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12787/f-secure

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


Index: vscan-fsav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba3-vscan/f-secure/vscan-fsav.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- vscan-fsav.c	27 Jul 2005 18:35:34 -0000	1.3
+++ vscan-fsav.c	28 Jul 2005 10:15:08 -0000	1.4
@@ -345,95 +345,99 @@
 static int vscan_close(vfs_handle_struct * handle, files_struct * fsp,
 		       int fd)
 {
+	SMB_STRUCT_STAT stat_buf;
 	fsav_handle *fsav;
 	pstring filepath;
-	int retval, rv, rc;
+	int retval = 0, rv = 0, rc = 0;
 	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;
 
+        /* get the file name */
+        pstrcpy(filepath, fsp->conn->connectpath);
+        pstrcat(filepath, "/");
+        pstrcat(filepath, fsp->fsp_name);
 
-	if (!fsp->modified) {
-		if ( vscan_config.common.verbose_file_logging )
-			vscan_syslog
-			    ("INFO: file %s was not modified - not scanned",
-			     filepath);
+        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);
 
-		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) {
-		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);
 	}
+	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 {
+		/* scan only file, do nothing */
 
+		fsav = fsav_create_handle();
+		if (fsav) {
+			fsav->userinstance = fsav_userinstance;
+			fsav->connect_uid = fsav_connect_uid;
+			fsav->maxnested = fsav_maxnested;
+			fsav->archive = fsav_archive;
+			fsav->timeout = fsav_timeout;
+			fsav->mime = fsav_mime;
+			fsav->binary = fsav_binary;
+			fsav->config_file = fsav_config_file;
+			fsav->db_dir = fsav_db_dir;
+			fsav->socket = fsav_socket;
+			fsav->user = fsav_user;
+			if (fsav_connect_handle(fsav) != 0) {
+				fsav_free_handle(fsav);
+				fsav = NULL;
+			}
 
-	/* scan only file, do nothing */
-
-	fsav = fsav_create_handle();
-	if (fsav) {
-		fsav->userinstance = fsav_userinstance;
-		fsav->connect_uid = fsav_connect_uid;
-		fsav->maxnested = fsav_maxnested;
-		fsav->archive = fsav_archive;
-		fsav->timeout = fsav_timeout;
-		fsav->mime = fsav_mime;
-		fsav->binary = fsav_binary;
-		fsav->config_file = fsav_config_file;
-		fsav->db_dir = fsav_db_dir;
-		fsav->socket = fsav_socket;
-		fsav->user = fsav_user;
-		if (fsav_connect_handle(fsav) != 0) {
-			fsav_free_handle(fsav);
-			fsav = NULL;
 		}
-
-	}
-	if (fsav) {
-		safe_strcpy(client_ip, fsp->conn->client_address,
+		if (fsav) {
+			safe_strcpy(client_ip, fsp->conn->client_address,
 			    CLIENT_IP_SIZE - 1);
-		rv = fsav_scan(fsav, filepath, client_ip);
-		if (rv == VSCAN_SCAN_VIRUS_FOUND) {
-			/* virus was found */
-			rc = vscan_do_infected_file_action(handle,
+			rv = fsav_scan(fsav, filepath, client_ip);
+			fsav_free(handle);
+			if (rv == VSCAN_SCAN_VIRUS_FOUND) {
+				/* virus 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);
-		}
-		/* FIXME: shouldn't we handle errors as well? */
-
-	}
+				/* 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);
+			} /* rv */
+		} /* fsav */
+	} /* scan-pre-conditions */
 	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