samba-vscan/openantivirus vscan-oav.c,1.37.2.2,1.37.2.3 vscan-oav.h,1.13.2.2,1.13.2.3 vscan-oav_core.c,1.18.2.2,1.18.2.3

Rainer Link <[email protected]> Sun, 02 May 2004 19:45:34 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/openantivirus
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21244/openantivirus

Modified Files:
      Tag: VSCAN_0_3
	vscan-oav.c vscan-oav.h vscan-oav_core.c 
Log Message:
started some more code-reorganisation; not finished; could have
broken stuff


Index: vscan-oav.h
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/openantivirus/vscan-oav.h,v
retrieving revision 1.13.2.2
retrieving revision 1.13.2.3
diff -u -d -r1.13.2.2 -r1.13.2.3
--- vscan-oav.h	3 Apr 2004 11:57:58 -0000	1.13.2.2
+++ vscan-oav.h	2 May 2004 19:45:32 -0000	1.13.2.3
@@ -84,7 +84,7 @@
 
 /* functions by vscan-oav_core */
 /* opens a socket */
-int vscan_oav_init(void); 
+int vscan_oav_init(const char* oav_ip, const unsigned short int oav_port); 
 /* scans a file */
 int vscan_oav_scanfile(int sockfd, char *scan_file, char* client_ip);
 /* closes socket */

Index: vscan-oav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/openantivirus/vscan-oav.c,v
retrieving revision 1.37.2.2
retrieving revision 1.37.2.3
diff -u -d -r1.37.2.2 -r1.37.2.3
--- vscan-oav.c	12 Sep 2003 07:12:16 -0000	1.37.2.2
+++ vscan-oav.c	2 May 2004 19:45:32 -0000	1.37.2.3
@@ -47,46 +47,13 @@
                                    PARAMCONF or as set via vfs options
                                 */
 
-ssize_t max_size;          	/* do not scan files greater than max_size
-                                   if max_size = 0, scan any file
-                                */
-
-BOOL verbose_file_logging;  	/* log ever file access */
-
-BOOL scan_on_open;         	/* scan a file before it is opened
-                                   Defaults to True
-                                */
-
-BOOL scan_on_close;        	/* scan a new file put on share or
-                                   if file was modified
-                                   Defaults to False
-                                */
-
-BOOL deny_access_on_error;      /* if connection to daemon fails,  should access to any
-                                   file be denied? Defaults to True 
-				*/
-
-
-BOOL deny_access_on_minor_error; /* if daemon returns non-critical error,
-                                    should access to the file be denied? */
+vscan_config_struct vscan_config; /* contains the vscan module configuration */
 
-BOOL send_warning_message;	/* send a warning message using the windows
-				   messenger service? */
+BOOL verbose_file_logging;
 
 fstring oav_ip;              	/* IP OAV ScannerDaemon runs on */
 unsigned short int oav_port; 	/* port number OAV ScannerDaemon listens on */
 
-fstring quarantine_dir;	/* directory for infected files */
-fstring quarantine_prefix;	/* prefix    for infected files */
-
-enum infected_file_action_enum infected_file_action; /* what to do with infected files;
-                                                        defaults to quarantine */
-
-int max_lrufiles;               /* specified the maximum entries in lrufiles list */
-time_t lrufiles_invalidate_time; /* specified the time in seconds after the lifetime
-                                    of an entry is expired and entry will be invalidated */
-
-pstring exclude_file_types;	/* list of file types which should be excluded from scanning */
 
 /* module version */
 static const char module_id[]=VSCAN_MODULE_STR" "SAMBA_VSCAN_VERSION_STR;
