samba-vscan/clamav vscan-clamav.c,1.1.2.11,1.1.2.12 vscan-clamav_core.c,1.5.2.9,1.5.2.10

Rainer Link <[email protected]> Fri, 24 Sep 2004 21:45:11 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/clamav
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6083

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


Index: vscan-clamav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav.c,v
retrieving revision 1.1.2.11
retrieving revision 1.1.2.12
diff -u -d -r1.1.2.11 -r1.1.2.12
--- vscan-clamav.c	24 Sep 2004 09:17:31 -0000	1.1.2.11
+++ vscan-clamav.c	24 Sep 2004 21:45:08 -0000	1.1.2.12
@@ -4,7 +4,7 @@
  * virusscanning VFS module for samba.  Log infected files via syslog
  * facility and block access using Clam AntiVirus Daemon.
  *
- * Copyright (C) Rainer Link, 2001-2003
+ * Copyright (C) Rainer Link, 2001-2004
  *               OpenAntiVirus.org <rainer-pBPPa8WU5k41Tgt60Rntydi2O/[email protected]>
  *               Dariusz Markowicz <[email protected]>, 2003
  * Copyright (C) Stefan (metze) Metzmacher, 2003
@@ -381,7 +381,7 @@
 		if ( verbose_file_logging )
 			vscan_syslog("INFO: File %s has size zero! Not scanned!", fname);
 	}
-	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);
 	} else
