samba-vscan/f-secure vscan-fsav.c,1.1.2.1,1.1.2.2

[email protected]
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/samba-vscan/f-secure
In directory sc8-pr-cvs1:/tmp/cvs-serv29548

Modified Files:
      Tag: VSCAN_0_3
	vscan-fsav.c 
Log Message:
updated to get it working with Samba 2.2.x, too


Index: vscan-fsav.c
===================================================================
RCS file: /cvsroot/openantivirus/samba-vscan/f-secure/Attic/vscan-fsav.c,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -d -r1.1.2.1 -r1.1.2.2
--- vscan-fsav.c	4 Dec 2003 16:31:13 -0000	1.1.2.1
+++ vscan-fsav.c	10 Dec 2003 15:17:08 -0000	1.1.2.2
@@ -200,15 +200,29 @@
 
 /* Implementation of vfs_ops.  */
 
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 static int vscan_connect(vfs_handle_struct * handle,
 			 connection_struct * conn, const char *svc,
 			 const char *user)
+#else
+static int vscan_connect(struct connection_struct *conn, 
+			PROTOTYPE_CONST char *svc, 
+			PROTOTYPE_CONST char *user)
+#endif
 {
-	int retval;
+        #if (SAMBA_VERSION_MAJOR==2 && SAMBA_VERSION_RELEASE>=4) || SAMBA_VERSION_MAJOR==3
+         #if !(SMB_VFS_INTERFACE_VERSION >= 6)
+          pstring opts_str;
+          PROTOTYPE_CONST char *p;
+         #endif
+        #endif
+        int retval;
 
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 	vscan_syslog
 	    ("samba-vscan (%s) connected (Samba 3.0), (c) by Rainer Link, OpenAntiVirus.org",
 	     module_id);
+#endif
 
 	/* set default value for configuration files */
 	fstrcpy(config_file, PARAMCONF);
@@ -266,15 +280,44 @@
 	pstrcpy(fsav_user, user);
 
 	vscan_syslog("INFO: connect to service %s by user %s", svc, user);
-	fstrcpy(config_file,
-		lp_parm_const_string(SNUM(conn), VSCAN_MODULE_STR,
-				     "config-file", PARAMCONF));
-	retval = pm_process(config_file, do_section, do_parameter);
-	DEBUG(10, ("pm_process returned %d\n", retval));
-	if (!retval)
+
+        #if (SAMBA_VERSION_MAJOR==2 && SAMBA_VERSION_RELEASE>=4) || SAMBA_VERSION_MAJOR==3
+         #if (SMB_VFS_INTERFACE_VERSION >= 6)
+          fstrcpy(config_file, lp_parm_const_string(SNUM(conn),VSCAN_MODULE_STR,"config-file",PARAMCONF));
+         #else
+          pstrcpy(opts_str, (const char*) lp_vfs_options(SNUM(conn)));
+          if( !*opts_str ) {
+                DEBUG(3, ("samba-vscan: no configuration file set - using default value (%s).\n", lp_vfs_options(SNUM(conn)))); 
+	  } else {
+                p = opts_str;
+                if ( next_token(&p, config_file, "=", sizeof(config_file)) ) {
+                        trim_string(config_file, " ", " ");
+                        if ( !strequal("config-file", config_file) ) {
+                                DEBUG(3, ("samba-vscan - connect: options %s is not config-file\n", config_file));
+                                /* setting default value */
+                                fstrcpy(config_file, PARAMCONF);
+
+                        } else {
+                                if ( !next_token(&p, config_file," \n",sizeof(config_file)) ) {
+                                        DEBUG(3, ("samba-vscan - connect: no option after config-file=\n"));
+                                        /* setting default value */
+                                        fstrcpy(config_file, PARAMCONF);
+                                } else {
+                                        trim_string(config_file, " ", " ");
+                                        DEBUG(3, ("samba-vscan - connect: config file name is %s\n", config_file));
+                                }
+                        }
+                }
+          }
+         #endif /*  #if (SMB_VFS_INTERFACE_VERSION >= 6)*/
+
+ 	 retval = pm_process(config_file, do_section, do_parameter);
+	 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"));
@@ -284,13 +327,19 @@
 	DEBUG(5, ("init file type\n"));
 	filetype_init(0, exclude_file_types);
 
-
-	return SMB_VFS_NEXT_CONNECT(handle, conn, svc, user);
-
+        #if (SMB_VFS_INTERFACE_VERSION >= 6)
+         return SMB_VFS_NEXT_CONNECT(handle, conn, svc, user);
+        #else
+         return default_vfs_ops.connect(conn, svc, user);
+        #endif
 }
 
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 static void vscan_disconnect(vfs_handle_struct * handle,
 			     connection_struct * conn)
