1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

s3:winbind:pwent: refactor duplication into wb_next_pwent_send_do()

Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
This commit is contained in:
Michael Adam 2015-01-19 13:51:39 +01:00 committed by Günther Deschner
parent 504b65c49c
commit 1ed41a5c39

View File

@ -31,12 +31,46 @@ struct wb_next_pwent_state {
static void wb_next_pwent_fetch_done(struct tevent_req *subreq);
static void wb_next_pwent_fill_done(struct tevent_req *subreq);
static void wb_next_pwent_send_do(struct tevent_req *req,
struct wb_next_pwent_state *state)
{
struct tevent_req *subreq;
if (state->gstate->next_user >= state->gstate->num_users) {
TALLOC_FREE(state->gstate->users);
state->gstate->domain = wb_next_domain(state->gstate->domain);
if (state->gstate->domain == NULL) {
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
return;
}
subreq = wb_query_user_list_send(state, state->ev,
state->gstate->domain);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
return;
}
subreq = wb_fill_pwent_send(state, state->ev,
&state->gstate->users[state->gstate->next_user],
state->pw);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
}
struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,
struct getpwent_state *gstate,
struct winbindd_pw *pw)
{
struct tevent_req *req, *subreq;
struct tevent_req *req;
struct wb_next_pwent_state *state;
req = tevent_req_create(mem_ctx, &state, struct wb_next_pwent_state);
@ -47,31 +81,11 @@ struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx,
state->gstate = gstate;
state->pw = pw;
if (state->gstate->next_user >= state->gstate->num_users) {
TALLOC_FREE(state->gstate->users);
state->gstate->domain = wb_next_domain(state->gstate->domain);
if (state->gstate->domain == NULL) {
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
return tevent_req_post(req, ev);
}
subreq = wb_query_user_list_send(state, state->ev,
state->gstate->domain);
if (tevent_req_nomem(subreq, req)) {
return tevent_req_post(req, ev);
}
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
return req;
}
subreq = wb_fill_pwent_send(
state, state->ev,
&state->gstate->users[state->gstate->next_user],
state->pw);
if (tevent_req_nomem(subreq, req)) {
wb_next_pwent_send_do(req, state);
if (!tevent_req_is_in_progress(req)) {
return tevent_req_post(req, ev);
}
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
return req;
}
@ -97,29 +111,7 @@ static void wb_next_pwent_fetch_done(struct tevent_req *subreq)
state->gstate->next_user = 0;
if (state->gstate->num_users == 0) {
state->gstate->domain = wb_next_domain(state->gstate->domain);
if (state->gstate->domain == NULL) {
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
return;
}
subreq = wb_query_user_list_send(state, state->ev,
state->gstate->domain);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
return;
}
subreq = wb_fill_pwent_send(
state, state->ev,
&state->gstate->users[state->gstate->next_user],
state->pw);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
wb_next_pwent_send_do(req, state);
}
static void wb_next_pwent_fill_done(struct tevent_req *subreq)
@ -139,32 +131,7 @@ static void wb_next_pwent_fill_done(struct tevent_req *subreq)
if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
state->gstate->next_user += 1;
if (state->gstate->next_user >= state->gstate->num_users) {
TALLOC_FREE(state->gstate->users);
state->gstate->domain = wb_next_domain(state->gstate->domain);
if (state->gstate->domain == NULL) {
tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
return;
}
subreq = wb_query_user_list_send(state, state->ev,
state->gstate->domain);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
return;
}
subreq = wb_fill_pwent_send(state,
state->ev,
&state->gstate->users[state->gstate->next_user],
state->pw);
if (tevent_req_nomem(subreq, req)) {
return;
}
tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
wb_next_pwent_send_do(req, state);
return;
} else if (tevent_req_nterror(req, status)) {