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_getgrsid_state
{
25 struct tevent_context
*ev
;
30 enum lsa_SidType type
;
32 struct talloc_dict
*members
;
35 static void wb_getgrsid_lookupsid_done(struct tevent_req
*subreq
);
36 static void wb_getgrsid_sid2gid_done(struct tevent_req
*subreq
);
37 static void wb_getgrsid_got_members(struct tevent_req
*subreq
);
39 struct tevent_req
*wb_getgrsid_send(TALLOC_CTX
*mem_ctx
,
40 struct tevent_context
*ev
,
41 const struct dom_sid
*group_sid
,
44 struct tevent_req
*req
, *subreq
;
45 struct wb_getgrsid_state
*state
;
47 req
= tevent_req_create(mem_ctx
, &state
, struct wb_getgrsid_state
);
51 sid_copy(&state
->sid
, group_sid
);
53 state
->max_nesting
= max_nesting
;
55 subreq
= wb_lookupsid_send(state
, ev
, &state
->sid
);
56 if (tevent_req_nomem(subreq
, req
)) {
57 return tevent_req_post(req
, ev
);
59 tevent_req_set_callback(subreq
, wb_getgrsid_lookupsid_done
, req
);
63 static void wb_getgrsid_lookupsid_done(struct tevent_req
*subreq
)
65 struct tevent_req
*req
= tevent_req_callback_data(
66 subreq
, struct tevent_req
);
67 struct wb_getgrsid_state
*state
= tevent_req_data(
68 req
, struct wb_getgrsid_state
);
71 status
= wb_lookupsid_recv(subreq
, state
, &state
->type
,
72 &state
->domname
, &state
->name
);
74 if (!NT_STATUS_IS_OK(status
)) {
75 tevent_req_nterror(req
, status
);
79 switch (state
->type
) {
80 case SID_NAME_DOM_GRP
:
82 case SID_NAME_WKN_GRP
:
85 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_GROUP
);
89 subreq
= wb_sid2gid_send(state
, state
->ev
, &state
->sid
);
90 if (tevent_req_nomem(subreq
, req
)) {
93 tevent_req_set_callback(subreq
, wb_getgrsid_sid2gid_done
, req
);
96 static void wb_getgrsid_sid2gid_done(struct tevent_req
*subreq
)
98 struct tevent_req
*req
= tevent_req_callback_data(
99 subreq
, struct tevent_req
);
100 struct wb_getgrsid_state
*state
= tevent_req_data(
101 req
, struct wb_getgrsid_state
);
104 status
= wb_sid2gid_recv(subreq
, &state
->gid
);
106 if (!NT_STATUS_IS_OK(status
)) {
107 tevent_req_nterror(req
, status
);
110 subreq
= wb_group_members_send(state
, state
->ev
, &state
->sid
,
111 state
->type
, state
->max_nesting
);
112 if (tevent_req_nomem(subreq
, req
)) {
115 tevent_req_set_callback(subreq
, wb_getgrsid_got_members
, req
);
118 static void wb_getgrsid_got_members(struct tevent_req
*subreq
)
120 struct tevent_req
*req
= tevent_req_callback_data(
121 subreq
, struct tevent_req
);
122 struct wb_getgrsid_state
*state
= tevent_req_data(
123 req
, struct wb_getgrsid_state
);
126 status
= wb_group_members_recv(subreq
, state
, &state
->members
);
128 if (!NT_STATUS_IS_OK(status
)) {
129 tevent_req_nterror(req
, status
);
132 tevent_req_done(req
);
135 NTSTATUS
wb_getgrsid_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
136 const char **domname
, const char **name
, gid_t
*gid
,
137 struct talloc_dict
**members
)
139 struct wb_getgrsid_state
*state
= tevent_req_data(
140 req
, struct wb_getgrsid_state
);
143 if (tevent_req_is_nterror(req
, &status
)) {
146 *domname
= talloc_move(mem_ctx
, &state
->domname
);
147 *name
= talloc_move(mem_ctx
, &state
->name
);
149 *members
= talloc_move(mem_ctx
, &state
->members
);