LDB ASYNC: misc changes
authorSimo Sorce <idra@samba.org>
Thu, 11 Sep 2008 22:38:40 +0000 (18:38 -0400)
committerStefan Metzmacher <metze@samba.org>
Mon, 29 Sep 2008 02:22:20 +0000 (04:22 +0200)
source4/cldap_server/rootdse.c
source4/dsdb/samdb/cracknames.c
source4/ldap_server/ldap_backend.c
source4/lib/ldb_wrap.c
source4/libcli/ldap/ldap_client.c
source4/torture/ldap/schema.c

index 4ff71c086342225f14c0b9bbfacff53f1d819026..65786e67085172b2ff90a4a7f98295ed31ffa15c 100644 (file)
@@ -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);
index 7324d898a65f6c579aa4ae1044f81d69a586b789..e02e8d81a6a6b46a7812c1ef5f95f8f2c28afe9e 100644 (file)
@@ -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) {
index b954038b8046502489c9db3a7564c95925a394f4..ffbef3d92fe9dbb0a9b117dbb028bd566be4009d 100644 (file)
@@ -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);
index 6c683a1e33068eb49f8d210f7c403966a3df75b7..617371333f0f9fba1346f682932f7f362ea55963 100644 (file)
@@ -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;
 }
-
-
-
index d7960f901ab707eddfa550eadac7f6151a546938..fc5863b671f32ee3d8ac4d757d35cab185542f64 100644 (file)
@@ -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);
 }
index dd1d2de33163b367753e310c951742e2a8d58ced..fdb4251c15ea8e2505c7ef77ad18315a1da54ad4 100644 (file)
@@ -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;
 }