samba3-vscan/sophos vscan-sophos.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/sophos
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32264/sophos

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


Index: vscan-sophos.c
===================================================================
RCS file: /cvsroot/openantivirus/samba3-vscan/sophos/vscan-sophos.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- vscan-sophos.c	23 Jul 2005 14:48:04 -0000	1.2
+++ vscan-sophos.c	27 Jul 2005 18:35:51 -0000	1.3
@@ -146,14 +146,11 @@
 
 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);
@@ -163,25 +160,48 @@
         /* scan files while opening? */
         if ( !vscan_config.common.scan_on_open ) {
                 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 ( 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);
         }
+	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);
+	}
 	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' not scanned as file type is on exclude list", filepath);
-                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+			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 */
@@ -195,33 +215,6 @@
                 } else if ( sockfd >= 0 ) {
 			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 ( vscan_config.common.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_sophos_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 ( vscan_config.common.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_sophos_end(sockfd);
-				
-				/* grant access */
-				return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
-                        }
-                        /* ok, we must check the file */
-
 			/* scan file */
 			retval = vscan_sophos_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