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/>.
22 #include "libcli/security/dom_sid.h"
24 struct winbindd_lookupname_state
{
25 struct tevent_context
*ev
;
27 enum lsa_SidType type
;
30 static void winbindd_lookupname_done(struct tevent_req
*subreq
);
32 struct tevent_req
*winbindd_lookupname_send(TALLOC_CTX
*mem_ctx
,
33 struct tevent_context
*ev
,
34 struct winbindd_cli_state
*cli
,
35 struct winbindd_request
*request
)
37 struct tevent_req
*req
, *subreq
;
38 struct winbindd_lookupname_state
*state
;
40 const char *domname
= NULL
;
41 const char *name
= NULL
;
42 const char *namespace = NULL
;
44 req
= tevent_req_create(mem_ctx
, &state
,
45 struct winbindd_lookupname_state
);
51 /* Ensure null termination */
52 request
->data
.name
.dom_name
[
53 sizeof(request
->data
.name
.dom_name
)-1]='\0';
54 request
->data
.name
.name
[sizeof(request
->data
.name
.name
)-1]='\0';
56 if (strlen(request
->data
.name
.dom_name
) == 0) {
57 /* cope with the name being a fully qualified name */
58 p
= strstr(request
->data
.name
.name
, lp_winbind_separator());
61 domname
= request
->data
.name
.name
;
65 p
= strchr(request
->data
.name
.name
, '@');
73 name
= request
->data
.name
.name
;
76 domname
= request
->data
.name
.dom_name
;
78 name
= request
->data
.name
.name
;
81 DEBUG(3, ("lookupname %s%s%s\n", domname
, lp_winbind_separator(),
84 subreq
= wb_lookupname_send(state
, ev
, namespace, domname
, name
, 0);
85 if (tevent_req_nomem(subreq
, req
)) {
86 return tevent_req_post(req
, ev
);
88 tevent_req_set_callback(subreq
, winbindd_lookupname_done
, req
);
92 static void winbindd_lookupname_done(struct tevent_req
*subreq
)
94 struct tevent_req
*req
= tevent_req_callback_data(
95 subreq
, struct tevent_req
);
96 struct winbindd_lookupname_state
*state
= tevent_req_data(
97 req
, struct winbindd_lookupname_state
);
100 status
= wb_lookupname_recv(subreq
, &state
->sid
, &state
->type
);
102 if (tevent_req_nterror(req
, status
)) {
105 tevent_req_done(req
);
108 NTSTATUS
winbindd_lookupname_recv(struct tevent_req
*req
,
109 struct winbindd_response
*response
)
111 struct winbindd_lookupname_state
*state
= tevent_req_data(
112 req
, struct winbindd_lookupname_state
);
115 if (tevent_req_is_nterror(req
, &status
)) {
116 struct dom_sid_buf buf
;
117 DEBUG(5, ("Could not convert sid %s: %s\n",
118 dom_sid_str_buf(&state
->sid
, &buf
),
122 sid_to_fstring(response
->data
.sid
.sid
, &state
->sid
);
123 response
->data
.sid
.type
= state
->type
;