2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETGRGID
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/>.
23 struct winbindd_getgrgid_state {
24 struct tevent_context *ev;
29 struct talloc_dict *members;
32 static void winbindd_getgrgid_gid2sid_done(struct tevent_req *subreq);
33 static void winbindd_getgrgid_done(struct tevent_req *subreq);
35 struct tevent_req *winbindd_getgrgid_send(TALLOC_CTX *mem_ctx,
36 struct tevent_context *ev,
37 struct winbindd_cli_state *cli,
38 struct winbindd_request *request)
40 struct tevent_req *req, *subreq;
41 struct winbindd_getgrgid_state *state;
43 req = tevent_req_create(mem_ctx, &state,
44 struct winbindd_getgrgid_state);
50 DEBUG(3, ("getgrgid %d\n", (int)request->data.gid));
52 subreq = wb_gid2sid_send(state, ev, request->data.gid);
53 if (tevent_req_nomem(subreq, req)) {
54 return tevent_req_post(req, ev);
56 tevent_req_set_callback(subreq, winbindd_getgrgid_gid2sid_done,
61 static void winbindd_getgrgid_gid2sid_done(struct tevent_req *subreq)
63 struct tevent_req *req = tevent_req_callback_data(
64 subreq, struct tevent_req);
65 struct winbindd_getgrgid_state *state = tevent_req_data(
66 req, struct winbindd_getgrgid_state);
69 status = wb_gid2sid_recv(subreq, &state->sid);
71 if (tevent_req_nterror(req, status)) {
75 subreq = wb_getgrsid_send(state, state->ev, &state->sid,
76 lp_winbind_expand_groups());
77 if (tevent_req_nomem(subreq, req)) {
80 tevent_req_set_callback(subreq, winbindd_getgrgid_done, req);
83 static void winbindd_getgrgid_done(struct tevent_req *subreq)
85 struct tevent_req *req = tevent_req_callback_data(
86 subreq, struct tevent_req);
87 struct winbindd_getgrgid_state *state = tevent_req_data(
88 req, struct winbindd_getgrgid_state);
91 status = wb_getgrsid_recv(subreq, state, &state->domname, &state->name,
92 &state->gid, &state->members);
94 if (tevent_req_nterror(req, status)) {
100 NTSTATUS winbindd_getgrgid_recv(struct tevent_req *req,
101 struct winbindd_response *response)
103 struct winbindd_getgrgid_state *state = tevent_req_data(
104 req, struct winbindd_getgrgid_state);
109 if (tevent_req_is_nterror(req, &status)) {
110 DEBUG(5, ("Could not convert sid %s: %s\n",
111 sid_string_dbg(&state->sid), nt_errstr(status)));
115 if (!fill_grent(talloc_tos(), &response->data.gr, state->domname,
116 state->name, state->gid)) {
117 DEBUG(5, ("fill_grent failed\n"));
118 return NT_STATUS_NO_MEMORY;
121 status = winbindd_print_groupmembers(state->members, response,
123 if (!NT_STATUS_IS_OK(status)) {
127 response->data.gr.num_gr_mem = (uint32)num_members;
129 /* Group membership lives at start of extra data */
131 response->data.gr.gr_mem_ofs = 0;
132 response->extra_data.data = buf;
133 response->length += talloc_get_size(response->extra_data.data);