[patch] Cascaded VFS v.4

Alexander Bokovoy a.bokovoy at sam-solutions.net
Mon Jul 8 10:47:02 GMT 2002


Greetings!

Attached is the new revision (v.4) of cascaded VFS patch for HEAD.

Changes from Simo's revision:

-- connection_struct now contains a pointer to smb_vfs_handle_struct
   instance which is an element of a linked list. Each element describes
   completely one module [private data as void*, dl handle]. Linked list
   is managed with appropriate DLIST_XXX macros. 

   Module developers receive an allocated smb_vfs_handle_struct via
   vfs_init() third argument vfs_handle . If they want to store persisent 
   information and share it between module functions during connection live, 
   such information should be stored in vfs_handle->data and freed on
   connection closing.

-- all modules are loaded w/o exporting their symbols to main smbd
   namespace (RTLD_GLOBAL is gone). That means that modules must have only
   two public functions: vfs_init() and vfs_done() which are called
   directly from smbd's code but not imported into smbd's namespace (there
   is no need for it at all -- they are used in place).

-- hence of that, initialization and finalization functions renamed back
   to vfs_init() and vfs_done() functions, fstrings/pstrings straggle
   removed from smbd/vfs.c code to follow up Samba 3.0 code policy.

-- CFLAGS/LDFLAGS propagation to examples/VFS/ added, along with new, generalised,
   examples/VFS/Makefile.in which does not need to be changed to add support for new
   modules.

Things not finished yet:

-- Move to lp_list in smbd/vfs.c:vfs_init() module list parsing.

-- Adoption of JFM's function registration proposal [needs brainstorming
   on how to preserve operation types with one-function registration API].

As usual, look at comments in include/vfs.h and code in examples/VFs/*.c
to get more infomation and examples of usage.

-- 
/ Alexander Bokovoy
---
QOTD:
	"I've always wanted to work in the Federal Mint.  And then go on
	strike.  To make less money."
-------------- next part --------------
diff -urN samba-3.0/examples/VFS/audit.c samba-3.0.current/examples/VFS/audit.c
--- samba-3.0/examples/VFS/audit.c	2002-03-20 12:43:38 +0200
+++ samba-3.0.current/examples/VFS/audit.c	2002-07-08 19:49:47 +0300
@@ -3,6 +3,7 @@
  * facility.
  *
  * Copyright (C) Tim Potter, 1999-2000
+ * Copyright (C) Alexander Bokovoy, 2002
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -47,134 +48,79 @@
 
 /* Function prototypes */
 
-int audit_connect(struct connection_struct *conn, const char *svc, const char *user);
-void audit_disconnect(struct connection_struct *conn);
-DIR *audit_opendir(struct connection_struct *conn, const char *fname);
-int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode);
-int audit_rmdir(struct connection_struct *conn, const char *path);
-int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode);
-int audit_close(struct files_struct *fsp, int fd);
-int audit_rename(struct connection_struct *conn, const char *old, const char *new);
-int audit_unlink(struct connection_struct *conn, const char *path);
-int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode);
-int audit_chmod_acl(struct connection_struct *conn, const char *name, mode_t mode);
-int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode);
-int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode);
+static int audit_connect(struct connection_struct *conn, const char *svc, const char *user);
+static void audit_disconnect(struct connection_struct *conn);
+static DIR *audit_opendir(struct connection_struct *conn, const char *fname);
+static int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode);
+static int audit_rmdir(struct connection_struct *conn, const char *path);
+static int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode);
+static int audit_close(struct files_struct *fsp, int fd);
+static int audit_rename(struct connection_struct *conn, const char *old, const char *new);
+static int audit_unlink(struct connection_struct *conn, const char *path);
+static int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode);
+static int audit_chmod_acl(struct connection_struct *conn, const char *name, mode_t mode);
+static int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode);
+static int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode);
 
 /* VFS operations */
 
-extern struct vfs_ops default_vfs_ops;   /* For passthrough operation */
+static struct vfs_ops default_vfs_ops;   /* For passthrough operation */
+static struct smb_vfs_handle_struct *audit_handle;
 
-struct vfs_ops audit_ops = {
+static vfs_op_tuple audit_ops[] = {
     
 	/* Disk operations */
 
-	audit_connect,
-	audit_disconnect,
-	NULL,                     /* disk free */
+	{audit_connect, 	SMB_VFS_OP_CONNECT, 	SMB_VFS_LAYER_LOGGER},
+	{audit_disconnect, 	SMB_VFS_OP_DISCONNECT, 	SMB_VFS_LAYER_LOGGER},
 
 	/* Directory operations */
 
-	audit_opendir,
-	NULL,                     /* readdir */
-	audit_mkdir,
-	audit_rmdir,
-	NULL,                     /* closedir */
+	{audit_opendir, 	SMB_VFS_OP_OPENDIR, 	SMB_VFS_LAYER_LOGGER},
+	{audit_mkdir, 		SMB_VFS_OP_MKDIR, 	SMB_VFS_LAYER_LOGGER},
+	{audit_rmdir, 		SMB_VFS_OP_RMDIR, 	SMB_VFS_LAYER_LOGGER},
 
 	/* File operations */
 
-	audit_open,
-	audit_close,
-	NULL,                     /* read  */
-	NULL,                     /* write */
-	NULL,                     /* lseek */
-	audit_rename,
-	NULL,                     /* fsync */
-	NULL,                     /* stat  */
-	NULL,                     /* fstat */
-	NULL,                     /* lstat */
-	audit_unlink,
-	audit_chmod,
-	audit_fchmod,
-	NULL,                     /* chown */
-	NULL,                     /* fchown */
-	NULL,                     /* chdir */
-	NULL,                     /* getwd */
-	NULL,                     /* utime */
-	NULL,                     /* ftruncate */
-	NULL,                     /* lock */
-	NULL,                     /* symlink */
-	NULL,                     /* readlink */
-	NULL,                     /* link */
-	NULL,                     /* mknod */
-	NULL,                     /* realpath */
-	NULL,                     /* fget_nt_acl */
-	NULL,                     /* get_nt_acl */
-	NULL,                     /* fset_nt_acl */
-	NULL,                      /* set_nt_acl */
-
-	audit_chmod_acl,		/* chmod_acl */
-	audit_fchmod_acl,		/* fchmod_acl */
-
-	NULL,			/* sys_acl_get_entry */
-	NULL,			/* sys_acl_get_tag_type */
-	NULL,			/* sys_acl_get_permset */
-	NULL,			/*sys_acl_get_qualifier */
-	NULL,			/* sys_acl_get_file */
-	NULL,			/* sys_acl_get_fd */
-	NULL,			/* sys_acl_clear_perms */
-	NULL,			/* sys_acl_add_perm */
-	NULL,			/* sys_acl_to_text */
-	NULL,			/* sys_acl_init */
-	NULL,			/* sys_acl_create_entry */
-	NULL,			/* sys_acl_set_tag_type */
-	NULL,			/* sys_acl_set_qualifier */
-	NULL,			/* sys_acl_set_permset */
-	NULL,			/* sys_acl_valid */
-	NULL,			/* sys_acl_set_file */
-	NULL,			/* sys_acl_set_fd */
-	NULL,			/* sys_acl_delete_def_file */
-	NULL,			/* sys_acl_get_perm */
-	NULL,			/* sys_acl_free_text */
-	NULL,			/* sys_acl_free_acl */
-	NULL			/* sys_acl_free_qualifier */
+	{audit_open, 		SMB_VFS_OP_OPEN, 	SMB_VFS_LAYER_LOGGER},
+	{audit_close, 		SMB_VFS_OP_CLOSE, 	SMB_VFS_LAYER_LOGGER},
+	{audit_rename, 		SMB_VFS_OP_RENAME, 	SMB_VFS_LAYER_LOGGER},
+	{audit_unlink, 		SMB_VFS_OP_UNLINK, 	SMB_VFS_LAYER_LOGGER},
+	{audit_chmod, 		SMB_VFS_OP_CHMOD, 	SMB_VFS_LAYER_LOGGER},
+	{audit_fchmod, 		SMB_VFS_OP_FCHMOD, 	SMB_VFS_LAYER_LOGGER},
+	{audit_chmod_acl, 	SMB_VFS_OP_CHMOD_ACL, 	SMB_VFS_LAYER_LOGGER},
+	{audit_fchmod_acl, 	SMB_VFS_OP_FCHMOD_ACL, 	SMB_VFS_LAYER_LOGGER},
+	
+	/* Finish VFS operations definition */
+	
+	{NULL, 			SMB_VFS_OP_NOOP, 	SMB_VFS_LAYER_NOOP}
 };
 
-/* VFS initialisation function.  Return initialised vfs_ops structure
-   back to SAMBA. */
+/* VFS initialisation function.  Return vfs_op_tuple array back to SAMBA. */
 
-struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
+vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops, 
+			struct smb_vfs_handle_struct *vfs_handle)
 {
-	struct vfs_ops tmp_ops;
-
 	*vfs_version = SMB_VFS_INTERFACE_VERSION;
-	memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
-
-	tmp_ops.connect = audit_connect;
-	tmp_ops.disconnect = audit_disconnect;
-	tmp_ops.opendir = audit_opendir;
-	tmp_ops.mkdir = audit_mkdir;
-	tmp_ops.rmdir = audit_rmdir;
-	tmp_ops.open = audit_open;
-	tmp_ops.close = audit_close;
-	tmp_ops.rename = audit_rename;
-	tmp_ops.unlink = audit_unlink;
-	tmp_ops.chmod = audit_chmod;
-	tmp_ops.chmod_acl = audit_chmod_acl;
-	tmp_ops.fchmod = audit_fchmod;
-	tmp_ops.fchmod_acl = audit_fchmod_acl;
-
-	memcpy(&audit_ops, &tmp_ops, sizeof(struct vfs_ops));
+	memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops));
+	
+	audit_handle = vfs_handle;
 
 	openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY);
 	syslog(SYSLOG_PRIORITY, "VFS_INIT: vfs_ops loaded\n");
