s3:net: fix some i18n messages in net_registry_getsd_internal().
[Samba.git] / source3 / winbindd / wb_lookupsid.c
blob80e0b80ca132dd4a680286b6000639cb1faaef2b
1 /*
2 Unix SMB/CIFS implementation.
3 async lookupsid
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/cli_wbint.h"
24 struct wb_lookupsid_state {
25 struct tevent_context *ev;
26 struct winbindd_domain *lookup_domain;
27 struct dom_sid sid;
28 enum lsa_SidType type;
29 const char *domname;
30 const char *name;
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;
42 req = tevent_req_create(mem_ctx, &state, struct wb_lookupsid_state);
43 if (req == NULL) {
44 return NULL;
46 sid_copy(&state->sid, sid);
47 state->ev = ev;
49 state->lookup_domain = find_lookup_domain_from_sid(sid);
50 if (state->lookup_domain == NULL) {
51 DEBUG(5, ("Could not find domain for sid %s\n",
52 sid_string_dbg(sid)));
53 tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
54 return tevent_req_post(req, ev);
57 subreq = rpccli_wbint_LookupSid_send(
58 state, ev, state->lookup_domain->child.rpccli,
59 &state->sid, &state->type, &state->domname, &state->name);
60 if (tevent_req_nomem(subreq, req)) {
61 return tevent_req_post(req, ev);
63 tevent_req_set_callback(subreq, wb_lookupsid_done, req);
64 return req;
67 static void wb_lookupsid_done(struct tevent_req *subreq)
69 struct tevent_req *req = tevent_req_callback_data(
70 subreq, struct tevent_req);
71 struct wb_lookupsid_state *state = tevent_req_data(
72 req, struct wb_lookupsid_state);
73 struct winbindd_domain *forest_root;
74 NTSTATUS status, result;
76 status = rpccli_wbint_LookupSid_recv(subreq, state, &result);
77 TALLOC_FREE(subreq);
78 if (!NT_STATUS_IS_OK(status)) {
79 tevent_req_nterror(req, status);
80 return;
82 if (NT_STATUS_IS_OK(result)) {
83 tevent_req_done(req);
84 return;
88 * Let's try the forest root
90 forest_root = find_root_domain();
91 if ((forest_root == NULL) || (forest_root == state->lookup_domain)) {
92 tevent_req_nterror(req, result);
93 return;
95 state->lookup_domain = forest_root;
97 subreq = rpccli_wbint_LookupSid_send(
98 state, state->ev, state->lookup_domain->child.rpccli,
99 &state->sid, &state->type, &state->domname, &state->name);
100 if (tevent_req_nomem(subreq, req)) {
101 return;
103 tevent_req_set_callback(subreq, wb_lookupsid_done, req);
106 NTSTATUS wb_lookupsid_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
107 enum lsa_SidType *type, const char **domain,
108 const char **name)
110 struct wb_lookupsid_state *state = tevent_req_data(
111 req, struct wb_lookupsid_state);
112 NTSTATUS status;
114 if (tevent_req_is_nterror(req, &status)) {
115 return status;
117 *type = state->type;
118 *domain = talloc_move(mem_ctx, &state->domname);
119 *name = talloc_move(mem_ctx, &state->name);
120 return NT_STATUS_OK;