2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_UID_TO_SID
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/dom_sid.h"
24 struct winbindd_uid_to_sid_state {
25 struct tevent_context *ev;
30 static void winbindd_uid_to_sid_done(struct tevent_req *subreq);
32 struct tevent_req *winbindd_uid_to_sid_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_uid_to_sid_state *state;
40 req = tevent_req_create(mem_ctx, &state,
41 struct winbindd_uid_to_sid_state);
47 DEBUG(3, ("uid_to_sid %d\n", (int)request->data.uid));
49 state->xid = (struct unixid) {
50 .id = request->data.uid, .type = ID_TYPE_UID };
52 subreq = wb_xids2sids_send(state, ev, &state->xid, 1);
53 if (tevent_req_nomem(subreq, req)) {
54 return tevent_req_post(req, ev);
56 tevent_req_set_callback(subreq, winbindd_uid_to_sid_done, req);
60 static void winbindd_uid_to_sid_done(struct tevent_req *subreq)
62 struct tevent_req *req = tevent_req_callback_data(
63 subreq, struct tevent_req);
64 struct winbindd_uid_to_sid_state *state = tevent_req_data(
65 req, struct winbindd_uid_to_sid_state);
68 status = wb_xids2sids_recv(subreq, state, &state->sid);
70 if (tevent_req_nterror(req, status)) {
76 NTSTATUS winbindd_uid_to_sid_recv(struct tevent_req *req,
77 struct winbindd_response *response)
79 struct winbindd_uid_to_sid_state *state = tevent_req_data(
80 req, struct winbindd_uid_to_sid_state);
83 if (tevent_req_is_nterror(req, &status)) {
84 DEBUG(5, ("Could not convert sid %s: %s\n",
85 sid_string_dbg(state->sid), nt_errstr(status)));
88 if (is_null_sid(state->sid)) {
89 return NT_STATUS_NONE_MAPPED;
91 sid_to_fstring(response->data.sid.sid, state->sid);
92 response->data.sid.type = SID_NAME_USER;