summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/ldb_tdb
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
commit5c9590587197dcb95007fdc54318187d5716c7c6 (patch)
treed5161aa628d8a4bc4f11bf849d76a451ff44522c /source4/lib/ldb/ldb_tdb
parent14b59bcbec1a288810efee5c9442dff30f1a474a (diff)
downloadsamba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.gz
samba-5c9590587197dcb95007fdc54318187d5716c7c6.tar.bz2
samba-5c9590587197dcb95007fdc54318187d5716c7c6.zip
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)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c27
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_search.c29
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c38
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.h6
4 files changed, 72 insertions, 28 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index de9665cb4d..75514fac83 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
#include "ldb/include/ldb_private.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
@@ -629,10 +630,9 @@ static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tr
const struct ldb_dn *base,
enum ldb_scope scope,
const struct dn_list *dn_list,
- const char * const attrs[], struct ldb_message ***res)
+ const char * const attrs[], struct ldb_result *res)
{
unsigned int i;
- int count = 0;
for (i = 0; i < dn_list->count; i++) {
struct ldb_message *msg;
@@ -641,13 +641,13 @@ static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tr
msg = talloc(module, struct ldb_message);
if (msg == NULL) {
- return -1;
+ return LDB_ERR_OTHER;
}
dn = ldb_dn_explode(msg, dn_list->dn[i]);
if (dn == NULL) {
talloc_free(msg);
- return -1;
+ return LDB_ERR_OTHER;
}
ret = ltdb_search_dn1(module, dn, msg);
@@ -661,20 +661,20 @@ static int ldb_index_filter(struct ldb_module *module, struct ldb_parse_tree *tr
if (ret == -1) {
/* an internal error */
talloc_free(msg);
- return -1;
+ return LDB_ERR_OTHER;
}
ret = 0;
if (ldb_match_msg(module->ldb, msg, tree, base, scope) == 1) {
- ret = ltdb_add_attr_results(module, msg, attrs, &count, res);
+ ret = ltdb_add_attr_results(module, msg, attrs, &(res->count), &(res->msgs));
}
talloc_free(msg);
if (ret != 0) {
- return -1;
+ return LDB_ERR_OTHER;
}
}
- return count;
+ return LDB_SUCCESS;
}
/*
@@ -686,7 +686,7 @@ int ltdb_search_indexed(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)
+ const char * const attrs[], struct ldb_result **res)
{
struct ltdb_private *ltdb = module->private_data;
struct dn_list *dn_list;
@@ -703,6 +703,13 @@ int ltdb_search_indexed(struct ldb_module *module,
return -1;
}
+ *res = talloc(module, struct ldb_result);
+ if (*res == NULL) {
+ return LDB_ERR_OTHER;
+ }
+ (*res)->count = 0;
+ (*res)->msgs = NULL;
+
if (scope == LDB_SCOPE_BASE) {
/* with BASE searches only one DN can match */
dn_list->dn = talloc_array(dn_list, char *, 1);
@@ -725,7 +732,7 @@ int ltdb_search_indexed(struct ldb_module *module,
/* we've got a candidate list - now filter by the full tree
and extract the needed attributes */
ret = ldb_index_filter(module, tree, base, scope, dn_list,
- attrs, res);
+ attrs, *res);
}
talloc_free(dn_list);
diff --git a/source4/lib/ldb/ldb_tdb/ldb_search.c b/source4/lib/ldb/ldb_tdb/ldb_search.c
index 97f8a7d0be..01a87e00b1 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_search.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_search.c
@@ -299,7 +299,7 @@ static int ltdb_unlock_read(struct ldb_module *module)
*/
int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
- int *count,
+ unsigned int *count,
struct ldb_message ***res)
{
struct ldb_context *ldb = module->ldb;
@@ -339,8 +339,8 @@ struct ltdb_search_info {
enum ldb_scope scope;
const char * const *attrs;
struct ldb_message **msgs;
- int failures;
- int count;
+ unsigned int failures;
+ unsigned int count;
};
@@ -406,15 +406,22 @@ static int ltdb_search_full(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)
+ const char * const attrs[], struct ldb_result **res)
{
struct ltdb_private *ltdb = module->private_data;
- int ret, count;
+ struct ldb_result *result;
+ int ret;
struct ltdb_search_info *sinfo;
+ result = talloc(ltdb, struct ldb_result);
+ if (result == NULL) {
+ return LDB_ERR_OTHER;
+ }
+
sinfo = talloc(ltdb, struct ltdb_search_info);
if (sinfo == NULL) {
- return -1;
+ talloc_free(result);
+ return LDB_ERR_OTHER;
}
sinfo->tree = tree;
@@ -429,16 +436,18 @@ static int ltdb_search_full(struct ldb_module *module,
ret = tdb_traverse_read(ltdb->tdb, search_func, sinfo);
if (ret == -1) {
+ talloc_free(result);
talloc_free(sinfo);
return -1;
}
- *res = talloc_steal(ltdb, sinfo->msgs);
- count = sinfo->count;
+ result->msgs = talloc_steal(result, sinfo->msgs);
+ result->count = sinfo->count;
+ *res = result;
talloc_free(sinfo);
- return count;
+ return LDB_SUCCESS;
}
@@ -448,7 +457,7 @@ static int ltdb_search_full(struct ldb_module *module,
*/
int ltdb_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)
+ const char * const attrs[], struct ldb_result **res)
{
int ret;
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index 5b2feb741b..d1e60e0f5d 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -733,13 +733,41 @@ static int ltdb_del_trans(struct ldb_module *module)
return LDB_SUCCESS;
}
+static int ltdb_request(struct ldb_module *module, struct ldb_request *req)
+{
+ switch (req->operation) {
+
+ case LDB_REQ_SEARCH:
+ return ltdb_search_bytree(module,
+ req->op.search.base,
+ req->op.search.scope,
+ req->op.search.tree,
+ req->op.search.attrs,
+ req->op.search.res);
+
+ case LDB_REQ_ADD:
+ return ltdb_add(module, req->op.add.message);
+
+ case LDB_REQ_MODIFY:
+ return ltdb_modify(module, req->op.mod.message);
+
+ case LDB_REQ_DELETE:
+ return ltdb_delete(module, req->op.del.dn);
+
+ case LDB_REQ_RENAME:
+ return ltdb_rename(module,
+ req->op.rename.olddn,
+ req->op.rename.newdn);
+
+ default:
+ return LDB_ERR_OPERATIONS_ERROR;
+
+ }
+}
+
static const struct ldb_module_ops ltdb_ops = {
.name = "tdb",
- .search_bytree = ltdb_search_bytree,
- .add_record = ltdb_add,
- .modify_record = ltdb_modify,
- .delete_record = ltdb_delete,
- .rename_record = ltdb_rename,
+ .request = ltdb_request,
.start_transaction = ltdb_start_trans,
.end_transaction = ltdb_end_trans,
.del_transaction = ltdb_del_trans
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.h b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
index 2819d865d3..54c58517bd 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.h
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.h
@@ -57,7 +57,7 @@ int ltdb_search_indexed(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);
+ const char * const attrs[], struct ldb_result **res);
int ltdb_index_add(struct ldb_module *module, const struct ldb_message *msg);
int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg);
int ltdb_reindex(struct ldb_module *module);
@@ -81,11 +81,11 @@ void ltdb_search_dn1_free(struct ldb_module *module, struct ldb_message *msg);
int ltdb_search_dn1(struct ldb_module *module, const struct ldb_dn *dn, struct ldb_message *msg);
int ltdb_add_attr_results(struct ldb_module *module, struct ldb_message *msg,
const char * const attrs[],
- int *count,
+ unsigned int *count,
struct ldb_message ***res);
int ltdb_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);
+ const char * const attrs[], struct ldb_result **res);
/* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */