From: Stefan Metzmacher Date: Fri, 7 Feb 2025 12:57:45 +0000 (+0100) Subject: winbindd: use struct winbindd_domain_ref in struct getgrent_state X-Git-Tag: tevent-0.17.0~838 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=88f163c20647eef1df6a1499948dffbcfe415a26;p=thirdparty%2Fsamba.git winbindd: use struct winbindd_domain_ref in struct getgrent_state In the next commits it will be possible that struct winbindd_domain instances become stale because trusted domains were reloaded. That means aync state structure should not use pointers to 'struct winbindd_domain' as they can become stale! Instead they should use 'struct winbindd_domain_ref domain' in the async state and use winbindd_domain_ref_set/get() to manage the 'struct winbindd_domain' pointer. Signed-off-by: Stefan Metzmacher Reviewed-by: Ralph Boehme --- diff --git a/source3/winbindd/wb_next_grent.c b/source3/winbindd/wb_next_grent.c index 5c2d447f46f..99586ac2641 100644 --- a/source3/winbindd/wb_next_grent.c +++ b/source3/winbindd/wb_next_grent.c @@ -37,18 +37,32 @@ static void wb_next_grent_send_do(struct tevent_req *req, struct wb_next_grent_state *state) { struct tevent_req *subreq; + struct winbindd_domain *domain = NULL; + bool valid; + + valid = winbindd_domain_ref_get(&state->gstate->domain, + &domain); + if (!valid) { + /* + * winbindd_domain_ref_get() already generated + * a debug message for the stale domain! + */ + tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES); + return; + } if (state->gstate->next_group >= state->gstate->num_groups) { TALLOC_FREE(state->gstate->groups); - state->gstate->domain = wb_next_domain(state->gstate->domain); - if (state->gstate->domain == NULL) { + domain = wb_next_domain(domain); + winbindd_domain_ref_set(&state->gstate->domain, domain); + if (domain == NULL) { tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES); return; } subreq = wb_query_group_list_send(state, state->ev, - state->gstate->domain); + domain); if (tevent_req_nomem(subreq, req)) { return; } @@ -108,9 +122,23 @@ static void wb_next_grent_fetch_done(struct tevent_req *subreq) &state->gstate->groups); TALLOC_FREE(subreq); if (!NT_STATUS_IS_OK(status)) { + struct winbindd_domain *domain = NULL; + bool valid; + + valid = winbindd_domain_ref_get(&state->gstate->domain, + &domain); + if (!valid) { + /* + * winbindd_domain_ref_get() already generated + * a debug message for the stale domain! + */ + tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES); + return; + } + /* Ignore errors here, just log it */ D_DEBUG("query_group_list for domain %s returned %s\n", - state->gstate->domain->name, nt_errstr(status)); + domain->name, nt_errstr(status)); state->gstate->num_groups = 0; } diff --git a/source3/winbindd/winbindd.h b/source3/winbindd/winbindd.h index fb6e10b02d1..8af4246c4d3 100644 --- a/source3/winbindd/winbindd.h +++ b/source3/winbindd/winbindd.h @@ -103,7 +103,7 @@ struct getpwent_state { }; struct getgrent_state { - struct winbindd_domain *domain; + struct winbindd_domain_ref domain; uint32_t next_group; uint32_t num_groups; struct wbint_Principal *groups;