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/cli_wbint.h"
24 struct wb_next_grent_state
{
25 struct tevent_context
*ev
;
27 struct getgrent_state
*gstate
;
28 struct wbint_Principals next_groups
;
29 struct winbindd_gr
*gr
;
30 struct talloc_dict
*members
;
33 static void wb_next_grent_fetch_done(struct tevent_req
*subreq
);
34 static void wb_next_grent_getgrsid_done(struct tevent_req
*subreq
);
36 struct tevent_req
*wb_next_grent_send(TALLOC_CTX
*mem_ctx
,
37 struct tevent_context
*ev
,
39 struct getgrent_state
*gstate
,
40 struct winbindd_gr
*gr
)
42 struct tevent_req
*req
, *subreq
;
43 struct wb_next_grent_state
*state
;
45 req
= tevent_req_create(mem_ctx
, &state
, struct wb_next_grent_state
);
50 state
->gstate
= gstate
;
53 if (state
->gstate
->next_group
>= state
->gstate
->num_groups
) {
54 TALLOC_FREE(state
->gstate
->groups
);
56 if (state
->gstate
->domain
== NULL
) {
57 state
->gstate
->domain
= domain_list();
59 state
->gstate
->domain
= state
->gstate
->domain
->next
;
62 if (state
->gstate
->domain
== NULL
) {
63 tevent_req_nterror(req
, NT_STATUS_NO_MORE_ENTRIES
);
64 return tevent_req_post(req
, ev
);
66 subreq
= rpccli_wbint_QueryGroupList_send(
67 state
, state
->ev
, state
->gstate
->domain
->child
.rpccli
,
69 if (tevent_req_nomem(subreq
, req
)) {
70 return tevent_req_post(req
, ev
);
72 tevent_req_set_callback(subreq
, wb_next_grent_fetch_done
, req
);
76 subreq
= wb_getgrsid_send(
78 &state
->gstate
->groups
[state
->gstate
->next_group
].sid
,
80 if (tevent_req_nomem(subreq
, req
)) {
81 return tevent_req_post(req
, ev
);
83 tevent_req_set_callback(subreq
, wb_next_grent_getgrsid_done
, req
);
87 static void wb_next_grent_fetch_done(struct tevent_req
*subreq
)
89 struct tevent_req
*req
= tevent_req_callback_data(
90 subreq
, struct tevent_req
);
91 struct wb_next_grent_state
*state
= tevent_req_data(
92 req
, struct wb_next_grent_state
);
93 NTSTATUS status
, result
;
95 status
= rpccli_wbint_QueryGroupList_recv(subreq
, state
, &result
);
97 if (!NT_STATUS_IS_OK(status
) || !NT_STATUS_IS_OK(result
)) {
98 /* Ignore errors here, just log it */
99 DEBUG(10, ("query_user_list for domain %s returned %s/%s\n",
100 state
->gstate
->domain
->name
,
101 nt_errstr(status
), nt_errstr(result
)));
102 tevent_req_nterror(req
, result
);
106 state
->gstate
->num_groups
= state
->next_groups
.num_principals
;
107 state
->gstate
->groups
= talloc_move(
108 state
->gstate
, &state
->next_groups
.principals
);
110 if (state
->gstate
->num_groups
== 0) {
111 state
->gstate
->domain
= state
->gstate
->domain
->next
;
112 if (state
->gstate
->domain
== NULL
) {
113 tevent_req_nterror(req
, NT_STATUS_NO_MORE_ENTRIES
);
116 subreq
= rpccli_wbint_QueryGroupList_send(
117 state
, state
->ev
, state
->gstate
->domain
->child
.rpccli
,
118 &state
->next_groups
);
119 if (tevent_req_nomem(subreq
, req
)) {
122 tevent_req_set_callback(subreq
, wb_next_grent_fetch_done
, req
);
126 state
->gstate
->next_group
= 0;
128 subreq
= wb_getgrsid_send(
130 &state
->gstate
->groups
[state
->gstate
->next_group
].sid
,
132 if (tevent_req_nomem(subreq
, req
)) {
135 tevent_req_set_callback(subreq
, wb_next_grent_getgrsid_done
, req
);
139 static void wb_next_grent_getgrsid_done(struct tevent_req
*subreq
)
141 struct tevent_req
*req
= tevent_req_callback_data(
142 subreq
, struct tevent_req
);
143 struct wb_next_grent_state
*state
= tevent_req_data(
144 req
, struct wb_next_grent_state
);
145 const char *domname
, *name
;
148 status
= wb_getgrsid_recv(subreq
, talloc_tos(), &domname
, &name
,
149 &state
->gr
->gr_gid
, &state
->members
);
151 if (!NT_STATUS_IS_OK(status
)) {
152 tevent_req_nterror(req
, status
);
155 if (!fill_grent(talloc_tos(), state
->gr
, domname
, name
,
156 state
->gr
->gr_gid
)) {
157 DEBUG(5, ("fill_grent failed\n"));
158 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
161 state
->gstate
->next_group
+= 1;
162 tevent_req_done(req
);
165 NTSTATUS
wb_next_grent_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
166 struct talloc_dict
**members
)
168 struct wb_next_grent_state
*state
= tevent_req_data(
169 req
, struct wb_next_grent_state
);
172 if (tevent_req_is_nterror(req
, &status
)) {
175 *members
= talloc_move(mem_ctx
, &state
->members
);