summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2005-12-26 16:46:55 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:47:45 -0500
commit448483199fb436309735f5203b3282fca2c517ec (patch)
treefcd663e46d0eac19b98037008a435bdd57ca7f8e /source4/lib
parentee10fb1a12391a76fe81e6e7a92d282ef885bc30 (diff)
downloadsamba-448483199fb436309735f5203b3282fca2c517ec.tar.gz
samba-448483199fb436309735f5203b3282fca2c517ec.tar.bz2
samba-448483199fb436309735f5203b3282fca2c517ec.zip
r12494: Support loading modules from .so files for most subsystems.
We now use a different system for initializing the modules for a subsystem. Most subsystems now have an init function that looks something like this: init_module_fn static_init[] = STATIC_AUTH_MODULES; init_module_fn *shared_init = load_samba_modules(NULL, "auth"); run_init_functions(static_init); run_init_functions(shared_init); talloc_free(shared_init); I hope to eliminate the other init functions later on (the init_programname_subsystems; defines). (This used to be commit b6d2ad4ce0a91c4be790dd258820c492ff1787ea)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/com/config.mk1
-rw-r--r--source4/lib/com/main.c15
-rw-r--r--source4/lib/module.c58
-rw-r--r--source4/lib/registry/common/reg_interface.c13
-rw-r--r--source4/lib/registry/config.mk1
-rw-r--r--source4/lib/util.c17
6 files changed, 81 insertions, 24 deletions
diff --git a/source4/lib/com/config.mk b/source4/lib/com/config.mk
index dc4fe644c6..77e3724924 100644
--- a/source4/lib/com/config.mk
+++ b/source4/lib/com/config.mk
@@ -1,4 +1,5 @@
[SUBSYSTEM::COM]
+INIT_FUNCTION = com_init
INIT_OBJ_FILES = \
tables.o \
rot.o \
diff --git a/source4/lib/com/main.c b/source4/lib/com/main.c
index 210e8ba79c..f264c3f25b 100644
--- a/source4/lib/com/main.c
+++ b/source4/lib/com/main.c
@@ -24,7 +24,7 @@
#include "lib/events/events.h"
#include "librpc/gen_ndr/com_dcom.h"
-WERROR com_init(struct com_context **ctx, struct event_context *event_ctx)
+WERROR com_init_ctx(struct com_context **ctx, struct event_context *event_ctx)
{
*ctx = talloc(NULL, struct com_context);
if (event_ctx == NULL) {
@@ -88,3 +88,16 @@ WERROR com_get_class_object(struct com_context *ctx, struct GUID *clsid, struct
return IUnknown_QueryInterface(iu, ctx, iid, ip);
}
+
+NTSTATUS com_init(void)
+{
+ init_module_fn static_init[] = STATIC_COM_MODULES;
+ init_module_fn *shared_init = load_samba_modules(NULL, "com");
+
+ run_init_functions(static_init);
+ run_init_functions(shared_init);
+
+ talloc_free(shared_init);
+
+ return NT_STATUS_OK;
+}
diff --git a/source4/lib/module.c b/source4/lib/module.c
index abb98cbf7b..672d8df7ce 100644
--- a/source4/lib/module.c
+++ b/source4/lib/module.c
@@ -21,65 +21,77 @@
#include "includes.h"
#include "system/dir.h"
-static BOOL load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name)
+static void *load_module(TALLOC_CTX *mem_ctx, const char *dir, const char *name)
{
char *path;
void *handle;
- BOOL (*init_module_fn) (void);
- BOOL ret;
+ void *init_fn;
path = talloc_asprintf(mem_ctx, "%s/%s", dir, name);
handle = dlopen(path, RTLD_NOW);
if (handle == NULL) {
DEBUG(0, ("Unable to open %s: %s\n", path, dlerror()));
- return False;
+ talloc_free(path);
+ return NULL;
}
- init_module_fn = dlsym(handle, "init_module");
+ init_fn = dlsym(handle, "init_module");
- if (init_module_fn == NULL) {
+ if (init_fn == NULL) {
DEBUG(0, ("Unable to find init_module() in %s: %s\n", path, dlerror()));
- return False;
- }
-
- ret = init_module_fn();
- if (!ret) {
DEBUG(1, ("Loading module '%s' failed\n", path));
+ dlclose(handle);
+ talloc_free(path);
+ return NULL;
}
- dlclose(handle);
-
talloc_free(path);
- return ret;
+ return init_fn;
}
-BOOL load_modules(const char *path)
+init_module_fn *load_modules(TALLOC_CTX *mem_ctx, const char *path)
{
DIR *dir;
struct dirent *entry;
- BOOL ret = True;
- TALLOC_CTX *mem_ctx;
-
- mem_ctx = talloc_init(NULL);
+ 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(mem_ctx);
- return False;
+ talloc_free(ret);
+ return NULL;
}
while((entry = readdir(dir))) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, ".."))
continue;
- ret &= load_module(mem_ctx, path, entry->d_name);
+ ret[success] = load_module(mem_ctx, path, entry->d_name);
+ if (ret[success]) {
+ ret = talloc_realloc(mem_ctx, ret, init_module_fn, success+2);
+ success++;
+ ret[success] = NULL;
+ }
}
closedir(dir);
- talloc_free(mem_ctx);
+ return ret;
+}
+
+BOOL run_init_functions(NTSTATUS (**fns) (void))
+{
+ int i;
+ BOOL ret;
+
+ if (fns == NULL)
+ return True;
+
+ for (i = 0; fns[i]; i++) { ret &= NT_STATUS_IS_OK(fns[i]()); }
return ret;
}
diff --git a/source4/lib/registry/common/reg_interface.c b/source4/lib/registry/common/reg_interface.c
index 87bc3fd70c..ac8b90dcdb 100644
--- a/source4/lib/registry/common/reg_interface.c
+++ b/source4/lib/registry/common/reg_interface.c
@@ -64,6 +64,19 @@ static struct reg_init_function_entry *reg_find_backend_entry(const char *name)
return NULL;
}
+NTSTATUS registry_init(void)
+{
+ init_module_fn static_init[] = STATIC_REGISTRY_MODULES;
+ init_module_fn *shared_init = load_samba_modules(NULL, "registry");
+
+ run_init_functions(static_init);
+ run_init_functions(shared_init);
+
+ talloc_free(shared_init);
+
+ return NT_STATUS_OK;
+}
+
/* Check whether a certain backend is present */
BOOL reg_has_backend(const char *backend)
{
diff --git a/source4/lib/registry/config.mk b/source4/lib/registry/config.mk
index 775e201f7e..768697e2a1 100644
--- a/source4/lib/registry/config.mk
+++ b/source4/lib/registry/config.mk
@@ -81,6 +81,7 @@ REQUIRED_SUBSYSTEMS = \
[LIBRARY::REGISTRY]
MAJOR_VERSION = 0
MINOR_VERSION = 0
+INIT_FUNCTION = registry_init
DESCRIPTION = Windows-style registry library
RELEASE_VERSION = 1
INIT_OBJ_FILES = \
diff --git a/source4/lib/util.c b/source4/lib/util.c
index 3b4064098c..3443d137d6 100644
--- a/source4/lib/util.c
+++ b/source4/lib/util.c
@@ -690,6 +690,23 @@ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
return fname;
}
+char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
+{
+ return talloc_asprintf(mem_ctx, "%s/%s", dyn_MODULESDIR, name);
+}
+
+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;
+}
+
void dump_data_pw(const char *msg, const uint8_t * data, size_t len)
{
#ifdef DEBUG_PASSWORD