lib/util: consolidate module loading into common code
authorAndrew Bartlett <abartlet@samba.org>
Fri, 9 Sep 2011 11:24:49 +0000 (21:24 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 6 Oct 2011 05:18:07 +0000 (07:18 +0200)
This creates a samba-modules private libary that handles the details.

Andrew Bartlett

31 files changed:
lib/util/modules.c [new file with mode: 0644]
lib/util/samba_modules.h [new file with mode: 0644]
lib/util/wscript_build
source3/Makefile.in
source3/include/includes.h
source3/include/module.h [deleted file]
source3/include/proto.h
source3/lib/module.c
source3/lib/util.c
source3/wscript_build
source4/auth/gensec/gensec_start.c
source4/auth/gensec/wscript_build
source4/auth/ntlm/auth.c
source4/auth/ntlm/wscript_build
source4/ntptr/ntptr_base.c
source4/ntvfs/ntvfs_base.c
source4/ntvfs/posix/pvfs_acl.c
source4/ntvfs/posix/wscript_build
source4/ntvfs/sysdep/sys_lease.c
source4/ntvfs/sysdep/sys_notify.c
source4/ntvfs/wscript_build
source4/param/param.h
source4/param/share.c
source4/param/util.c
source4/param/wscript_build
source4/rpc_server/dcerpc_server.c
source4/smbd/process_model.c
source4/smbd/server.c
source4/smbd/wscript_build
source4/torture/smbtorture.c
source4/torture/torture.c

diff --git a/lib/util/modules.c b/lib/util/modules.c
new file mode 100644 (file)
index 0000000..d25cabf
--- /dev/null
@@ -0,0 +1,243 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Jelmer Vernooij 2002-2003,2005-2007
+   Copyright (C) Stefan (metze) Metzmacher 2003
+   Copyright (C) Andrew Bartlett 2011
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "dynconfig/dynconfig.h"
+#include "lib/util/samba_modules.h"
+#include "system/filesys.h"
+#include "system/dir.h"
+
+/**
+ * Obtain the init function from a shared library file
+ */
+init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path)
+{
+       void *handle;
+       void *init_fn;
+
+       handle = dlopen(path, RTLD_NOW);
+       if (handle == NULL) {
+               DEBUG(0, ("Unable to open %s: %s\n", path, dlerror()));
+               return NULL;
+       }
+
+       init_fn = dlsym(handle, SAMBA_INIT_MODULE);
+
+       if (init_fn == NULL) {
+               DEBUG(0, ("Unable to find %s() in %s: %s\n",
+                         SAMBA_INIT_MODULE, path, dlerror()));
+               DEBUG(1, ("Loading module '%s' failed\n", path));
+               dlclose(handle);
+               return NULL;
+       }
+
+       return (init_module_fn)init_fn;
+}
+
+/**
+ * Obtain list of init functions from the modules in the specified
+ * directory
+ */
+init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
+{
+       DIR *dir;
+       struct dirent *entry;
+       char *filename;
+       int success = 0;
+       init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2);
+
+       ret[0] = NULL;
+
+       dir = opendir(path);
+       if (dir == NULL) {
+               talloc_free(ret);
+               return NULL;
+       }
+
+       while((entry = readdir(dir))) {
+               if (ISDOT(entry->d_name) || ISDOTDOT(entry->d_name))
+                       continue;
+
+               filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name);
+
+               ret[success] = load_module(mem_ctx, filename);
+               if (ret[success]) {
+                       ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
+                       success++;
+                       ret[success] = NULL;
+               }
+
+               talloc_free(filename);
+       }
+
+       closedir(dir);
+
+       return ret;
+}
+
+/**
+ * Run the specified init functions.
+ *
+ * @return true if all functions ran successfully, false otherwise
+ */
+bool run_init_functions(init_module_fn *fns)
+{
+       int i;
+       bool ret = true;
+
+       if (fns == NULL)
+               return true;
+
+       for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i]()); }
+
+       return ret;
+}
+
+/**
+ * Load the initialization functions from DSO files for a specific subsystem.
+ *
+ * Will return an array of function pointers to initialization functions
+ */
+
+init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
+{
+       char *path = modules_path(mem_ctx, subsystem);
+       init_module_fn *ret;
+
+       ret = load_modules(mem_ctx, path);
+
+       talloc_free(path);
+
+       return ret;
+}
+
+
+/* Load a dynamic module.  Only log a level 0 error if we are not checking
+   for the existence of a module (probling). */
+
+static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe)
+{
+       void *handle;
+       init_module_function *init;
+       NTSTATUS status;
+       const char *error;
+
+       /* Always try to use LAZY symbol resolving; if the plugin has
+        * backwards compatibility, there might be symbols in the
+        * plugin referencing to old (removed) functions
+        */
+       handle = dlopen(module_name, RTLD_LAZY);
+
+       /* This call should reset any possible non-fatal errors that
+          occured since last call to dl* functions */
+       error = dlerror();
+
+       if(!handle) {
+               int level = is_probe ? 3 : 0;
+               DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : ""));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       init = (init_module_function *)dlsym(handle, "init_samba_module");
+
+       /* we must check dlerror() to determine if it worked, because
+           dlsym() can validly return NULL */
+       error = dlerror();
+       if (error) {
+               DEBUG(0, ("Error trying to resolve symbol 'init_samba_module' "
+                         "in %s: %s\n", module_name, error));
+               dlclose(handle);
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       DEBUG(2, ("Module '%s' loaded\n", module_name));
+
+       status = init();
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("Module '%s' initialization failed: %s\n",
+                           module_name, get_friendly_nt_error_msg(status)));
+               dlclose(handle);
+       }
+
+       return status;
+}
+
+NTSTATUS smb_load_module(const char *module_name)
+{
+       return do_smb_load_module(module_name, false);
+}
+
+/* Load all modules in list and return number of
+ * modules that has been successfully loaded */
+int smb_load_modules(const char **modules)
+{
+       int i;
+       int success = 0;
+
+       for(i = 0; modules[i]; i++){
+               if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) {
+                       success++;
+               }
+       }
+
+       DEBUG(2, ("%d modules successfully loaded\n", success));
+
+       return success;
+}
+
+NTSTATUS smb_probe_module(const char *subsystem, const char *module)
+{
+       char *full_path = NULL;
+       TALLOC_CTX *ctx = talloc_stackframe();
+       NTSTATUS status;
+
+       /* Check for absolute path */
+
+       /* if we make any 'samba multibyte string'
+          calls here, we break
+          for loading string modules */
+
+       DEBUG(5, ("Probing module '%s'\n", module));
+
+       if (module[0] == '/') {
+               status = do_smb_load_module(module, true);
+               TALLOC_FREE(ctx);
+               return status;
+       }
+
+       full_path = talloc_asprintf(ctx,
+                                   "%s/%s.%s",
+                                   modules_path(ctx, subsystem),
+                                   module,
+                                   shlib_ext());
+       if (!full_path) {
+               TALLOC_FREE(ctx);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       DEBUG(5, ("Probing module '%s': Trying to load from %s\n",
+               module, full_path));
+
+       status = do_smb_load_module(full_path, true);
+
+       TALLOC_FREE(ctx);
+       return status;
+}
diff --git a/lib/util/samba_modules.h b/lib/util/samba_modules.h
new file mode 100644 (file)
index 0000000..2cca622
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+   Unix SMB/CIFS implementation.
+   Handling of idle/exit events
+   Copyright (C) Stefan (metze) Metzmacher     2003
+   Copyright (C) Andrew Bartlett 2011
+
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef _SAMBA_MODULES_H
+#define _SAMBA_MODULES_H
+
+/* Module support */
+typedef NTSTATUS (init_module_function) (void);
+typedef NTSTATUS (*init_module_fn) (void);
+
+NTSTATUS init_samba_module(void);
+
+/* this needs to be a string which is not in the C library. We
+   previously used "init_module", but that meant that modules which
+   did not define this function ended up calling the C library
+   function init_module() which makes a system call */
+#define SAMBA_INIT_MODULE "samba_init_module"
+
+/**
+ * Obtain the init function from a shared library file
+ */
+init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path);
+
+/**
+ * Obtain list of init functions from the modules in the specified
+ * directory
+ */
+init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path);
+
+/**
+ * Run the specified init functions.
+ *
+ * @return true if all functions ran successfully, false otherwise
+ */
+bool run_init_functions(init_module_fn *fns);
+
+/**
+ * Load the initialization functions from DSO files for a specific subsystem.
+ *
+ * Will return an array of function pointers to initialization functions
+ */
+init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem);
+
+NTSTATUS smb_load_module(const char *module_name);
+int smb_load_modules(const char **modules);
+NTSTATUS smb_probe_module(const char *subsystem, const char *module);
+
+#endif /* _SAMBA_MODULES_H */
index 70a639d2d7cbc0e8ef8ff90baab1fe8b7996d3ab..f4bd8852311ec8012dc7c1ea49024dcbd682e8a1 100755 (executable)
@@ -17,6 +17,12 @@ bld.SAMBA_LIBRARY('samba-util',
                   pc_files='samba-util.pc'
                   )
 
