mirror of
https://github.com/samba-team/samba.git
synced 2025-02-28 01:58:17 +03:00
tldap: Make tldap_search use tldap_search_all
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org>
This commit is contained in:
parent
0d1165a424
commit
f09cebd4fc
@ -189,8 +189,8 @@ TLDAPRC tldap_search(struct tldap_context *ld,
|
|||||||
struct tldap_control *sctrls, int num_sctrls,
|
struct tldap_control *sctrls, int num_sctrls,
|
||||||
struct tldap_control *cctrls, int num_cctrls,
|
struct tldap_control *cctrls, int num_cctrls,
|
||||||
int timelimit, int sizelimit, int deref,
|
int timelimit, int sizelimit, int deref,
|
||||||
TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
|
TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs);
|
||||||
struct tldap_message ***refs);
|
|
||||||
bool tldap_entry_dn(struct tldap_message *msg, char **dn);
|
bool tldap_entry_dn(struct tldap_message *msg, char **dn);
|
||||||
bool tldap_entry_attributes(struct tldap_message *msg,
|
bool tldap_entry_attributes(struct tldap_message *msg,
|
||||||
struct tldap_attribute **attributes,
|
struct tldap_attribute **attributes,
|
||||||
|
@ -1948,124 +1948,55 @@ TLDAPRC tldap_search_all_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
|
|||||||
return TLDAP_SUCCESS;
|
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,
|
TLDAPRC tldap_search(struct tldap_context *ld,
|
||||||
const char *base, int scope, const char *filter,
|
const char *base, int scope, const char *filter,
|
||||||
const char **attrs, int num_attrs, int attrsonly,
|
const char **attrs, int num_attrs, int attrsonly,
|
||||||
struct tldap_control *sctrls, int num_sctrls,
|
struct tldap_control *sctrls, int num_sctrls,
|
||||||
struct tldap_control *cctrls, int num_cctrls,
|
struct tldap_control *cctrls, int num_cctrls,
|
||||||
int timelimit, int sizelimit, int deref,
|
int timelimit, int sizelimit, int deref,
|
||||||
TALLOC_CTX *mem_ctx, struct tldap_message ***entries,
|
TALLOC_CTX *mem_ctx, struct tldap_message ***pmsgs)
|
||||||
struct tldap_message ***refs)
|
|
||||||
{
|
{
|
||||||
TALLOC_CTX *frame = talloc_stackframe();
|
TALLOC_CTX *frame;
|
||||||
struct tevent_context *ev;
|
struct tevent_context *ev;
|
||||||
struct tevent_req *req;
|
struct tevent_req *req;
|
||||||
struct tldap_sync_search_state state = {
|
TLDAPRC rc = TLDAP_NO_MEMORY;
|
||||||
.mem_ctx = mem_ctx, .rc = TLDAP_SUCCESS
|
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);
|
ev = samba_tevent_context_init(frame);
|
||||||
if (ev == NULL) {
|
if (ev == NULL) {
|
||||||
state.rc = TLDAP_NO_MEMORY;
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
req = tldap_search_all_send(frame, ev, ld, base, scope, filter,
|
||||||
req = tldap_search_send(frame, ev, ld, base, scope, filter,
|
attrs, num_attrs, attrsonly,
|
||||||
attrs, num_attrs, attrsonly,
|
sctrls, num_sctrls, cctrls, num_cctrls,
|
||||||
sctrls, num_sctrls, cctrls, num_cctrls,
|
timelimit, sizelimit, deref);
|
||||||
timelimit, sizelimit, deref);
|
|
||||||
if (req == NULL) {
|
if (req == NULL) {
|
||||||
state.rc = TLDAP_NO_MEMORY;
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
if (!tevent_req_poll(req, ev)) {
|
||||||
tevent_req_set_callback(req, tldap_search_cb, &state);
|
rc = TLDAP_OPERATIONS_ERROR;
|
||||||
|
goto fail;
|
||||||
if (!tevent_req_is_in_progress(req)) {
|
}
|
||||||
/* an error happend before sending */
|
rc = tldap_search_all_recv(req, mem_ctx, &msgs, &result);
|
||||||
if (tevent_req_is_ldap_error(req, &state.rc)) {
|
TALLOC_FREE(req);
|
||||||
goto fail;
|
if (!TLDAP_RC_IS_SUCCESS(rc)) {
|
||||||
}
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tevent_req_is_in_progress(req) &&
|
TALLOC_FREE(ld->last_msg);
|
||||||
TLDAP_RC_IS_SUCCESS(state.rc)) {
|
ld->last_msg = talloc_move(ld, &result);
|
||||||
if (tevent_loop_once(ev) == -1) {
|
|
||||||
return TLDAP_OPERATIONS_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!TLDAP_RC_IS_SUCCESS(state.rc)) {
|
*pmsgs = msgs;
|
||||||
return state.rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
fail:
|
fail:
|
||||||
TALLOC_FREE(frame);
|
TALLOC_FREE(frame);
|
||||||
return state.rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tldap_parse_search_entry(struct tldap_message *msg)
|
static bool tldap_parse_search_entry(struct tldap_message *msg)
|
||||||
|
@ -365,7 +365,7 @@ TLDAPRC tldap_search_va(struct tldap_context *ld, const char *base, int scope,
|
|||||||
attrs, num_attrs, attrsonly,
|
attrs, num_attrs, attrsonly,
|
||||||
NULL /*sctrls*/, 0, NULL /*cctrls*/, 0,
|
NULL /*sctrls*/, 0, NULL /*cctrls*/, 0,
|
||||||
0 /*timelimit*/, 0 /*sizelimit*/, 0 /*deref*/,
|
0 /*timelimit*/, 0 /*sizelimit*/, 0 /*deref*/,
|
||||||
mem_ctx, res, NULL);
|
mem_ctx, res);
|
||||||
TALLOC_FREE(filter);
|
TALLOC_FREE(filter);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -7993,7 +7993,7 @@ static bool run_tldap(int dummy)
|
|||||||
|
|
||||||
rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
|
rc = tldap_search(ld, "", TLDAP_SCOPE_BASE, filter,
|
||||||
NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
|
NULL, 0, 0, NULL, 0, NULL, 0, 0, 0, 0,
|
||||||
talloc_tos(), NULL, NULL);
|
talloc_tos(), NULL);
|
||||||
if (!TLDAP_RC_IS_SUCCESS(rc)) {
|
if (!TLDAP_RC_IS_SUCCESS(rc)) {
|
||||||
d_printf("tldap_search with complex filter failed: %s\n",
|
d_printf("tldap_search with complex filter failed: %s\n",
|
||||||
tldap_errstr(talloc_tos(), ld, rc));
|
tldap_errstr(talloc_tos(), ld, rc));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user