samba3-vscan/openantivirus vscan-oav.c,1.2,1.3

Rainer Link <[email protected]> Wed, 27 Jul 2005 18:35:53 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba3-vscan/openantivirus
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32264/openantivirus

Modified Files:
	vscan-oav.c 
Log Message:
changed the logic in vscan_open


Index: vscan-oav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba3-vscan/openantivirus/vscan-oav.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- vscan-oav.c	23 Jul 2005 14:48:04 -0000	1.2
+++ vscan-oav.c	27 Jul 2005 18:35:35 -0000	1.3
@@ -148,43 +148,62 @@
 
 static int vscan_open(vfs_handle_struct *handle, connection_struct *conn, const char *fname, int flags, mode_t mode)
 {
-	int retval, must_be_checked;
+	int retval, must_be_checked, sockfd, rc;
 	SMB_STRUCT_STAT stat_buf;
-	int sockfd;
 	pstring filepath;
 	char client_ip[CLIENT_IP_SIZE];
-	int rc;
 
 	/* Assemble complete file path */
 	pstrcpy(filepath, conn->connectpath);
 	pstrcat(filepath, "/");
 	pstrcat(filepath, fname);
 
-	/* the following if conditions look awfull, seems we need a (generic) decision module sooner or later ... */
-
         /* scan files while opening? */
         if ( !vscan_config.common.scan_on_open ) {
-		/* we should use vscan_syslog instead of DEBUG here ... */
                 DEBUG(3, ("samba-vscan - open: File '%s' not scanned as scan_on_open is not set\n", fname));
-		return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
         }
-
-        if ( (SMB_VFS_NEXT_STAT(handle, conn, fname, &stat_buf)) != 0 )    /* an error occured */ 
-		return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-	else if ( S_ISDIR(stat_buf.st_mode) ) 	/* is it a directory? */
-		return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-	else if ( ( stat_buf.st_size > vscan_config.common.max_size ) && ( vscan_config.common.max_size > 0 ) ) /* file is too large */
-		vscan_syslog("INFO: File %s is larger than specified maximum file size! Not scanned!", fname);
-	else if ( stat_buf.st_size == 0 ) /* do not scan empty files */
-		return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+        else if ( (SMB_VFS_NEXT_STAT(handle, conn, fname, &stat_buf)) != 0 ) {    /* an error occured */
+                if ( errno == ENOENT ) {
+                        if ( verbose_file_logging )
+                                vscan_syslog("INFO: File %s not found! Not scanned!", fname);
+                }
+                else {
+                        vscan_syslog("ERROR: File %s not readable or an error occured", fname);
+                }
+        }
+        else if ( S_ISDIR(stat_buf.st_mode) ) {         /* is it a directory? */
+                if ( verbose_file_logging )
+                        vscan_syslog("INFO: File %s is a directory! Not scanned!", fname);
+        }
+        else if ( ( stat_buf.st_size > vscan_config.common.max_size ) && ( vscan_config.common.max_size > 0 ) ) { /* file is
+too large */
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: File %s is larger than specified maximum file size! Not scanned!", fname);
+        }
+        else if ( stat_buf.st_size == 0 ) { /* do not scan empty files */
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: File %s has size zero! Not scanned!", fname);
+        }
         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);
+                        vscan_syslog("INFO: File '%s' not scanned as file is machted by exclude regexp", filepath);
         }
-	else if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
-		if ( verbose_file_logging )
-			vscan_syslog("INFO: file '%s' not scanned as file type is on exclude list", filepath);
-                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+        else if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
+                if ( verbose_file_logging )
+                        vscan_syslog("INFO: File '%s' not scanned as file type is on exclude list", filepath);
+        } else if ( (must_be_checked = lrufiles_must_be_checked(filepath, stat_buf.st_mtime)) == VSCAN_LRU_DENY_ACCESS ) {
+                /* file has already been checked and marked as infected */
+                /* deny access */
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: File '%s' has already been scanned and marked as infected. Not scanned any more. Access denied", filepath);
+
+                /* deny access */
+                errno = EACCES;
+                return -1;
+        } else if ( must_be_checked == VSCAN_LRU_GRANT_ACCESS )  {
+                /* file has already been checked, not marked as infected and not modified */
+                if ( vscan_config.common.verbose_file_logging )
+                        vscan_syslog("INFO: File '%s' has already been scanned, not marked as infected and not modified. Not scanned anymore. Access granted", filepath);
 	} else  
 	{
 		/* open socket */
@@ -200,33 +219,6 @@
 			/* get client IP */
 			safe_strcpy(client_ip, conn->client_address, CLIENT_IP_SIZE -1);
 
-                        /* must file actually be scanned? */
-                        must_be_checked = lrufiles_must_be_checked(filepath, stat_buf.st_mtime);
-                        if ( must_be_checked == VSCAN_LRU_DENY_ACCESS ) {
-                                /* file has already been checked and marked as infected */
-                                /* deny access */
-                                if ( verbose_file_logging )
-                                        vscan_syslog("File '%s' has already been scanned and marked as infected. Not scanned any more. Access denied", filepath);
-			
-				/* close socket */
-				vscan_oav_end(sockfd);
-				
-				/* deny access */
-                                errno = EACCES;
-                                return -1;
-                        } else if ( must_be_checked == VSCAN_LRU_GRANT_ACCESS )  {
-                                /* file has already been checked, not marked as infected and not modified */
-                                if ( verbose_file_logging )
-                                        vscan_syslog("File '%s' has already been scanned, not marked as infected and not modified. Not scanned anymore. Access granted", filepath);
-
-                                /* close socket */
-				vscan_oav_end(sockfd);
-				
-				/* grant access */
-				return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-                        }
-                        /* ok, we must check the file */
-
 			/* scan file */
 			retval = vscan_oav_scanfile(sockfd, filepath, client_ip);
 			if ( retval == VSCAN_SCAN_MINOR_ERROR && vscan_config.common.deny_access_on_minor_error ) {



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click