From 2bc0bbaea6f13ce25c7b45b46daf4677e72dd4ab Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 3 Jan 2012 16:54:39 +0100 Subject: [PATCH 1/2] s3-winbind: Move finding the domain to it's own function. This the first part to fix bug #8678. --- source3/winbindd/wb_next_pwent.c | 34 ++++++++++++++++++++++------------ 1 files changed, 22 insertions(+), 12 deletions(-) diff --git a/source3/winbindd/wb_next_pwent.c b/source3/winbindd/wb_next_pwent.c index d47b2fc..5fb45d5 100644 --- a/source3/winbindd/wb_next_pwent.c +++ b/source3/winbindd/wb_next_pwent.c @@ -31,6 +31,26 @@ 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 bool wb_next_find_domain(struct getpwent_state *state) +{ + if (state->domain == NULL) { + state->domain = domain_list(); + } else { + state->domain = state->domain->next; + } + + if ((state->domain != NULL) + && sid_check_is_domain(&state->domain->sid)) { + state->domain = state->domain->next; + } + + if (state->domain == NULL) { + return false; + } + + return true; +} + struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct getpwent_state *gstate, @@ -50,21 +70,11 @@ struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx, if (state->gstate->next_user >= state->gstate->num_users) { TALLOC_FREE(state->gstate->users); - if (state->gstate->domain == NULL) { - state->gstate->domain = domain_list(); - } else { - state->gstate->domain = state->gstate->domain->next; - } - - if ((state->gstate->domain != NULL) - && sid_check_is_domain(&state->gstate->domain->sid)) { - state->gstate->domain = state->gstate->domain->next; - } - - if (state->gstate->domain == NULL) { + if (!wb_next_find_domain(state->gstate)) { 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)) { -- 1.7.8 From b4e671131ab7d0c551e63d551a6eec4942f921ae Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 3 Jan 2012 16:55:25 +0100 Subject: [PATCH 2/2] s3-winbind: Fix segfault if we can't map the last user. This fixes bug #8678. The issue is caused by bug #8608. --- source3/winbindd/wb_next_pwent.c | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/source3/winbindd/wb_next_pwent.c b/source3/winbindd/wb_next_pwent.c index 5fb45d5..51931f9 100644 --- a/source3/winbindd/wb_next_pwent.c +++ b/source3/winbindd/wb_next_pwent.c @@ -165,6 +165,23 @@ 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); + + if (!wb_next_find_domain(state->gstate)) { + 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], -- 1.7.8