2 Unix SMB/CIFS implementation.
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 "librpc/gen_ndr/ndr_winbind_c.h"
23 #include "../libcli/security/security.h"
25 struct wb_lookupname_state
{
26 struct tevent_context
*ev
;
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,
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
);
52 D_INFO("WB command lookupname start.\n"
53 "Search namespace '%s' and domain '%s' for name '%s'.\n",
54 namespace, dom_name
, name
);
59 * Uppercase domain and name so that we become cache-friendly
61 state
->dom_name
= talloc_strdup_upper(state
, dom_name
);
62 if (tevent_req_nomem(state
->dom_name
, req
)) {
63 return tevent_req_post(req
, ev
);
65 state
->name
= talloc_strdup_upper(state
, name
);
66 if (tevent_req_nomem(state
->name
, req
)) {
67 return tevent_req_post(req
, ev
);
70 domain
= find_lookup_domain_from_name(namespace);
72 D_WARNING("Could not find domain for %s\n", namespace);
73 tevent_req_nterror(req
, NT_STATUS_NONE_MAPPED
);
74 return tevent_req_post(req
, ev
);
77 subreq
= dcerpc_wbint_LookupName_send(
78 state
, ev
, dom_child_handle(domain
),
79 state
->dom_name
, state
->name
,
80 flags
, &state
->type
, &state
->sid
);
81 if (tevent_req_nomem(subreq
, req
)) {
82 return tevent_req_post(req
, ev
);
84 tevent_req_set_callback(subreq
, wb_lookupname_done
, req
);
88 static void wb_lookupname_done(struct tevent_req
*subreq
)
90 struct tevent_req
*req
= tevent_req_callback_data(
91 subreq
, struct tevent_req
);
92 struct wb_lookupname_state
*state
= tevent_req_data(
93 req
, struct wb_lookupname_state
);
94 NTSTATUS status
, result
;
96 status
= dcerpc_wbint_LookupName_recv(subreq
, state
, &result
);
98 if (any_nt_status_not_ok(status
, result
, &status
)) {
99 tevent_req_nterror(req
, status
);
102 tevent_req_done(req
);
105 NTSTATUS
wb_lookupname_recv(struct tevent_req
*req
, struct dom_sid
*sid
,
106 enum lsa_SidType
*type
)
108 struct wb_lookupname_state
*state
= tevent_req_data(
109 req
, struct wb_lookupname_state
);
111 struct dom_sid_buf buf
;
113 if (tevent_req_is_nterror(req
, &status
)) {
116 sid_copy(sid
, &state
->sid
);
118 D_INFO("WB command lookupname end.\n"
119 "Found SID %s with SID type %d.\n",
120 dom_sid_str_buf(sid
, &buf
),