@@ -94,67 +61,21 @@
 
 static BOOL do_parameter(const char *param, const char *value)
 {
-        if ( StrCaseCmp("max file size", param) == 0 ) {
-		/* FIXME: sanity check missing! what, if value is out of range?
-		   atoi returns int - what about LFS? atoi should be avoided!
-		*/
-                max_size = atoi(value);
-                DEBUG(3, ("max file size is: %d\n", max_size));
-        } else if ( StrCaseCmp("verbose file logging", param) == 0 ) {
-                set_boolean(&verbose_file_logging, value);
-                DEBUG(3, ("verbose file logging is: %d\n", verbose_file_logging));
-        } else if ( StrCaseCmp("scan on open", param) == 0 ) {
-                set_boolean(&scan_on_open, value);
-                DEBUG(3, ("scan on open: %d\n", scan_on_open));
-        } else if ( StrCaseCmp("scan on close", param) == 0 ) {
-                set_boolean(&scan_on_close, value);
-                DEBUG(3, ("scan on close is: %d\n", scan_on_close));
-        } else if ( StrCaseCmp("deny access on error", param) == 0 ) {
-                set_boolean(&deny_access_on_error, value);
-                DEBUG(3, ("deny access on error is: %d\n", deny_access_on_error));
-        } else if ( StrCaseCmp("deny access on minor error", param) == 0 ) {
-                set_boolean(&deny_access_on_minor_error, value);
-                DEBUG(3, ("deny access on minor error is: %d\n", deny_access_on_minor_error));
-        } else if ( StrCaseCmp("send warning message", param) == 0 ) {
-                set_boolean(&send_warning_message, value);
-                DEBUG(3, ("send warning message is: %d\n", send_warning_message));
-        } else if ( StrCaseCmp("infected file action", param) == 0 ) {
-		if (StrCaseCmp("quarantine", value) == 0) {
-			infected_file_action = INFECTED_QUARANTINE;
-		} else if (StrCaseCmp("delete", value) == 0) {
-			infected_file_action = INFECTED_DELETE;
-		} else if (StrCaseCmp("nothing", value) == 0) {
-			infected_file_action = INFECTED_DO_NOTHING;
-		} else {
-			DEBUG(2, ("samba-vscan: badly formed infected file action in configuration file, parameter %s\n", value));
-		}
-                DEBUG(3, ("infected file action is: %d\n", infected_file_action));
-        } else if ( StrCaseCmp("quarantine directory", param) == 0 ) {
-                fstrcpy(quarantine_dir, value);
-                DEBUG(3, ("quarantine directory is: %s\n", quarantine_dir));
-        } else if ( StrCaseCmp("quarantine prefix", param) == 0 ) {
-                fstrcpy(quarantine_prefix, value);
-                DEBUG(3, ("quarantine prefix is: %s\n", quarantine_prefix));
-        } else if ( StrCaseCmp("max lru files entries", param) == 0 ) {
-                max_lrufiles = atoi(value);
-                DEBUG(3, ("max lru files entries is: %d\n", max_lrufiles));
-        } else if ( StrCaseCmp("lru file entry lifetime", param) == 0 ) {
-                lrufiles_invalidate_time = atol(value);
-                DEBUG(3, ("lru file entry lifetime is: %li\n", (long)lrufiles_invalidate_time));
-	} else if ( StrCaseCmp("exclude file types", param) == 0 ) {
-		pstrcpy(exclude_file_types, value);
-		DEBUG(3, ("Exclude list is: %s\n", exclude_file_types));
-        } else if ( StrCaseCmp("oav ip", param) == 0 ) {
-                fstrcpy(oav_ip, value);
-                DEBUG(3, ("OAV ScannerDaemon IP is: %s\n", oav_ip));
-        } else if ( StrCaseCmp("oav port", param) == 0 ) {
-                /* FIXME: oav_ip is short int ! atoi converts string to int
-                   overflow is possible. Should a check be added, if port number
-                   is too high? */
-                oav_port = atoi(value);
-                DEBUG(3, ("OAV ScannerDaemon port is: %d\n", oav_port));
-	} else
-                DEBUG(3, ("unknown parameter: %s\n", param));
+
+	if ( do_common_parameter(&vscan_config, param, value) == False ) {
+		/* parse VFS module specific configuration values */
+        	if ( StrCaseCmp("oav ip", param) == 0 ) {
+                	fstrcpy(oav_ip, value);
+                	DEBUG(3, ("OAV ScannerDaemon IP is: %s\n", oav_ip));
+	        } else if ( StrCaseCmp("oav port", param) == 0 ) {
+        	        /* FIXME: oav_ip is short int ! atoi converts string to int
+                	   overflow is possible. Should a check be added, if port number
+                   	   is too high? */
+	                oav_port = atoi(value);
+        	        DEBUG(3, ("OAV ScannerDaemon port is: %d\n", oav_port));
+		} else
+                	DEBUG(3, ("unknown parameter: %s\n", param));
+	}
 
         return True;
 }
@@ -192,34 +113,35 @@
         fstrcpy(config_file, PARAMCONF);
 
         /* set default value for max file size */
-        max_size = VSCAN_MAX_SIZE;
+        vscan_config.common.max_size = VSCAN_MAX_SIZE;
 
         /* set default value for file logging */
-        verbose_file_logging = VSCAN_VERBOSE_FILE_LOGGING;
+        vscan_config.common.verbose_file_logging = VSCAN_VERBOSE_FILE_LOGGING;
+	verbose_file_logging = VSCAN_VERBOSE_FILE_LOGGING;
 
         /* set default value for scan on open() */
-        scan_on_open = VSCAN_SCAN_ON_OPEN;
+        vscan_config.common.scan_on_open = VSCAN_SCAN_ON_OPEN;
 
         /* set default value for scan on close() */
