2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_LOOKUPSIDS
4 Copyright (C) Volker Lendecke 2011
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_lookupsids_state
{
27 struct lsa_RefDomainList
*domains
;
28 struct lsa_TransNameArray
*names
;
31 static void winbindd_lookupsids_done(struct tevent_req
*subreq
);
33 struct tevent_req
*winbindd_lookupsids_send(TALLOC_CTX
*mem_ctx
,
34 struct tevent_context
*ev
,
35 struct winbindd_cli_state
*cli
,
36 struct winbindd_request
*request
)
38 struct tevent_req
*req
, *subreq
;
39 struct winbindd_lookupsids_state
*state
;
41 req
= tevent_req_create(mem_ctx
, &state
,
42 struct winbindd_lookupsids_state
);
47 DEBUG(3, ("lookupsids\n"));
49 if (request
->extra_len
== 0) {
51 return tevent_req_post(req
, ev
);
53 if (request
->extra_data
.data
[request
->extra_len
-1] != '\0') {
54 DEBUG(10, ("Got invalid sids list\n"));
55 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
56 return tevent_req_post(req
, ev
);
58 if (!parse_sidlist(state
, request
->extra_data
.data
,
59 &state
->sids
, &state
->num_sids
)) {
60 DEBUG(10, ("parse_sidlist failed\n"));
61 tevent_req_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
62 return tevent_req_post(req
, ev
);
64 subreq
= wb_lookupsids_send(state
, ev
, state
->sids
, state
->num_sids
);
65 if (tevent_req_nomem(subreq
, req
)) {
66 return tevent_req_post(req
, ev
);
68 tevent_req_set_callback(subreq
, winbindd_lookupsids_done
, req
);
72 static void winbindd_lookupsids_done(struct tevent_req
*subreq
)
74 struct tevent_req
*req
= tevent_req_callback_data(
75 subreq
, struct tevent_req
);
76 struct winbindd_lookupsids_state
*state
= tevent_req_data(
77 req
, struct winbindd_lookupsids_state
);
80 status
= wb_lookupsids_recv(subreq
, state
, &state
->domains
,
83 if (tevent_req_nterror(req
, status
)) {
89 NTSTATUS
winbindd_lookupsids_recv(struct tevent_req
*req
,
90 struct winbindd_response
*response
)
92 struct winbindd_lookupsids_state
*state
= tevent_req_data(
93 req
, struct winbindd_lookupsids_state
);
98 if (tevent_req_is_nterror(req
, &status
)) {
99 DEBUG(5, ("wb_lookupsids failed: %s\n", nt_errstr(status
)));
103 result
= talloc_asprintf(response
, "%d\n", (int)state
->domains
->count
);
104 if (result
== NULL
) {
105 return NT_STATUS_NO_MEMORY
;
108 for (i
=0; i
<state
->domains
->count
; i
++) {
109 struct dom_sid_buf sid_str
;
111 result
= talloc_asprintf_append_buffer(
113 dom_sid_str_buf(state
->domains
->domains
[i
].sid
,
115 state
->domains
->domains
[i
].name
.string
);
116 if (result
== NULL
) {
117 return NT_STATUS_NO_MEMORY
;
121 result
= talloc_asprintf_append_buffer(
122 result
, "%d\n", (int)state
->names
->count
);
123 if (result
== NULL
) {
124 return NT_STATUS_NO_MEMORY
;
127 for (i
=0; i
<state
->names
->count
; i
++) {
128 struct lsa_TranslatedName
*name
;
130 name
= &state
->names
->names
[i
];
132 result
= talloc_asprintf_append_buffer(
133 result
, "%d %d %s\n",
134 (int)name
->sid_index
, (int)name
->sid_type
,
136 if (result
== NULL
) {
137 return NT_STATUS_NO_MEMORY
;
141 response
->extra_data
.data
= result
;
142 response
->length
+= talloc_get_size(result
);