summaryrefslogtreecommitdiff
path: root/source/lib/ldb/modules/operational.c
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-11-08 00:11:45 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:45:53 -0500
commit22c8c97e6fb466b41859e090e959d7f1134be780 (patch)
treee7566f016420c6f0e2e84523eed2d9edb9c55859 /source/lib/ldb/modules/operational.c
parentdbd01110d1a3e0f5914ae8d156723d6d6edf160c (diff)
downloadsamba-22c8c97e6fb466b41859e090e959d7f1134be780.tar.gz
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.
Diffstat (limited to 'source/lib/ldb/modules/operational.c')
-rw-r--r--source/lib/ldb/modules/operational.c84
1 files changed, 58 insertions, 26 deletions
diff --git a/source/lib/ldb/modules/operational.c b/source/lib/ldb/modules/operational.c
index 8a06e20c29e..7c554e8541b 100644
--- a/source/lib/ldb/modules/operational.c
+++ b/source/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 <time.h>
@@ -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;i<ARRAY_SIZE(parse_tree_sub);i++) {
- ldb_parse_tree_attr_replace(tree,
+ ldb_parse_tree_attr_replace(req->op.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;r<ret;r++) {
- if (operational_search_post_process(module, (*res)[r], attrs) != 0) {
+ for (r = 0; r < (*(req->op.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
};