attrs[i] = NULL;
}
- lreq = talloc(mem_ctx, struct ldb_request);
- if (lreq == NULL) goto nomem;
-
res = talloc_zero(mem_ctx, struct ldb_result);
if (res == NULL) goto nomem;
- lreq->operation = LDB_SEARCH;
- lreq->op.search.base = basedn;
- lreq->op.search.scope = scope;
- lreq->op.search.tree = search->tree;
- lreq->op.search.attrs = attrs;
-
- lreq->controls = NULL;
+ ldb_ret = ldb_build_search_req_ex(&lreq, cldapd->samctx, mem_ctx,
+ basedn, scope,
+ search->tree, attrs,
+ NULL,
+ res, ldb_search_default_callback,
+ NULL);
- lreq->context = res;
- lreq->callback = ldb_search_default_callback;
+ if (ldb_ret != LDB_SUCCESS) {
+ goto reply;
+ }
/* Copy the timeout from the incoming call */
ldb_set_timeout(cldapd->samctx, lreq, search->timelimit);
result_attrs,
NULL,
res,
- ldb_search_default_callback);
+ ldb_search_default_callback,
+ NULL);
if (ret == LDB_SUCCESS) {
struct ldb_search_options_control *search_options;
search_options = talloc(req, struct ldb_search_options_control);
return WERR_OK;
}
- ldb_set_timeout(sam_ctx, req, 0); /* use default timeout */
-
ret = ldb_request(sam_ctx, req);
if (ret == LDB_SUCCESS) {
struct ldb_dn *basedn;
struct ldb_result *res = NULL;
struct ldb_request *lreq;
+ struct ldb_control *search_control;
+ struct ldb_search_options_control *search_options;
enum ldb_scope scope = LDB_SCOPE_DEFAULT;
const char **attrs = NULL;
const char *scope_str, *errstr = NULL;
DEBUG(5,("ldb_request %s dn=%s filter=%s\n",
scope_str, req->basedn, ldb_filter_from_tree(call, req->tree)));
- lreq = talloc(local_ctx, struct ldb_request);
- NT_STATUS_HAVE_NO_MEMORY(lreq);
+ res = talloc_zero(local_ctx, struct ldb_result);
+ NT_STATUS_HAVE_NO_MEMORY(res);
- lreq->operation = LDB_SEARCH;
- lreq->op.search.base = basedn;
- lreq->op.search.scope = scope;
- lreq->op.search.tree = req->tree;
- lreq->op.search.attrs = attrs;
+ ldb_ret = ldb_build_search_req_ex(&lreq, samdb, local_ctx,
+ basedn, scope,
+ req->tree, attrs,
+ call->request->controls,
+ res, ldb_search_default_callback,
+ NULL);
- lreq->controls = call->request->controls;
+ if (ldb_ret != LDB_SUCCESS) {
+ goto reply;
+ }
if (call->conn->global_catalog) {
- struct ldb_control *search_control = ldb_request_get_control(lreq, LDB_CONTROL_SEARCH_OPTIONS_OID);
-
- struct ldb_search_options_control *search_options = NULL;
+ search_control = ldb_request_get_control(lreq, LDB_CONTROL_SEARCH_OPTIONS_OID);
+
+ search_options = NULL;
if (search_control) {
search_options = talloc_get_type(search_control->data, struct ldb_search_options_control);
search_options->search_options |= LDB_SEARCH_OPTION_PHANTOM_ROOT;
ldb_request_add_control(lreq, LDB_CONTROL_SEARCH_OPTIONS_OID, false, search_options);
}
}
-
- res = talloc_zero(lreq, struct ldb_result);
- NT_STATUS_HAVE_NO_MEMORY(res);
-
- lreq->context = res;
- lreq->callback = ldb_search_default_callback;
-
- /* Copy the timeout from the incoming call */
ldb_set_timeout(samdb, lreq, req->timelimit);
ldb_ret = ldb_request(samdb, lreq);
static int ldb_wrap_destructor(struct ldb_context *ldb)
{
size_t *startup_blocks = (size_t *)ldb_get_opaque(ldb, "startup_blocks");
+
if (startup_blocks &&
talloc_total_blocks(ldb) > *startup_blocks + 400) {
DEBUG(0,("WARNING: probable memory leak in ldb %s - %lu blocks (startup %lu) %lu bytes\n",
"%s/ldb",
lp_modulesdir(lp_ctx)));
-#if 0
- if (ev) {
- ldb_event_sys_op_init(ldb, ev);
- } else {
- talloc_free(ldb);
- return NULL;
- }
-#endif
-
if (ldb_set_opaque(ldb, "sessionInfo", session_info)) {
talloc_free(ldb);
return NULL;
return ldb;
}
-
-
-
packet_set_error_handler(conn->packet, ldap_error_handler);
packet_set_event_context(conn->packet, conn->event.event_ctx);
packet_set_fde(conn->packet, conn->event.fde);
- packet_set_serialise(conn->packet);
+/* packet_set_serialise(conn->packet); */
composite_done(ctx);
}
};
struct test_schema_ctx {
+ struct ldb_context *ldb;
+
struct ldb_paged_control *ctrl;
uint32_t count;
bool pending;
return true;
}
-static int test_schema_search_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares)
+static int test_schema_search_callback(struct ldb_request *req, struct ldb_reply *ares)
{
- struct test_schema_ctx *actx = talloc_get_type(context, struct test_schema_ctx);
+ struct test_schema_ctx *actx;
int ret = LDB_SUCCESS;
+ actx = talloc_get_type(req->context, struct test_schema_ctx);
+
+ 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:
actx->count++;
- ret = actx->callback(actx->private_data, ldb, ares->message);
+ ret = actx->callback(actx->private_data, actx->ldb, ares->message);
break;
case LDB_REPLY_REFERRAL:
actx->pending = true;
}
}
- break;
-
+ talloc_free(ares);
+ return ldb_request_done(req, LDB_SUCCESS);
+
default:
d_printf("%s: unknown Reply Type %u\n", __location__, ares->type);
- return LDB_ERR_OTHER;
+ return ldb_request_done(req, LDB_ERR_OTHER);
}
if (talloc_free(ares) == -1) {
d_printf("talloc_free failed\n");
actx->pending = 0;
- return LDB_ERR_OPERATIONS_ERROR;
+ return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR);
}
if (ret) {
- return LDB_ERR_OPERATIONS_ERROR;
+ return ldb_request_done(req, LDB_ERR_OPERATIONS_ERROR);
}
return LDB_SUCCESS;
int ret;
struct test_schema_ctx *actx;
- req = talloc(ldb, struct ldb_request);
- actx = talloc(req, struct test_schema_ctx);
+ actx = talloc(ldb, struct test_schema_ctx);
+ actx->ldb = ldb;
+ actx->private_data = private_data;
+ actx->callback= callback;
- ctrl = talloc_array(req, struct ldb_control *, 2);
+ ctrl = talloc_array(actx, struct ldb_control *, 2);
ctrl[0] = talloc(ctrl, struct ldb_control);
ctrl[0]->oid = LDB_CONTROL_PAGED_RESULTS_OID;
ctrl[0]->critical = true;
ctrl[0]->data = control;
ctrl[1] = NULL;
- req->operation = LDB_SEARCH;
- req->op.search.base = ldb_dn_new(req, ldb, root->schemadn);
- req->op.search.scope = LDB_SCOPE_SUBTREE;
- req->op.search.tree = ldb_parse_tree(req, filter);
- if (req->op.search.tree == NULL) return -1;
- req->op.search.attrs = NULL;
- req->controls = ctrl;
- req->context = actx;
- req->callback = test_schema_search_callback;
- ldb_set_timeout(ldb, req, 0);
-
- actx->count = 0;
- actx->ctrl = control;
- actx->callback = callback;
- actx->private_data = private_data;
+ ret = ldb_build_search_req(&req, ldb, actx,
+ ldb_dn_new(actx, ldb, root->schemadn),
+ LDB_SCOPE_SUBTREE,
+ filter, NULL,
+ ctrl,
+ actx, test_schema_search_callback,
+ NULL);
+
+ actx->ctrl = control;
+ actx->count = 0;
again:
actx->pending = false;
ret = ldb_request(ldb, req);
if (ret != LDB_SUCCESS) {
d_printf("search failed - %s\n", ldb_errstring(ldb));
+ talloc_free(actx);
return false;
}
ret = ldb_wait(req->handle, LDB_WAIT_ALL);
if (ret != LDB_SUCCESS) {
d_printf("search error - %s\n", ldb_errstring(ldb));
+ talloc_free(actx);
return false;
}
goto again;
d_printf("filter[%s] count[%u]\n", filter, actx->count);
+ talloc_free(actx);
return true;
}