2 Unix SMB/CIFS implementation.
4 Copyright (C) Pavel Filipenský 2023
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/security.h"
25 struct wb_alias_members_state
{
26 struct tevent_context
*ev
;
28 struct wbint_SidArray sids
;
31 static void wb_alias_members_done(struct tevent_req
*subreq
);
33 struct tevent_req
*wb_alias_members_send(TALLOC_CTX
*mem_ctx
,
34 struct tevent_context
*ev
,
35 const struct dom_sid
*sid
,
36 enum lsa_SidType type
,
39 struct tevent_req
*req
, *subreq
;
40 struct wb_alias_members_state
*state
;
41 struct winbindd_domain
*domain
;
43 struct dom_sid_buf buf
;
45 req
= tevent_req_create(mem_ctx
, &state
, struct wb_alias_members_state
);
49 D_INFO("WB command alias_members start.\nLooking up SID %s.\n",
50 dom_sid_str_buf(sid
, &buf
));
52 if (max_nesting
<= 0) {
53 D_DEBUG("Finished. The depth based on 'winbind expand groups' is %d.\n", max_nesting
);
54 state
->sids
.num_sids
= 0;
55 state
->sids
.sids
= NULL
;
57 return tevent_req_post(req
, ev
);
60 sid_copy(&state
->sid
, sid
);
62 status
= lookup_usergroups_cached(state
,
64 &state
->sids
.num_sids
,
66 if (NT_STATUS_IS_OK(status
)) {
68 return tevent_req_post(req
, ev
);
71 domain
= find_domain_from_sid_noinit(&state
->sid
);
73 DBG_WARNING("could not find domain entry for sid %s\n",
74 dom_sid_str_buf(&state
->sid
, &buf
));
75 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_ALIAS
);
76 return tevent_req_post(req
, ev
);
79 subreq
= dcerpc_wbint_LookupAliasMembers_send(state
,
81 dom_child_handle(domain
),
85 if (tevent_req_nomem(subreq
, req
)) {
86 return tevent_req_post(req
, ev
);
88 tevent_req_set_callback(subreq
, wb_alias_members_done
, req
);
92 static void wb_alias_members_done(struct tevent_req
*subreq
)
94 struct tevent_req
*req
=
95 tevent_req_callback_data(subreq
, struct tevent_req
);
96 struct wb_alias_members_state
*state
=
97 tevent_req_data(req
, struct wb_alias_members_state
);
98 NTSTATUS status
, result
;
100 status
= dcerpc_wbint_LookupAliasMembers_recv(subreq
, state
, &result
);
102 if (any_nt_status_not_ok(status
, result
, &status
)) {
103 D_WARNING("Failed with %s.\n", nt_errstr(status
));
104 tevent_req_nterror(req
, status
);
107 tevent_req_done(req
);
110 NTSTATUS
wb_alias_members_recv(struct tevent_req
*req
,
113 struct dom_sid
**sids
)
115 struct wb_alias_members_state
*state
=
116 tevent_req_data(req
, struct wb_alias_members_state
);
120 if (tevent_req_is_nterror(req
, &status
)) {
123 *num_sids
= state
->sids
.num_sids
;
124 *sids
= talloc_move(mem_ctx
, &state
->sids
.sids
);
126 D_INFO("WB command alias_members end.\nReceived %" PRIu32
" SID(s).\n",
128 if (CHECK_DEBUGLVL(DBGLVL_INFO
)) {
129 for (i
= 0; i
< *num_sids
; i
++) {
130 struct dom_sid_buf buf
;
131 D_INFO("%" PRIu32
": %s\n",
133 dom_sid_str_buf(&(*sids
)[i
], &buf
));