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/>.
23 struct winbindd_getsidaliases_state
{
29 static void winbindd_getsidaliases_done(struct tevent_req
*subreq
);
31 struct tevent_req
*winbindd_getsidaliases_send(TALLOC_CTX
*mem_ctx
,
32 struct tevent_context
*ev
,
33 struct winbindd_cli_state
*cli
,
34 struct winbindd_request
*request
)
36 struct tevent_req
*req
, *subreq
;
37 struct winbindd_getsidaliases_state
*state
;
38 struct winbindd_domain
*domain
;
42 req
= tevent_req_create(mem_ctx
, &state
,
43 struct winbindd_getsidaliases_state
);
48 /* Ensure null termination */
49 request
->data
.sid
[sizeof(request
->data
.sid
)-1]='\0';
51 DEBUG(3, ("getsidaliases %s\n", request
->data
.sid
));
53 if (!string_to_sid(&state
->sid
, request
->data
.sid
)) {
54 DEBUG(1, ("Could not get convert sid %s from string\n",
56 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
57 return tevent_req_post(req
, ev
);
60 domain
= find_domain_from_sid_noinit(&state
->sid
);
62 DEBUG(1,("could not find domain entry for sid %s\n",
64 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
65 return tevent_req_post(req
, ev
);
71 if ((request
->extra_data
.data
!= NULL
)
72 && !parse_sidlist(state
, request
->extra_data
.data
,
74 DEBUG(1, ("Could not parse SID list: %s\n",
75 request
->extra_data
.data
));
76 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
77 return tevent_req_post(req
, ev
);
80 subreq
= wb_lookupuseraliases_send(state
, ev
, domain
, num_sids
, sids
);
81 if (tevent_req_nomem(subreq
, req
)) {
82 return tevent_req_post(req
, ev
);
84 tevent_req_set_callback(subreq
, winbindd_getsidaliases_done
, req
);
88 static void winbindd_getsidaliases_done(struct tevent_req
*subreq
)
90 struct tevent_req
*req
= tevent_req_callback_data(
91 subreq
, struct tevent_req
);
92 struct winbindd_getsidaliases_state
*state
= tevent_req_data(
93 req
, struct winbindd_getsidaliases_state
);
96 status
= wb_lookupuseraliases_recv(subreq
, state
, &state
->num_aliases
,
99 if (!NT_STATUS_IS_OK(status
)) {
100 tevent_req_nterror(req
, status
);
103 tevent_req_done(req
);
106 NTSTATUS
winbindd_getsidaliases_recv(struct tevent_req
*req
,
107 struct winbindd_response
*response
)
109 struct winbindd_getsidaliases_state
*state
= tevent_req_data(
110 req
, struct winbindd_getsidaliases_state
);
115 if (tevent_req_is_nterror(req
, &status
)) {
119 sidlist
= talloc_strdup(response
, "");
120 if (sidlist
== NULL
) {
121 return NT_STATUS_NO_MEMORY
;
123 for (i
=0; i
<state
->num_aliases
; i
++) {
126 sid_compose(&sid
, &state
->sid
, state
->aliases
[i
]);
128 sidlist
= talloc_asprintf_append_buffer(
129 sidlist
, "%s\n", sid_to_fstring(tmp
, &sid
));
130 if (sidlist
== NULL
) {
131 return NT_STATUS_NO_MEMORY
;
134 response
->extra_data
.data
= sidlist
;
135 response
->length
+= talloc_get_size(sidlist
);
136 response
->data
.num_entries
= state
->num_aliases
;