From 1ed41a5c39069d9e95a5e82f1d0f9433bf7999f5 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Mon, 19 Jan 2015 13:51:39 +0100 Subject: [PATCH] s3:winbind:pwent: refactor duplication into wb_next_pwent_send_do() Signed-off-by: Michael Adam Reviewed-by: Guenther Deschner --- source3/winbindd/wb_next_pwent.c | 113 +++++++++++-------------------- 1 file changed, 40 insertions(+), 73 deletions(-) diff --git a/source3/winbindd/wb_next_pwent.c b/source3/winbindd/wb_next_pwent.c index a6159def5f3..af5e8d9f9aa 100644 --- a/source3/winbindd/wb_next_pwent.c +++ b/source3/winbindd/wb_next_pwent.c @@ -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)) {