From: Volker Lendecke Date: Tue, 22 Dec 2015 12:32:01 +0000 (+0100) Subject: tldap: Add tldap_search_all X-Git-Tag: tevent-0.9.27~94 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d29c45ce41c3360726b67e4683703b9eb433e29d;p=thirdparty%2Fsamba.git tldap: Add tldap_search_all Signed-off-by: Volker Lendecke TLDAPRC Reviewed-by: Guenther Deschner --- diff --git a/source3/include/tldap.h b/source3/include/tldap.h index 18317f79297..a5f2ddcd47f 100644 --- a/source3/include/tldap.h +++ b/source3/include/tldap.h @@ -171,6 +171,18 @@ struct tevent_req *tldap_search_send(TALLOC_CTX *mem_ctx, int deref); TLDAPRC tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct tldap_message **pmsg); + +struct tevent_req *tldap_search_all_send( + TALLOC_CTX *mem_ctx, struct tevent_context *ev, + 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); +TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct tldap_message ***msgs, + struct tldap_message **result); + TLDAPRC tldap_search(struct tldap_context *ld, const char *base, int scope, const char *filter, const char **attrs, int num_attrs, int attrsonly, diff --git a/source3/lib/tldap.c b/source3/lib/tldap.c index 0148d30eca3..3072482843a 100644 --- a/source3/lib/tldap.c +++ b/source3/lib/tldap.c @@ -1850,6 +1850,99 @@ TLDAPRC tldap_search_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, return TLDAP_SUCCESS; } +struct tldap_search_all_state { + struct tldap_message **msgs; + struct tldap_message *result; +}; + +static void tldap_search_all_done(struct tevent_req *subreq); + +struct tevent_req *tldap_search_all_send( + TALLOC_CTX *mem_ctx, struct tevent_context *ev, + 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) +{ + struct tevent_req *req, *subreq; + struct tldap_search_all_state *state; + + req = tevent_req_create(mem_ctx, &state, + struct tldap_search_all_state); + if (req == NULL) { + return NULL; + } + + subreq = tldap_search_send(state, ev, ld, base, scope, filter, + attrs, num_attrs, attrsonly, + sctrls, num_sctrls, cctrls, num_cctrls, + timelimit, sizelimit, deref); + if (tevent_req_nomem(subreq, req)) { + return tevent_req_post(req, ev); + } + tevent_req_set_callback(subreq, tldap_search_all_done, req); + return req; +} + +static void tldap_search_all_done(struct tevent_req *subreq) +{ + struct tevent_req *req = tevent_req_callback_data( + subreq, struct tevent_req); + struct tldap_search_all_state *state = tevent_req_data( + req, struct tldap_search_all_state); + struct tldap_message *msg, **tmp; + size_t num_msgs; + TLDAPRC rc; + int msgtype; + + rc = tldap_search_recv(subreq, state, &msg); + /* No TALLOC_FREE(subreq), this is multi-step */ + if (tevent_req_ldap_error(req, rc)) { + TALLOC_FREE(subreq); + return; + } + + msgtype = tldap_msg_type(msg); + if (msgtype == TLDAP_RES_SEARCH_RESULT) { + state->result = msg; + tevent_req_done(req); + return; + } + + num_msgs = talloc_array_length(state->msgs); + + tmp = talloc_realloc(state, state->msgs, struct tldap_message *, + num_msgs + 1); + if (tevent_req_nomem(tmp, req)) { + return; + } + state->msgs = tmp; + state->msgs[num_msgs] = talloc_move(state->msgs, &msg); +} + +TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, + struct tldap_message ***msgs, + struct tldap_message **result) +{ + struct tldap_search_all_state *state = tevent_req_data( + req, struct tldap_search_all_state); + TLDAPRC rc; + + if (tevent_req_is_ldap_error(req, &rc)) { + return rc; + } + + if (msgs != NULL) { + *msgs = talloc_move(mem_ctx, &state->msgs); + } + if (result != NULL) { + *result = talloc_move(mem_ctx, &state->result); + } + + return TLDAP_SUCCESS; +} + struct tldap_sync_search_state { TALLOC_CTX *mem_ctx; struct tldap_message **entries;