summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/dsdb/samdb/ldb_modules/objectguid.c53
-rw-r--r--source4/dsdb/samdb/ldb_modules/samldb.c23
-rw-r--r--source4/lib/ldb/common/ldb.c54
-rw-r--r--source4/lib/ldb/common/ldb_modules.c66
-rw-r--r--source4/lib/ldb/modules/ldb_map.c20
-rw-r--r--source4/lib/ldb/modules/rdn_name.c39
-rw-r--r--source4/lib/ldb/modules/schema.c26
-rw-r--r--source4/lib/ldb/modules/timestamps.c45
8 files changed, 78 insertions, 248 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/objectguid.c b/source4/dsdb/samdb/ldb_modules/objectguid.c
index 9e0946b17c..0a7fe3a42b 100644
--- a/source4/dsdb/samdb/ldb_modules/objectguid.c
+++ b/source4/dsdb/samdb/ldb_modules/objectguid.c
@@ -112,60 +112,11 @@ static int objectguid_add_record(struct ldb_module *module, const struct ldb_mes
return ret;
}
-/* modify_record: change modifyTimestamp as well */
-static int objectguid_modify_record(struct ldb_module *module, const struct ldb_message *msg)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_modify_record\n");
- return ldb_next_modify_record(module, msg);
-}
-
-static int objectguid_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
-static int objectguid_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
-
-static int objectguid_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int objectguid_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int objectguid_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectguid_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int objectguid_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
static const struct ldb_module_ops objectguid_ops = {
.name = "objectguid",
.search_bytree = objectguid_search_bytree,
- .add_record = objectguid_add_record,
- .modify_record = objectguid_modify_record,
- .delete_record = objectguid_delete_record,
- .rename_record = objectguid_rename_record,
- .start_transaction = objectguid_start_trans,
- .end_transaction = objectguid_end_trans,
- .del_transaction = objectguid_del_trans
+ .add_record = objectguid_add_record
};
@@ -187,7 +138,5 @@ struct ldb_module *objectguid_module_init(struct ldb_context *ldb, const char *o
ctx->prev = ctx->next = NULL;
ctx->ops = &objectguid_ops;
- talloc_set_destructor (ctx, objectguid_destructor);
-
return ctx;
}
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c
index 89c9daa924..906a2299f7 100644
--- a/source4/dsdb/samdb/ldb_modules/samldb.c
+++ b/source4/dsdb/samdb/ldb_modules/samldb.c
@@ -567,24 +567,6 @@ static int samldb_rename_record(struct ldb_module *module, const struct ldb_dn *
return ldb_next_rename_record(module, olddn, newdn);
}
-static int samldb_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int samldb_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int samldb_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "samldb_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
static int samldb_destructor(void *module_ctx)
{
/* struct ldb_module *ctx = module_ctx; */
@@ -598,10 +580,7 @@ static const struct ldb_module_ops samldb_ops = {
.add_record = samldb_add_record,
.modify_record = samldb_modify_record,
.delete_record = samldb_delete_record,
- .rename_record = samldb_rename_record,
- .start_transaction = samldb_start_trans,
- .end_transaction = samldb_end_trans,
- .del_transaction = samldb_del_trans
+ .rename_record = samldb_rename_record
};
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index 29ee323ad4..725044d3f4 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -114,16 +114,25 @@ static void ldb_reset_err_string(struct ldb_context *ldb)
}
}
+#define FIRST_OP(ldb, op) do { \
+ module = ldb->modules; \
+ while (module && module->ops->op == NULL) module = module->next; \
+ if (module == NULL) return -1; \
+} while (0)
+
/*
start a transaction
*/
int ldb_transaction_start(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, start_transaction);
+
ldb->transaction_active++;
ldb_reset_err_string(ldb);
- return ldb->modules->ops->start_transaction(ldb->modules);
+ return module->ops->start_transaction(module);
}
/*
@@ -131,6 +140,9 @@ int ldb_transaction_start(struct ldb_context *ldb)
*/
int ldb_transaction_commit(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, end_transaction);
+
if (ldb->transaction_active > 0) {
ldb->transaction_active--;
} else {
@@ -139,7 +151,7 @@ int ldb_transaction_commit(struct ldb_context *ldb)
ldb_reset_err_string(ldb);
- return ldb->modules->ops->end_transaction(ldb->modules);
+ return module->ops->end_transaction(module);
}
/*
@@ -147,6 +159,9 @@ int ldb_transaction_commit(struct ldb_context *ldb)
*/
int ldb_transaction_cancel(struct ldb_context *ldb)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, del_transaction);
+
if (ldb->transaction_active > 0) {
ldb->transaction_active--;
} else {
@@ -155,7 +170,7 @@ int ldb_transaction_cancel(struct ldb_context *ldb)
ldb_reset_err_string(ldb);
- return ldb->modules->ops->del_transaction(ldb->modules);
+ return module->ops->del_transaction(module);
}
/*
@@ -201,9 +216,12 @@ int ldb_search_bytree(struct ldb_context *ldb,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
+ struct ldb_module *module;
+ FIRST_OP(ldb, search_bytree);
+
ldb_reset_err_string(ldb);
- return ldb->modules->ops->search_bytree(ldb->modules, base, scope, tree, attrs, res);
+ return module->ops->search_bytree(module, base, scope, tree, attrs, res);
}
/*
@@ -213,8 +231,11 @@ int ldb_search_bytree(struct ldb_context *ldb,
int ldb_add(struct ldb_context *ldb,
const struct ldb_message *message)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, add_record);
+
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
@@ -224,12 +245,12 @@ int ldb_add(struct ldb_context *ldb,
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->add_record(ldb->modules, message);
+ status = module->ops->add_record(module, message);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->add_record(ldb->modules, message);
+ return module->ops->add_record(module, message);
}
/*
@@ -238,8 +259,11 @@ int ldb_add(struct ldb_context *ldb,
int ldb_modify(struct ldb_context *ldb,
const struct ldb_message *message)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, modify_record);
+
ldb_reset_err_string(ldb);
status = ldb_msg_sanity_check(message);
@@ -249,12 +273,12 @@ int ldb_modify(struct ldb_context *ldb,
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->modify_record(ldb->modules, message);
+ status = module->ops->modify_record(module, message);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->modify_record(ldb->modules, message);
+ return module->ops->modify_record(module, message);
}
@@ -263,20 +287,23 @@ int ldb_modify(struct ldb_context *ldb,
*/
int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, delete_record);
+
ldb_reset_err_string(ldb);
if (! ldb->transaction_active) {
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->delete_record(ldb->modules, dn);
+ status = module->ops->delete_record(module, dn);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->delete_record(ldb->modules, dn);
+ return module->ops->delete_record(module, dn);
}
/*
@@ -284,20 +311,23 @@ int ldb_delete(struct ldb_context *ldb, const struct ldb_dn *dn)
*/
int ldb_rename(struct ldb_context *ldb, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
+ struct ldb_module *module;
int status;
+ FIRST_OP(ldb, rename_record);
+
ldb_reset_err_string(ldb);
if (! ldb->transaction_active) {
status = ldb_transaction_start(ldb);
if (status != LDB_SUCCESS) return status;
- status = ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ status = module->ops->rename_record(module, olddn, newdn);
if (status != LDB_SUCCESS) return ldb_transaction_cancel(ldb);
return ldb_transaction_commit(ldb);
}
- return ldb->modules->ops->rename_record(ldb->modules, olddn, newdn);
+ return module->ops->rename_record(module, olddn, newdn);
}
diff --git a/source4/lib/ldb/common/ldb_modules.c b/source4/lib/ldb/common/ldb_modules.c
index 955e46b91a..b0ede9893b 100644
--- a/source4/lib/ldb/common/ldb_modules.c
+++ b/source4/lib/ldb/common/ldb_modules.c
@@ -213,6 +213,18 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[])
}
/*
+ by using this we allow ldb modules to only implement the functions they care about,
+ which makes writing a module simpler, and makes it more likely to keep working
+ when ldb is extended
+*/
+#define FIND_OP(module, op) do { \
+ module = module->next; \
+ while (module && module->ops->op == NULL) module = module->next; \
+ if (module == NULL) return -1; \
+} while (0)
+
+
+/*
helper functions to call the next module in chain
*/
int ldb_next_search_bytree(struct ldb_module *module,
@@ -221,10 +233,8 @@ int ldb_next_search_bytree(struct ldb_module *module,
struct ldb_parse_tree *tree,
const char * const *attrs, struct ldb_message ***res)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ FIND_OP(module, search_bytree);
+ return module->ops->search_bytree(module, base, scope, tree, attrs, res);
}
int ldb_next_search(struct ldb_module *module,
@@ -235,15 +245,13 @@ int ldb_next_search(struct ldb_module *module,
{
struct ldb_parse_tree *tree;
int ret;
- if (!module->next) {
- return -1;
- }
+ FIND_OP(module, search_bytree);
tree = ldb_parse_tree(module, expression);
if (tree == NULL) {
ldb_set_errstring(module, talloc_strdup(module, "Unable to parse search expression"));
return -1;
}
- ret = module->next->ops->search_bytree(module->next, base, scope, tree, attrs, res);
+ ret = module->ops->search_bytree(module, base, scope, tree, attrs, res);
talloc_free(tree);
return ret;
}
@@ -251,58 +259,44 @@ int ldb_next_search(struct ldb_module *module,
int ldb_next_add_record(struct ldb_module *module, const struct ldb_message *message)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->add_record(module->next, message);
+ FIND_OP(module, add_record);
+ return module->ops->add_record(module, message);
}
int ldb_next_modify_record(struct ldb_module *module, const struct ldb_message *message)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->modify_record(module->next, message);
+ FIND_OP(module, modify_record);
+ return module->ops->modify_record(module, message);
}
int ldb_next_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->delete_record(module->next, dn);
+ FIND_OP(module, delete_record);
+ return module->ops->delete_record(module, dn);
}
int ldb_next_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->rename_record(module->next, olddn, newdn);
+ FIND_OP(module, rename_record);
+ return module->ops->rename_record(module, olddn, newdn);
}
int ldb_next_start_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->start_transaction(module->next);
+ FIND_OP(module, start_transaction);
+ return module->ops->start_transaction(module);
}
int ldb_next_end_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->end_transaction(module->next);
+ FIND_OP(module, end_transaction);
+ return module->ops->end_transaction(module);
}
int ldb_next_del_trans(struct ldb_module *module)
{
- if (!module->next) {
- return -1;
- }
- return module->next->ops->del_transaction(module->next);
+ FIND_OP(module, del_transaction);
+ return module->ops->del_transaction(module);
}
void ldb_set_errstring(struct ldb_module *module, char *err_string)
diff --git a/source4/lib/ldb/modules/ldb_map.c b/source4/lib/ldb/modules/ldb_map.c
index 1da1ef661a..246fc5709d 100644
--- a/source4/lib/ldb/modules/ldb_map.c
+++ b/source4/lib/ldb/modules/ldb_map.c
@@ -1233,31 +1233,13 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg)
return (mp_ret == -1 || fb_ret == -1)?-1:0;
}
-static int map_start_trans(struct ldb_module *module)
-{
- return ldb_next_start_trans(module);
-}
-
-static int map_end_trans(struct ldb_module *module)
-{
- return ldb_next_end_trans(module);
-}
-
-static int map_del_trans(struct ldb_module *module)
-{
- return ldb_next_del_trans(module);
-}
-
static const struct ldb_module_ops map_ops = {
.name = "map",
.search_bytree = map_search_bytree,
.add_record = map_add,
.modify_record = map_modify,
.delete_record = map_delete,
- .rename_record = map_rename,
- .start_transaction = map_start_trans,
- .end_transaction = map_end_trans,
- .del_transaction = map_del_trans
+ .rename_record = map_rename
};
static char *map_find_url(struct ldb_context *ldb, const char *name)
diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c
index 0275952780..40ff75744e 100644
--- a/source4/lib/ldb/modules/rdn_name.c
+++ b/source4/lib/ldb/modules/rdn_name.c
@@ -194,53 +194,18 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me
return ret;
}
-static int rdn_name_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
{
ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n");
return ldb_next_rename_record(module, olddn, newdn);
}
-static int rdn_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int rdn_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int rdn_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int rdn_name_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
-
static const struct ldb_module_ops rdn_name_ops = {
.name = "rdn_name",
.search_bytree = rdn_name_search_bytree,
.add_record = rdn_name_add_record,
.modify_record = rdn_name_modify_record,
- .delete_record = rdn_name_delete_record,
- .rename_record = rdn_name_rename_record,
- .start_transaction = rdn_start_trans,
- .end_transaction = rdn_end_trans,
- .del_transaction = rdn_del_trans
+ .rename_record = rdn_name_rename_record
};
@@ -262,7 +227,5 @@ struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *opt
ctx->prev = ctx->next = NULL;
ctx->ops = &rdn_name_ops;
- talloc_set_destructor (ctx, rdn_name_destructor);
-
return ctx;
}
diff --git a/source4/lib/ldb/modules/schema.c b/source4/lib/ldb/modules/schema.c
index 7c1753b215..0cae110487 100644
--- a/source4/lib/ldb/modules/schema.c
+++ b/source4/lib/ldb/modules/schema.c
@@ -509,35 +509,13 @@ static int schema_rename_record(struct ldb_module *module, const struct ldb_dn *
return ldb_next_rename_record(module, olddn, newdn);
}
-static int schema_start_trans(struct ldb_module *module) {
- return ldb_next_start_trans(module);
-}
-
-static int schema_end_trans(struct ldb_module *module) {
- return ldb_next_end_trans(module);
-}
-
-static int schema_del_trans(struct ldb_module *module) {
- return ldb_next_del_trans(module);
-}
-
-static int schema_destructor(void *module_ctx)
-{
-/* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
-
static const struct ldb_module_ops schema_ops = {
.name = "schema",
.search_bytree = schema_search_bytree,
.add_record = schema_add_record,
.modify_record = schema_modify_record,
.delete_record = schema_delete_record,
- .rename_record = schema_rename_record,
- .start_transaction = schema_start_trans,
- .end_transaction = schema_end_trans,
- .del_transaction = schema_del_trans
+ .rename_record = schema_rename_record
};
#ifdef HAVE_DLOPEN_DISABLED
@@ -558,7 +536,5 @@ struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *optio
ctx->prev = ctx->next = NULL;
ctx->ops = &schema_ops;
- talloc_set_destructor (ctx, schema_destructor);
-
return ctx;
}
diff --git a/source4/lib/ldb/modules/timestamps.c b/source4/lib/ldb/modules/timestamps.c
index 5a1e54486a..13e9c2ccc4 100644
--- a/source4/lib/ldb/modules/timestamps.c
+++ b/source4/lib/ldb/modules/timestamps.c
@@ -191,53 +191,12 @@ static int timestamps_modify_record(struct ldb_module *module, const struct ldb_
return ret;
}
-static int timestamps_delete_record(struct ldb_module *module, const struct ldb_dn *dn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_delete_record\n");
- return ldb_next_delete_record(module, dn);
-}
-
-static int timestamps_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_rename_record\n");
- return ldb_next_rename_record(module, olddn, newdn);
-}
-
-static int timestamps_start_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_start_trans\n");
- return ldb_next_start_trans(module);
-}
-
-static int timestamps_end_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_end_trans\n");
- return ldb_next_end_trans(module);
-}
-
-static int timestamps_del_trans(struct ldb_module *module)
-{
- ldb_debug(module->ldb, LDB_DEBUG_TRACE, "timestamps_del_trans\n");
- return ldb_next_del_trans(module);
-}
-
-static int timestamps_destructor(void *module_ctx)
-{
- /* struct ldb_module *ctx = module_ctx; */
- /* put your clean-up functions here */
- return 0;
-}
static const struct ldb_module_ops timestamps_ops = {
.name = "timestamps",
.search_bytree = timestamps_search_bytree,
.add_record = timestamps_add_record,
- .modify_record = timestamps_modify_record,
- .delete_record = timestamps_delete_record,
- .rename_record = timestamps_rename_record,
- .start_transaction = timestamps_start_trans,
- .end_transaction = timestamps_end_trans,
- .del_transaction = timestamps_del_trans
+ .modify_record = timestamps_modify_record
};
@@ -259,7 +218,5 @@ struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *o
ctx->prev = ctx->next = NULL;
ctx->ops = &timestamps_ops;
- talloc_set_destructor (ctx, timestamps_destructor);
-
return ctx;
}