ctdb-daemon: Wait for eventd to be ready before connecting
[Samba.git] / source3 / winbindd / wb_lookupname.c
blobc7b027be80126e6590503d2a175d46a7a0eaa335
1 /*
2 Unix SMB/CIFS implementation.
3 async lookupname
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/ndr_winbind_c.h"
23 #include "../libcli/security/security.h"
25 struct wb_lookupname_state {
26 struct tevent_context *ev;
27 const char *dom_name;
28 const char *name;
29 uint32_t flags;
30 struct dom_sid sid;
31 enum lsa_SidType type;
34 static void wb_lookupname_done(struct tevent_req *subreq);
36 struct tevent_req *wb_lookupname_send(TALLOC_CTX *mem_ctx,
37 struct tevent_context *ev,
38 const char *namespace,
39 const char *dom_name,
40 const char *name,
41 uint32_t flags)
43 struct tevent_req *req, *subreq;
44 struct wb_lookupname_state *state;
45 struct winbindd_domain *domain;
47 req = tevent_req_create(mem_ctx, &state, struct wb_lookupname_state);
48 if (req == NULL) {
49 return NULL;
51 state->ev = ev;
52 state->flags = flags;
55 * Uppercase domain and name so that we become cache-friendly
57 state->dom_name = talloc_strdup_upper(state, dom_name);
58 if (tevent_req_nomem(state->dom_name, req)) {
59 return tevent_req_post(req, ev);
61 state->name = talloc_strdup_upper(state, name);
62 if (tevent_req_nomem(state->name, req)) {
63 return tevent_req_post(req, ev);
66 domain = find_lookup_domain_from_name(namespace);
67 if (domain == NULL) {
68 DEBUG(5, ("Could not find domain for %s\n", namespace));
69 tevent_req_nterror(req, NT_STATUS_NONE_MAPPED);
70 return tevent_req_post(req, ev);
73 subreq = dcerpc_wbint_LookupName_send(
74 state, ev, dom_child_handle(domain),
75 state->dom_name, state->name,
76 flags, &state->type, &state->sid);
77 if (tevent_req_nomem(subreq, req)) {
78 return tevent_req_post(req, ev);
80 tevent_req_set_callback(subreq, wb_lookupname_done, req);
81 return req;
84 static void wb_lookupname_done(struct tevent_req *subreq)
86 struct tevent_req *req = tevent_req_callback_data(
87 subreq, struct tevent_req);
88 struct wb_lookupname_state *state = tevent_req_data(
89 req, struct wb_lookupname_state);
90 NTSTATUS status, result;
92 status = dcerpc_wbint_LookupName_recv(subreq, state, &result);
93 TALLOC_FREE(subreq);
94 if (any_nt_status_not_ok(status, result, &status)) {
95 tevent_req_nterror(req, status);
96 return;
98 tevent_req_done(req);
101 NTSTATUS wb_lookupname_recv(struct tevent_req *req, struct dom_sid *sid,
102 enum lsa_SidType *type)
104 struct wb_lookupname_state *state = tevent_req_data(
105 req, struct wb_lookupname_state);
106 NTSTATUS status;
108 if (tevent_req_is_nterror(req, &status)) {
109 return status;
111 sid_copy(sid, &state->sid);
112 *type = state->type;
113 return NT_STATUS_OK;