tldap: Make tldap_search use tldap_search_all
authorVolker Lendecke <vl@samba.org>
Sun, 31 Jan 2016 14:29:29 +0000 (15:29 +0100)
committerGünther Deschner <gd@samba.org>
Wed, 3 Feb 2016 14:04:11 +0000 (15:04 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
source3/include/tldap.h
source3/lib/tldap.c
source3/lib/tldap_util.c
source3/torture/torture.c

index a5f2ddcd47fa5839027d270f0d36ec5a154142ec..0d7e55df9ca0957d8c31a5e3c4bda8805cb53ac4 100644 (file)
@@ -189,8 +189,8 @@ TLDAPRC tldap_search(struct tldap_context *ld,
                     struct tldap_control *sctrls, int num_sctrls,
                     struct tldap_control *cctrls, int num_cctrls,
                     int timelimit, int sizelimit, int deref,
-                    TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
-                    struct tldap_message ***refs);
+                    TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs);
+
 bool tldap_entry_dn(struct tldap_message *msg, char **dn);
 bool tldap_entry_attributes(struct tldap_message *msg,
                            struct tldap_attribute **attributes,
index 12203236b67c11939ec0aca31b1fe8d9ae154ba1..1f9462adaf9f4495c9bc6ac29558c11859a46589 100644 (file)
@@ -1948,124 +1948,55 @@ TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
        return TLDAP_SUCCESS;
 }
 
