s3-winbind: Fix segfault if we can't map the last user.
[samba.git] / source3 / winbindd / wb_next_pwent.c
index 998830952b296bdbab25fd7193edf2b6a89fa47a..8104568d7acfb6303aae48afde8850cfebeaba8f 100644 (file)
@@ -165,6 +165,24 @@ 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_find_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],