summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common/ldb_modules.c
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb/common/ldb_modules.c')
-rw-r--r--source4/lib/ldb/common/ldb_modules.c103
1 files changed, 74 insertions, 29 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 22d1ce112e..f8162aee8c 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -41,6 +41,10 @@
#include <sys/stat.h>
#include <unistd.h>
+#ifdef HAVE_DLOPEN_DISABLED
+#include <dlfcn.h>
+#endif
+
#define LDB_MODULE_PREFIX "modules"
#define LDB_MODULE_PREFIX_LEN 7
#define LDB_MODULE_SEP ':'
@@ -49,14 +53,15 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
{
struct ldb_module *current;
char **modules;
- char *p, *q;
- int pn, i;
+ int mnum, i;
/* find out which modules we are requested to activate */
modules = NULL;
- pn = 0;
+ mnum = 0;
if (options) {
+ char *q, *p;
+
for (i = 0; options[i] != NULL; i++) {
if (strncmp(options[i], LDB_MODULE_PREFIX,
LDB_MODULE_PREFIX_LEN) == 0) {
@@ -68,13 +73,13 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
do {
*p = '\0';
q = p + 1;
- pn++;
- modules = talloc_realloc(ldb, modules, char *, pn);
+ mnum++;
+ modules = talloc_realloc(ldb, modules, char *, mnum);
if (!modules) {
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in register_modules()\n");
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_load_modules()\n");
return -1;
}
- modules[pn - 1] = q;
+ modules[mnum - 1] = q;
} while ((p = strchr(q, LDB_MODULE_SEP)));
}
}
@@ -83,9 +88,10 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
if (!modules && strcmp("ldap", ldb->modules->ops->name)) {
/* no modules in the options, look for @MODULES in the
db (not for ldap) */
- int ret, j, k;
- const char * const attrs[] = { "@MODULE" , NULL};
+ int ret;
+ const char * const attrs[] = { "@LIST" , NULL};
struct ldb_message **msg = NULL;
+ char *modstr, *c, *p;
ret = ldb_search(ldb, "", LDB_SCOPE_BASE, "dn=@MODULES", attrs, &msg);
if (ret == 0) {
@@ -100,6 +106,7 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
return -1;
}
+/*
for (j = 0; j < msg[0]->num_elements; j++) {
for (k = 0; k < msg[0]->elements[j].num_values; k++) {
pn++;
@@ -115,12 +122,58 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
}
}
+*/
+ modstr = msg[0]->elements[0].values[0].data;
+ for (c = modstr, mnum = 0; c != NULL; mnum++) {
+ c = strchr(c, ',');
+ if (c != NULL) {
+ c++;
+ if (*c == '\0') { /* avoid failing if the modules string lasts with ',' */
+ break;
+ }
+ }
+ }
+
+
+ modules = talloc_array(ldb, char *, mnum);
+ if ( ! modules ) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_load_modules()\n");
+ return -1;
+ }
+
+ for (p = c = modstr, i = 0; mnum > i; i++) {
+ c = strchr(p, ',');
+ if (c) {
+ *c = '\0';
+ }
+ /* modules are seeked in inverse order. Lets place them as an admin would think the right order is */
+ modules[mnum - i - 1] = talloc_strdup(modules, p);
+ p = c + 1;
+ }
}
talloc_free(msg);
}
if (modules) {
- for (i = 0; i < pn; i++) {
+ for (i = 0; i < mnum; i++) {
+#ifdef HAVE_DLOPEN_DISABLED
+ void *handle;
+ ldb_module_init_function init;
+ struct stat st;
+ char *filename;
+ const char *errstr;
+#endif
+
+ if (strcmp(modules[i], "schema") == 0) {
+ current = schema_module_init(ldb, options);
+ if (!current) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
+ return -1;
+ }
+ DLIST_ADD(ldb->modules, current);
+ continue;
+ }
+
if (strcmp(modules[i], "timestamps") == 0) {
current = timestamps_module_init(ldb, options);
if (!current) {
@@ -131,8 +184,8 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
continue;
}
- if (strcmp(modules[i], "schema") == 0) {
- current = schema_module_init(ldb, options);
+ if (strcmp(modules[i], "samldb") == 0) {
+ current = samldb_module_init(ldb, options);
if (!current) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]);
return -1;
@@ -142,18 +195,18 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
#ifdef HAVE_DLOPEN_DISABLED
- {
- void *handle;
- ldb_module_init_function init;
- struct stat st;
- const char *errstr;
+ filename = talloc_asprintf(ldb, "%s.so", modules[i]);
+ if (!filename) {
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Talloc failed!\n");
+ return -1;
+ }
- if (stat(modules[i], &st) < 0) {
+ if (stat(filename, &st) < 0) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
return -1;
}
- handle = dlopen(modules[i], RTLD_LAZY);
+ handle = dlopen(filename, RTLD_LAZY);
if (!handle) {
ldb_debug(ldb, LDB_DEBUG_FATAL, "Error loading module %s [%s]\n", modules[i], dlerror());
@@ -174,10 +227,9 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
return -1;
}
DLIST_ADD(ldb->modules, current);
- }
#else
- ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
- return -1;
+ ldb_debug(ldb, LDB_DEBUG_FATAL, "Required module [%s] not found, bailing out!\n", modules[i]);
+ return -1;
#endif
}
}
@@ -188,13 +240,6 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
/*
helper functions to call the next module in chain
*/
-int ldb_next_close(struct ldb_module *module)
-{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->close(module->next);
-}
int ldb_next_search(struct ldb_module *module,
const char *base,