From 7d33ec3dfe78723d62f4941684060baeb9c4bda6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 9 Sep 2011 21:24:49 +1000 Subject: lib/util: consolidate module loading into common code This creates a samba-modules private libary that handles the details. Andrew Bartlett --- source4/auth/gensec/gensec_start.c | 1 + source4/auth/gensec/wscript_build | 2 +- source4/auth/ntlm/auth.c | 1 + source4/auth/ntlm/wscript_build | 2 +- source4/ntptr/ntptr_base.c | 1 + source4/ntvfs/ntvfs_base.c | 1 + source4/ntvfs/posix/pvfs_acl.c | 1 + source4/ntvfs/posix/wscript_build | 2 +- source4/ntvfs/sysdep/sys_lease.c | 1 + source4/ntvfs/sysdep/sys_notify.c | 1 + source4/ntvfs/wscript_build | 2 +- source4/param/param.h | 32 ------------ source4/param/share.c | 1 + source4/param/util.c | 104 ------------------------------------- source4/param/wscript_build | 2 +- source4/rpc_server/dcerpc_server.c | 1 + source4/smbd/process_model.c | 1 + source4/smbd/server.c | 1 + source4/smbd/wscript_build | 2 +- source4/torture/smbtorture.c | 1 + source4/torture/torture.c | 1 + 21 files changed, 19 insertions(+), 142 deletions(-) (limited to 'source4') diff --git a/source4/auth/gensec/gensec_start.c b/source4/auth/gensec/gensec_start.c index d754bb0cde..d400685a49 100644 --- a/source4/auth/gensec/gensec_start.c +++ b/source4/auth/gensec/gensec_start.c @@ -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; diff --git a/source4/auth/gensec/wscript_build b/source4/auth/gensec/wscript_build index c5c0c340ac..a7fa12f56a 100644 --- a/source4/auth/gensec/wscript_build +++ b/source4/auth/gensec/wscript_build @@ -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' diff --git a/source4/auth/ntlm/auth.c b/source4/auth/ntlm/auth.c index 69cbff6e9a..802bc1b40f 100644 --- a/source4/auth/ntlm/auth.c +++ b/source4/auth/ntlm/auth.c @@ -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 diff --git a/source4/auth/ntlm/wscript_build b/source4/auth/ntlm/wscript_build index 48f28f5775..29190f76f3 100644 --- a/source4/auth/ntlm/wscript_build +++ b/source4/auth/ntlm/wscript_build @@ -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 ) diff --git a/source4/ntptr/ntptr_base.c b/source4/ntptr/ntptr_base.c index 42e7b10d4a..3fe8960602 100644 --- a/source4/ntptr/ntptr_base.c +++ b/source4/ntptr/ntptr_base.c @@ -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 { diff --git a/source4/ntvfs/ntvfs_base.c b/source4/ntvfs/ntvfs_base.c index 448d2919df..8058181f89 100644 --- a/source4/ntvfs/ntvfs_base.c +++ b/source4/ntvfs/ntvfs_base.c @@ -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 diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c index cbe3e4e233..8157d862ec 100644 --- a/source4/ntvfs/posix/pvfs_acl.c +++ b/source4/ntvfs/posix/pvfs_acl.c @@ -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) diff --git a/source4/ntvfs/posix/wscript_build b/source4/ntvfs/posix/wscript_build index 84695eeafd..acceefadf6 100644 --- a/source4/ntvfs/posix/wscript_build +++ b/source4/ntvfs/posix/wscript_build @@ -3,7 +3,7 @@ bld.SAMBA_SUBSYSTEM('pvfs_acl', source='pvfs_acl.c', autoproto='vfs_acl_proto.h', - deps='events', + deps='events samba-modules', ) diff --git a/source4/ntvfs/sysdep/sys_lease.c b/source4/ntvfs/sysdep/sys_lease.c index 7865f717a4..9adb898274 100644 --- a/source4/ntvfs/sysdep/sys_lease.c +++ b/source4/ntvfs/sysdep/sys_lease.c @@ -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; diff --git a/source4/ntvfs/sysdep/sys_notify.c b/source4/ntvfs/sysdep/sys_notify.c index 03679b644d..00300cd25a 100644 --- a/source4/ntvfs/sysdep/sys_notify.c +++ b/source4/ntvfs/sysdep/sys_notify.c @@ -28,6 +28,7 @@ #include #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; diff --git a/source4/ntvfs/wscript_build b/source4/ntvfs/wscript_build index 6d554f2273..0ddd4e5ed4 100644 --- a/source4/ntvfs/wscript_build +++ b/source4/ntvfs/wscript_build @@ -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 ) diff --git a/source4/param/param.h b/source4/param/param.h index 02837c56d9..3b9a75d65a 100644 --- a/source4/param/param.h +++ b/source4/param/param.h @@ -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, diff --git a/source4/param/share.c b/source4/param/share.c index 477ced7167..da0470d560 100644 --- a/source4/param/share.c +++ b/source4/param/share.c @@ -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) { diff --git a/source4/param/util.c b/source4/param/util.c index d5b9583795..472096f60d 100644 --- a/source4/param/util.c +++ b/source4/param/util.c @@ -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) { diff --git a/source4/param/wscript_build b/source4/param/wscript_build index a35463799a..91e128f916 100644 --- a/source4/param/wscript_build +++ b/source4/param/wscript_build @@ -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' ) diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c index cbba5e2408..a16e6ac9d5 100644 --- a/source4/rpc_server/dcerpc_server.c +++ b/source4/rpc_server/dcerpc_server.c @@ -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 diff --git a/source4/smbd/process_model.c b/source4/smbd/process_model.c index 3c4c03ebf2..bbcbe3b6ac 100644 --- a/source4/smbd/process_model.c +++ b/source4/smbd/process_model.c @@ -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 { diff --git a/source4/smbd/server.c b/source4/smbd/server.c index ba8f8227a9..322e45569f 100644 --- a/source4/smbd/server.c +++ b/source4/smbd/server.c @@ -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 diff --git a/source4/smbd/wscript_build b/source4/smbd/wscript_build index d0eb100a64..ab92e3c920 100644 --- a/source4/smbd/wscript_build +++ b/source4/smbd/wscript_build @@ -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 ) diff --git a/source4/torture/smbtorture.c b/source4/torture/smbtorture.c index 83816e8be5..81ae11253c 100644 --- a/source4/torture/smbtorture.c +++ b/source4/torture/smbtorture.c @@ -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 diff --git a/source4/torture/torture.c b/source4/torture/torture.c index 9b1719ed7d..b066d3e1ac 100644 --- a/source4/torture/torture.c +++ b/source4/torture/torture.c @@ -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; -- cgit