-struct tldap_sync_search_state {
-       TALLOC_CTX *mem_ctx;
-       struct tldap_message **entries;
-       struct tldap_message **refs;
-       TLDAPRC rc;
-};
-
-static void tldap_search_cb(struct tevent_req *req)
-{
-       struct tldap_sync_search_state *state =
-               (struct tldap_sync_search_state *)
-               tevent_req_callback_data_void(req);
-       struct tldap_message *msg, **tmp;
-       int num_entries, num_refs;
-
-       state->rc = tldap_search_recv(req, talloc_tos(), &msg);
-       if (!TLDAP_RC_IS_SUCCESS(state->rc)) {
-               return;
-       }
-
-       switch (tldap_msg_type(msg)) {
-       case TLDAP_RES_SEARCH_ENTRY:
-               num_entries = talloc_array_length(state->entries);
-               tmp = talloc_realloc(state->mem_ctx, state->entries,
-                                    struct tldap_message *, num_entries + 1);
-               if (tmp == NULL) {
-                       state->rc = TLDAP_NO_MEMORY;
-                       return;
-               }
-               state->entries = tmp;
-               state->entries[num_entries] = talloc_move(state->entries,
-                                                         &msg);
-               break;
-       case TLDAP_RES_SEARCH_REFERENCE:
-               num_refs = talloc_array_length(state->refs);
-               tmp = talloc_realloc(state->mem_ctx, state->refs,
-                                    struct tldap_message *, num_refs + 1);
-               if (tmp == NULL) {
-                       state->rc = TLDAP_NO_MEMORY;
-                       return;
-               }
-               state->refs = tmp;
-               state->refs[num_refs] = talloc_move(state->refs, &msg);
-               break;
-       case TLDAP_RES_SEARCH_RESULT:
-               state->rc = TLDAP_SUCCESS;
-               break;
-       default:
-               state->rc = TLDAP_PROTOCOL_ERROR;
-               break;
-       }
-}
-
 TLDAPRC tldap_search(struct tldap_context *ld,
                     const char *base, int scope, const char *filter,
                     const char **attrs, int num_attrs, int attrsonly,
                     struct tldap_control *sctrls, int num_sctrls,
                     struct tldap_control *cctrls, int num_cctrls,
                     int timelimit, int sizelimit, int deref,
-                    TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
-                    struct tldap_message ***refs)
+                    TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs)
 {
-       TALLOC_CTX *frame = talloc_stackframe();
+       TALLOC_CTX *frame;
        struct tevent_context *ev;
        struct tevent_req *req;
-       struct tldap_sync_search_state state = {
-               .mem_ctx = mem_ctx, .rc = TLDAP_SUCCESS
-       };
+       TLDAPRC rc = TLDAP_NO_MEMORY;
+       struct tldap_message **msgs;
+       struct tldap_message *result;
+
+       if (tldap_pending_reqs(ld)) {
+               return TLDAP_BUSY;
+       }
+
+       frame = talloc_stackframe();
 
        ev = samba_tevent_context_init(frame);
        if (ev == NULL) {
-               state.rc = TLDAP_NO_MEMORY;
                goto fail;
        }
-
-       req = tldap_search_send(frame, ev, ld, base, scope, filter,
-                               attrs, num_attrs, attrsonly,
-                               sctrls, num_sctrls, cctrls, num_cctrls,
-                               timelimit, sizelimit, deref);
+       req = tldap_search_all_send(frame, ev, ld, base, scope, filter,
+                                   attrs, num_attrs, attrsonly,
+                                   sctrls, num_sctrls, cctrls, num_cctrls,
+                                   timelimit, sizelimit, deref);
        if (req == NULL) {
-               state.rc = TLDAP_NO_MEMORY;
                goto fail;
        }
-
-       tevent_req_set_callback(req, tldap_search_cb, &state);
-
-       if (!tevent_req_is_in_progress(req)) {
-               /* an error happend before sending */
-               if (tevent_req_is_ldap_error(req, &state.rc)) {
-                       goto fail;
-               }
+       if (!tevent_req_poll(req, ev)) {
+               rc = TLDAP_OPERATIONS_ERROR;
+               goto fail;
        }
-
-       while (tevent_req_is_in_progress(req) &&
-              TLDAP_RC_IS_SUCCESS(state.rc)) {
-               if (tevent_loop_once(ev) == -1) {
-                       return TLDAP_OPERATIONS_ERROR;
-               }
+       rc = tldap_search_all_recv(req, mem_ctx, &msgs, &result);
+       TALLOC_FREE(req);
+       if (!TLDAP_RC_IS_SUCCESS(rc)) {
+               return rc;
        }
 
-       if (!TLDAP_RC_IS_SUCCESS(state.rc)) {
-               return state.rc;
-       }
+       TALLOC_FREE(ld->last_msg);
+       ld->last_msg = talloc_move(ld, &result);
 
-       if (entries != NULL) {
-               *entries = state.entries;
-       } else {
-               TALLOC_FREE(state.entries);
-       }
-       if (refs != NULL) {
-               *refs = state.refs;
-       } else {
-               TALLOC_FREE(state.refs);
-       }
-       tldap_save_msg(ld, req);
+       *pmsgs = msgs;
 fail:
        TALLOC_FREE(frame);
-       return state.rc;
+       return rc;
 }
 
 static bool tldap_parse_search_entry(struct tldap_message *msg)
index 88e704fedf652e8b2e4bb60f7c6b8ce1f5eb59fd..b7233f68705fc7acb571878e9204903665d56997 100644 (file)
@@ -365,7 +365,7 @@ TLDAPRC tldap_search_va(struct tldap_context *ld, const char *base, int scope,
                          attrs, num_attrs, attrsonly,
                          NULL /*sctrls*/, 0, NULL /*cctrls*/, 0,
                          0 /*timelimit*/, 0 /*sizelimit*/, 0 /*deref*/,
-                         mem_ctx, res, NULL);
+                         mem_ctx, res);
        TALLOC_FREE(filter);
        return rc;
 }
index 8196993fe4b2c42396802a47bb54ac65bf9fb444..1df2ba0d7a744cfccc48bc4d981dca5e9c040bc4 100644 (file)
@@ -7993,7 +7993,7 @@ static bool run_tldap(int dummy)
 
        rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
                          NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
-                         talloc_tos(), NULL, NULL);
+                         talloc_tos(), NULL);
        if (!TLDAP_RC_IS_SUCCESS(rc)) {
                d_printf("tldap_search with complex filter failed: %s\n",
                         tldap_errstr(talloc_tos(), ld, rc));