]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
winbindd: use struct winbindd_domain_ref in struct getgrent_state
authorStefan Metzmacher <metze@samba.org>
Fri, 7 Feb 2025 12:57:45 +0000 (13:57 +0100)
committerRalph Boehme <slow@samba.org>
Sat, 8 Feb 2025 15:26:38 +0000 (15:26 +0000)
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 <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/winbindd/wb_next_grent.c
source3/winbindd/winbindd.h

index 5c2d447f46f6ce2de54f50e56bfb76de4d067ddf..99586ac26412d816e69dd307c75a7e249b2ad645 100644 (file)
@@ -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;
        }
 
index fb6e10b02d1f3b77be5d99a944d653eb1d6cfe00..8af4246c4d323598914dce63a3fc398eb98f47d9 100644 (file)
@@ -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;