summaryrefslogtreecommitdiff
path: root/source4/param
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2007-08-30 23:15:12 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 15:03:14 -0500
commit82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8 (patch)
tree0bf7585bb48057b24bf16a9e3ec9e654a9fdffc2 /source4/param
parent09c188e7353a74d05a674935c85e548bd09073ae (diff)
downloadsamba-82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8.tar.gz
samba-82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8.tar.bz2
samba-82037a75eae9deaf6ec80b5ecc3bb89aab6e6dd8.zip
r24814: Fix headers, trim core.h even more.
(This used to be commit 9647f860bdd5c0a74583e886182bd041a45e7655)
Diffstat (limited to 'source4/param')
-rw-r--r--source4/param/param.h2
-rw-r--r--source4/param/util.c87
2 files changed, 89 insertions, 0 deletions
diff --git a/source4/param/param.h b/source4/param/param.h
index 0438a87db9..c829e0bf57 100644
--- a/source4/param/param.h
+++ b/source4/param/param.h
@@ -42,6 +42,8 @@ struct smbsrv_connection;
#define Auto (2)
+typedef NTSTATUS (*init_module_fn) (void);
+
#include "param/proto.h"
#endif /* _PARAM_H */
diff --git a/source4/param/util.c b/source4/param/util.c
index 7af2693876..6e6e12596b 100644
--- a/source4/param/util.c
+++ b/source4/param/util.c
@@ -6,6 +6,7 @@
Copyright (C) Simo Sorce 2001
Copyright (C) Jim McDonough (jmcd@us.ibm.com) 2003.
Copyright (C) James J Myers 2003
+ Copyright (C) Jelmer Vernooij 2005-2007
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
@@ -25,6 +26,7 @@
#include "dynconfig.h"
#include "system/network.h"
#include "system/filesys.h"
+#include "system/dir.h"
/**
* @file
@@ -188,6 +190,91 @@ _PUBLIC_ char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
return fname;
}
+/**
+ * Obtain the init function from a shared library file
+ */
+_PUBLIC_ 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, "init_module");
+
+ if (init_fn == NULL) {
+ DEBUG(0, ("Unable to find init_module() in %s: %s\n", 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
+ */
+_PUBLIC_ 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
+ */
+_PUBLIC_ 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;
+}
+
static char *modules_path(TALLOC_CTX* mem_ctx, const char *name)
{
const char *env_moduledir = getenv("LD_SAMBA_MODULE_PATH");