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_xids_to_sids_state
{
27 struct tevent_context
*ev
;
35 static void winbindd_xids_to_sids_done(struct tevent_req
*subreq
);
37 struct tevent_req
*winbindd_xids_to_sids_send(TALLOC_CTX
*mem_ctx
,
38 struct tevent_context
*ev
,
39 struct winbindd_cli_state
*cli
,
40 struct winbindd_request
*request
)
42 struct tevent_req
*req
, *subreq
;
43 struct winbindd_xids_to_sids_state
*state
;
45 req
= tevent_req_create(mem_ctx
, &state
,
46 struct winbindd_xids_to_sids_state
);
52 DEBUG(3, ("xids_to_sids\n"));
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 DEBUG(10, ("Got invalid xids list\n"));
60 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
61 return tevent_req_post(req
, ev
);
63 if (!parse_xidlist(state
, request
->extra_data
.data
,
64 &state
->xids
, &state
->num_xids
)) {
65 DEBUG(10, ("parse_sidlist failed\n"));
66 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
67 return tevent_req_post(req
, ev
);
70 DEBUG(10, ("num_xids: %d\n", (int)state
->num_xids
));
72 subreq
= wb_xids2sids_send(state
, ev
, state
->xids
, state
->num_xids
);
73 if (tevent_req_nomem(subreq
, req
)) {
74 return tevent_req_post(req
, ev
);
76 tevent_req_set_callback(subreq
, winbindd_xids_to_sids_done
, req
);
80 static void winbindd_xids_to_sids_done(struct tevent_req
*subreq
)
82 struct tevent_req
*req
= tevent_req_callback_data(
83 subreq
, struct tevent_req
);
84 struct winbindd_xids_to_sids_state
*state
= tevent_req_data(
85 req
, struct winbindd_xids_to_sids_state
);
88 status
= wb_xids2sids_recv(subreq
, state
, &state
->sids
);
90 if (tevent_req_nterror(req
, status
)) {
96 NTSTATUS
winbindd_xids_to_sids_recv(struct tevent_req
*req
,
97 struct winbindd_response
*response
)
99 struct winbindd_xids_to_sids_state
*state
= tevent_req_data(
100 req
, struct winbindd_xids_to_sids_state
);
105 if (tevent_req_is_nterror(req
, &status
)) {
106 DEBUG(5, ("Could not convert sids: %s\n", nt_errstr(status
)));
110 result
= talloc_strdup(response
, "");
111 if (result
== NULL
) {
112 return NT_STATUS_NO_MEMORY
;
115 for (i
=0; i
<state
->num_xids
; i
++) {
116 char sidbuf
[DOM_SID_STR_BUFLEN
];
118 if (is_null_sid(&state
->sids
[i
])) {
119 strlcpy(sidbuf
, "-", sizeof(sidbuf
));
121 dom_sid_string_buf(&state
->sids
[i
],
122 sidbuf
, sizeof(sidbuf
));
125 result
= talloc_asprintf_append_buffer(
126 result
, "%s\n", sidbuf
);
127 if (result
== NULL
) {
128 return NT_STATUS_NO_MEMORY
;
132 response
->extra_data
.data
= result
;
133 response
->length
+= talloc_get_size(result
);