diff options
Diffstat (limited to 'examples/VFS')
-rw-r--r-- | examples/VFS/Makefile | 37 | ||||
-rw-r--r-- | examples/VFS/audit.c | 174 | ||||
-rw-r--r-- | examples/VFS/block/Makefile | 37 | ||||
-rw-r--r-- | examples/VFS/block/block.c | 144 | ||||
-rw-r--r-- | examples/VFS/recycle.c | 139 | ||||
-rw-r--r-- | examples/VFS/skel.c | 243 |
6 files changed, 548 insertions, 226 deletions
diff --git a/examples/VFS/Makefile b/examples/VFS/Makefile new file mode 100644 index 0000000000..f93cd0cb2d --- /dev/null +++ b/examples/VFS/Makefile @@ -0,0 +1,37 @@ +# +# 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 --git a/examples/VFS/audit.c b/examples/VFS/audit.c index 92b78c1c32..aad483c295 100644 --- a/examples/VFS/audit.c +++ b/examples/VFS/audit.c @@ -3,7 +3,6 @@ * 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 @@ -48,79 +47,134 @@ /* Function prototypes */ -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); +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); /* VFS operations */ -static struct vfs_ops default_vfs_ops; /* For passthrough operation */ -static struct smb_vfs_handle_struct *audit_handle; +extern struct vfs_ops default_vfs_ops; /* For passthrough operation */ -static vfs_op_tuple audit_ops[] = { +struct vfs_ops audit_ops = { /* Disk operations */ - {audit_connect, SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_LOGGER}, - {audit_disconnect, SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_LOGGER}, + audit_connect, + audit_disconnect, + NULL, /* disk free */ /* Directory operations */ - {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}, + audit_opendir, + NULL, /* readdir */ + audit_mkdir, + audit_rmdir, + NULL, /* closedir */ /* File operations */ - {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} + 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 */ }; -/* VFS initialisation function. Return vfs_op_tuple array back to SAMBA. */ +/* VFS initialisation function. Return initialised vfs_ops structure + back to SAMBA. */ -vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops, - struct smb_vfs_handle_struct *vfs_handle) +struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops) { + struct vfs_ops tmp_ops; + *vfs_version = SMB_VFS_INTERFACE_VERSION; - memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops)); - - audit_handle = vfs_handle; + 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)); openlog("smbd_audit", LOG_PID, SYSLOG_FACILITY); syslog(SYSLOG_PRIORITY, "VFS_INIT: vfs_ops loaded\n"); - return audit_ops; -} - -/* VFS finalization function. */ -void vfs_done(connection_struct *conn) -{ - syslog(SYSLOG_PRIORITY, "VFS_DONE: vfs module unloaded\n"); + return &audit_ops; } /* Implementation of vfs_ops. Pass everything on to the default operation but log event first. */ -static int audit_connect(struct connection_struct *conn, const char *svc, const char *user) +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); @@ -128,13 +182,13 @@ static int audit_connect(struct connection_struct *conn, const char *svc, const return default_vfs_ops.connect(conn, svc, user); } -static void audit_disconnect(struct connection_struct *conn) +void audit_disconnect(struct connection_struct *conn) { syslog(SYSLOG_PRIORITY, "disconnected\n"); default_vfs_ops.disconnect(conn); } -static DIR *audit_opendir(struct connection_struct *conn, const char *fname) +DIR *audit_opendir(struct connection_struct *conn, const char *fname) { DIR *result = default_vfs_ops.opendir(conn, fname); @@ -146,7 +200,7 @@ static DIR *audit_opendir(struct connection_struct *conn, const char *fname) return result; } -static int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode) +int audit_mkdir(struct connection_struct *conn, const char *path, mode_t mode) { int result = default_vfs_ops.mkdir(conn, path, mode); @@ -158,7 +212,7 @@ static int audit_mkdir(struct connection_struct *conn, const char *path, mode_t return result; } -static int audit_rmdir(struct connection_struct *conn, const char *path) +int audit_rmdir(struct connection_struct *conn, const char *path) { int result = default_vfs_ops.rmdir(conn, path); @@ -170,7 +224,7 @@ static int audit_rmdir(struct connection_struct *conn, const char *path) return result; } -static int audit_open(struct connection_struct *conn, const char *fname, int flags, mode_t mode) +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); @@ -183,7 +237,7 @@ static int audit_open(struct connection_struct *conn, const char *fname, int fla return result; } -static int audit_close(struct files_struct *fsp, int fd) +int audit_close(struct files_struct *fsp, int fd) { int result = default_vfs_ops.close(fsp, fd); @@ -195,7 +249,7 @@ static int audit_close(struct files_struct *fsp, int fd) return result; } -static int audit_rename(struct connection_struct *conn, const char *old, const char *new) +int audit_rename(struct connection_struct *conn, const char *old, const char *new) { int result = default_vfs_ops.rename(conn, old, new); @@ -207,7 +261,7 @@ static int audit_rename(struct connection_struct *conn, const char *old, const c return result; } -static int audit_unlink(struct connection_struct *conn, const char *path) +int audit_unlink(struct connection_struct *conn, const char *path) { int result = default_vfs_ops.unlink(conn, path); @@ -219,7 +273,7 @@ static int audit_unlink(struct connection_struct *conn, const char *path) return result; } -static int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode) +int audit_chmod(struct connection_struct *conn, const char *path, mode_t mode) { int result = default_vfs_ops.chmod(conn, path, mode); @@ -231,7 +285,7 @@ static int audit_chmod(struct connection_struct *conn, const char *path, mode_t return result; } -static int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode) +int audit_chmod_acl(struct connection_struct *conn, const char *path, mode_t mode) { int result = default_vfs_ops.chmod_acl(conn, path, mode); @@ -243,7 +297,7 @@ static int audit_chmod_acl(struct connection_struct *conn, const char *path, mod return result; } -static int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode) +int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode) { int result = default_vfs_ops.fchmod(fsp, fd, mode); @@ -255,7 +309,7 @@ static int audit_fchmod(struct files_struct *fsp, int fd, mode_t mode) return result; } -static int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode) +int audit_fchmod_acl(struct files_struct *fsp, int fd, mode_t mode) { int result = default_vfs_ops.fchmod_acl(fsp, fd, mode); diff --git a/examples/VFS/block/Makefile b/examples/VFS/block/Makefile new file mode 100644 index 0000000000..44b08681d6 --- /dev/null +++ b/examples/VFS/block/Makefile @@ -0,0 +1,37 @@ +# +# 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 --git a/examples/VFS/block/block.c b/examples/VFS/block/block.c index 9478b75f0f..f83ab6e07e 100644 --- a/examples/VFS/block/block.c +++ b/examples/VFS/block/block.c @@ -3,7 +3,6 @@ * 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 @@ -48,29 +47,93 @@ -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); +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 struct smb_vfs_handle_struct *block_handle; /* VFS operations */ -static struct vfs_ops default_vfs_ops; /* For passthrough operation */ +extern struct vfs_ops default_vfs_ops; /* For passthrough operation */ -static vfs_op_tuple block_vfs_ops[] = { +struct vfs_ops execute_vfs_ops = { /* Disk operations */ - {block_connect, SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, - {block_disconnect, SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_TRANSPARENT}, + block_connect, + block_disconnect, + NULL, /* disk free */ /* Directory operations */ - {block_opendir, SMB_VFS_OP_OPENDIR, SMB_VFS_LAYER_TRANSPARENT}, - - {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} + 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 */ }; @@ -82,13 +145,13 @@ extern BOOL pm_process(char *FileName, BOOL (*sfunc)(char *), BOOL(*pfunc)(char //functions -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); +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); @@ -113,7 +176,7 @@ static struct block_dir *pblock_dir = NULL; * Load the conf file into a table */ -static BOOL load_param(void) +BOOL load_param(void) { if ((pm_process(PARAMCONF,&get_section,&get_parameter_value)) == TRUE) @@ -131,7 +194,7 @@ static BOOL load_param(void) * */ -static BOOL enter_pblock_mount(char *dir) +BOOL enter_pblock_mount(char *dir) { struct stat stat_buf; static struct block_dir *tmp_pblock; @@ -179,7 +242,7 @@ static BOOL enter_pblock_mount(char *dir) * */ -static BOOL enter_pblock_dir(char *dir) +BOOL enter_pblock_dir(char *dir) { static struct block_dir *tmp_pblock; @@ -222,7 +285,7 @@ static BOOL enter_pblock_dir(char *dir) * Function callback for config section names */ -static BOOL get_section(char *sect) +BOOL get_section(char *sect) { return TRUE; } @@ -234,7 +297,7 @@ static BOOL get_section(char *sect) * */ -static BOOL get_parameter_value(char *param, char *value) +BOOL get_parameter_value(char *param, char *value) { int i = 0, maxargs = sizeof(params) / sizeof(char *); @@ -264,25 +327,24 @@ static BOOL get_parameter_value(char *param, char *value) -/* VFS initialisation function. Return initialised vfs_op_tuple array +/* VFS initialisation function. Return initialised vfs_ops structure back to SAMBA. */ -vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops, - struct smb_vfs_handle_struct *vfs_handle) +struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops) { + struct vfs_ops tmp_ops; + *vfs_version = SMB_VFS_INTERFACE_VERSION; - memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops)); - - block_handle = vfs_handle; - - return block_vfs_ops; -} + memcpy(&tmp_ops, def_vfs_ops, sizeof(struct vfs_ops)); + /* Override the ones we want. */ + tmp_ops.connect = block_connect; + tmp_ops.disconnect = block_disconnect; + tmp_ops.opendir = block_opendir; -/* VFS finalization function. */ -void vfs_done(connection_struct *conn) -{ + memcpy(&execute_vfs_ops, &tmp_ops, sizeof(struct vfs_ops)); + return(&execute_vfs_ops); } @@ -290,7 +352,7 @@ void vfs_done(connection_struct *conn) * VFS connect and param file loading */ -static int block_connect(connection_struct *conn, const char *service, const char *user) +int block_connect(struct connection_struct *conn, char *service, char *user) { if((load_param()) == FALSE) { @@ -310,7 +372,7 @@ static int block_connect(connection_struct *conn, const char *service, const cha */ -static void block_disconnect(struct connection_struct *conn) +void block_disconnect(struct connection_struct *conn) { struct block_dir *tmp_pblock = (pblock_mountp == NULL ? pblock_dir : pblock_mountp); @@ -341,7 +403,7 @@ static void block_disconnect(struct connection_struct *conn) * VFS opendir */ -static DIR *block_opendir(struct connection_struct *conn, char *fname) +DIR *block_opendir(struct connection_struct *conn, char *fname) { char *dir_name = NULL; @@ -375,7 +437,7 @@ static DIR *block_opendir(struct connection_struct *conn, char *fname) * Find mount point to block in list */ -static BOOL search(struct stat *stat_buf) +BOOL search(struct stat *stat_buf) { struct block_dir *tmp_pblock = pblock_mountp; @@ -397,7 +459,7 @@ static BOOL search(struct stat *stat_buf) * Find dir in list to block id the starting point is link from a share */ -static BOOL dir_search(char *link, char *dir) +BOOL dir_search(char *link, char *dir) { char buf[PATH_MAX +1], *ext_path; int len = 0; diff --git a/examples/VFS/recycle.c b/examples/VFS/recycle.c index ed89e59abf..6a1c98ce54 100644 --- a/examples/VFS/recycle.c +++ b/examples/VFS/recycle.c @@ -4,7 +4,6 @@ * * Copyright (C) 2001, Brandon Stone, Amherst College, <bbstone@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 @@ -41,67 +40,139 @@ /* VFS operations */ -static struct vfs_ops default_vfs_ops; /* For passthrough operation */ -static struct smb_vfs_handle_struct *recycle_handle; +extern struct vfs_ops default_vfs_ops; /* For passthrough operation */ + 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); -static vfs_op_tuple recycle_ops[] = { - +struct vfs_ops recycle_ops = { + /* Disk operations */ - {recycle_connect, SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_OPAQUE}, - {recycle_disconnect, SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_OPAQUE}, + recycle_connect, /* connect */ + recycle_disconnect, /* disconnect */ + NULL, /* disk free */ + + /* Directory operations */ + + NULL, /* opendir */ + NULL, /* readdir */ + NULL, /* mkdir */ + NULL, /* rmdir */ + NULL, /* closedir */ /* File operations */ - - {recycle_unlink, SMB_VFS_OP_UNLINK, SMB_VFS_LAYER_OPAQUE}, - - {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} + + 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 */ }; -/* VFS initialisation function. Return initialised vfs_op_tuple array back to SAMBA. */ +/* VFS initialisation function. Return initialised vfs_ops structure + back to SAMBA. */ -vfs_op_tuple *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops, - struct smb_vfs_handle_struct *vfs_handle) +struct vfs_ops *vfs_init(int *vfs_version, struct vfs_ops *def_vfs_ops) { - *vfs_version = SMB_VFS_INTERFACE_VERSION; - 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; -} + struct vfs_ops tmp_ops; -/* VFS finalization function. */ -void vfs_done(connection_struct *conn) -{ - DEBUG(3,("vfs_done_recycle: called for connection %p\n",conn)); + *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; } 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)); - 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" )); + 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)) )); return 0; /* No options. */ } - DEBUG(3,("recycle_connect: recycle name is %s\n", recycle_bin )); + 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 )); - recycle_handle->data = (void *)strdup(recycle_bin); + conn->vfs_private = (void *)strdup(recycle_bin); return 0; } static void recycle_disconnect(struct connection_struct *conn) { - SAFE_FREE(recycle_handle->data); + SAFE_FREE(conn->vfs_private); } static BOOL recycle_XXX_exist(connection_struct *conn, const char *dname, BOOL isdir) @@ -154,8 +225,8 @@ static int recycle_unlink(connection_struct *conn, const char *inname) *recycle_bin = '\0'; pstrcpy(fname, inname); - if (recycle_handle->data) - fstrcpy(recycle_bin, (const char *)recycle_handle->data); + if (conn->vfs_private) + fstrcpy(recycle_bin, (const char *)conn->vfs_private); if(!*recycle_bin) { DEBUG(3, ("recycle bin: share parameter not set, purging %s...\n", fname)); diff --git a/examples/VFS/skel.c b/examples/VFS/skel.c index b937682822..bb5486e690 100644 --- a/examples/VFS/skel.c +++ b/examples/VFS/skel.c @@ -3,7 +3,6 @@ * 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 @@ -39,8 +38,8 @@ #include <includes.h> #include <vfs.h> -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 */ +extern struct vfs_ops default_vfs_ops; /* For passthrough operation */ +extern struct vfs_ops skel_ops; static int skel_connect(struct connection_struct *conn, const char *service, const char *user) { @@ -350,110 +349,172 @@ static int skel_sys_acl_free_qualifier(struct connection_struct *conn, void *qua 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 */ -static vfs_op_tuple skel_ops[] = { +struct vfs_ops skel_ops = { /* Disk operations */ - {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}, + skel_connect, + skel_disconnect, + skel_disk_free, /* Directory operations */ - {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}, + skel_opendir, + skel_readdir, + skel_mkdir, + skel_rmdir, + skel_closedir, /* File operations */ - {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}, + 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, /* NT File ACL operations */ - {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}, + skel_fget_nt_acl, + skel_get_nt_acl, + skel_fset_nt_acl, + skel_set_nt_acl, /* POSIX ACL operations */ - {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, 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} + skel_chmod_acl, + skel_fchmod_acl, + + 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 }; - -/* 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")); -} |