From a846e592058726b670e40505493a4668bd856186 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 25 Nov 2003 03:15:26 +0000 Subject: [PATCH] CVS: ---------------------------------------------------------------------- CVS: Enter Log. Lines beginning with `CVS:' are removed automatically CVS: CVS: Committing in . CVS: CVS: Modified Files: CVS: Makefile.in configure.in include/includes.h include/ntvfs.h CVS: include/smb.h lib/iconv.c lib/module.c ntvfs/ntvfs_base.c CVS: ntvfs/cifs/vfs_cifs.c ntvfs/ipc/vfs_ipc.c CVS: ntvfs/posix/vfs_posix.c ntvfs/print/vfs_print.c CVS: ntvfs/reference/vfs_ref.c ntvfs/simple/vfs_simple.c CVS: passdb/pdb_interface.c CVS: Added Files: CVS: include/module.h CVS: ---------------------------------------------------------------------- Update to the modules system. Fixed: - get rid of smb_probe_module - merge older updates from 3.0 - introduced register_subsystem() and register_backend() functions - adapt ntvfs and charset to use new register functions - made smb_load_modules() work recursively (e.g. 'preload modules = /usr/lib/samba') - got rid of some old remains Things that still need work: - Did I break tankFS? I don't think so, but I can't test it here :-( - Add 'postload modules = ' (for modules that need to be loaded after fork() in smbd, if applicable) - Convert RPC, auth, passdb, etc to use new register_{subsystem,backend}() functions - Accept wildcards in 'preload modules' option, instead of loading recursively (This used to be commit 7512b9ab1a8b3103f7a6c13f736353c46a26b668) --- source4/configure.in | 234 ++++++++++++------------------ source4/include/includes.h | 3 +- source4/include/module.h | 30 ++++ source4/include/ntvfs.h | 3 + source4/include/smb.h | 3 - source4/lib/iconv.c | 11 +- source4/lib/module.c | 110 ++++++++------ source4/ntvfs/cifs/vfs_cifs.c | 14 +- source4/ntvfs/ipc/vfs_ipc.c | 14 +- source4/ntvfs/ntvfs_base.c | 36 ++--- source4/ntvfs/posix/vfs_posix.c | 16 +- source4/ntvfs/print/vfs_print.c | 14 +- source4/ntvfs/simple/vfs_simple.c | 14 +- source4/passdb/pdb_interface.c | 6 - 14 files changed, 259 insertions(+), 249 deletions(-) create mode 100644 source4/include/module.h diff --git a/source4/configure.in b/source4/configure.in index 5b91e778e49..f71141f7212 100644 --- a/source4/configure.in +++ b/source4/configure.in @@ -160,41 +160,6 @@ AC_SUBST(SMBWRAPPER) AC_SUBST(EXTRA_BIN_PROGS) AC_SUBST(EXTRA_SBIN_PROGS) AC_SUBST(EXTRA_ALL_TARGETS) -dnl For the DYNAMIC RPC stuff -dnl The complicated _YES and _NO stuff allows us to avoid a dependency -dnl on GNU Make. -AC_SUBST(LSA_DYNAMIC_YES) -AC_SUBST(LSA_DYNAMIC_NO) -LSA_DYNAMIC_YES="#" -LSA_DYNAMIC_NO= -AC_SUBST(NETLOG_DYNAMIC_YES) -AC_SUBST(NETLOG_DYNAMIC_NO) -NETLOG_DYNAMIC_YES="#" -NETLOG_DYNAMIC_NO= -AC_SUBST(SAMR_DYNAMIC_YES) -AC_SUBST(SAMR_DYNAMIC_NO) -SAMR_DYNAMIC_YES="#" -SAMR_DYNAMIC_NO= -AC_SUBST(SVC_DYNAMIC_YES) -AC_SUBST(SVC_DYNAMIC_NO) -SVC_DYNAMIC_YES="#" -SVC_DYNAMIC_NO= -AC_SUBST(WKS_DYNAMIC_YES) -AC_SUBST(WKS_DYNAMIC_NO) -WKS_DYNAMIC_YES="#" -WKS_DYNAMIC_NO= -AC_SUBST(REG_DYNAMIC_YES) -AC_SUBST(REG_DYNAMIC_NO) -REG_DYNAMIC_YES="#" -REG_DYNAMIC_NO= -AC_SUBST(SPOOLSS_DYNAMIC_YES) -AC_SUBST(SPOOLSS_DYNAMIC_NO) -SPOOLSS_DYNAMIC_YES="#" -SPOOLSS_DYNAMIC_NO= -AC_SUBST(DFS_DYNAMIC_YES) -AC_SUBST(DFS_DYNAMIC_NO) -DFS_DYNAMIC_YES="#" -DFS_DYNAMIC_NO= AC_ARG_ENABLE(debug, [ --enable-debug Turn on compiler debugging information (default=no)], @@ -204,19 +169,16 @@ AC_ARG_ENABLE(debug, AC_ARG_ENABLE(developer, [ --enable-developer Turn on developer warnings and debugging (default=no)], [if eval "test x$enable_developer = xyes"; then - CFLAGS="${CFLAGS} -gstabs -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER" + developer=yes + CFLAGS="${CFLAGS} -gstabs -Wall -Wshadow -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER" fi]) AC_ARG_ENABLE(krb5developer, [ --enable-krb5developer Turn on developer warnings and debugging, except -Wstrict-prototypes (default=no)], [if eval "test x$enable_krb5developer = xyes"; then + developer=yes CFLAGS="${CFLAGS} -gstabs -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER" fi]) -# compile with optimization and without debugging by default -if test "x$CFLAGS" = x; then - CFLAGS = "-O"; -fi - AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc Enable heap debugging [default=no]]) if test "x$enable_dmalloc" = xyes @@ -227,65 +189,18 @@ then LIBS="$LIBS -ldmalloc" fi -AC_ARG_ENABLE(dynrpc, [ --enable-dynrpc Enable dynamic RPC modules [default=no]]) - -if test x$enable_dynrpc = xyes -then - enable_dynrpc=lsa,samr,reg,wks,netlog,dfs -fi - -if test x$enable_dynrpc != xno -then - for i in `echo $enable_dynrpc | sed -e's/,/ /g'` - do case $i in lsa) - LSA_DYNAMIC_YES= - LSA_DYNAMIC_NO="#" - AC_DEFINE(RPC_LSA_DYNAMIC, 1, - [Define to make the LSA pipe dynamic]) - ;; samr) - SAMR_DYNAMIC_YES= - SAMR_DYNAMIC_NO="#" - AC_DEFINE(RPC_SAMR_DYNAMIC, 1, - [Define to make the SAMR pipe dynamic]) - ;; svc) - SVC_DYNAMIC_YES= - SVC_DYNAMIC_NO="#" - AC_DEFINE(RPC_SVC_DYNAMIC, 1, - [Define to make the SRVSVC pipe dynamic]) - ;; wks) - WKS_DYNAMIC_YES= - WKS_DYNAMIC_NO="#" - AC_DEFINE(RPC_WKS_DYNAMIC, 1, - [Define to make the WKSSVC pipe dynamic]) - ;; netlog) - NETLOG_DYNAMIC_YES= - NETLOG_DYNAMIC_NO="#" - AC_DEFINE(RPC_NETLOG_DYNAMIC, 1, - [Define to make the NETLOGON pipe dynamic]) - ;; reg) - REG_DYNAMIC_YES= - REG_DYNAMIC_NO="#" - AC_DEFINE(RPC_REG_DYNAMIC, 1, - [Define to make the WINREG pipe dynamic]) - ;; spoolss) - SPOOLSS_DYNAMIC_YES= - SPOOLSS_DYNAMIC_NO="#" - AC_DEFINE(RPC_SPOOLSS_DYNAMIC, 1, - [Define to make the SPOOLSS pipe dynamic]) - ;; dfs) - DFS_DYNAMIC_YES= - DFS_DYNAMIC_NO="#" - AC_DEFINE(RPC_DFS_DYNAMIC, 1, - [Define to make the NETDFS pipe dynamic]) - ;; esac - done -fi - dnl Checks for programs. AC_PROG_CC AC_PROG_INSTALL AC_PATH_PROG(PERL, perl) +# compile with optimization and without debugging by default, but +# allow people to set their own preference. +if test "x$CFLAGS" = x +then + CFLAGS="-O ${CFLAGS}" +fi + dnl Check if we use GNU ld LD=ld AC_PROG_LD_GNU @@ -341,6 +256,18 @@ AC_VALIDATE_CACHE_SYSTEM_TYPE DYNEXP= +dnl Add modules that have to be built by default here +dnl These have to be built static: +default_static_modules="pdb_smbpasswd auth_sam auth_unix auth_builtin ntvfs_ipc ntvfs_simple ntvfs_print ntvfs_cifs" + +dnl These are preferably build shared, and static if dlopen() is not available +default_shared_modules="vfs_recycle vfs_audit vfs_extd_audit vfs_netatalk vfs_fake_perms" + +if test "x$developer" = xyes; then + default_static_modules="$default_static_modules" + default_shared_modules="$default_shared_modules charset_weird" +fi + # # Config CPPFLAG settings for strange OS's that must be set # before other tests. @@ -2114,28 +2041,6 @@ AC_SUBST(SMBD_EXTRA_OBJS) AC_SUBST(SMBD_EXTRA_LIBS) -################################################# -# check for STFS NTVFS backend -STFS_ENABLED=# -AC_MSG_CHECKING(whether to use STFS NTVFS backend) -AC_ARG_WITH(stfs, -[ --with-stfs Include STFS NTVFS backend (default=no) ], -[ case "$withval" in - yes) - AC_MSG_RESULT(yes) - AC_DEFINE(WITH_NTVFS_STFS,1,[Whether to include STFS NTVFS backend]) - STFS_ENABLED= - ;; - *) - AC_MSG_RESULT(no) - ;; - esac ], - AC_MSG_RESULT(no) -) - -AC_SUBST(STFS_ENABLED) - - ################################################# # check for the DFS clear-text auth system AC_MSG_CHECKING(whether to use DFS clear-text auth) @@ -2511,21 +2416,15 @@ if test x"$samba_cv_HAVE_TRUNCATED_SALT" = x"yes"; then fi fi -######################################################################################## -## -## TESTS FOR SAM BACKENDS. KEEP THESE GROUPED TOGETHER -## -######################################################################################## - ################################################# -# check for a LDAP password database configuration backwards compatibility -AC_MSG_CHECKING(whether to use LDAP SAM 2.2 compatible configuration) -AC_ARG_WITH(ldapsam, -[ --with-ldapsam Include LDAP SAM 2.2 compatible configuration (default=no)], +# check for a NISPLUS_HOME support +AC_MSG_CHECKING(whether to use NISPLUS_HOME) +AC_ARG_WITH(nisplus-home, +[ --with-nisplus-home Include NISPLUS_HOME support (default=no)], [ case "$withval" in yes) AC_MSG_RESULT(yes) - AC_DEFINE(WITH_LDAP_SAMCONFIG,1,[Whether to include 2.2 compatibel LDAP SAM configuration]) + AC_DEFINE(WITH_NISPLUS_HOME,1,[Whether to include nisplus_home support]) ;; *) AC_MSG_RESULT(no) @@ -2535,14 +2434,14 @@ AC_ARG_WITH(ldapsam, ) ################################################# -# check for a TDB password database -AC_MSG_CHECKING(whether to use TDB SAM database) -AC_ARG_WITH(tdbsam, -[ --with-tdbsam Include experimental TDB SAM support (default=no)], +# check for syslog logging +AC_MSG_CHECKING(whether to use syslog logging) +AC_ARG_WITH(syslog, +[ --with-syslog Include experimental SYSLOG support (default=no)], [ case "$withval" in yes) AC_MSG_RESULT(yes) - AC_DEFINE(WITH_TDB_SAM,1,[Whether to include experimental TDB SAM support]) + AC_DEFINE(WITH_SYSLOG,1,[Whether to include experimental syslog support]) ;; *) AC_MSG_RESULT(no) @@ -2552,14 +2451,14 @@ AC_ARG_WITH(tdbsam, ) ################################################# -# check for a NISPLUS password database -AC_MSG_CHECKING(whether to use NISPLUS SAM database) -AC_ARG_WITH(nisplussam, -[ --with-nisplussam Include NISPLUS SAM support (default=no)], +# check for a shared memory profiling support +AC_MSG_CHECKING(whether to use profiling) +AC_ARG_WITH(profiling-data, +[ --with-profiling-data Include gathering source code profile information (default=no)], [ case "$withval" in yes) AC_MSG_RESULT(yes) - AC_DEFINE(WITH_NISPLUS_SAM,1,[Whether to include nisplus SAM support]) + AC_DEFINE(WITH_PROFILE,1,[Whether to use profiling]) ;; *) AC_MSG_RESULT(no) @@ -3415,6 +3314,65 @@ AC_ARG_WITH(python, esac ]) AC_SUBST(PYTHON) +for i in `echo $default_static_modules | sed -e's/,/ /g'` +do + eval MODULE_DEFAULT_$i=STATIC +done + +for i in `echo $default_shared_modules | sed -e's/,/ /g'` +do + dnl Fall back to static if dlopen() is not available + eval MODULE_DEFAULT_$i=STATIC + + if test x"$ac_cv_func_dlopen" = xyes; then + eval MODULE_DEFAULT_$i=SHARED + fi +done + +dnl Always built these modules static +MODULE_pdb_guest=STATIC +MODULE_idmap_tdb=STATIC + +AC_ARG_WITH(static-modules, +[ --with-static-modules=MODULES Comma-seperated list of names of modules to statically link in], +[ if test $withval; then + for i in `echo $withval | sed -e's/,/ /g'` + do + eval MODULE_$i=STATIC + done +fi ]) + +AC_ARG_WITH(shared-modules, +[ --with-shared-modules=MODULES Comma-seperated list of names of modules to build shared], +[ if test $withval; then + for i in `echo $withval | sed -e's/,/ /g'` + do + eval MODULE_$i=SHARED + done +fi ]) + +SMB_MODULE(charset_weird, modules/weird.o, "bin/weird.$SHLIBEXT", CHARSET) +SMB_SUBSYSTEM(CHARSET,lib/iconv.o) + +SMB_MODULE(ntvfs_cifs, \$(NTVFS_CIFS_OBJ), "bin/cifs.$SHLIBEXT$", NTVFS) +SMB_MODULE(ntvfs_simple, \$(NTVFS_SIMPLE_OBJ), "bin/ntvfs_simple.$SHLIBEXT$", NTVFS) +SMB_MODULE(ntvfs_print, \$(NTVFS_PRINT_OBJ), "bin/ntvfs_print.$SHLIBEXT$", NTVFS) +SMB_MODULE(ntvfs_ipc, \$(NTVFS_IPC_OBJ), "bin/ntvfs_ipc.$SHLIBEXT$", NTVFS) +SMB_MODULE(ntvfs_posix, \$(NTVFS_POSIX_OBJ), "bin/ntvfs_posix.$SHLIBEXT$", NTVFS) + +# Tank FS +SMB_MODULE(ntvfs_csm, \$(NTVFS_CSM_OBJ), "bin/ntvfs_csm.$SHLIBEXT$", NTVFS) +STFS_ENABLED="#" +if test "$MODULE_ntvfs_csm"; then + SMBD_EXTRA_LIBS="$SMBD_EXTRA_LIBS \$\(STFS_LIBS\)" + STFS_ENABLED= +fi +AC_SUBST(STFS_ENABLED) + +SMB_SUBSYSTEM(NTVFS,ntvfs/ntvfs_base.o) + +AC_DEFINE_UNQUOTED(STRING_STATIC_MODULES, "$string_static_modules", [String list of builtin modules]) + ################################################# # do extra things if we are running insure diff --git a/source4/include/includes.h b/source4/include/includes.h index 0f5e73cf563..908d2a4e76c 100644 --- a/source4/include/includes.h +++ b/source4/include/includes.h @@ -759,11 +759,12 @@ extern int errno; #include "ntlmssp.h" #include "auth.h" - #include "passdb.h" #include "session.h" +#include "module.h" + #include "asn_1.h" #include "popt.h" diff --git a/source4/include/module.h b/source4/include/module.h new file mode 100644 index 00000000000..02826595e40 --- /dev/null +++ b/source4/include/module.h @@ -0,0 +1,30 @@ +/* + Unix SMB/CIFS implementation. + Handling of idle/exit events + Copyright (C) Jelmer Vernooij 2003 + + 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. +*/ + +#ifndef _MODULE_H +#define _MODULE_H + +/* Module support */ +typedef NTSTATUS (*init_module_function) (void); + +/* Module that registers a backend for a certain subsystem */ +typedef NTSTATUS (*register_backend_function) (void *data); + +#endif /* _MODULE_H */ diff --git a/source4/include/ntvfs.h b/source4/include/ntvfs.h index 2b1f519b322..b972a4ef995 100644 --- a/source4/include/ntvfs.h +++ b/source4/include/ntvfs.h @@ -32,6 +32,9 @@ enum ntvfs_type {NTVFS_DISK, NTVFS_PRINT, NTVFS_IPC}; /* the ntvfs operations structure - contains function pointers to the backend implementations of each operation */ struct ntvfs_ops { + const char *name; + enum ntvfs_type type; + /* initial setup */ NTSTATUS (*connect)(struct request_context *req, const char *sharename); NTSTATUS (*disconnect)(struct tcon_context *conn); diff --git a/source4/include/smb.h b/source4/include/smb.h index f6a4281e012..e9f09ce0a55 100644 --- a/source4/include/smb.h +++ b/source4/include/smb.h @@ -1355,9 +1355,6 @@ typedef struct { #define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14 -/* Module support */ -typedef int (init_module_function) (void); - /* a set of flags to control handling of request structures */ #define REQ_CONTROL_PROTECTED (1<<0) /* don't destroy this request */ diff --git a/source4/lib/iconv.c b/source4/lib/iconv.c index 8f85e29c2ed..2a0b013257a 100644 --- a/source4/lib/iconv.c +++ b/source4/lib/iconv.c @@ -63,8 +63,9 @@ static struct charset_functions builtin_functions[] = { static struct charset_functions *charsets = NULL; -BOOL smb_register_charset(struct charset_functions *funcs) +static NTSTATUS charset_register_backend(void *_funcs) { + struct charset_functions *funcs = (struct charset_functions *)_funcs; struct charset_functions *c = charsets; DEBUG(5, ("Attempting to register new charset %s\n", funcs->name)); @@ -72,7 +73,7 @@ BOOL smb_register_charset(struct charset_functions *funcs) while(c) { if(!strcasecmp(c->name, funcs->name)){ DEBUG(2, ("Duplicate charset %s, not registering\n", funcs->name)); - return False; + return NT_STATUS_OBJECT_NAME_COLLISION; } c = c->next; } @@ -80,7 +81,7 @@ BOOL smb_register_charset(struct charset_functions *funcs) funcs->next = funcs->prev = NULL; DEBUG(5, ("Registered charset %s\n", funcs->name)); DLIST_ADD(charsets, funcs); - return True; + return NT_STATUS_OK; } static void lazy_initialize_iconv(void) @@ -90,8 +91,10 @@ static void lazy_initialize_iconv(void) if (!initialized) { initialized = True; + register_subsystem("charset", charset_register_backend); + for(i = 0; builtin_functions[i].name; i++) - smb_register_charset(&builtin_functions[i]); + register_backend("charset", &builtin_functions[i]); } } diff --git a/source4/lib/module.c b/source4/lib/module.c index 152e8931006..d45f99473ef 100644 --- a/source4/lib/module.c +++ b/source4/lib/module.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. module loading system - Copyright (C) Jelmer Vernooij 2002 + Copyright (C) Jelmer Vernooij 2002-2003 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 @@ -22,12 +22,32 @@ #include "includes.h" #ifdef HAVE_DLOPEN -int smb_load_module(const char *module_name) + +/* Load module (or directory with modules) recursively. + * Includes running the init_module() function */ +NTSTATUS smb_load_module(const char *module_name) { void *handle; - init_module_function *init; - int status; + init_module_function init; + NTSTATUS status; const char *error; + struct stat st; + DIR *dir; + struct dirent *dirent; + + stat(module_name, &st); + + /* If the argument is a directory, recursively load all files / + * directories in it */ + + /* How about symlinks pointing to themselves - wouldn't we rather + * want to use wildcards here? */ + if(S_ISDIR(st.st_mode)) { + dir = opendir(module_name); + while(dirent = readdir(dir)) { + smb_load_module(dirent->d_name); + } + } /* Always try to use LAZY symbol resolving; if the plugin has * backwards compatibility, there might be symbols in the @@ -37,17 +57,17 @@ int smb_load_module(const char *module_name) if(!handle) { DEBUG(0, ("Error loading module '%s': %s\n", module_name, sys_dlerror())); - return False; + return NT_STATUS_UNSUCCESSFUL; } - init = sys_dlsym(handle, "init_module"); + init = (init_module_function)sys_dlsym(handle, "init_module"); /* we must check sys_dlerror() to determine if it worked, because sys_dlsym() can validly return NULL */ error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_module' in %s: %s\n", module_name, error)); - return False; + return NT_STATUS_UNSUCCESSFUL; } status = init(); @@ -65,7 +85,7 @@ int smb_load_modules(const char **modules) int success = 0; for(i = 0; modules[i]; i++){ - if(smb_load_module(modules[i])) { + if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) { success++; } } @@ -75,47 +95,18 @@ int smb_load_modules(const char **modules) return success; } -int smb_probe_module(const char *subsystem, const char *module) -{ - char *full_path; - int rc; - TALLOC_CTX *mem_ctx; - - /* Check for absolute path */ - if(module[0] == '/')return smb_load_module(module); - - mem_ctx = talloc_init("smb_probe_module"); - if (!mem_ctx) { - DEBUG(0,("No memory for loading modules\n")); - return False; - } - full_path = talloc_strdup(mem_ctx, lib_path(mem_ctx, subsystem)); - full_path = talloc_asprintf(mem_ctx, "%s/%s.%s", - full_path, module, shlib_ext()); - - rc = smb_load_module(full_path); - talloc_destroy(mem_ctx); - return rc; -} - #else /* HAVE_DLOPEN */ -int smb_load_module(const char *module_name) +NTSTATUS smb_load_module(const char *module_name) { - DEBUG(0,("This samba executable has not been built with plugin support")); - return False; + DEBUG(0,("This samba executable has not been built with plugin support\n")); + return NT_STATUS_NOT_SUPPORTED; } int smb_load_modules(const char **modules) { - DEBUG(0,("This samba executable has not been built with plugin support")); - return False; -} - -int smb_probe_module(const char *subsystem, const char *module) -{ - DEBUG(0,("This samba executable has not been built with plugin support, not probing")); - return False; + DEBUG(0,("This samba executable has not been built with plugin support\n")); + return -1; } #endif /* HAVE_DLOPEN */ @@ -124,5 +115,38 @@ void init_modules(void) { if(lp_preload_modules()) smb_load_modules(lp_preload_modules()); - /* FIXME: load static modules */ +} + +struct subsystem { + char *name; + register_backend_function callback; + struct subsystem *prev, *next; +}; + +struct subsystem *subsystems = NULL; + +void register_subsystem(const char *name, register_backend_function callback) +{ + struct subsystem *s; + + s = smb_xmalloc(sizeof(struct subsystem)); + + s->name = smb_xstrdup(name); + s->callback = callback; + s->prev = s->next = NULL; + + DLIST_ADD(subsystems, s); +} + +NTSTATUS register_backend(const char *subsystem, void *args) +{ + /* Find the specified subsystem */ + struct subsystem *s = subsystems; + + while(s) { + if(!strcmp(subsystem, s->name)) return s->callback(args); + s = s->next; + } + + return NT_STATUS_NOT_IMPLEMENTED; } diff --git a/source4/ntvfs/cifs/vfs_cifs.c b/source4/ntvfs/cifs/vfs_cifs.c index 1afdb66a1c8..3903203505a 100644 --- a/source4/ntvfs/cifs/vfs_cifs.c +++ b/source4/ntvfs/cifs/vfs_cifs.c @@ -672,12 +672,15 @@ static NTSTATUS cvfs_trans2(struct request_context *req, struct smb_trans2 *tran /* initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem */ -BOOL cifs_vfs_init(void) +NTSTATUS ntvfs_cifs_init(void) { - BOOL ret; + NTSTATUS ret; struct ntvfs_ops ops; ZERO_STRUCT(ops); + + ops.name = "cifs"; + ops.type = NTVFS_DISK; /* fill in all the operations */ ops.connect = cvfs_connect; @@ -712,12 +715,11 @@ BOOL cifs_vfs_init(void) /* register ourselves with the NTVFS subsystem. We register under the name 'cifs'. */ - ret = ntvfs_register("cifs", NTVFS_DISK, &ops); + ret = register_backend("ntvfs", &ops); - if (!ret) { + if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register CIFS backend!\n")); - return False; } - return True; + return ret; } diff --git a/source4/ntvfs/ipc/vfs_ipc.c b/source4/ntvfs/ipc/vfs_ipc.c index b13c358dd56..da5c42507a1 100644 --- a/source4/ntvfs/ipc/vfs_ipc.c +++ b/source4/ntvfs/ipc/vfs_ipc.c @@ -248,14 +248,16 @@ NTSTATUS ipc_search_close(struct request_context *req, union smb_search_close *i /* initialialise the IPC backend, registering ourselves with the ntvfs subsystem */ -BOOL ipc_vfs_init(void) +NTSTATUS ntvfs_ipc_init(void) { - BOOL ret; + NTSTATUS ret; struct ntvfs_ops ops; ZERO_STRUCT(ops); /* fill in all the operations */ + ops.name = "ipc"; + ops.type = NTVFS_IPC; ops.connect = ipc_connect; ops.disconnect = ipc_disconnect; ops.unlink = ipc_unlink; @@ -284,12 +286,12 @@ BOOL ipc_vfs_init(void) ops.search_close = ipc_search_close; /* register ourselves with the NTVFS subsystem. */ - ret = ntvfs_register("ipc", NTVFS_IPC, &ops); + ret = register_backend("ntvfs", &ops); - if (!ret) { + if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register IPC backend!\n")); - return False; + return ret; } - return True; + return ret; } diff --git a/source4/ntvfs/ntvfs_base.c b/source4/ntvfs/ntvfs_base.c index 57cdb97e9f5..11f39c5d593 100644 --- a/source4/ntvfs/ntvfs_base.c +++ b/source4/ntvfs/ntvfs_base.c @@ -28,8 +28,6 @@ * can be more than one backend with the same name, as long as they * have different typesx */ static struct { - const char *name; - enum ntvfs_type type; struct ntvfs_ops *ops; } *backends = NULL; static int num_backends; @@ -42,13 +40,15 @@ static int num_backends; The 'type' is used to specify whether this is for a disk, printer or IPC$ share */ -BOOL ntvfs_register(const char *name, enum ntvfs_type type, struct ntvfs_ops *ops) +static NTSTATUS ntvfs_register(void *_ops) { - if (ntvfs_backend_byname(name, type) != NULL) { + struct ntvfs_ops *ops = _ops; + + if (ntvfs_backend_byname(ops->name, ops->type) != NULL) { /* its already registered! */ DEBUG(2,("NTVFS backend '%s' for type %d already registered\n", - name, (int)type)); - return False; + ops->name, (int)ops->type)); + return NT_STATUS_OBJECT_NAME_COLLISION; } backends = Realloc(backends, sizeof(backends[0]) * (num_backends+1)); @@ -56,13 +56,12 @@ BOOL ntvfs_register(const char *name, enum ntvfs_type type, struct ntvfs_ops *op smb_panic("out of memory in ntvfs_register"); } - backends[num_backends].name = smb_xstrdup(name); - backends[num_backends].type = type; backends[num_backends].ops = smb_xmemdup(ops, sizeof(*ops)); + backends[num_backends].ops->name = smb_xstrdup(ops->name); num_backends++; - return True; + return NT_STATUS_OK; } @@ -74,8 +73,8 @@ struct ntvfs_ops *ntvfs_backend_byname(const char *name, enum ntvfs_type type) int i; for (i=0;itype == type && + strcmp(backends[i].ops->name, name) == 0) { return backends[i].ops; } } @@ -105,19 +104,10 @@ int ntvfs_interface_version(struct ntvfs_critical_sizes *sizes) */ BOOL ntvfs_init(void) { - /* initialise our 3 basic backends. These are assumed to be - * present and are always built in */ - if (!posix_vfs_init() || - !ipc_vfs_init() || - !print_vfs_init()) { - return False; - } - /* initialize optional backends, e.g. CIFS. We allow failures here. */ - cifs_vfs_init(); + register_subsystem("ntvfs", ntvfs_register); -#if WITH_NTVFS_STFS - tank_vfs_init(); -#endif + /* FIXME: Perhaps panic if a basic backend, such as IPC, fails to initialise? */ + static_init_ntvfs; DEBUG(3,("NTVFS version %d initialised\n", NTVFS_INTERFACE_VERSION)); return True; diff --git a/source4/ntvfs/posix/vfs_posix.c b/source4/ntvfs/posix/vfs_posix.c index b27e7493a00..9a35f19322f 100644 --- a/source4/ntvfs/posix/vfs_posix.c +++ b/source4/ntvfs/posix/vfs_posix.c @@ -23,7 +23,7 @@ This is the default backend */ -#include "includes.h" +#include "include/includes.h" /* connect to a share - used when a tree_connect operation comes @@ -126,12 +126,15 @@ static NTSTATUS pvfs_unlink(struct ntvfs_context *ctx, const char *name, uint16 /* initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem */ -BOOL posix_vfs_init(void) +NTSTATUS ntvfs_posix_init(void) { - BOOL ret; + NTSTATUS ret; struct ntvfs_ops ops; ZERO_STRUCT(ops); + + ops.name = "default"; + ops.type = NTVFS_DISK; /* fill in all the operations */ ops.connect = pvfs_connect; @@ -140,12 +143,11 @@ BOOL posix_vfs_init(void) /* register ourselves with the NTVFS subsystem. We register under the name 'default' as we wish to be the default backend */ - ret = ntvfs_register("default", NTVFS_DISK, &ops); + ret = register_backend("ntvfs", &ops); - if (!ret) { + if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register POSIX backend!\n")); - return False; } - return True; + return ret; } diff --git a/source4/ntvfs/print/vfs_print.c b/source4/ntvfs/print/vfs_print.c index 2563f0ad9c7..82829d759a8 100644 --- a/source4/ntvfs/print/vfs_print.c +++ b/source4/ntvfs/print/vfs_print.c @@ -78,13 +78,16 @@ static NTSTATUS print_ioctl(struct request_context *req, struct smb_ioctl *io) /* initialialise the print backend, registering ourselves with the ntvfs subsystem */ -BOOL print_vfs_init(void) +NTSTATUS ntvfs_print_init(void) { - BOOL ret; + NTSTATUS ret; struct ntvfs_ops ops; ZERO_STRUCT(ops); + ops.name = "default"; + ops.type = NTVFS_PRINT; + /* fill in all the operations */ ops.connect = print_connect; ops.disconnect = print_disconnect; @@ -93,12 +96,11 @@ BOOL print_vfs_init(void) /* register ourselves with the NTVFS subsystem. We register under the name 'default' as we wish to be the default backend */ - ret = ntvfs_register("default", NTVFS_PRINT, &ops); + ret = register_backend("ntvfs", &ops); - if (!ret) { + if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register PRINT backend!\n")); - return False; } - return True; + return ret; } diff --git a/source4/ntvfs/simple/vfs_simple.c b/source4/ntvfs/simple/vfs_simple.c index c08b36fb395..f7ba41522cd 100644 --- a/source4/ntvfs/simple/vfs_simple.c +++ b/source4/ntvfs/simple/vfs_simple.c @@ -807,13 +807,16 @@ static NTSTATUS svfs_search_close(struct request_context *req, union smb_search_ /* initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem */ -BOOL posix_vfs_init(void) +NTSTATUS ntvfs_simple_init(void) { - BOOL ret; + NTSTATUS ret; struct ntvfs_ops ops; ZERO_STRUCT(ops); + ops.name = "simple"; + ops.type = NTVFS_DISK; + /* fill in all the operations */ ops.connect = svfs_connect; ops.disconnect = svfs_disconnect; @@ -844,12 +847,11 @@ BOOL posix_vfs_init(void) /* register ourselves with the NTVFS subsystem. We register under the name 'default' as we wish to be the default backend */ - ret = ntvfs_register("simple", NTVFS_DISK, &ops); + ret = register_backend("ntvfs", &ops); - if (!ret) { + if (!NT_STATUS_IS_OK(ret)) { DEBUG(0,("Failed to register POSIX backend!\n")); - return False; } - return True; + return ret; } diff --git a/source4/passdb/pdb_interface.c b/source4/passdb/pdb_interface.c index 48a039b3dee..ceb4ad771e5 100644 --- a/source4/passdb/pdb_interface.c +++ b/source4/passdb/pdb_interface.c @@ -450,12 +450,6 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c entry = pdb_find_backend_entry(module_name); - /* Try to find a module that contains this module */ - if(!entry) { - smb_probe_module("passdb", module_name); - entry = pdb_find_backend_entry(module_name); - } - /* No such backend found */ if(!entry) { SAFE_FREE(module_name); -- 2.34.1