2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_SIDS_TO_XIDS
4 Copyright (C) Volker Lendecke 2011
5 Copyright (C) Michael Adam 2012
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "../libcli/security/security.h"
26 struct winbindd_sids_to_xids_state
{
27 struct tevent_context
*ev
;
33 static void winbindd_sids_to_xids_done(struct tevent_req
*subreq
);
35 struct tevent_req
*winbindd_sids_to_xids_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_sids_to_xids_state
*state
;
43 req
= tevent_req_create(mem_ctx
, &state
,
44 struct winbindd_sids_to_xids_state
);
50 D_NOTICE("[%s (%u)] Winbind external command SIDS_TO_XIDS start.\n",
52 (unsigned int)cli
->pid
);
54 if (request
->extra_len
== 0) {
56 return tevent_req_post(req
, ev
);
58 if (request
->extra_data
.data
[request
->extra_len
-1] != '\0') {
59 D_DEBUG("Got invalid sids list\n");
60 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
61 return tevent_req_post(req
, ev
);
63 if (!parse_sidlist(state
, request
->extra_data
.data
,
64 &state
->sids
, &state
->num_sids
)) {
65 D_DEBUG("parse_sidlist failed\n");
66 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
67 return tevent_req_post(req
, ev
);
70 D_DEBUG("Resolving %"PRIu32
" SID(s).\n", state
->num_sids
);
72 subreq
= wb_sids2xids_send(state
, ev
, state
->sids
, state
->num_sids
);
73 if (tevent_req_nomem(subreq
, req
)) {
74 return tevent_req_post(req
, ev
);
77 tevent_req_set_callback(subreq
, winbindd_sids_to_xids_done
, req
);
81 static void winbindd_sids_to_xids_done(struct tevent_req
*subreq
)
83 struct tevent_req
*req
= tevent_req_callback_data(
84 subreq
, struct tevent_req
);
85 struct winbindd_sids_to_xids_state
*state
= tevent_req_data(
86 req
, struct winbindd_sids_to_xids_state
);
89 state
->xids
= talloc_zero_array(state
, struct unixid
, state
->num_sids
);
90 if (tevent_req_nomem(state
->xids
, req
)) {
94 status
= wb_sids2xids_recv(subreq
, state
->xids
, state
->num_sids
);
96 if (tevent_req_nterror(req
, status
)) {
102 NTSTATUS
winbindd_sids_to_xids_recv(struct tevent_req
*req
,
103 struct winbindd_response
*response
)
105 struct winbindd_sids_to_xids_state
*state
= tevent_req_data(
106 req
, struct winbindd_sids_to_xids_state
);
111 D_NOTICE("Winbind external command SIDS_TO_XIDS end.\n");
112 if (tevent_req_is_nterror(req
, &status
)) {
113 D_WARNING("Could not convert sids: %s\n", nt_errstr(status
));
117 result
= talloc_strdup(response
, "");
119 for (i
=0; i
<state
->num_sids
; i
++) {
124 xid
= state
->xids
[i
];
141 if (xid
.id
== UINT32_MAX
) {
146 talloc_asprintf_addbuf(
150 (unsigned long)xid
.id
);
152 talloc_asprintf_addbuf(&result
, "\n");
156 if (result
== NULL
) {
157 return NT_STATUS_NO_MEMORY
;
160 response
->extra_data
.data
= result
;
161 response
->length
+= talloc_get_size(result
);