-	return &audit_ops;
+	return audit_ops;
+}
+
+/* VFS finalization function. */
+void vfs_done(connection_struct *conn)
+{
+	syslog(SYSLOG_PRIORITY, "VFS_DONE: vfs module unloaded\n");
 }
 
 /* Implementation of vfs_ops.  Pass everything on to the default
    operation but log event first. */
 
-int audit_connect(struct connection_struct *conn, const char *svc, const char *user)
+static int audit_connect(struct connection_struct *conn, const char *svc, const char *user)
 {
 	syslog(SYSLOG_PRIORITY, "connect to service %s by user %s\n", 
 	       svc, user);
@@ -182,13 +128,13 @@
 	return default_vfs_ops.connect(conn, svc, user);
 }
 
-void audit_disconnect(struct connection_struct *conn)
+static void audit_disconnect(struct connection_struct *conn)
 {
 	syslog(SYSLOG_PRIORITY, "disconnected\n");
 	default_vfs_ops.disconnect(conn);
 }
 
-DIR *audit_opendir(struct connection_struct *conn, const char *fname)
+static DIR *audit_opendir(struct connection_struct *conn, const char *fname)
 {
 	DIR *result = default_vfs_ops.opendir(conn, fname);
 
@@ -200,7 +146,7 @@
 	return result;
 }
 
-int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode)
+static int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode)
 {
 	int result = default_vfs_ops.mkdir(conn, path, mode);
 
@@ -212,7 +158,7 @@
 	return result;
 }
 
-int audit_rmdir(struct connection_struct *conn, const char *path)
+static int audit_rmdir(struct connection_struct *conn, const char *path)
 {
 	int result = default_vfs_ops.rmdir(conn, path);
 
@@ -224,7 +170,7 @@
 	return result;
 }
 
-int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode)
+static int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode)
 {
 	int result = default_vfs_ops.open(conn, fname, flags, mode);
 
@@ -237,7 +183,7 @@
 	return result;
 }
 
-int audit_close(struct files_struct *fsp, int fd)
+static int audit_close(struct files_struct *fsp, int fd)
 {
 	int result = default_vfs_ops.close(fsp, fd);
 
@@ -249,7 +195,7 @@
 	return result;
 }
 
-int audit_rename(struct connection_struct *conn, const char *old, const char *new)
+static int audit_rename(struct connection_struct *conn, const char *old, const char *new)
 {
 	int result = default_vfs_ops.rename(conn, old, new);
 
@@ -261,7 +207,7 @@
 	return result;    
 }
 
-int audit_unlink(struct connection_struct *conn, const char *path)
+static int audit_unlink(struct connection_struct *conn, const char *path)
 {
 	int result = default_vfs_ops.unlink(conn, path);
 
@@ -273,7 +219,7 @@
 	return result;
 }
 
-int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode)
+static int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode)
 {
 	int result = default_vfs_ops.chmod(conn, path, mode);
 
@@ -285,7 +231,7 @@
 	return result;
 }
 
-int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode)
+static int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode)
 {
 	int result = default_vfs_ops.chmod_acl(conn, path, mode);
 
@@ -297,7 +243,7 @@
 	return result;
 }
 
-int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode)
+static int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode)
 {
 	int result = default_vfs_ops.fchmod(fsp, fd, mode);
 
@@ -309,7 +255,7 @@
 	return result;
 }
 
