summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-02-27 11:35:47 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:10:55 -0500
commitb1b14817eaa6e6579596d54166e17bc8d5605c01 (patch)
treeb1af59838a0337dd52b510374b048255397dfe24 /source4/lib/ldb/common
parentd2dc86994e7075490f95faa1cc85008feb38f04a (diff)
downloadsamba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.gz
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.tar.bz2
samba-b1b14817eaa6e6579596d54166e17bc8d5605c01.zip
r5585: LDB interfaces change:
changes: - ldb_wrap disappears from code and become a private structure of db_wrap.c thanks to our move to talloc in ldb code, we do not need to expose it anymore - removal of ldb_close() function form the code thanks to our move to talloc in ldb code, we do not need it anymore use talloc_free() to close and free an ldb database - some minor updates to ldb modules code to cope with the change and fix some bugs I found out during the process (This used to be commit d58be9e74b786a11a57e89df36081d55730dfe0a)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/ldb.c11
-rw-r--r--source4/lib/ldb/common/ldb_modules.c103
2 files changed, 75 insertions, 39 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 0fb371011f..40616c5963 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -69,7 +69,7 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
}
if (ldb_load_modules(ldb_ctx, options) != 0) {
- ldb_close(ldb_ctx);
+ talloc_free(ldb_ctx);
errno = EINVAL;
return NULL;
}
@@ -78,15 +78,6 @@ struct ldb_context *ldb_connect(const char *url, unsigned int flags,
}
/*
- close the connection to the database
-*/
-int ldb_close(struct ldb_context *ldb)
-{
- return ldb->modules->ops->close(ldb->modules);
-}
-
-
-/*
search the database given a LDAP-like search expression
return the number of records found, or -1 on error
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,