2 Unix SMB/CIFS implementation.
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/>.
22 #include "librpc/gen_ndr/ndr_winbind_c.h"
23 #include "libcli/security/dom_sid.h"
24 #include "passdb/machine_sid.h"
26 struct wb_next_pwent_state
{
27 struct tevent_context
*ev
;
28 struct getpwent_state
*gstate
;
29 struct dom_sid next_sid
;
30 struct winbindd_pw
*pw
;
33 static void wb_next_pwent_fetch_done(struct tevent_req
*subreq
);
34 static void wb_next_pwent_fill_done(struct tevent_req
*subreq
);
36 static void wb_next_pwent_send_do(struct tevent_req
*req
,
37 struct wb_next_pwent_state
*state
)
39 struct tevent_req
*subreq
;
41 if (state
->gstate
->next_user
>= state
->gstate
->rids
.num_rids
) {
42 TALLOC_FREE(state
->gstate
->rids
.rids
);
43 state
->gstate
->rids
.num_rids
= 0;
45 state
->gstate
->domain
= wb_next_domain(state
->gstate
->domain
);
46 if (state
->gstate
->domain
== NULL
) {
47 tevent_req_nterror(req
, NT_STATUS_NO_MORE_ENTRIES
);
51 subreq
= dcerpc_wbint_QueryUserRidList_send(
53 dom_child_handle(state
->gstate
->domain
),
54 &state
->gstate
->rids
);
55 if (tevent_req_nomem(subreq
, req
)) {
59 tevent_req_set_callback(subreq
, wb_next_pwent_fetch_done
, req
);
63 sid_compose(&state
->next_sid
, &state
->gstate
->domain
->sid
,
64 state
->gstate
->rids
.rids
[state
->gstate
->next_user
]);
66 subreq
= wb_getpwsid_send(state
, state
->ev
, &state
->next_sid
,
68 if (tevent_req_nomem(subreq
, req
)) {
72 tevent_req_set_callback(subreq
, wb_next_pwent_fill_done
, req
);
75 struct tevent_req
*wb_next_pwent_send(TALLOC_CTX
*mem_ctx
,
76 struct tevent_context
*ev
,
77 struct getpwent_state
*gstate
,
78 struct winbindd_pw
*pw
)
80 struct tevent_req
*req
;
81 struct wb_next_pwent_state
*state
;
83 req
= tevent_req_create(mem_ctx
, &state
, struct wb_next_pwent_state
);
88 state
->gstate
= gstate
;
91 wb_next_pwent_send_do(req
, state
);
92 if (!tevent_req_is_in_progress(req
)) {
93 return tevent_req_post(req
, ev
);
99 static void wb_next_pwent_fetch_done(struct tevent_req
*subreq
)
101 struct tevent_req
*req
= tevent_req_callback_data(
102 subreq
, struct tevent_req
);
103 struct wb_next_pwent_state
*state
= tevent_req_data(
104 req
, struct wb_next_pwent_state
);
105 NTSTATUS status
, result
;
107 status
= dcerpc_wbint_QueryUserRidList_recv(subreq
, state
->gstate
,
110 if (any_nt_status_not_ok(status
, result
, &status
)) {
111 /* Ignore errors here, just log it */
112 DEBUG(10, ("query_user_list for domain %s returned %s\n",
113 state
->gstate
->domain
->name
,
115 state
->gstate
->rids
.num_rids
= 0;
118 state
->gstate
->next_user
= 0;
120 wb_next_pwent_send_do(req
, state
);
123 static void wb_next_pwent_fill_done(struct tevent_req
*subreq
)
125 struct tevent_req
*req
= tevent_req_callback_data(
126 subreq
, struct tevent_req
);
127 struct wb_next_pwent_state
*state
= tevent_req_data(
128 req
, struct wb_next_pwent_state
);
131 status
= wb_getpwsid_recv(subreq
);
134 * When you try to enumerate users with 'getent passwd' and the user
135 * doesn't have a uid set we should just move on.
137 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
138 state
->gstate
->next_user
+= 1;
140 wb_next_pwent_send_do(req
, state
);
143 } else if (tevent_req_nterror(req
, status
)) {
146 state
->gstate
->next_user
+= 1;
147 tevent_req_done(req
);
150 NTSTATUS
wb_next_pwent_recv(struct tevent_req
*req
)
152 return tevent_req_simple_recv_ntstatus(req
);