diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/VFS/Makefile | 37 | ||||
-rw-r--r-- | examples/VFS/Makefile.in | 38 | ||||
-rw-r--r-- | examples/VFS/README | 22 | ||||
-rw-r--r-- | examples/VFS/block/Makefile | 37 | ||||
-rw-r--r-- | examples/VFS/block/Makefile.in | 42 | ||||
-rw-r--r-- | examples/VFS/block/block.c | 440 | ||||
-rw-r--r-- | examples/VFS/block/samba-block.conf | 6 | ||||
-rw-r--r-- | examples/VFS/block/smb.conf | 13 | ||||
-rw-r--r-- | examples/VFS/recycle.c | 590 | ||||
-rw-r--r-- | examples/pdb/mysql/Makefile.in | 2 | ||||
-rw-r--r-- | examples/pdb/mysql/pdb_mysql.c | 57 | ||||
-rw-r--r-- | examples/pdb/xml/Makefile.in | 2 | ||||
-rw-r--r-- | examples/pdb/xml/pdb_xml.c | 24 | ||||
-rwxr-xr-x | examples/printing/smbprint | 104 | ||||
-rwxr-xr-x | examples/printing/smbprint.old | 95 |
15 files changed, 817 insertions, 692 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/Makefile.in b/examples/VFS/Makefile.in index 46e1a90263..3126dfa3b8 100644 --- a/examples/VFS/Makefile.in +++ b/examples/VFS/Makefile.in @@ -1,24 +1,42 @@ +MAKEFILE = Makefile.vfs + +include $(MAKEFILE) + CC = @CC@ -CFLAGS = @CFLAGS@ -CPPFLAGS = @CPPFLAGS@ -LDFLAGS = @LDFLAGS@ +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) -# Auto target -default: $(patsubst %.c,%.so,$(wildcard *.c)) +# 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: %.o - $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< +%.so: %.lo + $(LIBTOOL) $(CC) $(LDSHFLAGS) $(LDFLAGS) -o $@ $< -%.o: %.c - $(CC) $(FLAGS) -c $< +%.lo: %.c + $(LIBTOOL) $(CC) $(FLAGS) -c $< # Misc targets clean: rm -rf .libs - rm -f core *~ *% *.bak *.o *.so + rm -f core *~ *% *.bak \ + $(VFS_OBJS) $(VFS_OBJS:.so=.o) $(VFS_OBJS:.so=.lo) diff --git a/examples/VFS/README b/examples/VFS/README index 1b09929059..c2f39f9727 100644 --- a/examples/VFS/README +++ b/examples/VFS/README @@ -17,26 +17,8 @@ construction. The following VFS modules are given: connect/disconnect, directory opens/create/remove, file open/close/rename/unlink/chmod. - recycle - A recycle-bin like modules. When used any unlink call - will be intercepted and files moved to the recycle - directory nstead of beeing deleted. - - block - A simple module to block access to certain mount points or - directories. This module only hides the specified directories - and all directories beneath them. It should NOT be used to - secure directories. If the name of a file in one of those - directories is known, the file can still be opened. - - netatalk - A netatalk module, that will ease co-existence of samba and - netatalk file sharing services. - Looka t the README for more informations. - -You may have problems to compile these modules, as shared libraries are -compiled and linked in different ways on different systems. -I currently tested them against GNU/linux and IRIX. +The libtool program, available from your favourite GNU software +archive, is required to compile these programs. To use the VFS modules, create a share similar to the one below. The important parameter is the 'vfs object' parameter which must point to 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/Makefile.in b/examples/VFS/block/Makefile.in new file mode 100644 index 0000000000..3126dfa3b8 --- /dev/null +++ b/examples/VFS/block/Makefile.in @@ -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 --git a/examples/VFS/block/block.c b/examples/VFS/block/block.c new file mode 100644 index 0000000000..9478b75f0f --- /dev/null +++ b/examples/VFS/block/block.c @@ -0,0 +1,440 @@ +/* + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * 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. + */ + +#include "config.h" +#include <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <string.h> +#include <stdlib.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + + +#ifdef HAVE_UTIME_H +#include <utime.h> +#endif +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif +#include <syslog.h> +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + + +#include <includes.h> +#include <vfs.h> + + + +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 */ + + +static struct vfs_ops default_vfs_ops; /* For passthrough operation */ + +static vfs_op_tuple block_vfs_ops[] = { + + /* Disk operations */ + + {block_connect, SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, + {block_disconnect, SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_TRANSPARENT}, + + /* Directory operations */ + + {block_opendir, SMB_VFS_OP_OPENDIR, SMB_VFS_LAYER_TRANSPARENT}, + + {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} +}; + + +#ifndef PARAMCONF +#define PARAMCONF "/etc/samba-block.conf" +#endif + +extern BOOL pm_process(char *FileName, BOOL (*sfunc)(char *), BOOL(*pfunc)(char * , 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); + + + +typedef struct block_dir +{ + dev_t st_dev; + int str_len; + char *dir_name; + struct block_dir *next; +} block_dir; + + +static char *params[] = {"mount_point","dir_name"}; +enum { MOUNT_POINT , DIR_NAME }; + +static struct block_dir *pblock_mountp = NULL; +static struct block_dir *pblock_dir = NULL; + + + +/* + * Load the conf file into a table + */ + +static BOOL load_param(void) +{ + + if ((pm_process(PARAMCONF,&get_section,&get_parameter_value)) == TRUE) + { + return TRUE; + + } + return FALSE; +} + + + +/* + * Enter the key and data into the list + * + */ + +static BOOL enter_pblock_mount(char *dir) +{ + struct stat stat_buf; + static struct block_dir *tmp_pblock; + + + if((stat(dir,&stat_buf)) != 0) + { + return FALSE; + } + + if(pblock_mountp == NULL) + { + pblock_mountp = calloc(1, sizeof(block_dir)); + if( pblock_mountp == NULL) + { + return FALSE; + } + tmp_pblock = pblock_mountp; + tmp_pblock->next = NULL; + + }else + { + tmp_pblock->next = calloc(1, sizeof(block_dir)); + if(tmp_pblock->next == NULL) + { + return FALSE; + } + tmp_pblock = tmp_pblock->next; + tmp_pblock->next = NULL; + + } + + + tmp_pblock->st_dev = stat_buf.st_dev; + tmp_pblock->dir_name = strdup(dir); + + + return TRUE; + +} + + +/* + * Enter the key and data into the list + * + */ + +static BOOL enter_pblock_dir(char *dir) +{ + static struct block_dir *tmp_pblock; + + + if(pblock_dir == NULL) + { + pblock_dir = calloc(1, sizeof(block_dir)); + if( pblock_dir == NULL) + { + return FALSE; + } + tmp_pblock = pblock_dir; + tmp_pblock->next = NULL; + + }else + { + tmp_pblock->next = calloc(1, sizeof(block_dir)); + if(tmp_pblock->next == NULL) + { + return FALSE; + } + tmp_pblock = tmp_pblock->next; + tmp_pblock->next = NULL; + + } + + + tmp_pblock->dir_name = strdup(dir); + tmp_pblock->str_len = strlen(dir); + + + return TRUE; + +} + + + + +/* + * Function callback for config section names + */ + +static BOOL get_section(char *sect) +{ + return TRUE; +} + + + +/* + * Function callback for config parameter value pairs + * + */ + +static BOOL get_parameter_value(char *param, char *value) +{ + int i = 0, maxargs = sizeof(params) / sizeof(char *); + + + for( i= 0; i < maxargs; i++) + { + if (strcmp(param,params[i]) == 0) + { + switch(i) + { + case MOUNT_POINT : + enter_pblock_mount(value); + break; + case DIR_NAME : + enter_pblock_dir(value); + break; + default : + break; + } + } + } + + return TRUE; + +} + + + + +/* VFS initialisation function. Return initialised 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) +{ + *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; +} + + +/* VFS finalization function. */ +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) +{ + if((load_param()) == FALSE) + { + + return -1; + + } + + DEBUG(0,("%s connecting \n",conn->user)); + + return (default_vfs_ops.connect(conn, service,user)); +} + +/* + * Free allocated structures and disconnect + * + */ + + +static void block_disconnect(struct connection_struct *conn) +{ + + struct block_dir *tmp_pblock = (pblock_mountp == NULL ? pblock_dir : pblock_mountp); + struct block_dir *free_pblock = NULL; + + while(tmp_pblock != NULL) + { + free(tmp_pblock->dir_name); + free_pblock = tmp_pblock; + tmp_pblock = tmp_pblock->next; + free(free_pblock); + + if(tmp_pblock == NULL && pblock_dir != NULL) + { + tmp_pblock = (pblock_mountp == NULL ? pblock_dir : NULL); + pblock_dir = NULL; + + } + + } + + + + default_vfs_ops.disconnect(conn); +} + +/* + * VFS opendir + */ + +static DIR *block_opendir(struct connection_struct *conn, char *fname) +{ + + char *dir_name = NULL; + struct stat stat_buf; + + dir_name = alloca((strlen(conn->origpath) + strlen(fname) + 2) * sizeof(char)); + + pstrcpy(dir_name,conn->origpath); + pstrcat(dir_name, "/"); + strncat(dir_name, fname, strcspn(fname,"/")); + + if((lstat(dir_name,&stat_buf)) == 0) + { + if((S_ISLNK(stat_buf.st_mode)) == 1) + { + stat(dir_name,&stat_buf); + if((search(&stat_buf) || dir_search(dir_name, fname) ) == TRUE) + { + DEBUG(0,("%s used link to blocked dir: %s \n", conn->user, dir_name)); + errno = EACCES; + return NULL; + } + } + } + + return (default_vfs_ops.opendir(conn, fname)); +} + + +/* + * Find mount point to block in list + */ + +static BOOL search(struct stat *stat_buf) +{ + struct block_dir *tmp_pblock = pblock_mountp; + + while(tmp_pblock != NULL) + { + + if(tmp_pblock->st_dev == stat_buf->st_dev) + { + return TRUE; + } + tmp_pblock = tmp_pblock->next; + } + + return FALSE; + +} + +/* + * Find dir in list to block id the starting point is link from a share + */ + +static BOOL dir_search(char *link, char *dir) +{ + char buf[PATH_MAX +1], *ext_path; + int len = 0; + struct block_dir *tmp_pblock = pblock_dir; + + if((len = readlink(link,buf,sizeof(buf))) == -1) + { + return TRUE; + + }else + { + buf[len] = '\0'; + } + + + if((ext_path = strchr(dir,'/')) != NULL) + { + pstrcat(buf,&ext_path[1]); + len = strlen(buf); + } + + while(tmp_pblock != NULL) + { + if(len < tmp_pblock->str_len) + { + tmp_pblock = tmp_pblock->next; + continue; + } + + if((strstr(buf,tmp_pblock->dir_name)) != NULL) + { + return TRUE; + } + tmp_pblock = tmp_pblock->next; + } + + + return FALSE; + +} diff --git a/examples/VFS/block/samba-block.conf b/examples/VFS/block/samba-block.conf new file mode 100644 index 0000000000..7a137980b7 --- /dev/null +++ b/examples/VFS/block/samba-block.conf @@ -0,0 +1,6 @@ +[ blocked ] +mount_point = / +mount_point = /boot +mount_point = /proc +dir_name = /usr/local/src/samba +dir_name = /usr/bin diff --git a/examples/VFS/block/smb.conf b/examples/VFS/block/smb.conf new file mode 100644 index 0000000000..368155f1f8 --- /dev/null +++ b/examples/VFS/block/smb.conf @@ -0,0 +1,13 @@ +[homes] + comment = Home Directories + vfs object = /usr/local/samba/lib/block.so + browseable = yes + writable = yes + + + + + + + + diff --git a/examples/VFS/recycle.c b/examples/VFS/recycle.c index a56619af31..ed89e59abf 100644 --- a/examples/VFS/recycle.c +++ b/examples/VFS/recycle.c @@ -1,558 +1,222 @@ -/* - * Recycle bin VFS module for Samba. +/* + * Auditing VFS module for samba. Log selected file operations to syslog + * facility. * * 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, - * Copyright (C) 2002, Juergen Hasch - added some options. - * Copyright (C) 2002, Simo Sorce * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * 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. */ -#include "includes.h" - -#define ALLOC_CHECK(ptr, label) do { if ((ptr) == NULL) { DEBUG(0, ("recycle.bin: out of memory!\n")); errno = ENOMEM; goto label; } } while(0) - -static int vfs_recycle_debug_level = DBGC_VFS; - -#undef DBGC_CLASS -#define DBGC_CLASS vfs_recycle_debug_level - -static const char *delimiter = "|"; /* delimiter for options */ - -/* One per connection */ - -typedef struct recycle_bin_struct -{ - TALLOC_CTX *ctx; - char *repository; /* name of the recycle bin directory */ - BOOL keep_dir_tree; /* keep directory structure of deleted file in recycle bin */ - BOOL versions; /* create versions of deleted files with identical name */ - BOOL touch; /* touch access date of deleted file */ - char *exclude; /* which files to exclude */ - char *exclude_dir; /* which directories to exclude */ - char *noversions; /* which files to exclude from versioning */ - SMB_OFF_T maxsize; /* maximum file size to be saved */ -} recycle_bin_struct; - +#include "config.h" +#include <stdio.h> +#include <sys/stat.h> +#ifdef HAVE_UTIME_H +#include <utime.h> +#endif +#ifdef HAVE_DIRENT_H +#include <dirent.h> +#endif +#include <syslog.h> +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif +#include <errno.h> +#include <string.h> +#include <includes.h> +#include <vfs.h> + /* VFS operations */ -static 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); -static int recycle_unlink(connection_struct *, const char *); - -#define VFS_OP(x) ((void *) x) static vfs_op_tuple recycle_ops[] = { /* Disk operations */ - {VFS_OP(recycle_connect), SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_TRANSPARENT}, - {VFS_OP(recycle_disconnect), SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_TRANSPARENT}, - /* File operations */ - {VFS_OP(recycle_unlink), SMB_VFS_OP_UNLINK, SMB_VFS_LAYER_TRANSPARENT}, + {recycle_connect, SMB_VFS_OP_CONNECT, SMB_VFS_LAYER_OPAQUE}, + {recycle_disconnect, SMB_VFS_OP_DISCONNECT, SMB_VFS_LAYER_OPAQUE}, - {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} + /* File operations */ + + {recycle_unlink, SMB_VFS_OP_UNLINK, SMB_VFS_LAYER_OPAQUE}, + + {NULL, SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP} }; -static BOOL check_bool_param(const char *value) -{ - if (strwicmp(value, "yes") == 0 || - strwicmp(value, "true") == 0 || - strwicmp(value, "1") == 0) - return True; - - return False; -} +/* VFS initialisation function. Return initialised vfs_op_tuple array back to SAMBA. */ -/** - * VFS initialisation function. - * - * @retval initialised vfs_op_tuple array - **/ -vfs_op_tuple *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) { - DEBUG(10, ("Initializing VFS module recycle\n")); *vfs_version = SMB_VFS_INTERFACE_VERSION; memcpy(&default_vfs_ops, def_vfs_ops, sizeof(struct vfs_ops)); - vfs_recycle_debug_level = debug_add_class("vfs_recycle_bin"); - if (vfs_recycle_debug_level == -1) { - vfs_recycle_debug_level = DBGC_VFS; - DEBUG(0, ("vfs_recycle: Couldn't register custom debugging class!\n")); - } else { - DEBUG(0, ("vfs_recycle: Debug class number of 'vfs_recycle': %d\n", vfs_recycle_debug_level)); - } + + /* Remember vfs_id for storing private information at connect */ + recycle_handle = vfs_handle; return recycle_ops; } -/** - * VFS finalization function. - * - **/ +/* VFS finalization function. */ void vfs_done(connection_struct *conn) { - DEBUG(10,("Called for connection %d\n", SNUM(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) { - TALLOC_CTX *ctx = NULL; - recycle_bin_struct *recbin; - char *servicename; - char *tmp_str; + fstring recycle_bin; - DEBUG(10, ("Called for service %s (%d) as user %s\n", service, SNUM(conn), user)); + DEBUG(3,("recycle_connect: called for service %s as user %s\n", service, user)); - if (!(ctx = talloc_init_named("recycle bin"))) { - DEBUG(0, ("Failed to allocate memory in VFS module recycle_bin\n")); - return 0; + 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. */ } - recbin = talloc(ctx,sizeof(recycle_bin_struct)); - if ( recbin == NULL) { - DEBUG(0, ("Failed to allocate memory in VFS module recycle_bin\n")); - return -1; - } - recbin->ctx = ctx; - - /* Set defaults */ - recbin->repository = talloc_strdup(ctx, ".recycle"); - ALLOC_CHECK(recbin->repository, error); - recbin->keep_dir_tree = False; - recbin->versions = False; - recbin->touch = False; - recbin->exclude = ""; - recbin->exclude_dir = ""; - recbin->noversions = ""; - recbin->maxsize = 0; - - /* parse configuration options */ - servicename = talloc_strdup(recbin->ctx, lp_servicename(SNUM(conn))); - DEBUG(10, ("servicename = %s\n",servicename)); - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "repository")) != NULL) { - recbin->repository = talloc_sub_conn(ctx, conn, tmp_str); - ALLOC_CHECK(recbin->repository, error); - trim_string(recbin->repository, "/", "/"); - DEBUG(5, ("recycle.bin: repository = %s\n", recbin->repository)); - } - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "keeptree")) != NULL) { - if (check_bool_param(tmp_str) == True) - recbin->keep_dir_tree = True; - DEBUG(5, ("recycle.bin: keeptree = %s\n", tmp_str)); - } - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "versions")) != NULL) { - if (check_bool_param(tmp_str) == True) - recbin->versions = True; - DEBUG(5, ("recycle.bin: versions = %s\n", tmp_str)); - } - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "touch")) != NULL) { - if (check_bool_param(tmp_str) == True) - recbin->touch = True; - DEBUG(5, ("recycle.bin: touch = %s\n", tmp_str)); - } - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "maxsize")) != NULL) { - recbin->maxsize = strtoul(tmp_str, NULL, 10); - if (recbin->maxsize == 0) { - recbin->maxsize = -1; - DEBUG(5, ("recycle.bin: maxsize = -infinite-\n")); - } else { - DEBUG(5, ("recycle.bin: maxsize = %ld\n", (long int)recbin->maxsize)); - } - } - if ((tmp_str = lp_parm_string(servicename, "vfs_recycle_bin", "exclude")) != NULL) { - recbin->exclude = talloc_strdup(ctx, tmp_str); - ALLOC_CHECK(recbin->exclude, error); - DEBUG(5, ("recycle.bin: exclude = %s\n", recbin->exclude)); - } - if ((tmp_str = lp_parm_string(servicename,"vfs_recycle_bin", "exclude_dir")) != NULL) { - recbin->exclude_dir = talloc_strdup(ctx, tmp_str); - ALLOC_CHECK(recbin->exclude_dir, error); - DEBUG(5, ("recycle.bin: exclude_dir = %s\n", recbin->exclude_dir)); - } - if ((tmp_str = lp_parm_string(servicename,"vfs_recycle_bin", "noversions")) != NULL) { - recbin->noversions = talloc_strdup(ctx, tmp_str); - ALLOC_CHECK(recbin->noversions, error); - DEBUG(5, ("recycle.bin: noversions = %s\n", recbin->noversions)); - } + DEBUG(3,("recycle_connect: recycle name is %s\n", recycle_bin )); - conn->vfs_private = (void *)recbin; - return default_vfs_ops.connect(conn, service, user); - -error: - talloc_destroy(ctx); - return -1; + recycle_handle->data = (void *)strdup(recycle_bin); + return 0; } static void recycle_disconnect(struct connection_struct *conn) { - DEBUG(10, ("Disconnecting VFS module recycle bin\n")); - if (conn->vfs_private) { - talloc_destroy(((recycle_bin_struct *)conn->vfs_private)->ctx); - conn->vfs_private = NULL; - } - default_vfs_ops.disconnect(conn); -} - -static BOOL recycle_directory_exist(connection_struct *conn, const char *dname) -{ - SMB_STRUCT_STAT st; - - if (default_vfs_ops.stat(conn, dname, &st) == 0) { - if (S_ISDIR(st.st_mode)) { - return True; - } - } - - return False; + SAFE_FREE(recycle_handle->data); } -static BOOL recycle_file_exist(connection_struct *conn, const char *fname) +static BOOL recycle_XXX_exist(connection_struct *conn, const char *dname, BOOL isdir) { SMB_STRUCT_STAT st; - if (default_vfs_ops.stat(conn, fname, &st) == 0) { - if (S_ISREG(st.st_mode)) { - return True; - } - } + if (default_vfs_ops.stat(conn,dname,&st) != 0) + return(False); - return False; + if (isdir) + return S_ISDIR(st.st_mode) ? True : False; + else + return S_ISREG(st.st_mode) ? True : False; } -/** - * Return file size - * @param conn connection - * @param fname file name - * @return size in bytes - **/ -static SMB_OFF_T recycle_get_file_size(connection_struct *conn, const char *fname) -{ - SMB_STRUCT_STAT st; - if (default_vfs_ops.stat(conn, fname, &st) != 0) { - DEBUG(0,("recycle.bin: stat for %s returned %s\n", fname, strerror(errno))); - return (SMB_OFF_T)0; - } - return(st.st_size); -} - -/** - * Create directory tree - * @param conn connection - * @param dname Directory tree to be created - * @return Returns True for success - **/ -static BOOL recycle_create_dir(connection_struct *conn, const char *dname) +static BOOL recycle_directory_exist(connection_struct *conn, const char *dname) { - int len; - mode_t mode; - char *new_dir = NULL; - char *tmp_str = NULL; - char *token; - char *tok_str; - BOOL ret = False; - - mode = S_IREAD | S_IWRITE | S_IEXEC; - - tmp_str = strdup(dname); - ALLOC_CHECK(tmp_str, done); - tok_str = tmp_str; - - len = strlen(dname); - new_dir = (char *)malloc(len + 1); - ALLOC_CHECK(new_dir, done); - *new_dir = '\0'; - - /* Create directory tree if neccessary */ - for(token = strtok(tok_str, "/"); token; token = strtok(NULL, "/")) { - safe_strcat(new_dir, token, len); - if (recycle_directory_exist(conn, new_dir)) - DEBUG(10, ("recycle.bin: dir %s already exists\n", new_dir)); - else { - DEBUG(5, ("recycle.bin: creating new dir %s\n", new_dir)); - if (default_vfs_ops.mkdir(conn, new_dir, mode) != 0) { - DEBUG(1,("recycle.bin: mkdir failed for %s with error: %s\n", new_dir, strerror(errno))); - ret = False; - goto done; - } - } - safe_strcat(new_dir, "/", len); - } - - ret = True; -done: - SAFE_FREE(tmp_str); - SAFE_FREE(new_dir); - return ret; + return recycle_XXX_exist(conn, dname, True); } -/** - * Check if needle is contained exactly in haystack - * @param haystack list of parameters separated by delimimiter character - * @param needle string to be matched exactly to haystack - * @return True if found - **/ -static BOOL checkparam(const char *haystack, const char *needle) +static BOOL recycle_file_exist(connection_struct *conn, const char *fname) { - char *token; - char *tok_str; - char *tmp_str; - BOOL ret = False; - - if (haystack == NULL || strlen(haystack) == 0 || needle == NULL || strlen(needle) == 0) { - return False; - } - - tmp_str = strdup(haystack); - ALLOC_CHECK(tmp_str, done); - token = tok_str = tmp_str; - - for(token = strtok(tok_str, delimiter); token; token = strtok(NULL, delimiter)) { - if(strcmp(token, needle) == 0) { - ret = True; - goto done; - } - } -done: - SAFE_FREE(tmp_str); - return ret; + return recycle_XXX_exist(conn, fname, False); } -/** - * Check if needle is contained in haystack, * and ? patterns are resolved - * @param haystack list of parameters separated by delimimiter character - * @param needle string to be matched exectly to haystack including pattern matching - * @return True if found - **/ -static BOOL matchparam(const char *haystack, const char *needle) +static SMB_OFF_T recycle_get_file_size(connection_struct *conn, const char *fname) { - char *token; - char *tok_str; - char *tmp_str; - BOOL ret = False; - - if (haystack == NULL || strlen(haystack) == 0 || needle == NULL || strlen(needle) == 0) { - return False; - } + SMB_STRUCT_STAT st; - tmp_str = strdup(haystack); - ALLOC_CHECK(tmp_str, done); - token = tok_str = tmp_str; + if (default_vfs_ops.stat(conn,fname,&st) != 0) + return (SMB_OFF_T)-1; - for(token = strtok(tok_str, delimiter); token; token = strtok(NULL, delimiter)) { - if (!unix_wild_match(token, needle)) { - ret = True; - goto done; - } - } -done: - SAFE_FREE(tmp_str); - return ret; + return(st.st_size); } -/** - * Touch access date - **/ -static void recycle_touch(connection_struct *conn, const char *fname) -{ - SMB_STRUCT_STAT st; - struct utimbuf tb; - time_t currtime; - - if (default_vfs_ops.stat(conn, fname, &st) != 0) { - DEBUG(0,("recycle.bin: stat for %s returned %s\n", fname, strerror(errno))); - return; - } - currtime = time(&currtime); - tb.actime = currtime; - tb.modtime = st.st_mtime; - - if (default_vfs_ops.utime(conn, fname, &tb) == -1 ) - DEBUG(0, ("recycle.bin: touching %s failed, reason = %s\n", fname, strerror(errno))); - } +/******************************************************************** + Check if file should be recycled +*********************************************************************/ -/** - * Check if file should be recycled - **/ static int recycle_unlink(connection_struct *conn, const char *inname) { - recycle_bin_struct *recbin; - char *file_name = NULL; - char *path_name = NULL; - char *temp_name = NULL; - char *final_name = NULL; - char *base; - int i; - SMB_BIG_UINT dfree, dsize, bsize; - SMB_OFF_T file_size, space_avail; - BOOL exist; - int rc = -1; - - file_name = strdup(inname); - ALLOC_CHECK(file_name, done); - - if (conn->vfs_private) - recbin = (recycle_bin_struct *)conn->vfs_private; - else { - DEBUG(0, ("Recycle bin not initialized!\n")); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; - } + fstring recycle_bin; + pstring fname; + char *base, *ext; + pstring bin; + int i=1, len, addlen; + int dir_mask=0770; + SMB_BIG_UINT dfree,dsize,bsize; - if(!recbin->repository || *(recbin->repository) == '\0') { - DEBUG(3, ("Recycle path not set, purging %s...\n", file_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; - } + *recycle_bin = '\0'; + pstrcpy(fname, inname); - /* we don't recycle the recycle bin... */ - if (strncmp(file_name, recbin->repository, strlen(recbin->repository)) == 0) { - DEBUG(3, ("File is within recycling bin, unlinking ...\n")); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; - } + if (recycle_handle->data) + fstrcpy(recycle_bin, (const char *)recycle_handle->data); - file_size = recycle_get_file_size(conn, file_name); - /* it is wrong to purge filenames only because they are empty imho - * --- simo - * - if(fsize == 0) { - DEBUG(3, ("File %s is empty, purging...\n", file_name)); - rc = default_vfs_ops.unlink(conn,file_name); - goto done; - } - */ - - /* FIXME: this is wrong, we should check the hole size of the recycle bin is - * not greater then maxsize, not the size of the single file, also it is better - * to remove older files - */ - if(recbin->maxsize > 0 && file_size > recbin->maxsize) { - DEBUG(3, ("File %s exceeds maximum recycle size, purging... \n", file_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; + if(!*recycle_bin) { + DEBUG(3, ("recycle bin: share parameter not set, purging %s...\n", fname)); + return default_vfs_ops.unlink(conn,fname); } - /* FIXME: this is wrong: moving files with rename does not change the disk space - * allocation - * - space_avail = default_vfs_ops.disk_free(conn, ".", True, &bsize, &dfree, &dsize) * 1024L; - DEBUG(5, ("space_avail = %Lu, file_size = %Lu\n", space_avail, file_size)); - if(space_avail < file_size) { - DEBUG(3, ("Not enough diskspace, purging file %s\n", file_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; - } - */ - - /* extract filename and path */ - path_name = (char *)malloc(PATH_MAX); - ALLOC_CHECK(path_name, done); - *path_name = '\0'; - safe_strcpy(path_name, file_name, PATH_MAX); - base = strrchr(path_name, '/'); - if (base == NULL) { - base = file_name; - safe_strcpy(path_name, "/", PATH_MAX); - } - else { - *base = '\0'; - base++; + if(recycle_get_file_size(conn, fname) == 0) { + DEBUG(3, ("recycle bin: file %s is empty, purging...\n", fname)); + return default_vfs_ops.unlink(conn,fname); } - DEBUG(10, ("recycle.bin: fname = %s\n", file_name)); /* original filename with path */ - DEBUG(10, ("recycle.bin: fpath = %s\n", path_name)); /* original path */ - DEBUG(10, ("recycle.bin: base = %s\n", base)); /* filename without path */ + base = strrchr(fname, '/'); + pstrcpy(bin, recycle_bin); + pstrcat(bin, "/"); - if (matchparam(recbin->exclude, base)) { - DEBUG(3, ("recycle.bin: file %s is excluded \n", base)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; + if(base == NULL) { + ext = strrchr(fname, '.'); + pstrcat(bin, fname); + } else { + ext = strrchr(base, '.'); + pstrcat(bin, base+1); } + DEBUG(3, ("recycle bin: base %s, ext %s, fname %s, bin %s\n", base, ext, fname, bin)); - /* FIXME: this check will fail if we have more than one level of directories, - * we shoud check for every level 1, 1/2, 1/2/3, 1/2/3/4 .... - * ---simo - */ - if (checkparam(recbin->exclude_dir, path_name)) { - DEBUG(3, ("recycle.bin: directory %s is excluded \n", path_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; + if(strcmp(fname,bin) == 0) { + DEBUG(3, ("recycle bin: file %s exists, purging...\n", fname)); + return default_vfs_ops.unlink(conn,fname); } - temp_name = (char *)malloc(PATH_MAX); - ALLOC_CHECK(temp_name, done); - safe_strcpy(temp_name, recbin->repository, PATH_MAX); - - /* see if we need to recreate the original directory structure in the recycle bin */ - if (recbin->keep_dir_tree == True) { - safe_strcat(temp_name, "/", PATH_MAX); - safe_strcat(temp_name, path_name, PATH_MAX); - } + len = strlen(bin); + if ( ext != NULL) + len = len - strlen(ext); - exist = recycle_directory_exist(conn, temp_name); - if (exist) { - DEBUG(10, ("recycle.bin: Directory already exists\n")); - } else { - DEBUG(10, ("recycle.bin: Creating directory %s\n", temp_name)); - if (recycle_create_dir(conn, temp_name) == False) { - DEBUG(3, ("Could not create directory, purging %s...\n", file_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; - } + addlen = sizeof(pstring)-len-1; + while(recycle_file_exist(conn,bin)) { + slprintf(bin+len, addlen, " (Copy #%d)", i++); + pstrcat(bin, ext); } - final_name = (char *)malloc(PATH_MAX); - ALLOC_CHECK(final_name, done); - snprintf(final_name, PATH_MAX, "%s/%s", temp_name, base); - DEBUG(10, ("recycle.bin: recycled file name%s\n", temp_name)); /* new filename with path */ - - /* check if we should delete file from recycle bin */ - if (recycle_file_exist(conn, final_name)) { - if (recbin->versions == False || matchparam(recbin->noversions, base) == True) { - DEBUG(3, ("recycle.bin: Removing old file %s from recycle bin\n", final_name)); - if (default_vfs_ops.unlink(conn, final_name) != 0) { - DEBUG(1, ("recycle.bin: Error deleting old file: %s\n", strerror(errno))); + DEBUG(3, ("recycle bin: moving source=%s to dest=%s\n", fname, bin)); + default_vfs_ops.disk_free(conn,".",True,&bsize,&dfree,&dsize); + if((unsigned int)dfree > 0) { + int ret; + if(!recycle_directory_exist(conn,recycle_bin)) { + DEBUG(3, ("recycle bin: directory %s nonexistant, creating...\n", recycle_bin)); + if (default_vfs_ops.mkdir(conn,recycle_bin,dir_mask) == -1) { + DEBUG(3, ("recycle bin: unable to create directory %s. Error was %s\n", + recycle_bin, strerror(errno) )); } } - } - - /* rename file we move to recycle bin */ - i = 1; - while (recycle_file_exist(conn, final_name)) { - snprintf(final_name, PATH_MAX, "%s/Copy #%d of %s", temp_name, i++, base); - } + DEBUG(3, ("recycle bin: move %s -> %s\n", fname, bin)); - DEBUG(10, ("recycle.bin: Moving %s to %s\n", file_name, final_name)); - rc = default_vfs_ops.rename(conn, file_name, final_name); - if (rc != 0) { - DEBUG(3, ("recycle.bin: Move error %d (%s), purging file %s (%s)\n", errno, strerror(errno), file_name, final_name)); - rc = default_vfs_ops.unlink(conn, file_name); - goto done; + ret = default_vfs_ops.rename(conn, fname, bin); + if (ret == -1) { + DEBUG(3, ("recycle bin: move error %d (%s)\n", errno, strerror(errno) )); + DEBUG(3, ("recycle bin: move failed, purging...\n")); + return default_vfs_ops.unlink(conn,fname); + } + return ret; + } else { + DEBUG(3, ("recycle bin: move failed, purging...\n")); + return default_vfs_ops.unlink(conn,fname); } - - /* touch access date of moved file */ - if (recbin->touch == True ) - recycle_touch(conn, final_name); - -done: - SAFE_FREE(file_name); - SAFE_FREE(path_name); - SAFE_FREE(temp_name); - SAFE_FREE(final_name); - return rc; } diff --git a/examples/pdb/mysql/Makefile.in b/examples/pdb/mysql/Makefile.in index 3ebecad762..1da6ea789e 100644 --- a/examples/pdb/mysql/Makefile.in +++ b/examples/pdb/mysql/Makefile.in @@ -2,6 +2,8 @@ PDB_OBJS = pdb_mysql.so PDB_LDFLAGS = -lmysqlclient MAKEFILE = Makefile.pdb +include $(MAKEFILE) + CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/mysql/pdb_mysql.c b/examples/pdb/mysql/pdb_mysql.c index 0cc1de6aaf..c7e9e781c3 100644 --- a/examples/pdb/mysql/pdb_mysql.c +++ b/examples/pdb/mysql/pdb_mysql.c @@ -80,6 +80,7 @@ typedef struct pdb_mysql_query { char *part1; char *part2; } pdb_mysql_query; + #define SET_DATA(data,methods) { \ if(!methods){ \ DEBUG(0, ("invalid methods!\n")); \ @@ -91,8 +92,8 @@ typedef struct pdb_mysql_query { return False; \ } \ } - -void pdb_mysql_int_field(struct pdb_methods *m, +void +pdb_mysql_int_field(struct pdb_methods *m, struct pdb_mysql_query *q, char *name, int value) { if (!name || strchr(name, '\'')) @@ -110,7 +111,8 @@ void pdb_mysql_int_field(struct pdb_methods *m, } } -static BOOL pdb_mysql_string_field(struct pdb_methods *methods, +static BOOL +pdb_mysql_string_field(struct pdb_methods *methods, struct pdb_mysql_query *q, char *name, const char *value) { @@ -143,7 +145,8 @@ static BOOL pdb_mysql_string_field(struct pdb_methods *methods, return True; } -static char * config_value(pdb_mysql_data * data, char *name, char *default_value) +static char * +config_value(pdb_mysql_data * data, char *name, char *default_value) { if (lp_parm_string(NULL, data->location, name)) return lp_parm_string(NULL, data->location, name); @@ -151,7 +154,9 @@ static char * config_value(pdb_mysql_data * data, char *name, char *default_valu return default_value; } -static char * config_value_write(pdb_mysql_data * data, char *name, char *default_value) { +static char * +config_value_write(pdb_mysql_data * data, char *name, char *default_value) +{ char *v = config_value(data, name, NULL); char *write; @@ -174,7 +179,8 @@ static char * config_value_write(pdb_mysql_data * data, char *name, char *defaul return write; } -static const char * config_value_read(pdb_mysql_data * data, char *name, char *default_value) +static const char * +config_value_read(pdb_mysql_data * data, char *name, char *default_value) { char *v = config_value(data, name, NULL); char *write; @@ -200,7 +206,8 @@ static const char * config_value_read(pdb_mysql_data * data, char *name, char *d } /* Wrapper for atol that returns 0 if 'a' points to NULL */ -static long xatol(char *a) +static long +xatol(char *a) { long ret = 0; @@ -210,7 +217,8 @@ static long xatol(char *a) return ret; } -static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) +static BOOL +row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) { MYSQL_ROW row; pstring temp; @@ -272,7 +280,8 @@ static BOOL row_to_sam_account(MYSQL_RES * r, SAM_ACCOUNT * u) return True; } -static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL +mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -377,7 +386,8 @@ static BOOL mysqlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void mysqlsam_endsampwent(struct pdb_methods *methods) +static void +mysqlsam_endsampwent(struct pdb_methods *methods) { struct pdb_mysql_data *data = (struct pdb_mysql_data *) methods->private_data; @@ -399,7 +409,8 @@ static void mysqlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL +mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { struct pdb_mysql_data *data; @@ -413,7 +424,8 @@ static BOOL mysqlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user return row_to_sam_account(data->pwent, user); } -BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, +BOOL +mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, const char *field, const char *sname) { char *esc_sname; @@ -539,7 +551,8 @@ BOOL mysqlsam_select_by_field(struct pdb_methods * methods, SAM_ACCOUNT * user, Lookup a name in the SAM database ******************************************************************/ -static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL +mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user, const char *sname) { struct pdb_mysql_data *data; @@ -560,7 +573,8 @@ static BOOL mysqlsam_getsampwnam(struct pdb_methods *methods, SAM_ACCOUNT * user Search by sid **************************************************************************/ -static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, +static BOOL +mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user, const DOM_SID * sid) { BOOL ret = False; @@ -583,7 +597,8 @@ static BOOL mysqlsam_getsampwsid(struct pdb_methods *methods, SAM_ACCOUNT * user Delete a SAM_ACCOUNT ****************************************************************************/ -static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, +static BOOL +mysqlsam_delete_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * sam_pass) { const char *sname = pdb_get_username(sam_pass); @@ -641,7 +656,8 @@ static BOOL mysqlsam_delete_sam_account(struct pdb_methods *methods, return True; } -static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, +static BOOL +mysqlsam_replace_sam_account(struct pdb_methods *methods, const SAM_ACCOUNT * newpwd, char isupdate) { pstring temp; @@ -873,18 +889,21 @@ static BOOL mysqlsam_replace_sam_account(struct pdb_methods *methods, return True; } -static BOOL mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) +static BOOL +mysqlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 0); } -static BOOL mysqlsam_update_sam_account(struct pdb_methods *methods, +static BOOL +mysqlsam_update_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * newpwd) { return mysqlsam_replace_sam_account(methods, newpwd, 1); } -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS +pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, char *location) { NTSTATUS nt_status; diff --git a/examples/pdb/xml/Makefile.in b/examples/pdb/xml/Makefile.in index 252641da6d..87d4546972 100644 --- a/examples/pdb/xml/Makefile.in +++ b/examples/pdb/xml/Makefile.in @@ -2,6 +2,8 @@ PDB_OBJS = pdb_xml.so PDB_CFLAGS = `xml2-config --cflags` PDB_LDFLAGS = `xml2-config --libs` +include $(MAKEFILE) + CC = @CC@ LIBTOOL = libtool CFLAGS = @CFLAGS@ $(PDB_CFLAGS) diff --git a/examples/pdb/xml/pdb_xml.c b/examples/pdb/xml/pdb_xml.c index 17261873cd..f237a7da9d 100644 --- a/examples/pdb/xml/pdb_xml.c +++ b/examples/pdb/xml/pdb_xml.c @@ -42,7 +42,8 @@ static char * iota(int a) { return tmp; } -BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL +parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { pstring temp; @@ -71,7 +72,8 @@ BOOL parsePass(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) return True; } -BOOL parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) +BOOL +parseUser(xmlDocPtr doc, xmlNsPtr ns, xmlNodePtr cur, SAM_ACCOUNT * u) { char *tmp; DOM_SID sid; @@ -240,7 +242,8 @@ typedef struct pdb_xml { xmlNsPtr ns; } pdb_xml; -xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) +xmlNodePtr +parseSambaXMLFile(struct pdb_xml *data) { xmlNodePtr cur; @@ -287,7 +290,8 @@ xmlNodePtr parseSambaXMLFile(struct pdb_xml *data) return cur; } -static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) +static BOOL +xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) { pdb_xml *data; @@ -310,7 +314,8 @@ static BOOL xmlsam_setsampwent(struct pdb_methods *methods, BOOL update) End enumeration of the passwd list. ****************************************************************/ -static void xmlsam_endsampwent(struct pdb_methods *methods) +static void +xmlsam_endsampwent(struct pdb_methods *methods) { pdb_xml *data; @@ -335,7 +340,8 @@ static void xmlsam_endsampwent(struct pdb_methods *methods) Get one SAM_ACCOUNT from the list (next in line) *****************************************************************/ -static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) +static BOOL +xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) { pdb_xml *data; @@ -367,7 +373,8 @@ static BOOL xmlsam_getsampwent(struct pdb_methods *methods, SAM_ACCOUNT * user) Adds an existing SAM_ACCOUNT ****************************************************************************/ -static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) +static BOOL +xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) { pstring temp; fstring sid_str; @@ -507,7 +514,8 @@ static BOOL xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT * u) return True; } -NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, +NTSTATUS +pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method, const char *location) { NTSTATUS nt_status; diff --git a/examples/printing/smbprint b/examples/printing/smbprint index 68bd66a13f..5a00a2a8aa 100755 --- a/examples/printing/smbprint +++ b/examples/printing/smbprint @@ -25,11 +25,6 @@ # # -t now causes translate to be used when sending files # -# Further modifications by Alfred Perlstein to fix some problems and -# improve the quality of the code (3-Dec-2001). -# -# More hacking by Richard Sharpe to improve portability. 9-Dec-2001. -# # In order for this to work the /etc/printcap entry must include an # accounting file (af=...): # @@ -51,10 +46,12 @@ # service=CJET_371 # password="" -#smbclient=/usr/pkg/bin/smbclient -# Assume that smbclient will be in the same place as smbprint +# +# Debugging log file, change to /dev/null if you like. +# +logfile=/tmp/smb-print.log +# logfile=/dev/null -smbclient="`dirname $0`/smbclient" # # The last parameter to the filter is the accounting file name. @@ -70,76 +67,29 @@ config_file=$spool_dir/.config # server # service # password -# username (optional) -# IP (optional) -# debug (optional) -# debugsmb (optional) -# debugfile (optional) -. $config_file - -if [ "x$password" = "x" ] ; then - password="-N" -fi +eval `cat $config_file` -if [ "x$username" == "x" ] ; then - username="$server"; -fi +while getopts t c; do + case $c in + t) + TRANS=1 + ;; -while test $# -gt 0; do - case "$1" in - -t) - TRANS=1 - ;; - - *) # Bad Parameters, ignore them ... - ;; - esac - shift + '?') # Bad parameters, ignore it ... + ;; + esac done - -command="print - ;" -if [ $TRANS -eq 1 ]; then - command="translate;$command"; -fi - -debugfile="/tmp/smb-print.log" -if [ "x$debug" = "x" ] ; then - debugfile=/dev/null debugargs= -else - if [ $debug -eq 0 ] ; then - debugfile=/dev/null debugargs= - else - set -x; exec >>$debugfile 2>&1 - debugargs="$debugfile." - #[ "x$debugsmb" == "x" ] || debugargs="$debugargs -d $debugsmb" - fi -fi - -if [ "x$smbconf" != "x" ]; then - - smbconf="-s $smbconf" - -fi - -if [ "x$IP" != "x" ]; then - - IP="-I $IP" - -fi - -if [ "x$debugargs" != "x" ]; then - - debugargs="-l $debugargs" - -fi - -$smbclient \ - "\\\\$server\\$service" \ - $password \ - $smbconf \ - $IP \ - $debugargs \ - -U $username \ - -P \ - -c "$command" # +# Some debugging help, change the >> to > if you want to same space. +# +echo "server $server, service $service" >> $logfile + +( +# NOTE You may wish to add the line `echo translate' if you want automatic +# CR/LF translation when printing. + if [ $TRANS -eq 1 ]; then + echo translate + fi + echo "print -" + cat +) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $server -N -P >> $logfile diff --git a/examples/printing/smbprint.old b/examples/printing/smbprint.old deleted file mode 100755 index 5a00a2a8aa..0000000000 --- a/examples/printing/smbprint.old +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/sh - -# This script is an input filter for printcap printing on a unix machine. It -# uses the smbclient program to print the file to the specified smb-based -# server and service. -# For example you could have a printcap entry like this -# -# smb:lp=/dev/null:sd=/usr/spool/smb:sh:if=/usr/local/samba/smbprint -# -# which would create a unix printer called "smb" that will print via this -# script. You will need to create the spool directory /usr/spool/smb with -# appropriate permissions and ownerships for your system. - -# Set these to the server and service you wish to print to -# In this example I have a WfWg PC called "lapland" that has a printer -# exported called "printer" with no password. - -# -# Script further altered by hamiltom@ecnz.co.nz (Michael Hamilton) -# so that the server, service, and password can be read from -# a /usr/var/spool/lpd/PRINTNAME/.config file. -# -# Script further modified by Richard Sharpe to fix some things. -# Get rid of the -x on the first line, and add parameters -# -# -t now causes translate to be used when sending files -# -# In order for this to work the /etc/printcap entry must include an -# accounting file (af=...): -# -# cdcolour:\ -# :cm=CD IBM Colorjet on 6th:\ -# :sd=/var/spool/lpd/cdcolour:\ -# :af=/var/spool/lpd/cdcolour/acct:\ -# :if=/usr/local/etc/smbprint:\ -# :mx=0:\ -# :lp=/dev/null: -# -# The /usr/var/spool/lpd/PRINTNAME/.config file should contain: -# server=PC_SERVER -# service=PR_SHARENAME -# password="password" -# -# E.g. -# server=PAULS_PC -# service=CJET_371 -# password="" - -# -# Debugging log file, change to /dev/null if you like. -# -logfile=/tmp/smb-print.log -# logfile=/dev/null - - -# -# The last parameter to the filter is the accounting file name. -# Extract the directory name from the file name. -# Concat this with /.config to get the config file. -# -TRANS=0 -eval acct_file=\${$#} -spool_dir=`dirname $acct_file` -config_file=$spool_dir/.config - -# Should read the following variables set in the config file: -# server -# service -# password -eval `cat $config_file` - -while getopts t c; do - case $c in - t) - TRANS=1 - ;; - - '?') # Bad parameters, ignore it ... - ;; - esac -done -# -# Some debugging help, change the >> to > if you want to same space. -# -echo "server $server, service $service" >> $logfile - -( -# NOTE You may wish to add the line `echo translate' if you want automatic -# CR/LF translation when printing. - if [ $TRANS -eq 1 ]; then - echo translate - fi - echo "print -" - cat -) | /usr/local/samba/bin/smbclient "\\\\$server\\$service" $password -U $server -N -P >> $logfile |