2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_GETSIDALIASES
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 "../libcli/security/security.h"
24 struct winbindd_getsidaliases_state
{
30 static void winbindd_getsidaliases_done(struct tevent_req
*subreq
);
32 struct tevent_req
*winbindd_getsidaliases_send(TALLOC_CTX
*mem_ctx
,
33 struct tevent_context
*ev
,
34 struct winbindd_cli_state
*cli
,
35 struct winbindd_request
*request
)
37 struct tevent_req
*req
, *subreq
;
38 struct winbindd_getsidaliases_state
*state
;
39 struct winbindd_domain
*domain
;
43 req
= tevent_req_create(mem_ctx
, &state
,
44 struct winbindd_getsidaliases_state
);
49 /* Ensure null termination */
50 request
->data
.sid
[sizeof(request
->data
.sid
)-1]='\0';
52 if (!string_to_sid(&state
->sid
, request
->data
.sid
)) {
53 D_WARNING("Could not get convert sid %s from string\n",
55 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
56 return tevent_req_post(req
, ev
);
59 domain
= find_domain_from_sid_noinit(&state
->sid
);
61 D_WARNING("could not find domain entry for sid %s\n",
63 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
64 return tevent_req_post(req
, ev
);
70 if (request
->extra_data
.data
!= NULL
) {
71 if (request
->extra_data
.data
[request
->extra_len
-1] != '\0') {
72 D_WARNING("Got non-NULL terminated sidlist\n");
73 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
74 return tevent_req_post(req
, ev
);
76 if (!parse_sidlist(state
, request
->extra_data
.data
,
78 D_WARNING("Could not parse SID list: %s\n",
79 request
->extra_data
.data
);
80 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
81 return tevent_req_post(req
, ev
);
85 D_NOTICE("[%s (%u)] Winbind external command GETSIDALIASES start.\n"
88 (unsigned int)cli
->pid
,
90 if (CHECK_DEBUGLVL(DBGLVL_DEBUG
)) {
91 for (i
= 0; i
< num_sids
; i
++) {
92 struct dom_sid_buf sidstr
;
93 D_NOTICE("%"PRIu32
": %s\n",
94 i
, dom_sid_str_buf(&sids
[i
], &sidstr
));
98 subreq
= wb_lookupuseraliases_send(state
, ev
, domain
, num_sids
, sids
);
99 if (tevent_req_nomem(subreq
, req
)) {
100 return tevent_req_post(req
, ev
);
102 tevent_req_set_callback(subreq
, winbindd_getsidaliases_done
, req
);
106 static void winbindd_getsidaliases_done(struct tevent_req
*subreq
)
108 struct tevent_req
*req
= tevent_req_callback_data(
109 subreq
, struct tevent_req
);
110 struct winbindd_getsidaliases_state
*state
= tevent_req_data(
111 req
, struct winbindd_getsidaliases_state
);
114 status
= wb_lookupuseraliases_recv(subreq
, state
, &state
->num_aliases
,
117 if (tevent_req_nterror(req
, status
)) {
120 tevent_req_done(req
);
123 NTSTATUS
winbindd_getsidaliases_recv(struct tevent_req
*req
,
124 struct winbindd_response
*response
)
126 struct winbindd_getsidaliases_state
*state
= tevent_req_data(
127 req
, struct winbindd_getsidaliases_state
);
132 if (tevent_req_is_nterror(req
, &status
)) {
133 D_WARNING("Failed with %s.\n", nt_errstr(status
));
137 sidlist
= talloc_strdup(response
, "");
139 D_NOTICE("Winbind external command GETSIDALIASES end.\n"
140 "Received %"PRIu32
" alias(es).\n",
142 for (i
=0; i
<state
->num_aliases
; i
++) {
144 struct dom_sid_buf tmp
;
145 sid_compose(&sid
, &state
->sid
, state
->aliases
[i
]);
147 talloc_asprintf_addbuf(
148 &sidlist
, "%s\n", dom_sid_str_buf(&sid
, &tmp
));
149 D_NOTICE("%"PRIu32
": %s\n", i
, dom_sid_str_buf(&sid
, &tmp
));
152 if (sidlist
== NULL
) {
153 return NT_STATUS_NO_MEMORY
;
156 response
->extra_data
.data
= sidlist
;
157 response
->length
+= talloc_get_size(sidlist
);
158 response
->data
.num_entries
= state
->num_aliases
;