+#else
+static void vscan_disconnect(struct connection_struct *conn)
+#endif
 {
 
 	vscan_syslog("INFO: disconnected");
@@ -298,12 +347,21 @@
 	lrufiles_destroy_all();
 	filetype_close();
 
-	SMB_VFS_NEXT_DISCONNECT(handle, conn);
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+        SMB_VFS_NEXT_DISCONNECT(handle, conn);
+#else
+        default_vfs_ops.disconnect(conn);
+#endif
 }
 
-
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 static int vscan_open(vfs_handle_struct * handle, connection_struct * conn,
 		      const char *fname, int flags, mode_t mode)
+#else
+static int vscan_open(struct connection_struct *conn, 
+			PROTOTYPE_CONST char *fname, int flags, mode_t mode)
+
+#endif
 {
 	int retval, must_be_checked;
 	SMB_STRUCT_STAT stat_buf;
@@ -320,29 +378,44 @@
 	pstrcat(filepath, fname);
 
 	/* scan files while opening? */
-	if (!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 ( !scan_on_open ) {
+                DEBUG(3, ("samba-vscan - open: File '%s' not scanned as scan_on_open is not set\n", fname));
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#else
+                return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
+        }
 
-	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 > max_size) && (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 (filetype_skipscan(filepath) == 1) {
-		if (verbose_file_logging)
-			vscan_syslog
-			    ("File '%s' not scanned as file type is on exclude list",
-			     filepath);
-		return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+        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 ( (default_vfs_ops.stat(conn, fname, &stat_buf)) != 0 )    /* an error occured */
+                return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
+        else if ( S_ISDIR(stat_buf.st_mode) )   /* is it a directory? */
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#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 */
+                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)
+                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#else
+                return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
+        else if ( filetype_skipscan(filepath) == 1 ) {
+                if ( verbose_file_logging )
+                        vscan_syslog("File '%s' not scanned as file type is on exclude list", filepath);
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+                return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#else
+                return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
 	} else {
 		fsav = fsav_create_handle();
 		if (fsav) {
@@ -403,9 +476,13 @@
 				fsav_free_handle(fsav);
 
 				/* grant access */
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 				return SMB_VFS_NEXT_OPEN(handle, conn,
 							 fname, flags,
 							 mode);
+#else
+				return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
 			}
 			/* ok, we must check the file */
 
@@ -445,12 +522,21 @@
 			} else if (retval == 1) {
 				fsav_free_handle(fsav);
 				/* do action ... */
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 				rc = vscan_do_infected_file_action(handle,
 								   conn,
 								   filepath,
 								   quarantine_dir,
 								   quarantine_prefix,
-								   infected_file_action);
+						   		   infected_file_action);
+#else
+				rc = rc = vscan_do_infected_file_action(&default_vfs_ops,
+                                                                   conn,
+                                                                   filepath,
+                                                                   quarantine_dir,
+                                                                   quarantine_prefix,
+                                                                   infected_file_action);
+#endif
 
 				/* add/update file. mark file as infected! */
 				lrufiles_add(filepath, stat_buf.st_mtime,
@@ -469,11 +555,20 @@
 		/* close handle */
 		fsav_free_handle(fsav);
 	}
-	return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+       return SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode);
+#else
+       return default_vfs_ops.open(conn, fname, flags, mode);
+#endif
+
 }
 
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
 static int vscan_close(vfs_handle_struct * handle, files_struct * fsp,
 		       int fd)
+#else
+static int vscan_close(struct files_struct *fsp, int fd)
+#endif
 {
 	fsav_handle *fsav;
 	pstring filepath;
@@ -481,7 +576,11 @@
 	char client_ip[CLIENT_IP_SIZE];
 
 	/* First close the file */
-	retval = SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+        retval = SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
+#else
+        retval = default_vfs_ops.close(fsp, fd);
+#endif
 
 	if (!scan_on_close) {
 		DEBUG(3,
@@ -546,19 +645,29 @@
 		rv = fsav_scan(fsav, filepath);
 		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);
+#else
+			rc = vscan_do_infected_file_action(&default_vfs_ops,
+                                                           fsp->conn,
+                                                           filepath,
+                                                           quarantine_dir,
+                                                           quarantine_prefix,
+                                                           infected_file_action);
+#endif
 		}
 
 	}
 	return retval;
 }
 