-        scan_on_close = VSCAN_SCAN_ON_CLOSE;
+        vscan_config.common.scan_on_close = VSCAN_SCAN_ON_CLOSE;
 
         /* set default value for deny access on error */
-        deny_access_on_error = VSCAN_DENY_ACCESS_ON_ERROR;
+        vscan_config.common.deny_access_on_error = VSCAN_DENY_ACCESS_ON_ERROR;
 
 	/* set default value for deny access on minor error */
-	deny_access_on_minor_error = VSCAN_DENY_ACCESS_ON_MINOR_ERROR;
+	vscan_config.common.deny_access_on_minor_error = VSCAN_DENY_ACCESS_ON_MINOR_ERROR;
  
 	/* set default value for send warning message */
-	send_warning_message = VSCAN_SEND_WARNING_MESSAGE;
+	vscan_config.common.send_warning_message = VSCAN_SEND_WARNING_MESSAGE;
 
         /* set default value for infected file action */
-        infected_file_action = VSCAN_INFECTED_FILE_ACTION;
+        vscan_config.common.infected_file_action = VSCAN_INFECTED_FILE_ACTION;
 
         /* set default value for quarantine directory */
-        fstrcpy(quarantine_dir, VSCAN_QUARANTINE_DIRECTORY);
+        fstrcpy(vscan_config.common.quarantine_dir, VSCAN_QUARANTINE_DIRECTORY);
 
         /* set default value for quarantine prefix */
-        fstrcpy(quarantine_prefix, VSCAN_QUARANTINE_PREFIX);
+        fstrcpy(vscan_config.common.quarantine_prefix, VSCAN_QUARANTINE_PREFIX);
 
         /* set default value for OAV ScannerDaemon IP */
         fstrcpy(oav_ip, VSCAN_OAV_IP);
@@ -228,13 +150,13 @@
         oav_port = VSCAN_OAV_PORT;
 
         /* set default value for maximum lrufile entries */
-        max_lrufiles = VSCAN_MAX_LRUFILES;
+        vscan_config.common.max_lrufiles = VSCAN_MAX_LRUFILES;
 
         /* time after an entry is considered as expired */
-        lrufiles_invalidate_time = VSCAN_LRUFILES_INVALIDATE_TIME;
+        vscan_config.common.lrufiles_invalidate_time = VSCAN_LRUFILES_INVALIDATE_TIME;
 
 	/* file type exclude ist */
-	pstrcpy(exclude_file_types, VSCAN_FT_EXCLUDE_LIST);	
+	pstrcpy(vscan_config.common.exclude_file_types, VSCAN_FT_EXCLUDE_LIST);	
 
 	vscan_syslog("INFO: connect to service %s by user %s", 
 	       svc, user);
@@ -269,17 +191,21 @@
           }
 	  #endif /*  #if (SMB_VFS_INTERFACE_VERSION >= 6)*/
           retval = pm_process(config_file, do_section, do_parameter);
+
+	  /* FIXME: this is lame! */
+	  verbose_file_logging = vscan_config.common.verbose_file_logging;
+
           DEBUG(10, ("pm_process returned %d\n", retval));
 	  if (!retval) vscan_syslog("ERROR: could not parse configuration file '%s'. File not found or not read-able. Using compiled-in defaults", config_file);
 	#endif
 
         /* initialise lrufiles list */
         DEBUG(5, ("init lrufiles list\n"));
-        lrufiles_init(max_lrufiles, lrufiles_invalidate_time);
+        lrufiles_init(vscan_config.common.max_lrufiles, vscan_config.common.lrufiles_invalidate_time);
 
 	/* initialise filetype */
 	DEBUG(5, ("init file type\n"));
-	filetype_init(0, exclude_file_types);
+	filetype_init(0, vscan_config.common.exclude_file_types);
 
 
 	#if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -332,7 +258,7 @@
 	/* the following if conditions look awfull, seems we need a (generic) decision module sooner or later ... */
 
         /* scan files while opening? */
-        if ( !scan_on_open ) {
+        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));
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -355,7 +281,7 @@
 #else
 		return default_vfs_ops.open(conn, fname, flags, mode);
 #endif
