samba-vscan/f-secure vscan-fsav.c,1.1.2.6,1.1.2.7 vscan-fsav_core.c,1.1.2.8,1.1.2.9

Rainer Link <[email protected]> Sat, 25 Sep 2004 12:27:06 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/f-secure
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6692/f-secure

Modified Files:
      Tag: VSCAN_0_3
	vscan-fsav.c vscan-fsav_core.c 
Log Message:
make the code a little bit more read-able (esp. the check for return values)


Index: vscan-fsav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/f-secure/Attic/vscan-fsav.c,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -d -r1.1.2.6 -r1.1.2.7
--- vscan-fsav.c	7 Apr 2004 10:01:34 -0000	1.1.2.6
+++ vscan-fsav.c	25 Sep 2004 12:27:04 -0000	1.1.2.7
@@ -416,7 +416,7 @@
 #else
                 return default_vfs_ops.open(conn, fname, flags, mode);
 #endif
-        else if ( filetype_skipscan(filepath) == 1 ) {
+        else if ( filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN ) {
                 if ( verbose_file_logging )
                         vscan_syslog("File '%s' not scanned as file type is on exclude list", filepath);
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -459,7 +459,7 @@
 			must_be_checked =
 			    lrufiles_must_be_checked(filepath,
 						     stat_buf.st_mtime);
-			if (must_be_checked == -1) {
+			if (must_be_checked == VSCAN_LRU_DENY_ACCESS) {
 				/* file has already been checked and marked as infected */
 				/* deny access */
 				if (verbose_file_logging)
@@ -473,7 +473,7 @@
 				/* deny access */
 				errno = EACCES;
 				return -1;
-			} else if (must_be_checked == 0) {
+			} 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)
@@ -497,7 +497,7 @@
 
 			/* scan file */
 			retval = fsav_scan(fsav, filepath, client_ip);
-			if (retval == -2 && deny_access_on_minor_error) {
+			if (retval == VSCAN_SCAN_MINOR_ERROR && 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",
@@ -512,7 +512,7 @@
 				/* deny access */
 				errno = EACCES;
 				return -1;
-			} else if (retval == -1 && deny_access_on_error) {
+			} else if (retval == VSCAN_SCAN_ERROR && 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",
@@ -528,7 +528,7 @@
 
 				errno = EACCES;
 				return -1;
-			} else if (retval == 1) {
+			} else if (retval == VSCAN_SCAN_VIRUS_FOUND) {
 				fsav_free_handle(fsav);
 				/* do action ... */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -554,7 +554,7 @@
 				/* virus found, deny acces */
 				errno = EACCES;
 				return -1;
-			} else if (retval == 0) {
+			} else if (retval == VSCAN_SCAN_OK) {
 				/* file is clean, add to lrufiles */
 				lrufiles_add(filepath, stat_buf.st_mtime,
 					     False);
@@ -619,7 +619,7 @@
 	}
 
 	/* don't scan files which are in the list of exclude file types */
-	if (filetype_skipscan(filepath) == 1) {
+	if (filetype_skipscan(filepath) == VSCAN_FT_SKIP_SCAN) {
 		if (verbose_file_logging)
 			vscan_syslog
 			    ("File '%s' not scanned as file type is on exclude list",
@@ -653,7 +653,7 @@
 		safe_strcpy(client_ip, fsp->conn->client_address,
 			    CLIENT_IP_SIZE - 1);
 		rv = fsav_scan(fsav, filepath, client_ip);
-		if (rv == 1) {
+		if (rv == VSCAN_SCAN_VIRUS_FOUND) {
 			/* virus was found */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
 			rc = vscan_do_infected_file_action(handle,
@@ -671,6 +671,7 @@
                                                            infected_file_action);
 #endif
 		}
+		/* FIXME: shouldn't we handle errors as well? */
 
 	}
 	return retval;

Index: vscan-fsav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/f-secure/Attic/vscan-fsav_core.c,v
retrieving revision 1.1.2.8
retrieving revision 1.1.2.9
diff -u -d -r1.1.2.8 -r1.1.2.9
--- vscan-fsav_core.c	3 Apr 2004 16:27:13 -0000	1.1.2.8
+++ vscan-fsav_core.c	25 Sep 2004 12:27:04 -0000	1.1.2.9
@@ -329,7 +329,7 @@
 int fsav_scan(fsav_handle * h, char *file, char* client_ip)
 {
 	if (!h)
-		return -1;
+		return VSCAN_SCAN_ERROR;
 
 	DEBUG(5, ("samba-vscan (%s) scan %s\n ", module_id, file));
         if ( verbose_file_logging )
@@ -340,23 +340,23 @@
 	snprintf(h->buffer, BUFFERSIZE, "SCAN\t%s\n", file);
 	if (fsav_process(h)) {
 		vscan_syslog("ERROR: unknown error occured");
-		return -1;
+		return VSCAN_SCAN_ERROR;
 	}
 
 	if (h->infected) {
 		/* virus found */
-		h->rc = 1;
+		h->rc = VSCAN_SCAN_VIRUS_FOUND;
 		vscan_fsav_log_virus(file, h->virusname, client_ip);
 	} else {
 		if (h->fail) {
 			/* error */
-			h->rc = -1;
+			h->rc = VSCAN_SCAN_ERROR;
 			if ( verbose_file_logging )
 				vscan_syslog("ERROR: file %s not found, not readable or an error occured", file);
 
 		} else {
 			/* no virus found, everything OK */
-			h->rc = 0;
+			h->rc = VSCAN_SCAN_OK;
 			if ( verbose_file_logging )
 	                        vscan_syslog("INFO: file %s is clean", file);
 		}



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php