s3:ntlmssp: make use of C99 types in ntlmssp_sign.c
[Samba/gebeck_regimport.git] / source3 / winbindd / winbindd_lookupname.c
blobc1d0bf04c1ba7f9be88156b4d881ab02af0ec090
1 /*
2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_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"
23 struct winbindd_lookupname_state {
24 struct tevent_context *ev;
25 struct dom_sid sid;
26 enum lsa_SidType type;
29 static void winbindd_lookupname_done(struct tevent_req *subreq);
31 struct tevent_req *winbindd_lookupname_send(TALLOC_CTX *mem_ctx,
32 struct tevent_context *ev,
33 struct winbindd_cli_state *cli,
34 struct winbindd_request *request)
36 struct tevent_req *req, *subreq;
37 struct winbindd_lookupname_state *state;
38 char *domname, *name, *p;
40 req = tevent_req_create(mem_ctx, &state,
41 struct winbindd_lookupname_state);
42 if (req == NULL) {
43 return NULL;
45 state->ev = ev;
47 /* Ensure null termination */
48 request->data.name.dom_name[
49 sizeof(request->data.name.dom_name)-1]='\0';
50 request->data.name.name[sizeof(request->data.name.name)-1]='\0';
52 /* cope with the name being a fully qualified name */
53 p = strstr(request->data.name.name, lp_winbind_separator());
54 if (p) {
55 *p = 0;
56 domname = request->data.name.name;
57 name = p+1;
58 } else if ((p = strchr(request->data.name.name, '@')) != NULL) {
59 /* upn */
60 domname = p + 1;
61 *p = 0;
62 name = request->data.name.name;
63 } else {
64 domname = request->data.name.dom_name;
65 name = request->data.name.name;
68 DEBUG(3, ("lookupname %s%s%s\n", domname, lp_winbind_separator(),
69 name));
71 subreq = wb_lookupname_send(state, ev, domname, name, 0);
72 if (tevent_req_nomem(subreq, req)) {
73 return tevent_req_post(req, ev);
75 tevent_req_set_callback(subreq, winbindd_lookupname_done, req);
76 return req;
79 static void winbindd_lookupname_done(struct tevent_req *subreq)
81 struct tevent_req *req = tevent_req_callback_data(
82 subreq, struct tevent_req);
83 struct winbindd_lookupname_state *state = tevent_req_data(
84 req, struct winbindd_lookupname_state);
85 NTSTATUS status;
87 status = wb_lookupname_recv(subreq, &state->sid, &state->type);
88 TALLOC_FREE(subreq);
89 if (!NT_STATUS_IS_OK(status)) {
90 tevent_req_nterror(req, status);
91 return;
93 tevent_req_done(req);
96 NTSTATUS winbindd_lookupname_recv(struct tevent_req *req,
97 struct winbindd_response *response)
99 struct winbindd_lookupname_state *state = tevent_req_data(
100 req, struct winbindd_lookupname_state);
101 NTSTATUS status;
103 if (tevent_req_is_nterror(req, &status)) {
104 DEBUG(5, ("Could not convert sid %s: %s\n",
105 sid_string_dbg(&state->sid), nt_errstr(status)));
106 return status;
108 sid_to_fstring(response->data.sid.sid, &state->sid);
109 response->data.sid.type = state->type;
110 return NT_STATUS_OK;