winbind: Pass upn unmodified to lookup names
[Samba.git] / source3 / winbindd / winbindd_lookupname.c
blobc5a7c135973952bc8b53ccabce5b48fe9448d771
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 *p = NULL;
39 const char *domname = NULL;
40 const char *name = NULL;
41 const char *namespace = NULL;
43 req = tevent_req_create(mem_ctx, &state,
44 struct winbindd_lookupname_state);
45 if (req == NULL) {
46 return NULL;
48 state->ev = ev;
50 /* Ensure null termination */
51 request->data.name.dom_name[
52 sizeof(request->data.name.dom_name)-1]='\0';
53 request->data.name.name[sizeof(request->data.name.name)-1]='\0';
55 if (strlen(request->data.name.dom_name) == 0) {
56 /* cope with the name being a fully qualified name */
57 p = strstr(request->data.name.name, lp_winbind_separator());
58 if (p != NULL) {
59 *p = '\0';
60 domname = request->data.name.name;
61 namespace = domname;
62 name = p + 1;
63 } else {
64 p = strchr(request->data.name.name, '@');
65 if (p != NULL) {
66 /* upn */
67 namespace = p + 1;
68 } else {
69 namespace = "";
71 domname = "";
72 name = request->data.name.name;
74 } else {
75 domname = request->data.name.dom_name;
76 namespace = domname;
77 name = request->data.name.name;
80 DEBUG(3, ("lookupname %s%s%s\n", domname, lp_winbind_separator(),
81 name));
83 subreq = wb_lookupname_send(state, ev, namespace, domname, name, 0);
84 if (tevent_req_nomem(subreq, req)) {
85 return tevent_req_post(req, ev);
87 tevent_req_set_callback(subreq, winbindd_lookupname_done, req);
88 return req;
91 static void winbindd_lookupname_done(struct tevent_req *subreq)
93 struct tevent_req *req = tevent_req_callback_data(
94 subreq, struct tevent_req);
95 struct winbindd_lookupname_state *state = tevent_req_data(
96 req, struct winbindd_lookupname_state);
97 NTSTATUS status;
99 status = wb_lookupname_recv(subreq, &state->sid, &state->type);
100 TALLOC_FREE(subreq);
101 if (tevent_req_nterror(req, status)) {
102 return;
104 tevent_req_done(req);
107 NTSTATUS winbindd_lookupname_recv(struct tevent_req *req,
108 struct winbindd_response *response)
110 struct winbindd_lookupname_state *state = tevent_req_data(
111 req, struct winbindd_lookupname_state);
112 NTSTATUS status;
114 if (tevent_req_is_nterror(req, &status)) {
115 DEBUG(5, ("Could not convert sid %s: %s\n",
116 sid_string_dbg(&state->sid), nt_errstr(status)));
117 return status;
119 sid_to_fstring(response->data.sid.sid, &state->sid);
120 response->data.sid.type = state->type;
121 return NT_STATUS_OK;