2 Unix SMB/CIFS implementation.
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 "librpc/gen_ndr/cli_wbint.h"
24 struct wb_lookupsid_state {
25 struct tevent_context *ev;
26 struct winbindd_domain *lookup_domain;
28 enum lsa_SidType type;
33 static void wb_lookupsid_done(struct tevent_req *subreq);
35 struct tevent_req *wb_lookupsid_send(TALLOC_CTX *mem_ctx,
36 struct tevent_context *ev,
37 const struct dom_sid *sid)
39 struct tevent_req *req, *subreq;
40 struct wb_lookupsid_state *state;
41 char *dom_name, *name;
44 req = tevent_req_create(mem_ctx, &state, struct wb_lookupsid_state);
48 sid_copy(&state->sid, sid);
51 state->lookup_domain = find_lookup_domain_from_sid(sid);
52 if (state->lookup_domain == NULL) {
53 DEBUG(5, ("Could not find domain for sid %s\n",
54 sid_string_dbg(sid)));
55 tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
56 return tevent_req_post(req, ev);
59 status = wcache_sid_to_name(state->lookup_domain, sid, state,
60 &dom_name, &name, &state->type);
61 if (NT_STATUS_IS_OK(status)) {
62 state->domname = dom_name;
65 return tevent_req_post(req, ev);
68 subreq = rpccli_wbint_LookupSid_send(
69 state, ev, state->lookup_domain->child.rpccli,
70 &state->sid, &state->type, &state->domname, &state->name);
71 if (tevent_req_nomem(subreq, req)) {
72 return tevent_req_post(req, ev);
74 tevent_req_set_callback(subreq, wb_lookupsid_done, req);
78 static void wb_lookupsid_done(struct tevent_req *subreq)
80 struct tevent_req *req = tevent_req_callback_data(
81 subreq, struct tevent_req);
82 struct wb_lookupsid_state *state = tevent_req_data(
83 req, struct wb_lookupsid_state);
84 struct winbindd_domain *forest_root;
85 NTSTATUS status, result;
87 status = rpccli_wbint_LookupSid_recv(subreq, state, &result);
89 if (!NT_STATUS_IS_OK(status)) {
90 tevent_req_nterror(req, status);
93 if (NT_STATUS_IS_OK(result)) {
99 * Let's try the forest root
101 forest_root = find_root_domain();
102 if ((forest_root == NULL) || (forest_root == state->lookup_domain)) {
103 tevent_req_nterror(req, result);
106 state->lookup_domain = forest_root;
108 subreq = rpccli_wbint_LookupSid_send(
109 state, state->ev, state->lookup_domain->child.rpccli,
110 &state->sid, &state->type, &state->domname, &state->name);
111 if (tevent_req_nomem(subreq, req)) {
114 tevent_req_set_callback(subreq, wb_lookupsid_done, req);
117 NTSTATUS wb_lookupsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
118 enum lsa_SidType *type, const char **domain,
121 struct wb_lookupsid_state *state = tevent_req_data(
122 req, struct wb_lookupsid_state);
125 if (tevent_req_is_nterror(req, &status)) {
129 *domain = talloc_move(mem_ctx, &state->domname);
130 *name = talloc_move(mem_ctx, &state->name);