summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2008-02-25 12:58:09 +0100
committerJelmer Vernooij <jelmer@samba.org>2008-02-25 12:58:09 +0100
commit584c4a518f4d18452b6515db132e4f75fba733a1 (patch)
treebbe367f36f092f233d7aefb61d75d5d1e1e85031 /source4/lib/ldb
parent03ab8f9d79f2a06b357b2f5d392ea8b5be263c5e (diff)
parent71943b209b181e1e4a65ab477b83780add7051ae (diff)
downloadsamba-584c4a518f4d18452b6515db132e4f75fba733a1.tar.gz
samba-584c4a518f4d18452b6515db132e4f75fba733a1.tar.bz2
samba-584c4a518f4d18452b6515db132e4f75fba733a1.zip
Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into v4-0-gmake3
Conflicts: source/build/smb_build/header.pm source/build/smb_build/makefile.pm source/lib/ldb/include/ldb_private.h (This used to be commit 1a646af0647f021d99473a8991c35e616a423ea6)
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/Makefile.in2
-rw-r--r--source4/lib/ldb/common/ldb.c73
-rw-r--r--source4/lib/ldb/common/ldb_modules.c75
-rw-r--r--source4/lib/ldb/config.mk19
-rw-r--r--source4/lib/ldb/include/ldb_private.h39
-rw-r--r--source4/lib/ldb/ldb.mk2
-rw-r--r--source4/lib/ldb/ldb_ildap/config.mk1
-rw-r--r--source4/lib/ldb/ldb_ildap/ldb_ildap.c21
-rw-r--r--source4/lib/ldb/ldb_ldap/ldb_ldap.c20
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map.c38
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map.h17
-rw-r--r--source4/lib/ldb/ldb_map/ldb_map_private.h7
-rw-r--r--source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c8
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c8
-rw-r--r--source4/lib/ldb/modules/asq.c8
-rw-r--r--source4/lib/ldb/modules/operational.c7
-rw-r--r--source4/lib/ldb/modules/paged_results.c8
-rw-r--r--source4/lib/ldb/modules/paged_searches.c8
-rw-r--r--source4/lib/ldb/modules/rdn_name.c8
-rw-r--r--source4/lib/ldb/modules/skel.c7
-rw-r--r--source4/lib/ldb/modules/sort.c7
-rw-r--r--source4/lib/ldb/nssldb/ldb-nss.c5
-rw-r--r--source4/lib/ldb/tests/sample_module.c9
-rw-r--r--source4/lib/ldb/tools/ad2oLschema.c2
-rw-r--r--source4/lib/ldb/tools/cmdline.c2
-rw-r--r--source4/lib/ldb/tools/ldbadd.c2
-rw-r--r--source4/lib/ldb/tools/ldbdel.c2
-rw-r--r--source4/lib/ldb/tools/ldbedit.c2
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c2
-rw-r--r--source4/lib/ldb/tools/ldbrename.c2
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c2
-rw-r--r--source4/lib/ldb/tools/ldbtest.c2
-rw-r--r--source4/lib/ldb/tools/oLschema2ldif.c2
33 files changed, 187 insertions, 230 deletions
diff --git a/source4/lib/ldb/Makefile.in b/source4/lib/ldb/Makefile.in
index 756beb1fed..d88f82b726 100644
--- a/source4/lib/ldb/Makefile.in
+++ b/source4/lib/ldb/Makefile.in
@@ -125,7 +125,7 @@ realdistclean:: distclean
check:: test @PYTHON_CHECK_TARGET@
-check-soloading: sample_module.$(SHLIBEXT)
+check-soloading: sample.$(SHLIBEXT)
LDB_MODULES_PATH=$(builddir) $(srcdir)/tests/test-soloading.sh
test:: all check-soloading
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 87f791cb38..3c9ef3ff69 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -56,20 +56,51 @@ struct ldb_context *ldb_init(void *mem_ctx)
return ldb;
}
-struct ldb_backend {
- const char *name;
- ldb_connect_fn connect_fn;
- struct ldb_backend *prev, *next;
+static struct backends_list_entry {
+ struct ldb_backend_ops *ops;
+ struct backends_list_entry *prev, *next;
} *ldb_backends = NULL;
+#ifndef STATIC_LIBLDB_BACKENDS
+
+#ifdef HAVE_LDB_LDAP
+#define LDAP_INIT &ldb_ldap_backend_ops, \
+ &ldb_ildap_backend_ops, \
+ &ldb_ldaps_backend_ops,
+#else
+#define LDAP_INIT
+#endif
+
+#ifdef HAVE_LDB_SQLITE3
+#define SQLITE3_INIT &ldb_sqlite3_backend_ops,
+#else
+#define SQLITE3_INIT
+#endif
+
+#define STATIC_LIBLDB_BACKENDS \
+ LDAP_INIT \
+ SQLITE3_INIT \
+ &ldb_tdb_backend_ops, \
+ NULL
+#endif
+
+const static struct ldb_backend_ops *builtin_backends[] = {
+ STATIC_LIBLDB_BACKENDS
+};
static ldb_connect_fn ldb_find_backend(const char *url)
{
- struct ldb_backend *backend;
+ struct backends_list_entry *backend;
+ int i;
+
+ for (i = 0; builtin_backends[i]; i++) {
+ if (strncmp(builtin_backends[i]->name, url, strlen(builtin_backends[i]->name)) == 0)
+ return builtin_backends[i]->connect_fn;
+ }
for (backend = ldb_backends; backend; backend = backend->next) {
- if (strncmp(backend->name, url, strlen(backend->name)) == 0) {
- return backend->connect_fn;
+ if (strncmp(backend->ops->name, url, strlen(backend->ops->name)) == 0) {
+ return backend->ops->connect_fn;
}
}
@@ -81,7 +112,8 @@ static ldb_connect_fn ldb_find_backend(const char *url)
*/
int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
{
- struct ldb_backend *backend = talloc(talloc_autofree_context(), struct ldb_backend);
+ struct ldb_backend_ops *backend = talloc(talloc_autofree_context(), struct ldb_backend_ops);
+ struct backends_list_entry *entry = talloc(talloc_autofree_context(), struct backends_list_entry);
if (ldb_find_backend(url_prefix)) {
return LDB_SUCCESS;
@@ -91,7 +123,8 @@ int ldb_register_backend(const char *url_prefix, ldb_connect_fn connectfn)
backend->name = talloc_strdup(backend, url_prefix);
backend->connect_fn = connectfn;
- DLIST_ADD(ldb_backends, backend);
+ entry->ops = backend;
+ DLIST_ADD(ldb_backends, entry);
return LDB_SUCCESS;
}
@@ -135,6 +168,19 @@ int ldb_connect_backend(struct ldb_context *ldb, const char *url, const char *op
}
}
+ if (fn == NULL) {
+ struct ldb_backend_ops *ops;
+ char *symbol_name = talloc_asprintf(ldb, "ldb_%s_backend_ops", backend);
+ if (symbol_name == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ ops = ldb_dso_load_symbol(ldb, backend, symbol_name);
+ if (ops != NULL) {
+ fn = ops->connect_fn;
+ }
+ talloc_free(symbol_name);
+ }
+
talloc_free(backend);
if (fn == NULL) {
@@ -236,7 +282,6 @@ int ldb_connect(struct ldb_context *ldb, const char *url, unsigned int flags, co
int ret;
const char *url2;
/* We seem to need to do this here, or else some utilities don't get ldb backends */
- ldb_global_init();
ldb->flags = flags;
@@ -463,11 +508,17 @@ static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_reque
int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type)
{
+ int ret;
if (!handle) {
return LDB_SUCCESS;
}
- return handle->module->ops->wait(handle, type);
+ ret = handle->module->ops->wait(handle, type);
+ if (!ldb_errstring(handle->module->ldb)) {
+ /* Set a default error string, to place the blame somewhere */
+ ldb_asprintf_errstring(handle->module->ldb, "error waiting on module %s: %s (%d)", handle->module->ops->name, ldb_strerror(ret), ret);
+ }
+ return ret;
}
/* set the specified timeout or, if timeout is 0 set the default timeout */
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index a3bf71d0d8..a4e0b94188 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -125,9 +125,30 @@ static struct ops_list_entry {
struct ops_list_entry *next;
} *registered_modules = NULL;
+#ifndef STATIC_LIBLDB_MODULES
+
+#define STATIC_LIBLDB_MODULES \
+ ldb_operational_module_ops, \
+ ldb_rdn_name_module_ops, \
+ ldb_paged_results_module_ops, \
+ ldb_sort_module_ops, \
+ ldb_asq_module_ops, \
+ NULL
+#endif
+
+const static struct ldb_module_ops *builtin_modules[] = {
+ STATIC_LIBLDB_MODULES
+};
+
static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
{
struct ops_list_entry *e;
+ int i;
+
+ for (i = 0; builtin_modules[i]; i++) {
+ if (strcmp(builtin_modules[i]->name, name) == 0)
+ return builtin_modules[i];
+ }
for (e = registered_modules; e; e = e->next) {
if (strcmp(e->ops->name, name) == 0)
@@ -137,51 +158,6 @@ static const struct ldb_module_ops *ldb_find_module_ops(const char *name)
return NULL;
}
-#ifndef STATIC_LIBLDB_MODULES
-
-#ifdef HAVE_LDB_LDAP
-#define LDAP_INIT ldb_ldap_init,
-#else
-#define LDAP_INIT
-#endif
-
-#ifdef HAVE_LDB_SQLITE3
-#define SQLITE3_INIT ldb_sqlite3_init,
-#else
-#define SQLITE3_INIT
-#endif
-
-#define STATIC_LIBLDB_MODULES \
- LDAP_INIT \
- SQLITE3_INIT \
- ldb_tdb_init, \
- ldb_operational_init, \
- ldb_rdn_name_init, \
- ldb_paged_results_init, \
- ldb_sort_init, \
- ldb_asq_init, \
- NULL
-#endif
-
-int ldb_global_init(void)
-{
- int (*static_init_fns[])(void) = { STATIC_LIBLDB_MODULES };
-
- static int initialized = 0;
- int ret = 0, i;
-
- if (initialized)
- return 0;
-
- initialized = 1;
-
- for (i = 0; static_init_fns[i]; i++) {
- if (static_init_fns[i]() == -1)
- ret = -1;
- }
-
- return ret;
-}
int ldb_register_module(const struct ldb_module_ops *ops)
{
@@ -256,8 +232,13 @@ int ldb_load_modules_list(struct ldb_context *ldb, const char **module_list, str
}
if (ops == NULL) {
- ops = ldb_dso_load_symbol(ldb, module_list[i],
- "ldb_module_ops");
+ char *symbol_name = talloc_asprintf(ldb, "ldb_%s_module_ops",
+ module_list[i]);
+ if (symbol_name == NULL) {
+ return LDB_ERR_OPERATIONS_ERROR;
+ }
+ ops = ldb_dso_load_symbol(ldb, module_list[i], symbol_name);
+ talloc_free(symbol_name);
}
if (ops == NULL) {
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 0e7caa381f..d6980f341a 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -3,7 +3,7 @@
[MODULE::ldb_asq]
PRIVATE_DEPENDENCIES = LIBTALLOC
CFLAGS = -Ilib/ldb/include
-INIT_FUNCTION = ldb_asq_init
+INIT_FUNCTION = &ldb_asq_module_ops
SUBSYSTEM = LIBLDB
OBJ_FILES = \
modules/asq.o
@@ -15,7 +15,7 @@ OBJ_FILES = \
[MODULE::ldb_server_sort]
PRIVATE_DEPENDENCIES = LIBTALLOC
CFLAGS = -Ilib/ldb/include
-INIT_FUNCTION = ldb_sort_init
+INIT_FUNCTION = &ldb_server_sort_module_ops
SUBSYSTEM = LIBLDB
OBJ_FILES = \
modules/sort.o
@@ -25,7 +25,7 @@ OBJ_FILES = \
################################################
# Start MODULE ldb_paged_results
[MODULE::ldb_paged_results]
-INIT_FUNCTION = ldb_paged_results_init
+INIT_FUNCTION = &ldb_paged_results_module_ops
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC
SUBSYSTEM = LIBLDB
@@ -37,7 +37,7 @@ OBJ_FILES = \
################################################
# Start MODULE ldb_paged_results
[MODULE::ldb_paged_searches]
-INIT_FUNCTION = ldb_paged_searches_init
+INIT_FUNCTION = &ldb_paged_searches_module_ops
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC
SUBSYSTEM = LIBLDB
@@ -52,7 +52,7 @@ OBJ_FILES = \
SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC
-INIT_FUNCTION = ldb_operational_init
+INIT_FUNCTION = &ldb_operational_module_ops
OBJ_FILES = \
modules/operational.o
# End MODULE ldb_operational
@@ -64,7 +64,7 @@ OBJ_FILES = \
SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC
-INIT_FUNCTION = ldb_rdn_name_init
+INIT_FUNCTION = &ldb_rdn_name_module_ops
OBJ_FILES = \
modules/rdn_name.o
# End MODULE ldb_rdn_name
@@ -88,7 +88,7 @@ OBJ_FILES = \
SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC
-INIT_FUNCTION = ldb_skel_init
+INIT_FUNCTION = &ldb_skel_module_ops
OBJ_FILES = modules/skel.o
# End MODULE ldb_skel
################################################
@@ -99,7 +99,6 @@ OBJ_FILES = modules/skel.o
SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include
PRIVATE_DEPENDENCIES = LIBTALLOC SQLITE3 LIBTALLOC
-INIT_FUNCTION = ldb_sqlite3_init
OBJ_FILES = \
ldb_sqlite3/ldb_sqlite3.o
# End MODULE ldb_sqlite3
@@ -110,7 +109,6 @@ OBJ_FILES = \
[MODULE::ldb_tdb]
SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include -Ilib/ldb/ldb_tdb
-INIT_FUNCTION = ldb_tdb_init
OBJ_FILES = \
ldb_tdb/ldb_tdb.o \
ldb_tdb/ldb_search.o \
@@ -128,10 +126,9 @@ PRIVATE_DEPENDENCIES = \
[LIBRARY::LIBLDB]
VERSION = 0.0.1
SO_VERSION = 0
-OUTPUT_TYPE = SHARED_LIBRARY
CFLAGS = -Ilib/ldb/include
PC_FILE = ldb.pc
-INIT_FUNCTION_TYPE = int (*) (void)
+INIT_FUNCTION_TYPE = extern const struct ldb_module_ops
OBJ_FILES = \
common/ldb.o \
common/ldb_ldif.o \
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 61d5f5148a..d2dcc675a5 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -41,6 +41,8 @@ struct ldb_context;
struct ldb_module_ops;
+struct ldb_backend_ops;
+
/* basic module structure */
struct ldb_module {
struct ldb_module *prev, *next;
@@ -70,9 +72,16 @@ struct ldb_module_ops {
int (*sequence_number)(struct ldb_module *, struct ldb_request *);
};
+
typedef int (*ldb_connect_fn) (struct ldb_context *ldb, const char *url, unsigned int flags, const char *options[],
struct ldb_module **module);
+
+struct ldb_backend_ops {
+ const char *name;
+ ldb_connect_fn connect_fn;
+};
+
const char *ldb_default_modules_dir(void);
/*
@@ -170,19 +179,23 @@ void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level,
/* The following definitions come from lib/ldb/common/ldb_ldif.c */
int ldb_should_b64_encode(const struct ldb_val *val);
-int ldb_objectclass_init(void);
-int ldb_operational_init(void);
-int ldb_paged_results_init(void);
-int ldb_paged_searches_init(void);
-int ldb_rdn_name_init(void);
-int ldb_schema_init(void);
-int ldb_asq_init(void);
-int ldb_sort_init(void);
-int ldb_ldap_init(void);
-int ldb_ildap_init(void);
-int ldb_tdb_init(void);
-int ldb_skel_init(void);
-int ldb_sqlite3_init(void);
+extern const struct ldb_module_ops ldb_objectclass_module_ops;
+extern const struct ldb_module_ops ldb_operational_module_ops;
+extern const struct ldb_module_ops ldb_paged_results_module_ops;
+extern const struct ldb_module_ops ldb_rdn_name_module_ops;
+extern const struct ldb_module_ops ldb_schema_module_ops;
+extern const struct ldb_module_ops ldb_asq_module_ops;
+extern const struct ldb_module_ops ldb_sort_module_ops;
+extern const struct ldb_module_ops ldb_ldap_module_ops;
+extern const struct ldb_module_ops ldb_ildap_module_ops;
+extern const struct ldb_module_ops ldb_tdb_module_ops;
+extern const struct ldb_module_ops ldb_sqlite3_module_ops;
+
+extern const struct ldb_backend_ops ldb_tdb_backend_ops;
+extern const struct ldb_backend_ops ldb_sqlite3_backend_ops;
+extern const struct ldb_backend_ops ldb_ldap_backend_ops;
+extern const struct ldb_backend_ops ldb_ildap_backend_ops;
+extern const struct ldb_backend_ops ldb_ldaps_backend_ops;
int ldb_match_msg(struct ldb_context *ldb,
const struct ldb_message *msg,
diff --git a/source4/lib/ldb/ldb.mk b/source4/lib/ldb/ldb.mk
index 6119f085d8..cc920178bc 100644
--- a/source4/lib/ldb/ldb.mk
+++ b/source4/lib/ldb/ldb.mk
@@ -31,7 +31,7 @@ lib/libldb.a: $(OBJS)
ar -rv $@ $(OBJS)
@-ranlib $@
-sample_module.$(SHLIBEXT): tests/sample_module.o
+sample.$(SHLIBEXT): tests/sample_module.o
$(MDLD) $(MDLD_FLAGS) -o $@ tests/sample_module.o
bin/ldbadd: tools/ldbadd.o tools/cmdline.o $(LIBS)
diff --git a/source4/lib/ldb/ldb_ildap/config.mk b/source4/lib/ldb/ldb_ildap/config.mk
index 01d9ec88ff..3062dc886f 100644
--- a/source4/lib/ldb/ldb_ildap/config.mk
+++ b/source4/lib/ldb/ldb_ildap/config.mk
@@ -5,7 +5,6 @@ SUBSYSTEM = LIBLDB
CFLAGS = -Ilib/ldb/include
OUTPUT_TYPE = SHARED_LIBRARY
PRIVATE_DEPENDENCIES = LIBTALLOC LIBCLI_LDAP CREDENTIALS
-INIT_FUNCTION = ldb_ildap_init
ALIASES = ldapi ldaps ldap
OBJ_FILES = \
ldb_ildap.o
diff --git a/source4/lib/ldb/ldb_ildap/ldb_ildap.c b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
index a834e912d4..995b584f51 100644
--- a/source4/lib/ldb/ldb_ildap/ldb_ildap.c
+++ b/source4/lib/ldb/ldb_ildap/ldb_ildap.c
@@ -811,9 +811,18 @@ failed:
return -1;
}
-int ldb_ildap_init(void)
-{
- return ldb_register_backend("ldap", ildb_connect) +
- ldb_register_backend("ldapi", ildb_connect) +
- ldb_register_backend("ldaps", ildb_connect);
-}
+_PUBLIC_ const struct ldb_backend_ops ldb_ldap_backend_ops = {
+ .name = "ldap",
+ .connect_fn = ildb_connect
+};
+
+_PUBLIC_ const struct ldb_backend_ops ldb_ildap_backend_ops = {
+ .name = "ildap",
+ .connect_fn = ildb_connect
+};
+
+_PUBLIC_ const struct ldb_backend_ops ldb_ldaps_backend_ops = {
+ .name = "ldaps",
+ .connect_fn = ildb_connect
+};
+
diff --git a/source4/lib/ldb/ldb_ldap/ldb_ldap.c b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
index d897350c2f..3f6ff3fd5b 100644
--- a/source4/lib/ldb/ldb_ldap/ldb_ldap.c
+++ b/source4/lib/ldb/ldb_ldap/ldb_ldap.c
@@ -826,9 +826,17 @@ failed:
return -1;
}
-int ldb_ldap_init(void)
-{
- return ldb_register_backend("ldap", lldb_connect) +
- ldb_register_backend("ldapi", lldb_connect) +
- ldb_register_backend("ldaps", lldb_connect);
-}
+_PUBLIC_ struct ldb_backend_ops ldb_ldap_backend_ops = {
+ .name = "ldap",
+ .connect_fn = lldb_connect
+};
+
+_PUBLIC_ struct ldb_backend_ops ldb_ldapi_backend_ops = {
+ .name = "ldapi",
+ .connect_fn = lldb_connect
+};
+
+_PUBLIC_ struct ldb_backend_ops ldb_ldaps_backend_ops = {
+ .name = "ldaps",
+ .connect_fn = lldb_connect
+};
diff --git a/source4/lib/ldb/ldb_map/ldb_map.c b/source4/lib/ldb/ldb_map/ldb_map.c
index 9582f36130..9c189feb11 100644
--- a/source4/lib/ldb/ldb_map/ldb_map.c
+++ b/source4/lib/ldb/ldb_map/ldb_map.c
@@ -1186,7 +1186,7 @@ static int map_wait_all(struct ldb_handle *handle)
}
/* Wait for pending requests to finish. */
-static int map_wait(struct ldb_handle *handle, enum ldb_wait_type type)
+int map_wait(struct ldb_handle *handle, enum ldb_wait_type type)
{
if (type == LDB_WAIT_ALL) {
return map_wait_all(handle);
@@ -1199,16 +1199,6 @@ static int map_wait(struct ldb_handle *handle, enum ldb_wait_type type)
/* Module initialization
* ===================== */
-/* Provided module operations */
-static const struct ldb_module_ops map_ops = {
- .name = "ldb_map",
- .add = map_add,
- .modify = map_modify,
- .del = map_delete,
- .rename = map_rename,
- .search = map_search,
- .wait = map_wait,
-};
/* Builtin mappings for DNs and objectClasses */
static const struct ldb_map_attribute builtin_attribute_maps[] = {
@@ -1344,12 +1334,6 @@ static int map_init_maps(struct ldb_module *module, struct ldb_map_context *data
return LDB_SUCCESS;
}
-/* Copy the list of provided module operations. */
-_PUBLIC_ struct ldb_module_ops ldb_map_get_ops(void)
-{
- return map_ops;
-}
-
/* Initialize global private data. */
_PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attrs,
const struct ldb_map_objectclass *ocls,
@@ -1393,23 +1377,3 @@ _PUBLIC_ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attrib
return LDB_SUCCESS;
}
-
-/* Usage note for initialization of this module:
- *
- * ldb_map is meant to be used from a different module that sets up
- * the mappings and gets registered in ldb.
- *
- * 'ldb_map_init' initializes the private data of this module and
- * stores the attribute and objectClass maps in there. It also looks
- * up the '@MAP' special DN so requests can be redirected to the
- * remote partition.
- *
- * This function should be called from the 'init_context' op of the
- * module using ldb_map.
- *
- * 'ldb_map_get_ops' returns a copy of ldb_maps module operations.
- *
- * It should be called from the initialize function of the using
- * module, which should then override the 'init_context' op with a
- * function making the appropriate calls to 'ldb_map_init'.
- */
diff --git a/source4/lib/ldb/ldb_map/ldb_map.h b/source4/lib/ldb/ldb_map/ldb_map.h
index ef4da4e654..e40bb9cd7e 100644
--- a/source4/lib/ldb/ldb_map/ldb_map.h
+++ b/source4/lib/ldb/ldb_map/ldb_map.h
@@ -155,8 +155,19 @@ int ldb_map_init(struct ldb_module *module, const struct ldb_map_attribute *attr
const char *add_objectclass,
const char *name);
-/* get copy of map_ops */
-struct ldb_module_ops
-ldb_map_get_ops(void);
+int map_add(struct ldb_module *module, struct ldb_request *req);
+int map_search(struct ldb_module *module, struct ldb_request *req);
+int map_rename(struct ldb_module *module, struct ldb_request *req);
+int map_delete(struct ldb_module *module, struct ldb_request *req);
+int map_modify(struct ldb_module *module, struct ldb_request *req);
+int map_wait(struct ldb_handle *handle, enum ldb_wait_type type);
+
+#define LDB_MAP_OPS \
+ .add = map_add, \
+ .modify = map_modify, \
+ .del = map_delete, \
+ .rename = map_rename, \
+ .search = map_search, \
+ .wait = map_wait,
#endif /* __LDB_MAP_H__ */
diff --git a/source4/lib/ldb/ldb_map/ldb_map_private.h b/source4/lib/ldb/ldb_map/ldb_map_private.h
index 2c35097069..58a9f2704e 100644
--- a/source4/lib/ldb/ldb_map/ldb_map_private.h
+++ b/source4/lib/ldb/ldb_map/ldb_map_private.h
@@ -98,20 +98,13 @@ int map_subtree_collect_remote_simple(struct ldb_module *module, void *mem_ctx,
/* The following definitions come from lib/ldb/modules/ldb_map_inbound.c */
int map_add_do_remote(struct ldb_handle *handle);
int map_add_do_local(struct ldb_handle *handle);
-int map_add(struct ldb_module *module, struct ldb_request *req);
int map_modify_do_remote(struct ldb_handle *handle);
int map_modify_do_local(struct ldb_handle *handle);
-int map_modify(struct ldb_module *module, struct ldb_request *req);
int map_delete_do_remote(struct ldb_handle *handle);
int map_delete_do_local(struct ldb_handle *handle);
-int map_delete(struct ldb_module *module, struct ldb_request *req);
int map_rename_do_remote(struct ldb_handle *handle);
int map_rename_do_fixup(struct ldb_handle *handle);
int map_rename_do_local(struct ldb_handle *handle);
-int map_rename(struct ldb_module *module, struct ldb_request *req);
-
-/* The following definitions come from lib/ldb/modules/ldb_map_outbound.c */
-int map_search(struct ldb_module *module, struct ldb_request *req);
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index 1ec3b1aabd..8742e257f3 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -1903,7 +1903,7 @@ failed:
return -1;
}
-int ldb_sqlite3_init(void)
-{
- return ldb_register_backend("sqlite3", lsqlite3_connect);
-}
+const struct ldb_backend_ops ldb_sqlite3_backend_ops = {
+ .name = "sqlite3",
+ .connect_fn = lsqlite3_connect
+};
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 45a8109584..11d6c30710 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -1107,7 +1107,7 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url,
return 0;
}
-int ldb_tdb_init(void)
-{
- return ldb_register_backend("tdb", ltdb_connect);
-}
+const struct ldb_backend_ops ldb_tdb_backend_ops = {
+ .name = "tdb",
+ .connect_fn = ltdb_connect
+};
diff --git a/source4/lib/ldb/modules/asq.c b/source4/lib/ldb/modules/asq.c
index b6a8594166..eb27263b16 100644
--- a/source4/lib/ldb/modules/asq.c
+++ b/source4/lib/ldb/modules/asq.c
@@ -473,15 +473,9 @@ static int asq_init(struct ldb_module *module)
return ldb_next_init(module);
}
-
-static const struct ldb_module_ops asq_ops = {
+const struct ldb_module_ops ldb_asq_module_ops = {
.name = "asq",
.search = asq_search,
.wait = asq_wait,
.init_context = asq_init
};
-
-int ldb_asq_init(void)
-{
- return ldb_register_module(&asq_ops);
-}
diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c
index 45f23aa0c1..7dc4ae08c3 100644
--- a/source4/lib/ldb/modules/operational.c
+++ b/source4/lib/ldb/modules/operational.c
@@ -304,13 +304,8 @@ static int operational_init(struct ldb_module *ctx)
return ldb_next_init(ctx);
}
-static const struct ldb_module_ops operational_ops = {
+const struct ldb_module_ops ldb_operational_module_ops = {
.name = "operational",
.search = operational_search,
.init_context = operational_init
};
-
-int ldb_operational_init(void)
-{
- return ldb_register_module(&operational_ops);
-}
diff --git a/source4/lib/ldb/modules/paged_results.c b/source4/lib/ldb/modules/paged_results.c
index ee1bbe0335..b62b1f92cb 100644
--- a/source4/lib/ldb/modules/paged_results.c
+++ b/source4/lib/ldb/modules/paged_results.c
@@ -549,15 +549,9 @@ static int paged_request_init(struct ldb_module *module)
return ldb_next_init(module);
}
-static const struct ldb_module_ops paged_ops = {
+const struct ldb_module_ops ldb_paged_results_module_ops = {
.name = "paged_results",
.search = paged_search,
.wait = paged_wait,
.init_context = paged_request_init
};
-
-int ldb_paged_results_init(void)
-{
- return ldb_register_module(&paged_ops);
-}
-
diff --git a/source4/lib/ldb/modules/paged_searches.c b/source4/lib/ldb/modules/paged_searches.c
index fd580a3c4a..40e87f70d6 100644
--- a/source4/lib/ldb/modules/paged_searches.c
+++ b/source4/lib/ldb/modules/paged_searches.c
@@ -455,15 +455,9 @@ static int ps_init(struct ldb_module *module)
return ldb_next_init(module);
}
-static const struct ldb_module_ops ps_ops = {
+_PUBLIC_ const struct ldb_module_ops ldb_paged_searches_module_ops = {
.name = "paged_searches",
.search = ps_search,
.wait = ps_wait,
.init_context = ps_init
};
-
-int ldb_paged_searches_init(void)
-{
- return ldb_register_module(&ps_ops);
-}
-
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index 1a0ddbb3c4..c4de8e8da8 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -326,15 +326,9 @@ static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type)
return rdn_name_wait_once(handle);
}
-static const struct ldb_module_ops rdn_name_ops = {
+const struct ldb_module_ops ldb_rdn_name_module_ops = {
.name = "rdn_name",
.add = rdn_name_add,
.rename = rdn_name_rename,
.wait = rdn_name_wait
};
-
-
-int ldb_rdn_name_init(void)
-{
- return ldb_register_module(&rdn_name_ops);
-}
diff --git a/source4/lib/ldb/modules/skel.c b/source4/lib/ldb/modules/skel.c
index 5400c502f1..0cd29ac4b7 100644
--- a/source4/lib/ldb/modules/skel.c
+++ b/source4/lib/ldb/modules/skel.c
@@ -116,7 +116,7 @@ static int skel_init(struct ldb_module *module)
return ldb_next_init(module);
}
-static const struct ldb_module_ops skel_ops = {
+const struct ldb_module_ops ldb_skel_module_ops = {
.name = "skel",
.init_context = skel_init,
.search = skel_search,
@@ -129,8 +129,3 @@ static const struct ldb_module_ops skel_ops = {
.end_transaction = skel_end_trans,
.del_transaction = skel_del_trans,
};
-
-int ldb_skel_init(void)
-{
- return ldb_register_module(&skel_ops);
-}
diff --git a/source4/lib/ldb/modules/sort.c b/source4/lib/ldb/modules/sort.c
index 89b9a4fb19..746befa559 100644
--- a/source4/lib/ldb/modules/sort.c
+++ b/source4/lib/ldb/modules/sort.c
@@ -450,14 +450,9 @@ static int server_sort_init(struct ldb_module *module)
return ldb_next_init(module);
}
-static const struct ldb_module_ops server_sort_ops = {
+const struct ldb_module_ops ldb_server_sort_module_ops = {
.name = "server_sort",
.search = server_sort_search,
.wait = server_sort_wait,
.init_context = server_sort_init
};
-
-int ldb_sort_init(void)
-{
- return ldb_register_module(&server_sort_ops);
-}
diff --git a/source4/lib/ldb/nssldb/ldb-nss.c b/source4/lib/ldb/nssldb/ldb-nss.c
index 199212dbbf..e256f41a4d 100644
--- a/source4/lib/ldb/nssldb/ldb-nss.c
+++ b/source4/lib/ldb/nssldb/ldb-nss.c
@@ -45,11 +45,6 @@ NSS_STATUS _ldb_nss_init(void)
_ldb_nss_ctx->pid = mypid;
- ret = ldb_global_init();
- if (ret != 0) {
- goto failed;
- }
-
_ldb_nss_ctx->ldb = ldb_init(_ldb_nss_ctx);
if (_ldb_nss_ctx->ldb == NULL) {
goto failed;
diff --git a/source4/lib/ldb/tests/sample_module.c b/source4/lib/ldb/tests/sample_module.c
index 8ab1d33146..98d8e865dd 100644
--- a/source4/lib/ldb/tests/sample_module.c
+++ b/source4/lib/ldb/tests/sample_module.c
@@ -32,12 +32,7 @@ int sample_add(struct ldb_module *mod, struct ldb_request *req)
return ldb_next_request(mod, req);
}
-static const struct ldb_module_ops sample_ops = {
- .name = "sample_module",
+_PUBLIC_ const struct ldb_module_ops ldb_sample_module_ops = {
+ .name = "sample",
.add = sample_add,
};
-
-int init_module(void)
-{
- return ldb_register_module(&sample_ops);
-}
diff --git a/source4/lib/ldb/tools/ad2oLschema.c b/source4/lib/ldb/tools/ad2oLschema.c
index dec8a5f972..67b16dd06e 100644
--- a/source4/lib/ldb/tools/ad2oLschema.c
+++ b/source4/lib/ldb/tools/ad2oLschema.c
@@ -656,8 +656,6 @@ static struct schema_conv process_convert(struct ldb_context *ldb, enum convert_
const char *target_str;
enum convert_target target;
- ldb_global_init();
-
ctx = talloc_new(NULL);
ldb = ldb_init(ctx);
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index 8ee1994615..c9c77c4e47 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -80,8 +80,6 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
{ NULL }
};
- ldb_global_init();
-
#if (_SAMBA_BUILD_ >= 4)
r = ldb_register_samba_handlers(ldb);
if (r != 0) {
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index d34193b86c..4ee66c4fc0 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -88,8 +88,6 @@ int main(int argc, const char **argv)
int i, ret=0, count=0;
struct ldb_cmdline *options;
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index fcd0978779..184172b22b 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -77,8 +77,6 @@ int main(int argc, const char **argv)
int ret = 0, i;
struct ldb_cmdline *options;
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index ed98a6d615..a9fd064bf8 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -279,8 +279,6 @@ int main(int argc, const char **argv)
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
const char * const * attrs = NULL;
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index ed12380095..dd6206b824 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -89,8 +89,6 @@ int main(int argc, const char **argv)
int i, ret=LDB_SUCCESS;
struct ldb_cmdline *options;
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c
index c160e87ee4..b36310a500 100644
--- a/source4/lib/ldb/tools/ldbrename.c
+++ b/source4/lib/ldb/tools/ldbrename.c
@@ -56,8 +56,6 @@ int main(int argc, const char **argv)
struct ldb_cmdline *options;
struct ldb_dn *dn1, *dn2;
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 24ceb30963..e25bd19965 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -276,8 +276,6 @@ int main(int argc, const char **argv)
int ret = -1;
const char *expression = "(|(objectClass=*)(distinguishedName=*))";
- ldb_global_init();
-
ldb = ldb_init(NULL);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index 5c21dd3830..57a7848733 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -393,8 +393,6 @@ int main(int argc, const char **argv)
TALLOC_CTX *mem_ctx = talloc_new(NULL);
struct ldb_context *ldb;
- ldb_global_init();
-
ldb = ldb_init(mem_ctx);
options = ldb_cmdline_process(ldb, argc, argv, usage);
diff --git a/source4/lib/ldb/tools/oLschema2ldif.c b/source4/lib/ldb/tools/oLschema2ldif.c
index 7b5f1b835c..1846a2c852 100644
--- a/source4/lib/ldb/tools/oLschema2ldif.c
+++ b/source4/lib/ldb/tools/oLschema2ldif.c
@@ -560,8 +560,6 @@ static void usage(void)
struct ldb_cmdline *options;
FILE *in = stdin;
FILE *out = stdout;
- ldb_global_init();
-
ctx = talloc_new(NULL);
ldb_ctx = ldb_init(ctx);