+bld.SAMBA_LIBRARY('samba-modules',
+                 source='modules.c',
+                 deps='errors samba-util',
+                 local_include=False,
+                 private_library=True)
+
 bld.SAMBA_LIBRARY('asn1util',
                   source='asn1.c',
                   deps='talloc samba-util',
index c736ae8d06b119e56d0345d32cedd7c753a183c2..a048090ceee5f626a37a51a9d1f5288c582fbd53 100644 (file)
@@ -464,7 +464,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) $(LIBTSOCKET_OBJ) \
          ../lib/util/charset/charset_macosxfs.o intl/lang_tdb.o \
          lib/conn_tdb.o lib/adt_tree.o lib/gencache.o \
          lib/sessionid_tdb.o \
-         lib/module.o lib/events.o @LIBTEVENT_OBJ0@ \
+         ../lib/util/modules.o lib/events.o @LIBTEVENT_OBJ0@ \
          @CCAN_OBJ@ \
          lib/server_contexts.o \
          lib/server_prefork.o \
index b644089712725b5407890037a7a893bda47c0aca..786fb4e574a1f79f5a0a4e9eeb85e60d1bd83934 100644 (file)
@@ -524,7 +524,7 @@ typedef char fstring[FSTRING_LEN];
 #include "smb.h"
 #include "../lib/util/byteorder.h"
 
