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 "passdb/machine_sid.h"
25 struct wb_next_grent_state
{
26 struct tevent_context
*ev
;
28 struct getgrent_state
*gstate
;
29 struct winbindd_gr
*gr
;
30 struct db_context
*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 static void wb_next_grent_send_do(struct tevent_req
*req
,
37 struct wb_next_grent_state
*state
)
39 struct tevent_req
*subreq
;
41 if (state
->gstate
->next_group
>= state
->gstate
->num_groups
) {
42 TALLOC_FREE(state
->gstate
->groups
);
44 state
->gstate
->domain
= wb_next_domain(state
->gstate
->domain
);
45 if (state
->gstate
->domain
== NULL
) {
46 tevent_req_nterror(req
, NT_STATUS_NO_MORE_ENTRIES
);
50 subreq
= wb_query_group_list_send(state
, state
->ev
,
51 state
->gstate
->domain
);
52 if (tevent_req_nomem(subreq
, req
)) {
55 tevent_req_set_callback(subreq
, wb_next_grent_fetch_done
, req
);
59 subreq
= wb_getgrsid_send(
61 &state
->gstate
->groups
[state
->gstate
->next_group
].sid
,
63 if (tevent_req_nomem(subreq
, req
)) {
66 tevent_req_set_callback(subreq
, wb_next_grent_getgrsid_done
, req
);
69 struct tevent_req
*wb_next_grent_send(TALLOC_CTX
*mem_ctx
,
70 struct tevent_context
*ev
,
72 struct getgrent_state
*gstate
,
73 struct winbindd_gr
*gr
)
75 struct tevent_req
*req
;
76 struct wb_next_grent_state
*state
;
78 req
= tevent_req_create(mem_ctx
, &state
, struct wb_next_grent_state
);
83 D_INFO("WB command next_grent start.\n");
86 state
->gstate
= gstate
;
88 state
->max_nesting
= max_nesting
;
90 wb_next_grent_send_do(req
, state
);
91 if (!tevent_req_is_in_progress(req
)) {
92 return tevent_req_post(req
, ev
);
98 static void wb_next_grent_fetch_done(struct tevent_req
*subreq
)
100 struct tevent_req
*req
= tevent_req_callback_data(
101 subreq
, struct tevent_req
);
102 struct wb_next_grent_state
*state
= tevent_req_data(
103 req
, struct wb_next_grent_state
);
106 status
= wb_query_group_list_recv(subreq
, state
->gstate
,
107 &state
->gstate
->num_groups
,
108 &state
->gstate
->groups
);
110 if (!NT_STATUS_IS_OK(status
)) {
111 /* Ignore errors here, just log it */
112 D_DEBUG("query_group_list for domain %s returned %s\n",
113 state
->gstate
->domain
->name
, nt_errstr(status
));
114 state
->gstate
->num_groups
= 0;
117 state
->gstate
->next_group
= 0;
119 wb_next_grent_send_do(req
, state
);
122 static void wb_next_grent_getgrsid_done(struct tevent_req
*subreq
)
124 struct tevent_req
*req
= tevent_req_callback_data(
125 subreq
, struct tevent_req
);
126 struct wb_next_grent_state
*state
= tevent_req_data(
127 req
, struct wb_next_grent_state
);
128 const char *domname
, *name
;
131 status
= wb_getgrsid_recv(subreq
, talloc_tos(), &domname
, &name
,
132 &state
->gr
->gr_gid
, &state
->members
);
135 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
136 state
->gstate
->next_group
+= 1;
138 wb_next_grent_send_do(req
, state
);
141 } else if (tevent_req_nterror(req
, status
)) {
145 if (!fill_grent(talloc_tos(), state
->gr
, domname
, name
,
146 state
->gr
->gr_gid
)) {
147 D_WARNING("fill_grent failed\n");
148 tevent_req_nterror(req
, NT_STATUS_NO_MEMORY
);
151 state
->gstate
->next_group
+= 1;
152 tevent_req_done(req
);
155 NTSTATUS
wb_next_grent_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
156 struct db_context
**members
)
158 struct wb_next_grent_state
*state
= tevent_req_data(
159 req
, struct wb_next_grent_state
);
162 D_INFO("WB command next_grent end.\n");
163 if (tevent_req_is_nterror(req
, &status
)) {
164 D_WARNING("Failed with %s.\n", nt_errstr(status
));
167 *members
= talloc_move(mem_ctx
, &state
->members
);