-	else if ( ( stat_buf.st_size > max_size ) && ( max_size > 0 ) ) /* file is too large */
+	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 */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -374,9 +300,9 @@
 	} else  
 	{
 		/* open socket */
-		sockfd = vscan_oav_init();
+		sockfd = vscan_oav_init(oav_ip, oav_port);
 
-                if ( sockfd == -1 && deny_access_on_error ) {
+                if ( sockfd == -1 && vscan_config.common.deny_access_on_error ) {
                         /* an error occured - can not communicate to daemon - deny access */
                         vscan_syslog("ERROR: can not communicate to daemon - access denied");
                         errno = EACCES;
@@ -419,7 +345,7 @@
 
 			/* scan file */
 			retval = vscan_oav_scanfile(sockfd, filepath, client_ip);
-			if ( retval == -2 && deny_access_on_minor_error ) {
+			if ( retval == -2 && vscan_config.common.deny_access_on_minor_error ) {
 				/* a minor error occured - deny access */
 				vscan_syslog("ERROR: daemon failed with a minor error - access to file %s denied", fname);
 				vscan_oav_end(sockfd);
@@ -430,7 +356,7 @@
                                 /* deny access */
 				errno = EACCES;
 				return -1;
-                        } else if ( retval == -1 && deny_access_on_error ) {
+                        } else if ( retval == -1 && vscan_config.common.deny_access_on_error ) {
                                 /* an error occured - can not communicate to daemon - deny access */
                                 vscan_syslog("ERROR: can not communicate to daemon - access to file %s denied", fname);
 				vscan_oav_end(sockfd);
@@ -448,9 +374,9 @@
 				/* do action ... */
 				
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
-				rc = vscan_do_infected_file_action(handle, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+				rc = vscan_do_infected_file_action(handle, conn, filepath, vscan_config.common.quarantine_dir, vscan_config.common.quarantine_prefix, vscan_config.common.infected_file_action);
 #else
-				rc = vscan_do_infected_file_action(&default_vfs_ops, conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+				rc = vscan_do_infected_file_action(&default_vfs_ops, 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! */
@@ -494,7 +420,7 @@
         retval = default_vfs_ops.close(fsp, fd);
 #endif
 
-        if ( !scan_on_close ) {
+        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;
         }
@@ -526,7 +452,7 @@
 
 
 	/* scan only file, do nothing */	
-        sockfd = vscan_oav_init();
+        sockfd = vscan_oav_init(oav_ip, oav_port);
 
         if ( sockfd >= 0 ) {
 		safe_strcpy(client_ip, fsp->conn->client_address, CLIENT_IP_SIZE -1);
@@ -535,9 +461,9 @@
 		if ( rv == 1 ) {
 			/* virus was found */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
-			rc = vscan_do_infected_file_action(handle, fsp->conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+			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
-			rc = vscan_do_infected_file_action(&default_vfs_ops, fsp->conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
+			rc = 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
 		}
 

Index: vscan-oav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/openantivirus/Attic/vscan-oav_core.c,v
retrieving revision 1.18.2.2
retrieving revision 1.18.2.3
diff -u -d -r1.18.2.2 -r1.18.2.3
--- vscan-oav_core.c	3 Jan 2004 14:59:41 -0000	1.18.2.2
+++ vscan-oav_core.c	2 May 2004 19:45:32 -0000	1.18.2.3
@@ -19,43 +19,14 @@
 /* hum, global vars ... */
 extern BOOL verbose_file_logging;
 extern BOOL send_warning_message;
-extern fstring  oav_ip;
-extern unsigned short int oav_port;
 
 
 /* initialise socket to ScannerDaemon
    returns -1 on error or the socket descriptor */
-int vscan_oav_init(void)
+int vscan_oav_init(const char* oav_ip, const unsigned short int oav_port)
 {
 
-	int sockfd;
-	struct sockaddr_in servaddr;
-
-	/* create socket */
-        if (( sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
-               vscan_syslog("ERROR: can not create socket!\n");
-               return -1; 
-        }
-
-	bzero(&servaddr, sizeof(servaddr));
-        servaddr.sin_family = AF_INET;
-        servaddr.sin_port = htons(oav_port);
-
-	/* hm, inet_pton may not exist on all systems - FIXME ! */
-        if ( inet_pton(AF_INET, oav_ip, &servaddr.sin_addr) <= 0 ) {
-                vscan_syslog("ERROR: inet_pton failed!\n");
-                return -1;
-	}
-
-	/* connect to socket */
-	if ( connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0 )
-        {
-                vscan_syslog("ERROR: can not connect to ScannerDaemon (IP: '%s', port: '%d')!\n", oav_ip, oav_port);
-                return -1;
-        }
-
-
-	return sockfd;
+	return vscan_inet_socket_init("ScannerDaemon", oav_ip, oav_port); 
 
 }
 
@@ -188,9 +159,5 @@
 */
 void vscan_oav_end(int sockfd)
 {
-	/* sockfd == -1 indicates an error while connecting to socket */
-	if ( sockfd >= 0 ) {
-		close(sockfd);
-	}
-
+	vscan_socket_end(sockfd);
 }



-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click