KCC: kcc.my_site_guid was not really used
[Samba.git] / source3 / winbindd / wb_next_pwent.c
blobaf5e8d9f9aaf9e14d90d133f3d3cdfa1f18c53a6
1 /*
2 Unix SMB/CIFS implementation.
3 async next_pwent
4 Copyright (C) Volker Lendecke 2009
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/ndr_winbind_c.h"
23 #include "passdb/machine_sid.h"
25 struct wb_next_pwent_state {
26 struct tevent_context *ev;
27 struct getpwent_state *gstate;
28 struct winbindd_pw *pw;
31 static void wb_next_pwent_fetch_done(struct tevent_req *subreq);
32 static void wb_next_pwent_fill_done(struct tevent_req *subreq);
34 static void wb_next_pwent_send_do(struct tevent_req *req,
35 struct wb_next_pwent_state *state)
37 struct tevent_req *subreq;
39 if (state->gstate->next_user >= state->gstate->num_users) {
40 TALLOC_FREE(state->gstate->users);
42 state->gstate->domain = wb_next_domain(state->gstate->domain);
43 if (state->gstate->domain == NULL) {
44 tevent_req_nterror(req, NT_STATUS_NO_MORE_ENTRIES);
45 return;
48 subreq = wb_query_user_list_send(state, state->ev,
49 state->gstate->domain);
50 if (tevent_req_nomem(subreq, req)) {
51 return;
54 tevent_req_set_callback(subreq, wb_next_pwent_fetch_done, req);
55 return;
58 subreq = wb_fill_pwent_send(state, state->ev,
59 &state->gstate->users[state->gstate->next_user],
60 state->pw);
61 if (tevent_req_nomem(subreq, req)) {
62 return;
65 tevent_req_set_callback(subreq, wb_next_pwent_fill_done, req);
68 struct tevent_req *wb_next_pwent_send(TALLOC_CTX *mem_ctx,
69 struct tevent_context *ev,
70 struct getpwent_state *gstate,
71 struct winbindd_pw *pw)
73 struct tevent_req *req;
74 struct wb_next_pwent_state *state;
76 req = tevent_req_create(mem_ctx, &state, struct wb_next_pwent_state);
77 if (req == NULL) {
78 return NULL;
80 state->ev = ev;
81 state->gstate = gstate;
82 state->pw = pw;
84 wb_next_pwent_send_do(req, state);
85 if (!tevent_req_is_in_progress(req)) {
86 return tevent_req_post(req, ev);
89 return req;
92 static void wb_next_pwent_fetch_done(struct tevent_req *subreq)
94 struct tevent_req *req = tevent_req_callback_data(
95 subreq, struct tevent_req);
96 struct wb_next_pwent_state *state = tevent_req_data(
97 req, struct wb_next_pwent_state);
98 NTSTATUS status;
100 status = wb_query_user_list_recv(subreq, state->gstate,
101 &state->gstate->num_users,
102 &state->gstate->users);
103 TALLOC_FREE(subreq);
104 if (!NT_STATUS_IS_OK(status)) {
105 /* Ignore errors here, just log it */
106 DEBUG(10, ("query_user_list for domain %s returned %s\n",
107 state->gstate->domain->name,
108 nt_errstr(status)));
109 state->gstate->num_users = 0;
112 state->gstate->next_user = 0;
114 wb_next_pwent_send_do(req, state);
117 static void wb_next_pwent_fill_done(struct tevent_req *subreq)
119 struct tevent_req *req = tevent_req_callback_data(
120 subreq, struct tevent_req);
121 struct wb_next_pwent_state *state = tevent_req_data(
122 req, struct wb_next_pwent_state);
123 NTSTATUS status;
125 status = wb_fill_pwent_recv(subreq);
126 TALLOC_FREE(subreq);
128 * When you try to enumerate users with 'getent passwd' and the user
129 * doesn't have a uid set we should just move on.
131 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
132 state->gstate->next_user += 1;
134 wb_next_pwent_send_do(req, state);
136 return;
137 } else if (tevent_req_nterror(req, status)) {
138 return;
140 state->gstate->next_user += 1;
141 tevent_req_done(req);
144 NTSTATUS wb_next_pwent_recv(struct tevent_req *req)
146 return tevent_req_simple_recv_ntstatus(req);