summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/ldb_wrap.c22
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c76
2 files changed, 44 insertions, 54 deletions
diff --git a/source4/lib/ldb/ldb_wrap.c b/source4/lib/ldb/ldb_wrap.c
index c15fd2b9ae..cc8099f27f 100644
--- a/source4/lib/ldb/ldb_wrap.c
+++ b/source4/lib/ldb/ldb_wrap.c
@@ -3156,15 +3156,14 @@ SWIGINTERN ldb_error ldb_search_ex(ldb *self,TALLOC_CTX *mem_ctx,ldb_dn *base,en
attrs,
controls,
res,
- ldb_search_default_callback);
+ ldb_search_default_callback,
+ NULL);
if (ret != 0) {
talloc_free(res);
return ret;
}
- ldb_set_timeout(self, req, 0); /* use default timeout */
-
ret = ldb_request(self, req);
if (ret == 0) {
@@ -3506,22 +3505,6 @@ int py_module_del_transaction(struct ldb_module *mod)
return LDB_SUCCESS;
}
-int py_module_wait(struct ldb_handle *mod, enum ldb_wait_type wait_type)
-{
- PyObject *py_ldb = mod->private_data;
- PyObject *py_result;
-
- py_result = PyObject_CallMethod(py_ldb, "wait", "i", wait_type);
-
- if (py_result == NULL) {
- return LDB_ERR_OPERATIONS_ERROR;
- }
-
- Py_DECREF(py_result);
-
- return LDB_SUCCESS;
-}
-
int py_module_sequence_number(struct ldb_module *mod, struct ldb_request *req)
{
PyObject *py_ldb = mod->private_data;
@@ -6665,7 +6648,6 @@ SWIGINTERN PyObject *_wrap_register_module(PyObject *SWIGUNUSEDPARM(self), PyObj
arg1->start_transaction = py_module_start_transaction;
arg1->end_transaction = py_module_end_transaction;
arg1->del_transaction = py_module_del_transaction;
- arg1->wait = py_module_wait;
arg1->sequence_number = py_module_sequence_number;
result = ldb_register_module((struct ldb_module_ops const *)arg1);
if (result != 0) {
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index b3d1f934a6..ceabd5cd78 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/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;