-int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode)
+static int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode)
 {
 	int result = default_vfs_ops.fchmod_acl(fsp, fd, mode);
 
diff -urN samba-3.0/examples/VFS/block/block.c samba-3.0.current/examples/VFS/block/block.c
--- samba-3.0/examples/VFS/block/block.c	2002-03-20 12:43:39 +0200
+++ samba-3.0.current/examples/VFS/block/block.c	2002-07-08 17:59:51 +0300
@@ -3,6 +3,7 @@
  * Block access from links to dev mount points specified in PARAMCONF file
  *
  * Copyright (C) Ronald Kuetemeier, 2001
+ * Copyright (C) Alexander Bokovoy, 2002
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -47,93 +48,29 @@
 
 
 
-DIR *block_opendir(struct connection_struct *conn, char *fname);
-int block_connect(struct connection_struct *conn, const char *service, const char *user);    
-void block_disconnect(struct connection_struct *conn);    
+static DIR *block_opendir(connection_struct *conn, char *fname);
+static int block_connect(connection_struct *conn, const char *service, const char *user);    
+static void block_disconnect(connection_struct *conn);    
 
+static struct smb_vfs_handle_struct *block_handle;
 
 /* VFS operations */
 
 
-extern struct vfs_ops default_vfs_ops;   /* For passthrough operation */
+static struct vfs_ops default_vfs_ops;   /* For passthrough operation */
 
-struct vfs_ops execute_vfs_ops = {
+static vfs_op_tuple block_vfs_ops[] = {
     
 	/* Disk operations */
 
-	block_connect,
-	block_disconnect,
-	NULL,					/* disk free */
+	{block_connect,		SMB_VFS_OP_CONNECT,	SMB_VFS_LAYER_TRANSPARENT},
+	{block_disconnect,	SMB_VFS_OP_DISCONNECT,	SMB_VFS_LAYER_TRANSPARENT},
 
 	/* Directory operations */
 
-	block_opendir,
-	NULL,					/* readdir */
-	NULL,					/* mkdir */
-	NULL,					/* rmdir */
-	NULL,					/* closedir */
-
-	/* File operations */
-
-	NULL,					/* open */
-	NULL,					/* close */
-	NULL,					/* read  */
-	NULL,					/* write */
-	NULL,					/* lseek */
-	NULL,					/* rename */
-	NULL,					/* fsync */
-	NULL,					/* stat  */
-	NULL,					/* fstat */
-	NULL,					/* lstat */
-	NULL,					/* unlink */
-	NULL,					/* chmod */
-	NULL,					/* fchmod */
-	NULL,					/* chown */
-	NULL,					/* fchown */
-	NULL,					/* chdir */
-	NULL,					/* getwd */
-	NULL,					/* utime */
-	NULL,					/* ftruncate */
-	NULL,					/* lock */
-	NULL,					/* symlink */
-	NULL,					/* readlink */
-	NULL,					/* link */
-	NULL,					/* mknod */
-	NULL,					/* realpath */
-
-	/* NT ACL operations */
-
-	NULL,					/* fget_nt_acl */
-	NULL,					/* get_nt_acl */
-	NULL,					/* fset_nt_acl */
-	NULL,					/* set_nt_acl */
-
-	/* POSIX ACL operations. */
-
-	NULL,					/* chmod_acl */
-	NULL,					/* fchmod_acl */
-	NULL,					/* sys_acl_get_entry */
-	NULL,					/* sys_acl_get_tag_type */
-	NULL,					/* sys_acl_get_permset */
-	NULL,					/* sys_acl_get_qualifier */
-	NULL,					/* sys_acl_get_file */
-	NULL,					/* sys_acl_get_fd */
-	NULL,					/* sys_acl_clear_perms */
-	NULL,					/* sys_acl_add_perm */
-	NULL,					/* sys_acl_to_text */
-	NULL,					/* sys_acl_init */
-	NULL,					/* sys_acl_create_entry */
-	NULL,					/* sys_acl_set_tag_type */
-	NULL,					/* sys_acl_set_qualifier */
-	NULL,					/* sys_acl_set_permset */
-	NULL,					/* sys_acl_valid */
-	NULL,					/* sys_acl_set_file */
-	NULL,					/* sys_acl_set_fd */
-	NULL,					/* sys_acl_delete_def_file */
-	NULL,					/* sys_acl_get_perm */
-	NULL,					/* sys_acl_free_text */
-	NULL,					/* sys_acl_free_acl */
-	NULL					/* sys_acl_free_qualifier */
+	{block_opendir,		SMB_VFS_OP_OPENDIR,	SMB_VFS_LAYER_TRANSPARENT},
+	
+	{NULL,			SMB_VFS_OP_NOOP,	SMB_VFS_LAYER_NOOP}
 };
 
 
@@ -145,13 +82,13 @@
 
 //functions
 
-BOOL enter_pblock_mount(char *dir);
-BOOL get_section(char *sect);
-BOOL get_parameter_value(char *param, char *value);
-BOOL load_param(void);
-BOOL search(struct stat *stat_buf);
-BOOL dir_search(char *link, char *dir);
-BOOL enter_pblock_dir(char *dir);
+static BOOL enter_pblock_mount(char *dir);
+static BOOL get_section(char *sect);
+static BOOL get_parameter_value(char *param, char *value);
+static BOOL load_param(void);
+static BOOL search(struct stat *stat_buf);
+static BOOL dir_search(char *link, char *dir);
+static BOOL enter_pblock_dir(char *dir);
 
 
 
@@ -176,7 +113,7 @@
  * Load the conf file into a table
  */
 
-BOOL load_param(void)
+static BOOL load_param(void)
 {
 
 	if ((pm_process(PARAMCONF,&get_section,&get_parameter_value)) == TRUE)
@@ -194,7 +131,7 @@
  * 
  */
 
-BOOL enter_pblock_mount(char *dir)
+static BOOL enter_pblock_mount(char *dir)
 {
 	struct stat stat_buf;
 	static struct block_dir *tmp_pblock;
@@ -242,7 +179,7 @@
  * 
  */
 
-BOOL enter_pblock_dir(char *dir)
+static BOOL enter_pblock_dir(char *dir)
 {
 	static struct block_dir *tmp_pblock;
 	
@@ -285,7 +222,7 @@
  * Function callback for config section names 
  */
 
-BOOL get_section(char *sect)
+static BOOL get_section(char *sect)
 {
 	return TRUE;	
 }
@@ -297,7 +234,7 @@
  *
  */
 
-BOOL get_parameter_value(char *param, char *value)
+static BOOL get_parameter_value(char *param, char *value)
 {
 	int i = 0, maxargs = sizeof(params) / sizeof(char *);
 
@@ -327,24 +264,25 @@
 
 
 
-/* VFS initialisation function.  Return initialised vfs_ops structure
+/* VFS initialisation function.  Return initialised vfs_op_tuple array
    back to SAMBA. */
 
-struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
+vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops,
+			struct smb_vfs_handle_struct *vfs_handle)
 {
-	struct vfs_ops tmp_ops;
-
 	*vfs_version = SMB_VFS_INTERFACE_VERSION;
 	
-	memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
+	memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops));
+	
+	block_handle = vfs_handle;
+
+	return block_vfs_ops;
+}
 
-	/* Override the ones we want. */
-	tmp_ops.connect = block_connect;
-	tmp_ops.disconnect = block_disconnect;
-	tmp_ops.opendir = block_opendir;
 
-	memcpy(&execute_vfs_ops, &tmp_ops, sizeof(struct vfs_ops));
-	return(&execute_vfs_ops);
+/* VFS finalization function. */
+void vfs_done(connection_struct *conn)
+{
 }
 
 
@@ -352,7 +290,7 @@
  * VFS connect and param file loading
  */
 
-int block_connect(struct connection_struct *conn, char *service, char *user)
+static int block_connect(connection_struct *conn, const char *service, const char *user)
 {
 	if((load_param()) == FALSE)
 	{
@@ -372,7 +310,7 @@
  */
 
 
-void block_disconnect(struct connection_struct *conn)
+static void block_disconnect(struct connection_struct *conn)
 {
 	
 	struct block_dir *tmp_pblock = (pblock_mountp == NULL ? pblock_dir : pblock_mountp);
@@ -403,7 +341,7 @@
  * VFS opendir
  */
 
-DIR *block_opendir(struct connection_struct *conn, char *fname)
+static DIR *block_opendir(struct connection_struct *conn, char *fname)
 {
 
 	char *dir_name = NULL; 
@@ -437,7 +375,7 @@
  * Find mount point to block in list
  */
 
-BOOL search(struct stat *stat_buf)
+static BOOL search(struct stat *stat_buf)
 {
 	struct block_dir *tmp_pblock = pblock_mountp;
 
@@ -459,7 +397,7 @@
  * Find dir in list to block id the starting point is link from a share
  */
 
-BOOL dir_search(char *link, char *dir)
+static BOOL dir_search(char *link, char *dir)
 {
 	char buf[PATH_MAX +1], *ext_path;
 	int len = 0;
diff -urN samba-3.0/examples/VFS/block/Makefile samba-3.0.current/examples/VFS/block/Makefile
--- samba-3.0/examples/VFS/block/Makefile	2002-07-01 14:52:08 +0300
+++ samba-3.0.current/examples/VFS/block/Makefile	1970-01-01 03:00:00 +0300
@@ -1,37 +0,0 @@
-#
-# Makefile for samba-vfs examples
-#
-#
-
-# Variables
-
-CC = gcc
-LIBTOOL = libtool
-
-SAMBA_SRC = ../../../source
-SAMBA_INCL = ${SAMBA_SRC}/include
-UBIQX_SRC = ${SAMBA_SRC}/ubiqx
-SMBWR_SRC = ${SAMBA_SRC}/smbwrapper
-CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g -D_LARGEFILE63_SOURCE -D_GNU_SOURCE -fno-builtin  
- 
-
-VFS_OBJS = block.so
-
-# Default target
-
-default: $(VFS_OBJS)
-
-# Pattern rules
-
-%.so: %.lo
-	$(LIBTOOL) $(CC) -shared -o $@ $< $(LDFLAGS)
-
-%.lo: %.c
-	$(LIBTOOL) $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
-
-# Misc targets
-
-clean:
-	rm -rf .libs
-	rm -f core *~ *% *.bak \
-		$(VFS_OBJS) $(VFS_OBJS:.so=.o) $(VFS_OBJS:.so=.lo) 
diff -urN samba-3.0/examples/VFS/block/Makefile.in samba-3.0.current/examples/VFS/block/Makefile.in
--- samba-3.0/examples/VFS/block/Makefile.in	1970-01-01 03:00:00 +0300
+++ samba-3.0.current/examples/VFS/block/Makefile.in	2002-07-08 19:47:39 +0300
@@ -0,0 +1,42 @@
+MAKEFILE	= Makefile.vfs
+
+include	$(MAKEFILE)
+
+CC		= @CC@
+LIBTOOL		= libtool
+CFLAGS		= @CFLAGS@ $(VFS_CFLAGS)
+CPPFLAGS	= @CPPFLAGS@ $(VFS_CPPFLAGS)
+LDFLAGS		= @LDFLAGS@ $(VFS_LDFLAGS)
+LDSHFLAGS	= -shared
+srcdir		= @builddir@
+FLAGS		=  $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper  -I. $(CPPFLAGS) -I$(srcdir)
+
+# Default target
+
+default: $(VFS_OBJS)
+
+# if file doesn't exist try to create one; 
+# it is possible that some variables will be 
+# defined correctly
+Makefile.vfs:
+	@echo -ne "VFS_OBJS\t= " > $(MAKEFILE); \
+	for i in *.c; do \
+	echo -n $$i" " | sed -e 's/\(.*\)\.c\(.*\)/\1\.so\2/g' >> $(MAKEFILE); \
+	done; \
+	echo -ne "\nVFS_CFLAGS\t= \nVFS_CPPFLAGS\t= \nVFS_LDFLAGS\t= \n" >> $(MAKEFILE)
+	make
+
+# Pattern rules
+
+%.so: %.lo
+	$(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< 
+
+%.lo: %.c
+	$(LIBTOOL) $(CC) $(FLAGS) -c $<
+
+# Misc targets
+
+clean:
+	rm -rf .libs
+	rm -f core *~ *% *.bak \
+	$(VFS_OBJS) $(VFS_OBJS:.so=.o) $(VFS_OBJS:.so=.lo) 
diff -urN samba-3.0/examples/VFS/Makefile samba-3.0.current/examples/VFS/Makefile
--- samba-3.0/examples/VFS/Makefile	2002-05-15 12:55:09 +0300
+++ samba-3.0.current/examples/VFS/Makefile	1970-01-01 03:00:00 +0300
@@ -1,37 +0,0 @@
-#
-# Makefile for samba-vfs examples
-#
-#
-
-# Variables
-
-CC = gcc
-LIBTOOL = libtool
-
-SAMBA_SRC = ../../source
-SAMBA_INCL = ../../source/include
-POPT_INCL = ../../source/popt
-UBIQX_SRC = ../../source/ubiqx
-SMBWR_SRC = ../../source/smbwrapper
-KRB5_SRC = /usr/kerberos/include
-CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(POPT_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -I$(KRB5_SRC) -Wall -g
-VFS_OBJS = audit.so skel.so recycle.so
-
-# Default target
-
-default: $(VFS_OBJS)
-
-# Pattern rules
-
-%.so: %.lo
-	$(LIBTOOL) $(CC) -shared -o $@ $< $(LDFLAGS)
-
-%.lo: %.c
-	$(LIBTOOL) $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
-
-# Misc targets
-
-clean:
-	rm -rf .libs
-	rm -f core *~ *% *.bak \
-		$(VFS_OBJS) $(VFS_OBJS:.so=.o) $(VFS_OBJS:.so=.lo) 
diff -urN samba-3.0/examples/VFS/Makefile.in samba-3.0.current/examples/VFS/Makefile.in
--- samba-3.0/examples/VFS/Makefile.in	1970-01-01 03:00:00 +0300
+++ samba-3.0.current/examples/VFS/Makefile.in	2002-07-08 19:47:39 +0300
@@ -0,0 +1,42 @@
+MAKEFILE	= Makefile.vfs
+
+include	$(MAKEFILE)
+
+CC		= @CC@
+LIBTOOL		= libtool
+CFLAGS		= @CFLAGS@ $(VFS_CFLAGS)
+CPPFLAGS	= @CPPFLAGS@ $(VFS_CPPFLAGS)
+LDFLAGS		= @LDFLAGS@ $(VFS_LDFLAGS)
+LDSHFLAGS	= -shared
+srcdir		= @builddir@
+FLAGS		=  $(CFLAGS) -Iinclude -I$(srcdir)/include -I$(srcdir)/ubiqx -I$(srcdir)/smbwrapper  -I. $(CPPFLAGS) -I$(srcdir)
+
+# Default target
+
+default: $(VFS_OBJS)
+
+# if file doesn't exist try to create one; 
+# it is possible that some variables will be 
+# defined correctly
+Makefile.vfs:
+	@echo -ne "VFS_OBJS\t= " > $(MAKEFILE); \
+	for i in *.c; do \
+	echo -n $$i" " | sed -e 's/\(.*\)\.c\(.*\)/\1\.so\2/g' >> $(MAKEFILE); \
+	done; \
+	echo -ne "\nVFS_CFLAGS\t= \nVFS_CPPFLAGS\t= \nVFS_LDFLAGS\t= \n" >> $(MAKEFILE)
+	make
+
+# Pattern rules
+
+%.so: %.lo
+	$(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< 
+
+%.lo: %.c
+	$(LIBTOOL) $(CC) $(FLAGS) -c $<
+
+# Misc targets
+
+clean:
+	rm -rf .libs
+	rm -f core *~ *% *.bak \
+	$(VFS_OBJS) $(VFS_OBJS:.so=.o) $(VFS_OBJS:.so=.lo) 
diff -urN samba-3.0/examples/VFS/recycle.c samba-3.0.current/examples/VFS/recycle.c
--- samba-3.0/examples/VFS/recycle.c	2002-05-15 12:55:09 +0300
+++ samba-3.0.current/examples/VFS/recycle.c	2002-07-08 17:58:42 +0300
@@ -4,6 +4,7 @@
  *
  * Copyright (C) 2001, Brandon Stone, Amherst College, <bbstone at amherst.edu>.
  * Copyright (C) 2002, Jeremy Allison - modified to make a VFS module.
+ * Copyright (C) 2002, Alexander Bokovoy - cascaded VFS adoption,
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -40,139 +41,67 @@
  
 /* VFS operations */
 
-extern struct vfs_ops default_vfs_ops;   /* For passthrough operation */
-
+static struct vfs_ops default_vfs_ops;   /* For passthrough operation */
+static struct smb_vfs_handle_struct *recycle_handle;
 static int recycle_unlink(connection_struct *, const char *);
 static int recycle_connect(struct connection_struct *conn, const char *service, const char *user);
 static void recycle_disconnect(struct connection_struct *conn);
 
-struct vfs_ops recycle_ops = {
-    
+static vfs_op_tuple recycle_ops[] = {
+
 	/* Disk operations */
 
-	recycle_connect,		/* connect */
-	recycle_disconnect,		/* disconnect */
-	NULL,				/* disk free */
-
-	/* Directory operations */
-
-	NULL,				/* opendir */
-	NULL,				/* readdir */
-	NULL,				/* mkdir */
-	NULL,				/* rmdir */
-	NULL,				/* closedir */
+	{recycle_connect,	SMB_VFS_OP_CONNECT,	SMB_VFS_LAYER_OPAQUE},
+	{recycle_disconnect,	SMB_VFS_OP_DISCONNECT,	SMB_VFS_LAYER_OPAQUE},
 
 	/* File operations */
-
-	NULL,				/* open */
-	NULL,				/* close */
-	NULL,				/* read  */
-	NULL,				/* write */
-	NULL,				/* lseek */
-	NULL,				/* rename */
-	NULL,				/* fsync */
-	NULL,				/* stat  */
-	NULL,				/* fstat */
-	NULL,				/* lstat */
-	recycle_unlink,
-	NULL,				/* chmod */
-	NULL,				/* fchmod */
-	NULL,				/* chown */
-	NULL,				/* fchown */
-	NULL,				/* chdir */
-	NULL,				/* getwd */
-	NULL,				/* utime */
-	NULL,				/* ftruncate */
-	NULL,				/* lock */
-	NULL,				/* symlink */
-	NULL,				/* readlink */
-	NULL,				/* link */
-	NULL,				/* mknod */
-	NULL,				/* realpath */
-	NULL,				/* fget_nt_acl */
-	NULL,				/* get_nt_acl */
-	NULL,				/* fset_nt_acl */
-	NULL,				/* set_nt_acl */
-
-	NULL,				/* chmod_acl */
-	NULL,				/* fchmod_acl */
-
-	NULL,				/* sys_acl_get_entry */
-	NULL,				/* sys_acl_get_tag_type */
-	NULL,				/* sys_acl_get_permset */
-	NULL,				/* sys_acl_get_qualifier */
-	NULL,				/* sys_acl_get_file */
-	NULL,				/* sys_acl_get_fd */
-	NULL,				/* sys_acl_clear_perms */
-	NULL,				/* sys_acl_add_perm */
-	NULL,				/* sys_acl_to_text */
-	NULL,				/* sys_acl_init */
-	NULL,				/* sys_acl_create_entry */
-	NULL,				/* sys_acl_set_tag_type */
-	NULL,				/* sys_acl_set_qualifier */
-	NULL,				/* sys_acl_set_permset */
-	NULL,				/* sys_acl_valid */
-	NULL,				/* sys_acl_set_file */
-	NULL,				/* sys_acl_set_fd */
-	NULL,				/* sys_acl_delete_def_file */
-	NULL,				/* sys_acl_get_perm */
-	NULL,				/* sys_acl_free_text */
-	NULL,				/* sys_acl_free_acl */
-	NULL				/* sys_acl_free_qualifier */
+	
+	{recycle_unlink,	SMB_VFS_OP_UNLINK,	SMB_VFS_LAYER_OPAQUE},
+	
+	{NULL,			SMB_VFS_OP_NOOP,	SMB_VFS_LAYER_NOOP}
 };
 
-/* VFS initialisation function.  Return initialised vfs_ops structure
-   back to SAMBA. */
+/* VFS initialisation function.  Return initialised vfs_op_tuple array back to SAMBA. */
 
-struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
+vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops,
+			struct smb_vfs_handle_struct *vfs_handle)
 {
-	struct vfs_ops tmp_ops;
-
 	*vfs_version = SMB_VFS_INTERFACE_VERSION;
-	memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
-	tmp_ops.unlink = recycle_unlink;
-	tmp_ops.connect = recycle_connect;
-	tmp_ops.disconnect = recycle_disconnect;
-	memcpy(&recycle_ops, &tmp_ops, sizeof(struct vfs_ops));
-	return &recycle_ops;
+	memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops));
+	
+	/* Remember vfs_id for storing private information at connect */
+	recycle_handle = vfs_handle;
+
+	return recycle_ops;
+}
+
+/* VFS finalization function. */
+void vfs_done(connection_struct *conn)
+{
+	DEBUG(3,("vfs_done_recycle: called for connection %p\n",conn));
 }
 
 static int recycle_connect(struct connection_struct *conn, const char *service, const char *user)
 {
-	pstring opts_str;
 	fstring recycle_bin;
-	char *p;
 
 	DEBUG(3,("recycle_connect: called for service %s as user %s\n", service, user));
 
-	pstrcpy(opts_str, (const char *)lp_vfs_options(SNUM(conn)));
-	if (!*opts_str) {
-		DEBUG(3,("recycle_connect: No options listed (%s).\n", lp_vfs_options(SNUM(conn)) ));
+	fstrcpy(recycle_bin, (const char *)lp_parm_string(lp_servicename(SNUM(conn)),"vfs","recycle bin"));
+	if (!*recycle_bin) {
+		DEBUG(3,("recycle_connect: No options listed (vfs:recycle bin).\n" ));
 		return 0; /* No options. */
 	}
 
-	p = opts_str;
-	if (next_token(&p,recycle_bin,"=",sizeof(recycle_bin))) {
-		if (!strequal("recycle", recycle_bin)) {
-			DEBUG(3,("recycle_connect: option %s is not recycle\n", recycle_bin ));
-			return -1;
-		}
-	}
-
-	if (!next_token(&p,recycle_bin," \n",sizeof(recycle_bin))) {
-		DEBUG(3,("recycle_connect: no option after recycle=\n"));
-		return -1;
-	}
-
-	DEBUG(10,("recycle_connect: recycle name is %s\n", recycle_bin ));
+	DEBUG(3,("recycle_connect: recycle name is %s\n", recycle_bin ));
 
-	conn->vfs_private = (void *)strdup(recycle_bin);
+	recycle_handle->data = (void *)strdup(recycle_bin);
 	return 0;
 }
 
 static void recycle_disconnect(struct connection_struct *conn)
 {
-	SAFE_FREE(conn->vfs_private);
+	SAFE_FREE(recycle_handle->data);
 }
 
 static BOOL recycle_XXX_exist(connection_struct *conn, const char *dname, BOOL isdir)
@@ -225,8 +154,8 @@
 	*recycle_bin = '\0';
 	pstrcpy(fname, inname);
 
-	if (conn->vfs_private)
-		fstrcpy(recycle_bin, (const char *)conn->vfs_private);
+	if (recycle_handle->data)
+		fstrcpy(recycle_bin, (const char *)recycle_handle->data);
 
 	if(!*recycle_bin) {
 		DEBUG(3, ("recycle bin: share parameter not set, purging %s...\n", fname));
diff -urN samba-3.0/examples/VFS/skel.c samba-3.0.current/examples/VFS/skel.c
--- samba-3.0/examples/VFS/skel.c	2002-03-20 12:43:39 +0200
+++ samba-3.0.current/examples/VFS/skel.c	2002-07-08 17:58:36 +0300
@@ -3,6 +3,7 @@
  * calls to disk functions.
  *
  * Copyright (C) Tim Potter, 1999-2000
+ * Copyright (C) Alexander Bokovoy, 2002
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -38,8 +39,8 @@
 #include <includes.h>
 #include <vfs.h>
 
-extern struct vfs_ops default_vfs_ops;   /* For passthrough operation */
-extern struct vfs_ops skel_ops;
+static struct vfs_ops default_vfs_ops;   /* For passthrough operation */
+static struct smb_vfs_handle_struct *skel_handle; /* use skel_handle->data for storing per-instance private data */
 
 static int skel_connect(struct connection_struct *conn, const char *service, const char *user)    
 {
@@ -349,172 +350,110 @@
 	return default_vfs_ops.sys_acl_free_qualifier(conn, qualifier, tagtype);
 }
 
-/* VFS initialisation - return vfs_ops function pointer structure */
-
-struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops)
-{
-	struct vfs_ops tmp_ops;
-
-	DEBUG(3, ("Initialising default vfs hooks\n"));
-
-	*vfs_version = SMB_VFS_INTERFACE_VERSION;
-	memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops));
-
-	tmp_ops.connect = skel_connect;
-	tmp_ops.disconnect = skel_disconnect;
-	tmp_ops.disk_free = skel_disk_free;
-
-	/* Directory operations */
-
-	tmp_ops.opendir = skel_opendir;
-	tmp_ops.readdir = skel_readdir;
-	tmp_ops.mkdir = skel_mkdir;
-	tmp_ops.rmdir = skel_rmdir;
-	tmp_ops.closedir = skel_closedir;
-
-	/* File operations */
-
-	tmp_ops.open = skel_open;
-	tmp_ops.close = skel_close;
-	tmp_ops.read = skel_read;
-	tmp_ops.write = skel_write;
-	tmp_ops.lseek = skel_lseek;
-	tmp_ops.rename = skel_rename;
-	tmp_ops.fsync = skel_fsync;
-	tmp_ops.stat = skel_stat;
-	tmp_ops.fstat = skel_fstat;
-	tmp_ops.lstat = skel_lstat;
-	tmp_ops.unlink = skel_unlink;
-	tmp_ops.chmod = skel_chmod;
-	tmp_ops.fchmod = skel_fchmod;
-	tmp_ops.chown = skel_chown;
-	tmp_ops.fchown = skel_fchown;
-	tmp_ops.chdir = skel_chdir;
-	tmp_ops.getwd = skel_getwd;
-	tmp_ops.utime = skel_utime;
-	tmp_ops.ftruncate = skel_ftruncate;
-	tmp_ops.lock = skel_lock;
-	tmp_ops.symlink = skel_symlink;
-	tmp_ops.readlink = skel_readlink;
-	tmp_ops.link = skel_link;
-	tmp_ops.mknod = skel_mknod;
-	tmp_ops.realpath = skel_realpath;
-
-	tmp_ops.fget_nt_acl = skel_fget_nt_acl;
-	tmp_ops.get_nt_acl = skel_get_nt_acl;
-	tmp_ops.fset_nt_acl = skel_fset_nt_acl;
-	tmp_ops.set_nt_acl = skel_set_nt_acl;
-
-	/* POSIX ACL operations. */
-
-	tmp_ops.chmod_acl = skel_chmod_acl;
-	tmp_ops.fchmod_acl = skel_fchmod_acl;
-	tmp_ops.sys_acl_get_entry = skel_sys_acl_get_entry;
-	tmp_ops.sys_acl_get_tag_type = skel_sys_acl_get_tag_type;
-	tmp_ops.sys_acl_get_permset = skel_sys_acl_get_permset;
-	tmp_ops.sys_acl_get_qualifier = skel_sys_acl_get_qualifier;
-	tmp_ops.sys_acl_get_file = skel_sys_acl_get_file;
-	tmp_ops.sys_acl_get_fd = skel_sys_acl_get_fd;
-	tmp_ops.sys_acl_clear_perms = skel_sys_acl_clear_perms;
-	tmp_ops.sys_acl_add_perm = skel_sys_acl_add_perm;
-	tmp_ops.sys_acl_to_text = skel_sys_acl_to_text;
-	tmp_ops.sys_acl_init = skel_sys_acl_init;
-	tmp_ops.sys_acl_create_entry = skel_sys_acl_create_entry;
-	tmp_ops.sys_acl_set_tag_type = skel_sys_acl_set_tag_type;
-	tmp_ops.sys_acl_set_qualifier = skel_sys_acl_set_qualifier;
-	tmp_ops.sys_acl_set_permset = skel_sys_acl_set_permset;
-	tmp_ops.sys_acl_valid = skel_sys_acl_valid;
-	tmp_ops.sys_acl_set_file = skel_sys_acl_set_file;
-	tmp_ops.sys_acl_set_fd = skel_sys_acl_set_fd;
-	tmp_ops.sys_acl_delete_def_file = skel_sys_acl_delete_def_file;
-	tmp_ops.sys_acl_get_perm = skel_sys_acl_get_perm;
-	tmp_ops.sys_acl_free_text = skel_sys_acl_free_text;
-	tmp_ops.sys_acl_free_acl = skel_sys_acl_free_acl;
-	tmp_ops.sys_acl_free_qualifier = skel_sys_acl_free_qualifier;
-
-	memcpy(&skel_ops, &tmp_ops, sizeof(struct vfs_ops));
-
-	return &skel_ops;
-}
 
 /* VFS operations structure */
 
-struct vfs_ops skel_ops = {
+static vfs_op_tuple skel_ops[] = {
 
 	/* Disk operations */
 
-	skel_connect,
-	skel_disconnect,
-	skel_disk_free,
+	{skel_connect,			SMB_VFS_OP_CONNECT, 		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_disconnect,		SMB_VFS_OP_DISCONNECT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_disk_free,		SMB_VFS_OP_DISK_FREE,		SMB_VFS_LAYER_TRANSPARENT},
 	
 	/* Directory operations */
 
-	skel_opendir,
-	skel_readdir,
-	skel_mkdir,
-	skel_rmdir,
-	skel_closedir,
+	{skel_opendir,			SMB_VFS_OP_OPENDIR,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_readdir,			SMB_VFS_OP_READDIR,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_mkdir,			SMB_VFS_OP_MKDIR,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_rmdir,			SMB_VFS_OP_RMDIR,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_closedir,			SMB_VFS_OP_CLOSEDIR,		SMB_VFS_LAYER_TRANSPARENT},
 
 	/* File operations */
 
-	skel_open,
-	skel_close,
-	skel_read,
-	skel_write,
-	skel_lseek,
-	skel_rename,
-	skel_fsync,
-	skel_stat,
-	skel_fstat,
-	skel_lstat,
-	skel_unlink,
-	skel_chmod,
-	skel_fchmod,
-	skel_chown,
-	skel_fchown,
-	skel_chdir,
-	skel_getwd,
-	skel_utime,
-	skel_ftruncate,
-	skel_lock,
-	skel_symlink,
-	skel_readlink,
-	skel_link,
-	skel_mknod,
-	skel_realpath,
+	{skel_open,			SMB_VFS_OP_OPEN,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_close,			SMB_VFS_OP_CLOSE,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_read,			SMB_VFS_OP_READ,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_write,			SMB_VFS_OP_WRITE,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_lseek,			SMB_VFS_OP_LSEEK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_rename,			SMB_VFS_OP_RENAME,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fsync,			SMB_VFS_OP_FSYNC,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_stat,			SMB_VFS_OP_STAT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fstat,			SMB_VFS_OP_FSTAT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_lstat,			SMB_VFS_OP_LSTAT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_unlink,			SMB_VFS_OP_UNLINK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_chmod,			SMB_VFS_OP_CHMOD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fchmod,			SMB_VFS_OP_FCHMOD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_chown,			SMB_VFS_OP_CHOWN,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fchown,			SMB_VFS_OP_FCHOWN,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_chdir,			SMB_VFS_OP_CHDIR,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_getwd,			SMB_VFS_OP_GETWD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_utime,			SMB_VFS_OP_UTIME,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_ftruncate,		SMB_VFS_OP_FTRUNCATE,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_lock,			SMB_VFS_OP_LOCK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_symlink,			SMB_VFS_OP_SYMLINK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_readlink,			SMB_VFS_OP_READLINK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_link,			SMB_VFS_OP_LINK,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_mknod,			SMB_VFS_OP_MKNOD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_realpath,			SMB_VFS_OP_REALPATH,		SMB_VFS_LAYER_TRANSPARENT},
 
 	/* NT File ACL operations */
 
-	skel_fget_nt_acl,
-	skel_get_nt_acl,
-	skel_fset_nt_acl,
-	skel_set_nt_acl,
+	{skel_fget_nt_acl,		SMB_VFS_OP_FGET_NT_ACL,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_get_nt_acl,		SMB_VFS_OP_GET_NT_ACL,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fset_nt_acl,		SMB_VFS_OP_FSET_NT_ACL,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_set_nt_acl,		SMB_VFS_OP_SET_NT_ACL,		SMB_VFS_LAYER_TRANSPARENT},
 
 	/* POSIX ACL operations */
 
-	skel_chmod_acl,
-	skel_fchmod_acl,
+	{skel_chmod_acl,		SMB_VFS_OP_CHMOD_ACL,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_fchmod_acl,		SMB_VFS_OP_FCHMOD_ACL,		SMB_VFS_LAYER_TRANSPARENT},
 
-	skel_sys_acl_get_entry,
-	skel_sys_acl_get_tag_type,
-	skel_sys_acl_get_permset,
-	skel_sys_acl_get_qualifier,
-	skel_sys_acl_get_file,
-	skel_sys_acl_get_fd,
-	skel_sys_acl_clear_perms,
-	skel_sys_acl_add_perm,
-	skel_sys_acl_to_text,
-	skel_sys_acl_init,
-	skel_sys_acl_create_entry,
-	skel_sys_acl_set_tag_type,
-	skel_sys_acl_set_qualifier,
-	skel_sys_acl_set_permset,
-	skel_sys_acl_valid,
-	skel_sys_acl_set_file,
-	skel_sys_acl_set_fd,
-	skel_sys_acl_delete_def_file,
-	skel_sys_acl_get_perm,
-	skel_sys_acl_free_text,
-	skel_sys_acl_free_acl,
-	skel_sys_acl_free_qualifier
+	{skel_sys_acl_get_entry,	SMB_VFS_OP_SYS_ACL_GET_ENTRY,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_tag_type,	SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_permset,	SMB_VFS_OP_SYS_ACL_GET_PERMSET,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_qualifier,	SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_file,		SMB_VFS_OP_SYS_ACL_GET_FILE,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_fd,		SMB_VFS_OP_SYS_ACL_GET_FD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_clear_perms,	SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_add_perm,		SMB_VFS_OP_SYS_ACL_ADD_PERM,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_to_text,		SMB_VFS_OP_SYS_ACL_TO_TEXT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_init,		SMB_VFS_OP_SYS_ACL_INIT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_create_entry,	SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_set_tag_type,	SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_set_qualifier,	SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_set_permset,	SMB_VFS_OP_SYS_ACL_SET_PERMSET,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_valid,		SMB_VFS_OP_SYS_ACL_VALID,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_set_file,		SMB_VFS_OP_SYS_ACL_SET_FILE,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_set_fd,		SMB_VFS_OP_SYS_ACL_SET_FD,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_delete_def_file,	SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,	SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_get_perm,		SMB_VFS_OP_SYS_ACL_GET_PERM,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_free_text,	SMB_VFS_OP_SYS_ACL_FREE_TEXT,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_free_acl,		SMB_VFS_OP_SYS_ACL_FREE_ACL,		SMB_VFS_LAYER_TRANSPARENT},
+	{skel_sys_acl_free_qualifier,	SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,	SMB_VFS_LAYER_TRANSPARENT},
+	
+	{NULL,	SMB_VFS_OP_NOOP,	SMB_VFS_LAYER_NOOP}
 };
+
+/* VFS initialisation - return initialized vfs_op_tuple array back to Samba */
+
+vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops,
+			struct smb_vfs_handle_struct *vfs_handle)
+{
+	DEBUG(3, ("Initialising default vfs hooks\n"));
+
+	*vfs_version = SMB_VFS_INTERFACE_VERSION;
+	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
+	*/
+	skel_handle = vfs_handle;
+	return skel_ops;
+}
+
+/* VFS finalization function */
+void vfs_done(connection_struct *conn)
+{
+	DEBUG(3, ("Finalizing default vfs hooks\n"));
+}
diff -urN samba-3.0/source/configure.in samba-3.0.current/source/configure.in
--- samba-3.0/source/configure.in	2002-07-04 11:45:02 +0300
+++ samba-3.0.current/source/configure.in	2002-07-08 18:44:55 +0300
@@ -2820,7 +2820,7 @@
 builddir=`pwd`
 AC_SUBST(builddir)
 
-AC_OUTPUT(include/stamp-h Makefile script/findsmb)
+AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/VFS/block/Makefile)
 
 #################################################
 # Print very concise instructions on building/use
diff -urN samba-3.0/source/include/smb.h samba-3.0.current/source/include/smb.h
--- samba-3.0/source/include/smb.h	2002-07-08 13:50:46 +0300
+++ samba-3.0.current/source/include/smb.h	2002-07-08 16:06:51 +0300
@@ -444,6 +444,15 @@
 #include "smb_acls.h"
 #include "vfs.h"
 
+typedef struct smb_vfs_handle_struct
+{
+    void *data;
+    /* Handle on dlopen() call */
+    void *handle;
+    struct smb_vfs_handle_struct  *next, *prev;
+    
+} smb_vfs_handle_struct;
+
 typedef struct connection_struct
 {
 	struct connection_struct *next, *prev;
@@ -461,9 +470,7 @@
 	char *origpath;
 
 	struct vfs_ops vfs_ops;                   /* Filesystem operations */
-	/* Handle on dlopen() call */
-	void *dl_handle;
-	void *vfs_private;
+	struct smb_vfs_handle_struct *vfs_private;
 
 	char *user; /* name of user who *opened* this connection */
 	uid_t uid; /* uid of user who *opened* this connection */
diff -urN samba-3.0/source/include/vfs.h samba-3.0.current/source/include/vfs.h
--- samba-3.0/source/include/vfs.h	2002-03-22 14:29:25 +0200
+++ samba-3.0.current/source/include/vfs.h	2002-07-08 18:53:23 +0300
@@ -1,7 +1,8 @@
 /* 
    Unix SMB/CIFS implementation.
    VFS structures and parameters
-   Copyright (C) Tim Potter 1999
+   Copyright (C) Tim Potter				1999
+   Copyright (C) Alexander Bokovoy			2002
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -16,6 +17,8 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+   This work was sponsored by Optifacio Software Services, Inc.
 */
 
 #ifndef _VFS_H
@@ -40,7 +43,48 @@
 
 /* Changed to version 2 for CIFS UNIX extensions (mknod and link added). JRA. */
 /* Changed to version 3 for POSIX acl extensions. JRA. */
-#define SMB_VFS_INTERFACE_VERSION 3
+/* Changed to version 4 for cascaded VFS interface. Alexander Bokovoy. */
+#define SMB_VFS_INTERFACE_VERSION 5
+
+
+/* Version of supported cascaded interface backward copmatibility.
+   (version 4 corresponds to SMB_VFS_INTERFACE_VERSION 4)
+   It is used in vfs_init_custom() to detect VFS modules which conform to cascaded 
+   VFS interface but implement elder version than current version of Samba uses.
+   This allows to use old modules with new VFS interface as far as combined VFS operation
+   set is coherent (will be in most cases). 
+*/
+#define SMB_VFS_INTERFACE_CASCADED 4
+
+/*
+    Each VFS module must provide following global functions:
+    vfs_init	-- initialization function
+    vfs_done	-- finalization function
+    
+    vfs_init must return proper initialized vfs_op_tuple[] array
+    which describes all operations this module claims to intercept. This function
+    is called whenever module is loaded into smbd process using sys_dlopen().
+    
+    vfs_init must store somewhere vfs_handle reference if module wants to store per-instance
+    private information for further usage. vfs_handle->data should be used to
+    store such information. Do not try to change other fields in this structure
+    or results likely to be unpredictable.
+    
+    vfs_done must perform finalization of the module. In particular,
+    this function must free vfs_ops structure returned to module from smb_vfs_get_opaque_ops()
+    function if it is used (see below). This function is called whenever module 
+    is unloaded from smbd process using sys_dlclose().
+    
+    Prototypes:
+    vfs_op_tuple *vfs_init(int *vfs_version, const struct vfs_ops *def_vfs_ops,
+			    struct smb_vfs_handle_struct *vfs_handle);
+    void	  vfs_done(connection_struct *conn);
+    
+    All intercepted VFS operations must be declared as static functions inside module source
+    in order to keep smbd namespace unpolluted. See source of skel, audit, and recycle bin
+    example VFS modules for more details.
+    
+*/
 
 /* VFS operations structure */
 
@@ -135,4 +179,157 @@
     char *value;
 };
 
+/*
+    Available VFS operations. These values must be in sync with vfs_ops struct.
+    In particular, if new operations are added to vfs_ops, appropriate constants
+    should be added to vfs_op_type so that order of them kept same as in vfs_ops.
+*/
+
+typedef enum _vfs_op_type {
+
+	SMB_VFS_OP_NOOP = -1,
+	
+	/* Disk operations */
+
+	SMB_VFS_OP_CONNECT = 0,
+	SMB_VFS_OP_DISCONNECT,
+	SMB_VFS_OP_DISK_FREE,
+
+	/* Directory operations */
+
+	SMB_VFS_OP_OPENDIR,
+	SMB_VFS_OP_READDIR,
+	SMB_VFS_OP_MKDIR,
+	SMB_VFS_OP_RMDIR,
+	SMB_VFS_OP_CLOSEDIR,
+
+	/* File operations */
+
+	SMB_VFS_OP_OPEN,
+	SMB_VFS_OP_CLOSE,
+	SMB_VFS_OP_READ,
+	SMB_VFS_OP_WRITE,
+	SMB_VFS_OP_LSEEK,
+	SMB_VFS_OP_RENAME,
+	SMB_VFS_OP_FSYNC,
+	SMB_VFS_OP_STAT,
+	SMB_VFS_OP_FSTAT,
+	SMB_VFS_OP_LSTAT,
+	SMB_VFS_OP_UNLINK,
+	SMB_VFS_OP_CHMOD,
+	SMB_VFS_OP_FCHMOD,
+	SMB_VFS_OP_CHOWN,
+	SMB_VFS_OP_FCHOWN,
+	SMB_VFS_OP_CHDIR,
+	SMB_VFS_OP_GETWD,
+	SMB_VFS_OP_UTIME,
+	SMB_VFS_OP_FTRUNCATE,
+	SMB_VFS_OP_LOCK,
+	SMB_VFS_OP_SYMLINK,
+	SMB_VFS_OP_READLINK,
+	SMB_VFS_OP_LINK,
+	SMB_VFS_OP_MKNOD,
+	SMB_VFS_OP_REALPATH,
+
+	/* NT ACL operations. */
+
+	SMB_VFS_OP_FGET_NT_ACL,
+	SMB_VFS_OP_GET_NT_ACL,
+	SMB_VFS_OP_FSET_NT_ACL,
+	SMB_VFS_OP_SET_NT_ACL,
+
+	/* POSIX ACL operations. */
+
+	SMB_VFS_OP_CHMOD_ACL,
+	SMB_VFS_OP_FCHMOD_ACL,
+
+	SMB_VFS_OP_SYS_ACL_GET_ENTRY,
+	SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
+	SMB_VFS_OP_SYS_ACL_GET_PERMSET,
+	SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
+	SMB_VFS_OP_SYS_ACL_GET_FILE,
+	SMB_VFS_OP_SYS_ACL_GET_FD,
+	SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
+	SMB_VFS_OP_SYS_ACL_ADD_PERM,
+	SMB_VFS_OP_SYS_ACL_TO_TEXT,
+	SMB_VFS_OP_SYS_ACL_INIT,
+	SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
+	SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
+	SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
+	SMB_VFS_OP_SYS_ACL_SET_PERMSET,
+	SMB_VFS_OP_SYS_ACL_VALID,
+	SMB_VFS_OP_SYS_ACL_SET_FILE,
+	SMB_VFS_OP_SYS_ACL_SET_FD,
+	SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
+	SMB_VFS_OP_SYS_ACL_GET_PERM,
+	SMB_VFS_OP_SYS_ACL_FREE_TEXT,
+	SMB_VFS_OP_SYS_ACL_FREE_ACL,
+	SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
+	
+	/* This should always be last enum value */
+	
+	SMB_VFS_OP_LAST
+} vfs_op_type;
+
+/*
+    Possible VFS operation layers (per-operation)
+    
+    These values are used by VFS subsystem when building vfs_ops for connection
+    from multiple VFS modules. Internally, Samba differentiates only opaque and
+    transparent layers at this process. Other types are used for providing better
+    diagnosing facilities.
+    
+    Most modules will provide transparent layers. Opaque layer is for modules
+    which implement actual file system calls (like DB-based VFS). For example,
+    default POSIX VFS which is built in into Samba is an opaque VFS module.
+    
+    Other layer types (audit, splitter, scanner) were designed to provide different 
+    degree of transparency and for diagnosing VFS module behaviour.
+    
+    Each module can implement several layers at the same time provided that only
+    one layer is used per each operation.
+    
+*/
+
+typedef enum _vfs_op_layer {
+	SMB_VFS_LAYER_NOOP = -1,	/* - For using in VFS module to indicate end of array */
+					/*   of operations description */
+	SMB_VFS_LAYER_OPAQUE = 0,	/* - Final level, does not call anything beyond itself */
+	SMB_VFS_LAYER_TRANSPARENT,	/* - Normal operation, calls underlying layer after */
+					/*   possibly changing passed data */
+	SMB_VFS_LAYER_LOGGER,		/* - Logs data, calls underlying layer, logging does not */
+					/*   use Samba VFS */
+	SMB_VFS_LAYER_SPLITTER,		/* - Splits operation, calls underlying layer _and_ own facility, */
+					/*   then combines result */
+	SMB_VFS_LAYER_SCANNER		/* - Checks data and possibly initiates additional */
+					/*   file activity like logging to files _inside_ samba VFS */
+} vfs_op_layer;
+
+/*
+    VFS operation description. Each VFS module initialization function returns to VFS subsystem 
+    an array of vfs_op_tuple which describes all operations this module is willing to intercept. 
+    VFS subsystem initializes then vfs_ops using this information and passes it 
+    to next VFS module as underlying vfs_ops and to connection after all VFS modules are initialized.
+*/
+
+typedef struct _vfs_op_tuple {
+	void* op;
+	vfs_op_type type;
+	vfs_op_layer layer;
+} vfs_op_tuple;
+
+/*
+    Return vfs_ops filled with current opaque VFS operations. This function is designed to
+    be called from VFS module initialization function for those modules which needs 'direct' VFS
+    access (loggers or initiators of file operations other than connection asks for).
+    
+    Returned vfs_ops must be cleaned up in VFS module's finalizer function (vfs_done_<module_name>)
+    using safe_free().
+    
+    Prototype:
+    struct vfs_ops *smb_vfs_get_opaque_ops();
+    
+    This prototype will be available via include/proto.h
+*/
+
 #endif /* _VFS_H */
diff -urN samba-3.0/source/param/loadparm.c samba-3.0.current/source/param/loadparm.c
--- samba-3.0/source/param/loadparm.c	2002-07-04 11:45:02 +0300
+++ samba-3.0.current/source/param/loadparm.c	2002-07-08 14:33:22 +0300
@@ -313,6 +313,7 @@
 	char *fstype;
 	char *szVfsObjectFile;
 	char *szVfsOptions;
+	char *szVfsPath;
 	int iMinPrintSpace;
 	int iMaxPrintJobs;
 	int iWriteCacheSize;
@@ -431,6 +432,7 @@
 	NULL,			/* fstype */
 	NULL,			/* vfs object */
 	NULL,			/* vfs options */
+	NULL,			/* vfs path */
 	0,			/* iMinPrintSpace */
 	1000,			/* iMaxPrintJobs */
 	0,			/* iWriteCacheSize */
@@ -1021,6 +1023,7 @@
 	
 	{"vfs object", P_STRING, P_LOCAL, &sDefault.szVfsObjectFile, handle_vfs_object, NULL, FLAG_SHARE},
 	{"vfs options", P_STRING, P_LOCAL, &sDefault.szVfsOptions, NULL, NULL, FLAG_SHARE},
+	{"vfs path", P_STRING, P_LOCAL, &sDefault.szVfsPath, NULL, NULL, FLAG_SHARE},
 
 	
 	{"msdfs root", P_BOOL, P_LOCAL, &sDefault.bMSDfsRoot, NULL, NULL, FLAG_SHARE},
@@ -1642,6 +1645,7 @@
 FN_LOCAL_STRING(lp_fstype, fstype)
 FN_LOCAL_STRING(lp_vfsobj, szVfsObjectFile)
 FN_LOCAL_STRING(lp_vfs_options, szVfsOptions)
+FN_LOCAL_STRING(lp_vfs_path, szVfsPath)
 static FN_LOCAL_STRING(lp_volume, volume)
 FN_LOCAL_STRING(lp_mangled_map, szMangledMap)
 FN_LOCAL_STRING(lp_veto_files, szVetoFiles)
diff -urN samba-3.0/source/smbd/conn.c samba-3.0.current/source/smbd/conn.c
--- samba-3.0/source/smbd/conn.c	2002-05-17 11:51:20 +0300
+++ samba-3.0.current/source/smbd/conn.c	2002-07-08 17:44:56 +0300
@@ -2,6 +2,7 @@
    Unix SMB/CIFS implementation.
    Manage connections_struct structures
    Copyright (C) Andrew Tridgell 1998
+   Copyright (C) Alexander Bokovoy 2002
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -162,11 +163,25 @@
 
 void conn_free(connection_struct *conn)
 {
+ 	smb_vfs_handle_struct *handle, *thandle;
+ 	void (*done_fptr)(connection_struct *conn);
+
 	/* Free vfs_connection_struct */
-	    
-	if (conn->dl_handle != NULL) {
-		/* Close dlopen() handle */
-		sys_dlclose(conn->dl_handle);
+	handle = conn->vfs_private;
+	while(handle) {
+ 		/* Close dlopen() handle */
+ 		done_fptr = (void (*)(connection_struct *))sys_dlsym(handle->handle, "vfs_done");
+ 
+ 		if (done_fptr == NULL) {
+ 			DEBUG(3, ("No vfs_done() symbol found in module with handle %p, ignoring\n", handle->handle));
+ 		} else {
+ 			done_fptr(conn);
+ 		}
+     		sys_dlclose(handle->handle);
+		DLIST_REMOVE(conn->vfs_private, handle);
+		thandle = handle->next;
+		SAFE_FREE(handle);
+		handle = thandle;
 	}
 
 	DLIST_REMOVE(Connections, conn);
diff -urN samba-3.0/source/smbd/vfs.c samba-3.0.current/source/smbd/vfs.c
--- samba-3.0/source/smbd/vfs.c	2002-07-01 14:52:22 +0300
+++ samba-3.0.current/source/smbd/vfs.c	2002-07-08 19:06:54 +0300
@@ -3,6 +3,7 @@
    Version 1.9.
    VFS initialisation and support functions
    Copyright (C) Tim Potter 1999
+   Copyright (C) Alexander Bokovoy 2002
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -17,6 +18,8 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+   This work was sponsored by Optifacio Software Services, Inc.
 */
 
 #include "includes.h"
@@ -28,6 +31,12 @@
 	void *fptr;
 };
 
+/*
+  Opaque (final) vfs operations. This is a combination of first-met opaque vfs operations
+  across all currently processed modules.  */
+
+static vfs_op_tuple vfs_opaque_ops[SMB_VFS_OP_LAST];
+
 /* Default vfs hooks.  WARNING: The order of these initialisers is
    very important.  They must be in the same order as defined in
    vfs.h.  Change at your own peril. */
@@ -117,58 +126,75 @@
   initialise default vfs hooks
 ****************************************************************************/
 
-static BOOL vfs_init_default(connection_struct *conn)
+static void vfs_init_default(connection_struct *conn)
 {
 	DEBUG(3, ("Initialising default vfs hooks\n"));
 
 	memcpy(&conn->vfs_ops, &default_vfs_ops, sizeof(struct vfs_ops));
-	return True;
+	conn->vfs_private = NULL;
 }
 
 /****************************************************************************
   initialise custom vfs hooks
 ****************************************************************************/
 
-static BOOL vfs_init_custom(connection_struct *conn)
+static BOOL vfs_init_custom(connection_struct *conn, const char *vfs_object)
 {
 	int vfs_version = -1;
-	struct vfs_ops *ops, *(*init_fptr)(int *, struct vfs_ops *);
+ 	vfs_op_tuple *ops, *(*init_fptr)(int *, const struct vfs_ops *, struct smb_vfs_handle_struct *);
+ 	int i;
 
-	DEBUG(3, ("Initialising custom vfs hooks from %s\n", lp_vfsobj(SNUM(conn))));
+	DEBUG(3, ("Initialising custom vfs hooks from %s\n", vfs_object));
 
 	/* Open object file */
 
-	if ((conn->dl_handle = sys_dlopen(lp_vfsobj(SNUM(conn)), RTLD_NOW | RTLD_GLOBAL)) == NULL) {
-		DEBUG(0, ("Error opening %s: %s\n", lp_vfsobj(SNUM(conn)), sys_dlerror()));
+	if ((conn->vfs_private->handle = sys_dlopen(vfs_object, RTLD_NOW)) == NULL) {
+		DEBUG(0, ("Error opening %s: %s\n", vfs_object, sys_dlerror()));
 		return False;
 	}
 
 	/* Get handle on vfs_init() symbol */
 
-	init_fptr = (struct vfs_ops *(*)(int *, struct vfs_ops *))sys_dlsym(conn->dl_handle, "vfs_init");
+	init_fptr = (vfs_op_tuple *(*)(int *, const struct vfs_ops *, struct smb_vfs_handle_struct *))sys_dlsym(conn->vfs_private->handle, "vfs_init");
 
 	if (init_fptr == NULL) {
-		DEBUG(0, ("No vfs_init() symbol found in %s\n", lp_vfsobj(SNUM(conn))));
+		DEBUG(0, ("No vfs_init() symbol found in %s\n", vfs_object));
 		return False;
 	}
 
 	/* Initialise vfs_ops structure */
 
-	conn->vfs_ops = default_vfs_ops;
-
-	if ((ops = init_fptr(&vfs_version, &default_vfs_ops)) == NULL) {
-		DEBUG(0, ("vfs_init function from %s failed\n", lp_vfsobj(SNUM(conn))));
-		return False;
-	}
-
-	if (vfs_version != SMB_VFS_INTERFACE_VERSION) {
-		DEBUG(0, ("vfs_init returned wrong interface version info (was %d, should be %d)\n",
-			vfs_version, SMB_VFS_INTERFACE_VERSION ));
-		return False;
-	}
-
-	if (ops != &conn->vfs_ops) {
-		memcpy(&conn->vfs_ops, ops, sizeof(struct vfs_ops));
+ 	if ((ops = init_fptr(&vfs_version, &conn->vfs_ops, conn->vfs_private)) == NULL) {
+ 		DEBUG(0, ("vfs_init() function from %s failed\n", vfs_object));
+ 		return False;
+ 	}
+  
+ 	if ((vfs_version < SMB_VFS_INTERFACE_CASCADED)) {
+ 		DEBUG(0, ("vfs_init() returned wrong interface version info (was %d, should be no less than %d)\n",
+ 			vfs_version, SMB_VFS_INTERFACE_VERSION ));
+  		return False;
+  	}
+  
+ 	if ((vfs_version < SMB_VFS_INTERFACE_VERSION)) {
+ 		DEBUG(0, ("Warning: vfs_init() states that module confirms interface version #%d, current interface version is #%d.\n\
+Proceeding in compatibility mode, new operations (since version #%d) will fallback to default ones.\n",
+ 			vfs_version, SMB_VFS_INTERFACE_VERSION, vfs_version ));
+  		return False;
+  	}
+  
+ 	for(i=0; ops[i].op != NULL; i++) {
+ 	  DEBUG(3, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
+ 	  if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
+ 	    /* Check whether this operation was already made opaque by different module */
+ 	    if(vfs_opaque_ops[ops[i].type].op == ((void**)&default_vfs_ops)[ops[i].type]) {
+ 	      /* No, it isn't overloaded yet. Overload. */
+ 	      DEBUG(3, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
+ 	      vfs_opaque_ops[ops[i].type] = ops[i];
+ 	    }
+ 	  }
+ 	  /* Change current VFS disposition*/
+ 	  DEBUG(3, ("Accepting operation type %d from module %s\n", ops[i].type, vfs_object));
+ 	  ((void**)&conn->vfs_ops)[ops[i].type] = ops[i].op;
 	}
 
 	return True;
@@ -180,21 +206,70 @@
 
 BOOL smbd_vfs_init(connection_struct *conn)
 {
+	char **vfs_objects, *vfsobj, *vfs_module, *vfs_path;
+	int nobj, i;
+	struct smb_vfs_handle_struct *handle;
+	
+	/* Normal share - initialise with disk access functions */
+	vfs_init_default(conn);
+
+	/* Override VFS functions if 'vfs object' was specified*/
 	if (*lp_vfsobj(SNUM(conn))) {
- 
-		/* Loadable object file */
- 
-		if (!vfs_init_custom(conn)) {
-			DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed\n"));
-			return False;
+		vfsobj = NULL;
+		for(i=0; i<SMB_VFS_OP_LAST; i++) {
+		  vfs_opaque_ops[i].op = ((void**)&default_vfs_ops)[i];
+		  vfs_opaque_ops[i].type = i;
+		  vfs_opaque_ops[i].layer = SMB_VFS_LAYER_OPAQUE;
+		}
+		if (string_set(&vfsobj, lp_vfsobj(SNUM(conn)))) {
+			/* Parse passed modules specification to array of modules */
+			set_first_token(vfsobj);
+			/* We are using default separators: ' \t\r\n' */
+			vfs_objects = toktocliplist(&nobj, NULL);
+			if (vfs_objects) {
+				vfs_path = lp_vfs_path(SNUM(conn));
+				conn->vfs_private = NULL;
+				for(i=nobj-1; i>=0; i--) {
+					handle = (struct smb_vfs_handle_struct *) smb_xmalloc(sizeof(smb_vfs_handle_struct));
+					/* Loadable object file */
+					handle->handle = NULL;
+					DLIST_ADD(conn->vfs_private, handle)
+					vfs_module = NULL;
+					if (vfs_path) {
+						asprintf(&vfs_module, "%s/%s", vfs_path, vfs_objects[i]);
+					} else {
+						asprintf(&vfs_module, "%s", vfs_objects[i]);
+					}
+					if (!vfs_init_custom(conn, vfs_module)) {
+						DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_module));
+						string_free(&vfsobj);
+						SAFE_FREE(vfs_module);
+						return False;
+					}
+					SAFE_FREE(vfs_module);
+				}
+			}
+			string_free(&vfsobj);
+			return True;
 		}
-
-		return True;
 	}
- 
-	/* Normal share - initialise with disk access functions */
- 
-	return vfs_init_default(conn);
+	return True;
+}
+
+/*******************************************************************
+ Create vfs_ops reflecting current vfs_opaque_ops
+*******************************************************************/
+struct vfs_ops *smb_vfs_get_opaque_ops()
+{
+  int i;
+  struct vfs_ops *ops;
+
+  ops = smb_xmalloc(sizeof(struct vfs_ops));
+
+  for(i=0; i<SMB_VFS_OP_LAST; i++) {
+    ((void**)ops)[i] = vfs_opaque_ops[i].op;
+  }
+  return ops;
 }
 
 /*******************************************************************


More information about the samba-technical mailing list