-
+#if (SMB_VFS_INTERFACE_VERSION >= 6)
+/* Samba 3.0 */
 NTSTATUS init_module(void)
 {
 	NTSTATUS ret;
@@ -573,6 +682,105 @@
 
 	return ret;
 }
+#else
+/* VFS initialisation function.  Return initialised vfs_ops structure
+   back to SAMBA. */
+#if SAMBA_VERSION_MAJOR==3
+ /* Samba 3.0 alphaX */
+ vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops,
+                        struct smb_vfs_handle_struct *vfs_handle)
+#else
+ /* Samba 2.2.x */
+ #if SAMBA_VERSION_RELEASE>=4
+  /* Samba 2.2.4 */
+  struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
+ #elif SAMBA_VERSION_RELEASE==2
+  /* Samba 2.2.2 / Samba 2.2.3 !!! */
+  struct vfs_ops *vfs_init(int* Version, struct vfs_ops *ops)
+ #elif SAMBA_VERSION_RELEASE==1
+  /* Samba 2.2.1 */
+  struct vfs_ops *vfs_module_init(int *vfs_version)
+ #else
+  /* Samba 2.2.0 */
+  struct vfs_ops *vfs_init(int *vfs_version)
+ #endif
+#endif
+{
+        #if SAMBA_VERSION_MAJOR!=3
+         #if SAMBA_VERSION_RELEASE>=4
+          /* Samba 2.2.4 */
+          struct vfs_ops tmp_ops;
+         #endif
+        #endif
+
+        openlog("smbd_"VSCAN_MODULE_STR, LOG_PID, SYSLOG_FACILITY);
+
+        #if SAMBA_VERSION_MAJOR==3
+         /* Samba 3.0 alphaX */
+         *vfs_version = SMB_VFS_INTERFACE_VERSION;
+         vscan_syslog("samba-vscan (%s) loaded (Samba 3.x), (c) by Rainer Link, OpenAntiVirus.org", module_id);
+        #else
+         /* Samba 2.2.x */
+         #if SAMBA_VERSION_RELEASE>=4
+          /* Samba 2.2.4 */
+          *vfs_version = SMB_VFS_INTERFACE_VERSION;
+          vscan_syslog("samba-vscan (%s) loaded (Samba >=2.2.4), (c) by Rainer Link, OpenAntiVirus.org", module_id);
+         #elif SAMBA_VERSION_RELEASE==2
+          /* Samba 2.2.2 / Samba 2.2.3 !!! */
+          *Version = SMB_VFS_INTERFACE_VERSION;
+          vscan_syslog("samba-vscan (%s) loaded (Samba 2.2.2/2.2.3), (c) by Rainer Link, OpenAntiVirus.org", module_id);
+         #else
+          /* Samba 2.2.1 / Samba 2.2.0 */
+          *vfs_version = SMB_VFS_INTERFACE_VERSION;
+          vscan_syslog("samba-vscan (%s) loaded (Samba 2.2.0/2.2.1), (c) by Rainer Link, OpenAntiVirus.org",
+               module_id);
+         #endif
+        #endif
+
+
+        #if SAMBA_VERSION_MAJOR==3
+         /* Samba 3.0 alphaX */
+         DEBUG(3, ("Initialising default vfs hooks\n"));
+         memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops));
+
+         /* Remember vfs_handle for further allocation and referencing of
+            private information in vfs_handle->data
+         */
+         vscan_handle = vfs_handle;
+         return vscan_ops;
+        #else
+         /* Samba 2.2.x */
+         #if SAMBA_VERSION_RELEASE>=4
+          /* Samba 2.2.4 */
+
+          *vfs_version = SMB_VFS_INTERFACE_VERSION;
+          memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
+          tmp_ops.connect = vscan_connect;
+          tmp_ops.disconnect = vscan_disconnect;
+          tmp_ops.open = vscan_open;
+          tmp_ops.close = vscan_close;
+          memcpy(&vscan_ops, &tmp_ops, sizeof(struct vfs_ops));
+          return(&vscan_ops);
+
+         #else
+          /* Samba 2.2.3-2.2.0 */
+          return(&vscan_ops);
+         #endif
+        #endif
+}
+
+
+#if SAMBA_VERSION_MAJOR==3
+/* VFS finalization function */
+void vfs_done(connection_struct *conn)
+{
+        DEBUG(3, ("Finalizing default vfs hooks\n"));
+}
+#endif
+
+#endif /* #if (SMB_VFS_INTERFACE_VERSION >= 6) */
+
+
 
 /*
  * init done




-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.