summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2008-09-11 18:38:40 -0400
committerStefan Metzmacher <metze@samba.org>2008-09-29 04:22:20 +0200
commitb2901da479f5e711986de48df4910910460fe7db (patch)
treeda33b32d795781a689793b41b76a76a017f06d6a
parentf14a2b3386e9f44111cee010f6864602e5b833cd (diff)
downloadsamba-b2901da479f5e711986de48df4910910460fe7db.tar.gz
samba-b2901da479f5e711986de48df4910910460fe7db.tar.bz2
samba-b2901da479f5e711986de48df4910910460fe7db.zip
LDB ASYNC: misc changes
-rw-r--r--source4/cldap_server/rootdse.c21
-rw-r--r--source4/dsdb/samdb/cracknames.c5
-rw-r--r--source4/ldap_server/ldap_backend.c35
-rw-r--r--source4/lib/ldb_wrap.c13
-rw-r--r--source4/libcli/ldap/ldap_client.c2
-rw-r--r--source4/torture/ldap/schema.c64
6 files changed, 67 insertions, 73 deletions
diff --git a/source4/cldap_server/rootdse.c b/source4/cldap_server/rootdse.c
index 4ff71c0863..65786e6708 100644
--- a/source4/cldap_server/rootdse.c
+++ b/source4/cldap_server/rootdse.c
@@ -66,22 +66,19 @@ static void cldapd_rootdse_fill(struct cldapd_server *cldapd,
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);
diff --git a/source4/dsdb/samdb/cracknames.c b/source4/dsdb/samdb/cracknames.c
index 7324d898a6..e02e8d81a6 100644
--- a/source4/dsdb/samdb/cracknames.c
+++ b/source4/dsdb/samdb/cracknames.c
@@ -797,7 +797,8 @@ static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_
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);
@@ -812,8 +813,6 @@ static WERROR DsCrackNameOneFilter(struct ldb_context *sam_ctx, TALLOC_CTX *mem_
return WERR_OK;
}
- ldb_set_timeout(sam_ctx, req, 0); /* use default timeout */
-
ret = ldb_request(sam_ctx, req);
if (ret == LDB_SUCCESS) {
diff --git a/source4/ldap_server/ldap_backend.c b/source4/ldap_server/ldap_backend.c
index b954038b80..ffbef3d92f 100644
--- a/source4/ldap_server/ldap_backend.c
+++ b/source4/ldap_server/ldap_backend.c
@@ -158,6 +158,8 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
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;
@@ -216,21 +218,24 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
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;
@@ -241,14 +246,6 @@ static NTSTATUS ldapsrv_SearchRequest(struct ldapsrv_call *call)
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);
diff --git a/source4/lib/ldb_wrap.c b/source4/lib/ldb_wrap.c
index 6c683a1e33..617371333f 100644
--- a/source4/lib/ldb_wrap.c
+++ b/source4/lib/ldb_wrap.c
@@ -71,6 +71,7 @@ static void ldb_wrap_debug(void *context, enum ldb_debug_level level,
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",
@@ -124,15 +125,6 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
"%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;
@@ -198,6 +190,3 @@ struct ldb_context *ldb_wrap_connect(TALLOC_CTX *mem_ctx,
return ldb;
}
-
-
-
diff --git a/source4/libcli/ldap/ldap_client.c b/source4/libcli/ldap/ldap_client.c
index d7960f901a..fc5863b671 100644
--- a/source4/libcli/ldap/ldap_client.c
+++ b/source4/libcli/ldap/ldap_client.c
@@ -435,7 +435,7 @@ static void ldap_connect_got_sock(struct composite_context *ctx,
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);
}
diff --git a/source4/torture/ldap/schema.c b/source4/torture/ldap/schema.c
index dd1d2de331..fdb4251c15 100644
--- a/source4/torture/ldap/schema.c
+++ b/source4/torture/ldap/schema.c
@@ -41,6 +41,8 @@ struct test_rootDSE {
};
struct test_schema_ctx {
+ struct ldb_context *ldb;
+
struct ldb_paged_control *ctrl;
uint32_t count;
bool pending;
@@ -82,15 +84,24 @@ static bool test_search_rootDSE(struct ldb_context *ldb, struct test_rootDSE *ro
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:
@@ -118,21 +129,22 @@ static int test_schema_search_callback(struct ldb_context *ldb, void *context, s
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;
@@ -149,10 +161,12 @@ static bool test_create_schema_type(struct ldb_context *ldb, struct test_rootDSE
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;
@@ -163,33 +177,30 @@ static bool test_create_schema_type(struct ldb_context *ldb, struct test_rootDSE
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;
}
@@ -197,6 +208,7 @@ again:
goto again;
d_printf("filter[%s] count[%u]\n", filter, actx->count);
+ talloc_free(actx);
return true;
}