-#include "module.h"
+#include "../lib/util/samba_modules.h"
 #include "../lib/util/talloc_stack.h"
 #include "../lib/util/smb_threads.h"
 #include "../lib/util/smb_threads_internal.h"
diff --git a/source3/include/module.h b/source3/include/module.h
deleted file mode 100644 (file)
index 667fac6..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-   Handling of idle/exit events
-   Copyright (C) Stefan (metze) Metzmacher     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 3 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, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _MODULE_H
-#define _MODULE_H
-
-/* Module support */
-typedef NTSTATUS (init_module_function) (void);
-
-NTSTATUS init_samba_module(void);
-
-#endif /* _MODULE_H */
index f6e7236664635884fc4d32550d9610c04ab0bf98..ffc90ffd2c0e62a3b3bf2d3ffb46abe12b181a3b 100644 (file)
@@ -185,16 +185,6 @@ void init_ldap_debugging(void);
 char *escape_ldap_string(TALLOC_CTX *mem_ctx, const char *s);
 char *escape_rdn_val_string_alloc(const char *s);
 
-/* The following definitions come from lib/module.c  */
-
-NTSTATUS smb_load_module(const char *module_name);
-int smb_load_modules(const char **modules);
-NTSTATUS smb_probe_module(const char *subsystem, const char *module);
-NTSTATUS smb_load_module(const char *module_name);
-int smb_load_modules(const char **modules);
-NTSTATUS smb_probe_module(const char *subsystem, const char *module);
-void init_modules(void);
-
 /* The following definitions come from lib/ms_fnmatch.c  */
 
 int ms_fnmatch(const char *pattern, const char *string, bool translate_pattern,
@@ -604,6 +594,7 @@ bool map_open_params_to_ntcreate(const char *smb_base_fname,
                                 uint32 *pcreate_disposition,
                                 uint32 *pcreate_options,
                                 uint32_t *pprivate_flags);
+void init_modules(void);
 
 /* The following definitions come from lib/util_cmdline.c  */
 
index 9cd3884c517a6403b6659b75588dd9f7665f8fe3..a85d7d05280dd6e64c85cf368d94496c011655cd 100644 (file)
 */
 
 #include "includes.h"
-
-/* Load a dynamic module.  Only log a level 0 error if we are not checking 
-   for the existence of a module (probling). */
-
-static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe)
-{
-       void *handle;
-       init_module_function *init;
-       NTSTATUS status;
-       const char *error;
-
-       /* Always try to use LAZY symbol resolving; if the plugin has 
-        * backwards compatibility, there might be symbols in the 
-        * plugin referencing to old (removed) functions
-        */
-       handle = dlopen(module_name, RTLD_LAZY);
-
-       /* This call should reset any possible non-fatal errors that 
-          occured since last call to dl* functions */
-       error = dlerror();
-
-       if(!handle) {
-               int level = is_probe ? 3 : 0;
-               DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : ""));
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       init = (init_module_function *)dlsym(handle, "init_samba_module");
-
-       /* we must check dlerror() to determine if it worked, because
-           dlsym() can validly return NULL */
-       error = dlerror();
-       if (error) {
-               DEBUG(0, ("Error trying to resolve symbol 'init_samba_module' "
-                         "in %s: %s\n", module_name, error));
-               dlclose(handle);
-               return NT_STATUS_UNSUCCESSFUL;
-       }
-
-       DEBUG(2, ("Module '%s' loaded\n", module_name));
-
-       status = init();
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Module '%s' initialization failed: %s\n",
-                           module_name, get_friendly_nt_error_msg(status)));
-               dlclose(handle);
-       }
-
-       return status;
-}
-
-NTSTATUS smb_load_module(const char *module_name)
-{
-       return do_smb_load_module(module_name, False);
-}
-
-/* Load all modules in list and return number of
- * modules that has been successfully loaded */
-int smb_load_modules(const char **modules)
-{
-       int i;
-       int success = 0;
-
-       for(i = 0; modules[i]; i++){
-               if(NT_STATUS_IS_OK(smb_load_module(modules[i]))) {
-                       success++;
-               }
-       }
-
-       DEBUG(2, ("%d modules successfully loaded\n", success));
-
-       return success;
-}
-
-NTSTATUS smb_probe_module(const char *subsystem, const char *module)
-{
-       char *full_path = NULL;
-       TALLOC_CTX *ctx = talloc_stackframe();
-       NTSTATUS status;
-
-       /* Check for absolute path */
-
-       /* if we make any 'samba multibyte string'
-          calls here, we break
-          for loading string modules */
-
-       DEBUG(5, ("Probing module '%s'\n", module));
-
-       if (module[0] == '/') {
-               status = do_smb_load_module(module, True);
-               TALLOC_FREE(ctx);
-               return status;
-       }
-
-       full_path = talloc_asprintf(ctx,
-                                   "%s/%s.%s",
-                                   modules_path(ctx, subsystem),
-                                   module,
-                                   shlib_ext());
-       if (!full_path) {
-               TALLOC_FREE(ctx);
-               return NT_STATUS_NO_MEMORY;
-       }
-
-       DEBUG(5, ("Probing module '%s': Trying to load from %s\n",
-               module, full_path));
-
-       status = do_smb_load_module(full_path, True);
-
-       TALLOC_FREE(ctx);
-       return status;
-}
-
-void init_modules(void)
-{
-       /* FIXME: This can cause undefined symbol errors :
-        *  smb_register_vfs() isn't available in nmbd, for example */
-       if(lp_preload_modules()) 
-               smb_load_modules(lp_preload_modules());
-}
index 887d1849ee8cc1aee0238615f243f75a14dee97f..f29568fca02ca3f3e787f3e28ea32936f7048773 100644 (file)
@@ -2414,3 +2414,12 @@ bool map_open_params_to_ntcreate(const char *smb_base_fname,
        return True;
 
 }
