From 5c9590587197dcb95007fdc54318187d5716c7c6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 8 Nov 2005 00:11:45 +0000 Subject: r11567: Ldb API change patch. This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780) --- source4/lib/ldb/modules/operational.c | 84 ++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 26 deletions(-) (limited to 'source4/lib/ldb/modules/operational.c') diff --git a/source4/lib/ldb/modules/operational.c b/source4/lib/ldb/modules/operational.c index 8a06e20c29..7c554e8541 100644 --- a/source4/lib/ldb/modules/operational.c +++ b/source4/lib/ldb/modules/operational.c @@ -76,6 +76,7 @@ #include "includes.h" #include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" #include "ldb/include/ldb_private.h" #include @@ -174,23 +175,20 @@ failed: /* hook search operations */ -static int operational_search_bytree(struct ldb_module *module, - const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, - struct ldb_message ***res) +static int operational_search_bytree(struct ldb_module *module, struct ldb_request *req) { int i, r, a; int ret; + const char * const *attrs = req->op.search.attrs; const char **search_attrs = NULL; - (*res) = NULL; + *(req->op.search.res) = NULL; /* replace any attributes in the parse tree that are searchable, but are stored using a different name in the backend */ for (i=0;iop.search.tree, parse_tree_sub[i].attr, parse_tree_sub[i].replace); } @@ -213,18 +211,22 @@ static int operational_search_bytree(struct ldb_module *module, } } - + /* use new set of attrs if any */ + if (search_attrs) req->op.search.attrs = search_attrs; /* perform the search */ - ret = ldb_next_search_bytree(module, base, scope, tree, - search_attrs?search_attrs:attrs, res); - if (ret <= 0) { + ret = ldb_next_request(module, req); + /* set back saved attrs if needed */ + if (search_attrs) req->op.search.attrs = attrs; + + /* check operation result */ + if (ret != LDB_SUCCESS) { return ret; } /* for each record returned post-process to add any derived attributes that have been asked for */ - for (r=0;rop.search.res))->count; r++) { + if (operational_search_post_process(module, (*(req->op.search.res))->msgs[r], attrs) != 0) { goto failed; } } @@ -235,9 +237,9 @@ static int operational_search_bytree(struct ldb_module *module, failed: talloc_free(search_attrs); - talloc_free(*res); + talloc_free(*(req->op.search.res)); ldb_oom(module->ldb); - return -1; + return LDB_ERR_OTHER; } /* @@ -273,15 +275,15 @@ static int add_time_element(struct ldb_message *msg, const char *attr, time_t t) /* hook add record ops */ -static int operational_add_record(struct ldb_module *module, - const struct ldb_message *msg) +static int operational_add(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.add.message; time_t t = time(NULL); struct ldb_message *msg2; int ret; if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* we have to copy the message as the caller might have it as a const */ @@ -294,7 +296,13 @@ static int operational_add_record(struct ldb_module *module, talloc_free(msg2); return -1; } - ret = ldb_next_add_record(module, msg2); + /* use the new structure for the call chain below this point */ + req->op.add.message = msg2; + /* go on with the call chain */ + ret = ldb_next_request(module, req); + /* put back saved message */ + req->op.add.message = msg; + /* free temproary compy */ talloc_free(msg2); return ret; } @@ -302,15 +310,15 @@ static int operational_add_record(struct ldb_module *module, /* hook modify record ops */ -static int operational_modify_record(struct ldb_module *module, - const struct ldb_message *msg) +static int operational_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; time_t t = time(NULL); struct ldb_message *msg2; int ret; if (ldb_dn_is_special(msg->dn)) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } /* we have to copy the message as the caller might have it as a const */ @@ -322,16 +330,40 @@ static int operational_modify_record(struct ldb_module *module, talloc_free(msg2); return -1; } - ret = ldb_next_modify_record(module, msg2); + /* use the new structure for the call chain below this point */ + req->op.mod.message = msg2; + /* go on with the call chain */ + ret = ldb_next_request(module, req); + /* put back saved message */ + req->op.mod.message = msg; + /* free temproary compy */ talloc_free(msg2); return ret; } + +static int operational_request(struct ldb_module *module, struct ldb_request *req) +{ + switch (req->operation) { + + case LDB_REQ_SEARCH: + return operational_search_bytree(module, req); + + case LDB_REQ_ADD: + return operational_add(module, req); + + case LDB_REQ_MODIFY: + return operational_modify(module, req); + + default: + return ldb_next_request(module, req); + + } +} + static const struct ldb_module_ops operational_ops = { .name = "operational", - .search_bytree = operational_search_bytree, - .add_record = operational_add_record, - .modify_record = operational_modify_record + .request = operational_request }; -- cgit