@@ -392,7 +392,7 @@
 		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 == -1 ) {
+                if ( must_be_checked == VSCAN_LRU_DENY_ACCESS ) {
                         /* file has already been checked and marked as infected */
                         /* deny access */
                         if ( verbose_file_logging )
@@ -401,7 +401,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 )
                                 vscan_syslog("File '%s' has already been scanned, not marked as infected and not modified. Not scanned anymore. Access granted", filepath);
@@ -417,7 +417,7 @@
 
 			/* open socket */
 			sockfd = vscan_clamav_init();
-	                if ( sockfd == -1 ) {
+	                if ( sockfd == VSCAN_SCAN_ERROR ) {
 				if( deny_access_on_error ) {
 		                        /* an error occured - can not communicate to daemon - deny access */
 					vscan_syslog("ERROR: can not communicate to daemon - access denied");
@@ -433,11 +433,11 @@
 				vscan_clamav_end(sockfd);
 			}
 #endif
-			if ( 0 == retval ) {
+			if ( retval == VSCAN_SCAN_OK ) {
                                 /* file is clean, add to lrufiles */
                                 lrufiles_add(filepath, stat_buf.st_mtime, False);
 			}
-			else if ( 1 == retval ) {
+			else if ( retval == VSCAN_SCAN_VIRUS_FOUND ) {
 				/* virus found */
 				/* do action ... */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
@@ -453,7 +453,7 @@
 				errno = EACCES; 
 				return -1;
 			}
-			else if ( -2 == retval ) {
+			else if ( retval == VSCAN_SCAN_MINOR_ERROR ) {
 				/* to be safe, remove file from lrufiles */
 				lrufiles_delete(filepath);
 
@@ -467,7 +467,7 @@
 				}
 				/* a minor error occured - Not scanned */
 				vscan_syslog("ERROR: daemon failed with a minor error - file %s Not scanned!", fname);
-                        } else if ( -1 == retval ) {
+                        } else if ( retval == VSCAN_SCAN_ERROR ) {
 				/* to be safe, remove file from lrufiles */
 				lrufiles_delete(filepath);
 
@@ -533,7 +533,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", filepath);
 		return retval;
@@ -573,7 +573,7 @@
 	}
 #endif	/* LIBCLAMAV */
 
-	if ( rv == 1 ) {
+	if ( rv == VSCAN_SCAN_VIRUS_FOUND ) {
 		/* virus was found */
 #if (SMB_VFS_INTERFACE_VERSION >= 6)
 		vscan_do_infected_file_action(handle, fsp->conn, filepath, quarantine_dir, quarantine_prefix, infected_file_action);
@@ -583,7 +583,7 @@
 		/* add/update file, mark file as infected! */
 		lrufiles_add(filepath, stat_buf.st_mtime, True);
 	}
-	else if( rv == 0 ) {
+	else if( rv == VSCAN_SCAN_OK ) {
 		/* add/update file, mark file as clean! */
 		lrufiles_add(filepath, stat_buf.st_mtime, False);
 	}

Index: vscan-clamav_core.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/clamav/vscan-clamav_core.c,v
retrieving revision 1.5.2.9
retrieving revision 1.5.2.10
diff -u -d -r1.5.2.9 -r1.5.2.10
--- vscan-clamav_core.c	9 Sep 2004 13:10:56 -0000	1.5.2.9
+++ vscan-clamav_core.c	24 Sep 2004 21:45:09 -0000	1.5.2.10
@@ -3,7 +3,7 @@
  * 
  * Core Interface for Clam AntiVirus Daemon
  *
- * Copyright (C) Rainer Link, 2001-2002
+ * Copyright (C) Rainer Link, 2001-2004
  *               OpenAntiVirus.org <rainer-pBPPa8WU5k41Tgt60Rntydi2O/[email protected]>
  *               Dariusz Markowicz <[email protected]>, 2003
  *
@@ -77,7 +77,8 @@
 
 #ifdef LIBCLAMAV
 /* Scan a file using lib clamav
- Returns -2 on minor error,  -1 on error, 0 if a no virus was found,                             1 if a virus was found
+ Returns -2 on minor error,  -1 on error, 0 if a no virus was found,
+ 1 if a virus was found
 */
 int vscan_clamav_lib_scanfile(char* scan_file, char* client_ip)
 {
@@ -91,15 +92,15 @@
 	if (verbose_file_logging) {
 		vscan_syslog("INFO: file %s is clean", scan_file);
 	}
-	return 0;
+	return VSCAN_SCAN_OK;
     }
     if ( ret == CL_VIRUS ) {  /* virus found */
 	vscan_clamav_log_virus(scan_file, virname, client_ip);	
-	return 1;
+	return VSCAN_SCAN_VIRUS_FOUND;
     }
     /* error */
     vscan_syslog("ERROR: file %s not found, not readable or an error occured (lib return code: %d)", scan_file, ret);
-    return -2;
+    return VSCAN_SCAN_MINOR_ERROR;
 }
 #else	/* LIBCLAMAV */
 
@@ -120,7 +121,7 @@
     fpin = fdopen(sockfd, "r");
     if (fpin == NULL) {
         vscan_syslog("ERROR: Can not open stream for reading - %s", strerror(errno));
-        return -1;
+        return VSCAN_SCAN_ERROR;
     }
  
     memset(buff, 0, sizeof(buff));
@@ -130,7 +131,7 @@
     /* prepare clamd command */
     if (!(request = (char *)malloc(len))) {
         vscan_syslog("ERROR: can not allocate memory");
-        return -1; /* error allocating memory */
+        return VSCAN_SCAN_ERROR; /* error allocating memory */
     }
 
     if (verbose_file_logging)
@@ -142,7 +143,7 @@
         free(request);
 
         vscan_syslog("ERROR: can not write to the clamd socket");
-        return -1; /* error writing to the clamd socket */
+        return VSCAN_SCAN_ERROR; /* error writing to the clamd socket */
     }
 
     free(request);
@@ -163,23 +164,23 @@
             p1[1] = '\0';
 
             vscan_clamav_log_virus(scan_file, vir, client_ip);
-            return 1;
+            return VSCAN_SCAN_VIRUS_FOUND;
         }
 	if ((NULL !=  strstr(buff, "OK\n"))) {
             if (verbose_file_logging)
                 vscan_syslog("INFO: file %s is clean", scan_file);
 
-            return 0;
+            return VSCAN_SCAN_OK;
         }
 
         vscan_syslog("ERROR: file %s not found, not readable or an error occured", scan_file);
-        return -2;
+        return VSCAN_SCAN_MINOR_ERROR;
     }
 
     fclose(fpin);
 
-    vscan_syslog("ERROR: can not get result from clamd");
-    return -1;
+    vscan_syslog("ERROR: could not get result from clamd");
+    return VSCAN_SCAN_ERROR;
 }
 #endif /* LIBCLAMAV */
 



-------------------------------------------------------
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