diff options
Diffstat (limited to 'source4/lib')
-rw-r--r-- | source4/lib/ldb/common/ldb_modules.c | 92 | ||||
-rw-r--r-- | source4/lib/ldb/include/ldb.h | 4 |
2 files changed, 33 insertions, 63 deletions
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c index 6802cc8955..9c536789b9 100644 --- a/source4/lib/ldb/common/ldb_modules.c +++ b/source4/lib/ldb/common/ldb_modules.c @@ -122,6 +122,20 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) { char **modules = NULL; int i; + struct { + const char *name; + ldb_module_init_t init; + } well_known_modules[] = { + { "schema", schema_module_init }, + { "timestamps", timestamps_module_init }, + { "rdn_name", rdn_name_module_init }, +#ifdef _SAMBA_BUILD_ + { "objectguid", objectguid_module_init }, + { "samldb", samldb_module_init }, + { "samba3sam", ldb_samba3sam_module_init }, +#endif + { NULL, NULL } + }; /* find out which modules we are requested to activate */ @@ -161,7 +175,8 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) return -1; } - modules = ldb_modules_list_from_string(ldb, msg[0]->elements[0].values[0].data); + modules = ldb_modules_list_from_string(ldb, + (const char *)msg[0]->elements[0].values[0].data); } @@ -175,71 +190,22 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) for (i = 0; modules[i] != NULL; i++) { struct ldb_module *current; - - 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) { - ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]); - return -1; + int m; + for (m=0;well_known_modules[m].name;m++) { + if (strcmp(modules[i], well_known_modules[m].name) == 0) { + current = well_known_modules[m].init(ldb, options); + if (current == NULL) { + ldb_debug(ldb, LDB_DEBUG_FATAL, "function 'init_module' in %s fails\n", modules[i]); + return -1; + } + DLIST_ADD(ldb->modules, current); + break; } - DLIST_ADD(ldb->modules, current); - continue; } - - if (strcmp(modules[i], "rdn_name") == 0) { - current = rdn_name_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 (well_known_modules[m].name == NULL) { + ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", + modules[i]); } - -#ifdef _SAMBA_BUILD_ - if (strcmp(modules[i], "objectguid") == 0) { - current = objectguid_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], "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; - } - DLIST_ADD(ldb->modules, current); - continue; - } - - if (strcmp(modules[i], "samba3sam") == 0) { - current = ldb_samba3sam_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; - } - -#endif - - ldb_debug(ldb, LDB_DEBUG_WARNING, "WARNING: Module [%s] not found\n", modules[i]); } talloc_free(modules); diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h index f371c340cc..73bac2088a 100644 --- a/source4/lib/ldb/include/ldb.h +++ b/source4/lib/ldb/include/ldb.h @@ -143,6 +143,10 @@ typedef int (*ldb_traverse_fn)(struct ldb_context *, const struct ldb_message *) struct ldb_module; +/* module initialisation function */ +typedef struct ldb_module *(*ldb_module_init_t)(struct ldb_context *, const char **); + + /* debugging uses one of the following levels */ enum ldb_debug_level {LDB_DEBUG_FATAL, LDB_DEBUG_ERROR, LDB_DEBUG_WARNING, LDB_DEBUG_TRACE}; |