+
+
+void init_modules(void)
+{
+       /* FIXME: This can cause undefined symbol errors :
+        *  smb_register_vfs() isn't available in nmbd, for example */
+       if(lp_preload_modules())
+               smb_load_modules(lp_preload_modules());
+}
index d105f1fb5a34eb27a1b320bfc954a21d22ee6f39..74a688072588ce52b195cad79cd7451d2e727cb3 100755 (executable)
@@ -817,7 +817,7 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
 
 bld.SAMBA3_SUBSYSTEM('samba3core',
                    source=LIB_SRC,
-                   deps='LIBTSOCKET LIBCRYPTO ndr security NDR_SECURITY samba-util NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 UTIL_TDB UTIL_PW SAMBA_VERSION KRB5_WRAP flag_mapping util_reg PTHREADPOOL interfaces cap string_init param util_str CHARSET3 namearray dbwrap util_sec util_malloc memcache ccan errors3',
+                   deps='LIBTSOCKET LIBCRYPTO ndr security NDR_SECURITY samba-util NDR_MESSAGING LIBASYNC_REQ tdb-wrap3 UTIL_TDB UTIL_PW SAMBA_VERSION KRB5_WRAP flag_mapping util_reg PTHREADPOOL interfaces cap string_init param util_str CHARSET3 namearray dbwrap util_sec util_malloc memcache ccan errors3 samba-modules',
                    vars=locals())
 
 bld.SAMBA3_LIBRARY('smbd_shim',
index d754bb0cde1f92c7aab3a2a9f3530257985f2b8f..d400685a49a04d820444b102835629b8fd6ed97f 100644 (file)
@@ -35,6 +35,7 @@
 #include "param/param.h"
 #include "lib/util/tsort.h"
 #include "auth/gensec/gensec_toplevel_proto.h"
+#include "lib/util/samba_modules.h"
 
 /* the list of currently registered GENSEC backends */
 static struct gensec_security_ops **generic_security_ops;
index c5c0c340acb5632e7ac04015fa680dad86c82ca8..a7fa12f56a34ef0109cc2f1a0568b3026775a59e 100644 (file)
@@ -4,7 +4,7 @@ bld.SAMBA_LIBRARY('gensec',
        source='gensec_start.c socket.c gensec_tstream.c',
        pc_files='gensec.pc',
        autoproto='gensec_proto.h',
-       public_deps='tevent-util samba-util errors LIBPACKET auth_system_session gensec_runtime',
+       public_deps='tevent-util samba-util errors LIBPACKET auth_system_session gensec_runtime samba-modules',
        public_headers='',
        deps='com_err',
        vnum='0.0.1'
index 69cbff6e9a54c1f6bc184e9ef127b36f1d575b61..802bc1b40fbdad1d6b3acd5c2a7484c0b98cd3e3 100644 (file)
@@ -27,6 +27,7 @@
 #include "param/param.h"
 #include "dsdb/samdb/samdb.h"
 #include "libcli/wbclient/wbclient.h"
+#include "lib/util/samba_modules.h"
 
 /***************************************************************************
  Set a fixed challenge
index 48f28f57758dbe9ce5d2d93b6a1bddc84128a50e..29190f76f35470a2aee0fb83220c3daf9c45adbc 100644 (file)
@@ -51,7 +51,7 @@ bld.SAMBA_MODULE('auth4_unix',
 bld.SAMBA_LIBRARY('auth4',
        source='auth.c auth_util.c auth_simple.c',
        autoproto='auth_proto.h',
-       deps='samba-util security samdb samba-credentials tevent-util LIBWBCLIENT_OLD auth_unix_token',
+       deps='samba-util security samdb samba-credentials tevent-util LIBWBCLIENT_OLD auth_unix_token samba-modules',
        private_library=True
        )
 
index 42e7b10d4a6de758c799499cba2449bb3e75f583..3fe8960602a35dd7b135caeb4e08ed3fa67d3535 100644 (file)
@@ -25,6 +25,7 @@
 #include "includes.h"
 #include "ntptr/ntptr.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 /* the list of currently registered NTPTR backends */
 static struct ntptr_backend {
index 448d2919df33bda602c357dfa2f50bfd1f6fa1e8..8058181f89df42236731cf787224864bb3e52f9e 100644 (file)
@@ -26,6 +26,7 @@
 #include "../lib/util/dlinklist.h"
 #include "ntvfs/ntvfs.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 /* the list of currently registered NTVFS backends, note that there
  * can be more than one backend with the same name, as long as they
index cbe3e4e233ff5b632bc6a94ba58af65d5b977ccf..8157d862ec2fdb06d911428ebff5091dd961c87b 100644 (file)
@@ -26,6 +26,7 @@
 #include "libcli/security/security.h"
 #include "param/param.h"
 #include "../lib/util/unix_privs.h"
+#include "lib/util/samba_modules.h"
 
 #if defined(UID_WRAPPER)
 #if !defined(UID_WRAPPER_REPLACE) && !defined(UID_WRAPPER_NOT_REPLACE)
index 84695eeafd6ded913001d5ceb060ac569cad9e9c..acceefadf69cf8037f2ce4ba2999709c24725cc1 100644 (file)
@@ -3,7 +3,7 @@
 bld.SAMBA_SUBSYSTEM('pvfs_acl',
        source='pvfs_acl.c',
        autoproto='vfs_acl_proto.h',
-       deps='events',
+       deps='events samba-modules',
        )
 
 
index 7865f717a425f23cc3f1a5cb967d9cfd08c70f0b..9adb89827422bbd62b59dfbcc4f53c8b3122510c 100644 (file)
@@ -27,6 +27,7 @@
 #include "ntvfs/sysdep/sys_lease.h"
 #include "../lib/util/dlinklist.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 /* list of registered backends */
 static struct sys_lease_ops *backends;
index 03679b644de48bcfc354ec45ffecf3cd6ad1bdc6..00300cd25a6332b4111bc96f1698a25cc50040c1 100644 (file)
@@ -28,6 +28,7 @@
 #include <tevent.h>
 #include "../lib/util/dlinklist.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 /* list of registered backends */
 static struct sys_notify_backend *backends;
index 6d554f2273599262cbadc15a05007a1cd0316c89..0ddd4e5ed40a0e146e1935a47fcfbf4283febda3 100644 (file)
@@ -67,7 +67,7 @@ bld.SAMBA_MODULE('ntvfs_nbench',
 bld.SAMBA_LIBRARY('ntvfs',
                   source='ntvfs_base.c ntvfs_generic.c ntvfs_interface.c ntvfs_util.c',
                   autoproto='ntvfs_proto.h',
-                  deps='tevent',
+                  deps='tevent samba-modules',
                   private_library=True
                   )
 
index 02837c56d94f6aef6f86ade608b3907f4eebb620..3b9a75d65a61aff2be6a587b62d88d603503d3b1 100644 (file)
@@ -39,14 +39,6 @@ struct smbsrv_connection;
 
 #define Auto (2)
 
-typedef NTSTATUS (*init_module_fn) (void);
-
-/* this needs to be a string which is not in the C library. We
-   previously used "init_module", but that meant that modules which
-   did not define this function ended up calling the C library
-   function init_module() which makes a system call */
-#define SAMBA_INIT_MODULE "samba_init_module"
-
 #include "libds/common/roles.h"
 
 struct loadparm_context;
@@ -293,30 +285,6 @@ char *smbd_tmp_path(TALLOC_CTX *mem_ctx,
                             struct loadparm_context *lp_ctx,
                             const char *name);
 
-/**
- * Obtain the init function from a shared library file
- */
-init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path);
-
-/**
- * Obtain list of init functions from the modules in the specified
- * directory
- */
-init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path);
-
-/**
- * Run the specified init functions.
- *
- * @return true if all functions ran successfully, false otherwise
- */
-bool run_init_functions(init_module_fn *fns);
-
-/**
- * Load the initialization functions from DSO files for a specific subsystem.
- *
- * Will return an array of function pointers to initialization functions
- */
-init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem);
 const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
                                       struct loadparm_context *lp_ctx);
 struct smb_iconv_handle *smb_iconv_handle_reinit_lp(TALLOC_CTX *mem_ctx,
index 477ced7167a866bdeabf4e6f5e1b95da0dd8b36d..da0470d5606c5924bd2c34e95ce4e7ce60dd3eae 100644 (file)
@@ -22,6 +22,7 @@
 #include "includes.h"
 #include "param/share.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 const char *share_string_option(struct share_config *scfg, const char *opt_name, const char *defval)
 {
index d5b9583795869b436a8dbaae16647079dce1cf30..472096f60d295ccdd08b071a7165de82d09406db 100644 (file)
@@ -236,110 +236,6 @@ char *smbd_tmp_path(TALLOC_CTX *mem_ctx,
        return fname;
 }
 
-/**
- * Obtain the init function from a shared library file
- */
-init_module_fn load_module(TALLOC_CTX *mem_ctx, const char *path)
-{
-       void *handle;
-       void *init_fn;
-
-       handle = dlopen(path, RTLD_NOW);
-       if (handle == NULL) {
-               DEBUG(0, ("Unable to open %s: %s\n", path, dlerror()));
-               return NULL;
-       }
-
-       init_fn = dlsym(handle, SAMBA_INIT_MODULE);
-
-       if (init_fn == NULL) {
-               DEBUG(0, ("Unable to find %s() in %s: %s\n", 
-                         SAMBA_INIT_MODULE, path, dlerror()));
-               DEBUG(1, ("Loading module '%s' failed\n", path));
-               dlclose(handle);
-               return NULL;
-       }
-
-       return (init_module_fn)init_fn;
-}
-
-/**
- * Obtain list of init functions from the modules in the specified
- * directory
- */
-init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
-{
-       DIR *dir;
-       struct dirent *entry;
-       char *filename;
-       int success = 0;
-       init_module_fn *ret = talloc_array(mem_ctx, init_module_fn, 2);
-
-       ret[0] = NULL;
-       
-       dir = opendir(path);
-       if (dir == NULL) {
-               talloc_free(ret);
-               return NULL;
-       }
-
-       while((entry = readdir(dir))) {
-               if (ISDOT(entry->d_name) || ISDOTDOT(entry->d_name))
-                       continue;
-
-               filename = talloc_asprintf(mem_ctx, "%s/%s", path, entry->d_name);
-
-               ret[success] = load_module(mem_ctx, filename);
-               if (ret[success]) {
-                       ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
-                       success++;
-                       ret[success] = NULL;
-               }
-
-               talloc_free(filename);
-       }
-
-       closedir(dir);
-
-       return ret;
-}
-
-/**
- * Run the specified init functions.
- *
- * @return true if all functions ran successfully, false otherwise
- */
-bool run_init_functions(init_module_fn *fns)
-{
-       int i;
-       bool ret = true;
-       
-       if (fns == NULL)
-               return true;
-       
-       for (i = 0; fns[i]; i++) { ret &= (bool)NT_STATUS_IS_OK(fns[i]()); }
-
-       return ret;
-}
-
-/**
- * Load the initialization functions from DSO files for a specific subsystem.
- *
- * Will return an array of function pointers to initialization functions
- */
-
-init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem)
-{
-       char *path = modules_path(mem_ctx, subsystem);
-       init_module_fn *ret;
-
-       ret = load_modules(mem_ctx, path);
-
-       talloc_free(path);
-
-       return ret;
-}
-
 const char *lpcfg_imessaging_path(TALLOC_CTX *mem_ctx,
                                       struct loadparm_context *lp_ctx)
 {
index a35463799afc3ea401c371ef63dd6db46a5230e4..91e128f916c16a1c6ab35627f40672c4e461791f 100644 (file)
@@ -32,7 +32,7 @@ bld.SAMBA_SUBSYSTEM('PROVISION',
 bld.SAMBA_SUBSYSTEM('share',
        source='share.c',
        public_headers='share.h',
-       deps='samba-util'
+       deps='samba-util samba-modules'
        )
 
 
index cbba5e24085958ba42dc8330cc67a1033571815a..a16e6ac9d5f2e4894239ac44043f4d748d4f5d63 100644 (file)
@@ -39,6 +39,7 @@
 #include "smbd/process_model.h"
 #include "lib/messaging/irpc.h"
 #include "librpc/rpc/rpc_common.h"
+#include "lib/util/samba_modules.h"
 
 /* this is only used when the client asks for an unknown interface */
 #define DUMMY_ASSOC_GROUP 0x0FFFFFFF
index 3c4c03ebf2c425c1a7821dae70f5fc13348c7974..bbcbe3b6acc789369efdcda80dab7b794c71b9df 100644 (file)
@@ -21,6 +21,7 @@
 #include "includes.h"
 #include "smbd/process_model.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 /* the list of currently registered process models */
 static struct process_model {
index ba8f8227a931db7e775879c9739492b2c6c2a713..322e45569fd693ed045dd907ab0f1e4bb7282f66 100644 (file)
@@ -42,6 +42,7 @@
 #include "librpc/gen_ndr/ndr_irpc.h"
 #include "cluster/cluster.h"
 #include "dynconfig/dynconfig.h"
+#include "lib/util/samba_modules.h"
 
 /*
   recursively delete a directory tree
index d0eb100a6430b1442812b4d9c59599f77fe23d71..ab92e3c9209e53a357641f506762dd934f0c6ffe 100644 (file)
@@ -76,7 +76,7 @@ bld.SAMBA_MODULE('process_model_onefork',
 bld.SAMBA_LIBRARY('process_model',
                   source='process_model.c',
                   autoproto='process_model_proto.h',
-                  deps='samba-util samba-hostconfig',
+                  deps='samba-util samba-hostconfig samba-modules',
                   private_library=True
                   )
 
index 83816e8be55a25dfaf7c57ab5d39d24429910264..81ae11253c938d55b685cc5771523df33016a4ab 100644 (file)
@@ -32,6 +32,7 @@
 #include "librpc/rpc/dcerpc.h"
 #include "auth/gensec/gensec.h"
 #include "param/param.h"
+#include "lib/util/samba_modules.h"
 
 #if HAVE_READLINE_HISTORY_H
 #include <readline/history.h>
index 9b1719ed7d677326391a6d1dc2d753aaca760b2b..b066d3e1ac612b302de21326c2c5d09966026388 100644 (file)
@@ -23,6 +23,7 @@
 #include "param/param.h"
 #include "lib/cmdline/popt_common.h"
 #include "torture/smbtorture.h"
+#include "lib/util/samba_modules.h"
 
 _PUBLIC_ int torture_numops=10;
 _PUBLIC_ int torture_entries=1000;