summaryrefslogtreecommitdiffstats
path: root/ldb/tools
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-09-25 02:28:56 -0400
committerSimo Sorce <idra@samba.org>2008-09-25 03:21:34 -0400
commit9bd63b97c9c3132a0b3c8c6bd1c67f8c31a54c3c (patch)
treeaf51399e30505f1111308f8d582934ab83d31396 /ldb/tools
parentf698831f0ae0cd86225eb647ae4aeb813f08d3b5 (diff)
downloadsssd-9bd63b97c9c3132a0b3c8c6bd1c67f8c31a54c3c.tar.gz
sssd-9bd63b97c9c3132a0b3c8c6bd1c67f8c31a54c3c.tar.xz
sssd-9bd63b97c9c3132a0b3c8c6bd1c67f8c31a54c3c.zip
Sync ldb with upstream (includes uncommitted ldb async patches)
Diffstat (limited to 'ldb/tools')
-rw-r--r--ldb/tools/ldbdel.c2
-rw-r--r--ldb/tools/ldbedit.c2
-rw-r--r--ldb/tools/ldbsearch.c76
-rw-r--r--ldb/tools/ldbtest.c4
4 files changed, 46 insertions, 38 deletions
diff --git a/ldb/tools/ldbdel.c b/ldb/tools/ldbdel.c
index e66d4fb97..22d4aa697 100644
--- a/ldb/tools/ldbdel.c
+++ b/ldb/tools/ldbdel.c
@@ -40,7 +40,7 @@ static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn)
const char *attrs[] = { NULL };
struct ldb_result *res;
- ret = ldb_search(ldb, dn, LDB_SCOPE_SUBTREE, "distinguishedName=*", attrs, &res);
+ ret = ldb_search(ldb, ldb, &res, dn, LDB_SCOPE_SUBTREE, attrs, "distinguishedName=*");
if (ret != LDB_SUCCESS) return -1;
for (i = 0; i < res->count; i++) {
diff --git a/ldb/tools/ldbedit.c b/ldb/tools/ldbedit.c
index e58a5a271..b2a040cd0 100644
--- a/ldb/tools/ldbedit.c
+++ b/ldb/tools/ldbedit.c
@@ -303,7 +303,7 @@ int main(int argc, const char **argv)
}
}
- ret = ldb_search(ldb, basedn, options->scope, expression, attrs, &result);
+ ret = ldb_search(ldb, ldb, &result, basedn, options->scope, attrs, "%s", expression);
if (ret != LDB_SUCCESS) {
printf("search failed - %s\n", ldb_errstring(ldb));
exit(1);
diff --git a/ldb/tools/ldbsearch.c b/ldb/tools/ldbsearch.c
index b3d1f934a..ceabd5cd7 100644
--- a/ldb/tools/ldbsearch.c
+++ b/ldb/tools/ldbsearch.c
@@ -56,6 +56,7 @@ static int do_compare_msg(struct ldb_message **el1,
}
struct search_context {
+ struct ldb_context *ldb;
struct ldb_control **req_ctrls;
int sort;
@@ -101,7 +102,7 @@ static int store_referral(char *referral, struct search_context *sctx) {
return 0;
}
-static int display_message(struct ldb_context *ldb, struct ldb_message *msg, struct search_context *sctx) {
+static int display_message(struct ldb_message *msg, struct search_context *sctx) {
struct ldb_ldif ldif;
sctx->entries++;
@@ -119,7 +120,7 @@ static int display_message(struct ldb_context *ldb, struct ldb_message *msg, str
ldb_msg_sort_elements(ldif.msg);
}
- ldb_ldif_write_file(ldb, stdout, &ldif);
+ ldb_ldif_write_file(sctx->ldb, stdout, &ldif);
return 0;
}
@@ -133,18 +134,26 @@ static int display_referral(char *referral, struct search_context *sctx)
return 0;
}
-static int search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+static int search_callback(struct ldb_request *req, struct ldb_reply *ares)
{
- struct search_context *sctx = talloc_get_type(context, struct search_context);
+ struct search_context *sctx;
int ret;
+
+ sctx = talloc_get_type(req->context, struct search_context);
+
+ if (!ares) {
+ return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR);
+ }
+ if (ares->error != LDB_SUCCESS) {
+ return ldb_request_done(req, ares->error);
+ }
switch (ares->type) {
-
case LDB_REPLY_ENTRY:
if (sctx->sort) {
ret = store_message(ares->message, sctx);
} else {
- ret = display_message(ldb, ares->message, sctx);
+ ret = display_message(ares->message, sctx);
}
break;
@@ -154,6 +163,9 @@ static int search_callback(struct ldb_context *ldb, void *context, struct ldb_re
} else {
ret = display_referral(ares->referral, sctx);
}
+ if (ret) {
+ return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR);
+ }
break;
case LDB_REPLY_DONE:
@@ -161,22 +173,13 @@ static int search_callback(struct ldb_context *ldb, void *context, struct ldb_re
if (handle_controls_reply(ares->controls, sctx->req_ctrls) == 1)
sctx->pending = 1;
}
- ret = 0;
- break;
-
- default:
- fprintf(stderr, "unknown Reply Type\n");
- return LDB_ERR_OTHER;
- }
-
- if (talloc_free(ares) == -1) {
- fprintf(stderr, "talloc_free failed\n");
- sctx->pending = 0;
- return LDB_ERR_OPERATIONS_ERROR;
+ talloc_free(ares);
+ return ldb_request_done(req, LDB_SUCCESS);
}
+ talloc_free(ares);
if (ret) {
- return LDB_ERR_OPERATIONS_ERROR;
+ return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR);
}
return LDB_SUCCESS;
@@ -192,12 +195,12 @@ static int do_search(struct ldb_context *ldb,
struct search_context *sctx;
int ret;
- req = talloc(ldb, struct ldb_request);
- if (!req) return -1;
+ req = NULL;
- sctx = talloc(req, struct search_context);
+ sctx = talloc(ldb, struct search_context);
if (!sctx) return -1;
+ sctx->ldb = ldb;
sctx->sort = options->sorted;
sctx->num_stored = 0;
sctx->refs_stored = 0;
@@ -214,18 +217,22 @@ static int do_search(struct ldb_context *ldb,
basedn = ldb_get_default_basedn(ldb);
}
- req->operation = LDB_SEARCH;
- req->op.search.base = basedn;
- req->op.search.scope = options->scope;
- req->op.search.tree = ldb_parse_tree(req, expression);
- if (req->op.search.tree == NULL) return -1;
- req->op.search.attrs = attrs;
- req->controls = sctx->req_ctrls;
- req->context = sctx;
- req->callback = &search_callback;
- ldb_set_timeout(ldb, req, 0); /* TODO: make this settable by command line */
-
again:
+ /* free any previous requests */
+ if (req) talloc_free(req);
+
+ ret = ldb_build_search_req(&req, ldb, ldb,
+ basedn, options->scope,
+ expression, attrs,
+ sctx->req_ctrls,
+ sctx, search_callback,
+ NULL);
+ if (ret != LDB_SUCCESS) {
+ talloc_free(sctx);
+ printf("allocating request failed: %s\n", ldb_errstring(ldb));
+ return -1;
+ }
+
sctx->pending = 0;
ret = ldb_request(ldb, req);
@@ -251,7 +258,7 @@ again:
ldb, (ldb_qsort_cmp_fn_t)do_compare_msg);
}
for (i = 0; i < sctx->num_stored; i++) {
- display_message(ldb, sctx->store[i], sctx);
+ display_message(sctx->store[i], sctx);
}
for (i = 0; i < sctx->refs_stored; i++) {
@@ -262,6 +269,7 @@ again:
printf("# returned %d records\n# %d entries\n# %d referrals\n",
sctx->entries + sctx->refs, sctx->entries, sctx->refs);
+ talloc_free(sctx);
talloc_free(req);
return 0;
diff --git a/ldb/tools/ldbtest.c b/ldb/tools/ldbtest.c
index 169ff02da..f3d6d621a 100644
--- a/ldb/tools/ldbtest.c
+++ b/ldb/tools/ldbtest.c
@@ -227,7 +227,7 @@ static void search_uid(struct ldb_context *ldb, struct ldb_dn *basedn, int nreco
int ret;
expr = talloc_asprintf(ldb, "(uid=TEST%d)", uid);
- ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, expr, NULL, &res);
+ ret = ldb_search(ldb, ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, "%s", expr);
if (ret != LDB_SUCCESS || (uid < nrecords && res->count != 1)) {
printf("Failed to find %s - %s\n", expr, ldb_errstring(ldb));
@@ -354,7 +354,7 @@ static void start_test_index(struct ldb_context **ldb)
basedn = ldb_dn_new(*ldb, *ldb, options->basedn);
- ret = ldb_search(*ldb, basedn, LDB_SCOPE_SUBTREE, "uid=test", NULL, &res);
+ ret = ldb_search(*ldb, *ldb, &res, basedn, LDB_SCOPE_SUBTREE, NULL, "uid=test");
if (ret != LDB_SUCCESS) {
printf("Search with (uid=test) filter failed!\n");
exit(1);