2 * Unix SMB/CIFS implementation.
3 * async implementation of WINBINDD_DOMAIN_INFO
4 * Copyright (C) Volker Lendecke 2018
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 "lib/util/string_wrappers.h"
23 #include "lib/global_contexts.h"
24 #include "librpc/gen_ndr/ndr_winbind_c.h"
26 struct winbindd_domain_info_state
{
27 struct winbindd_domain
*domain
;
32 static void winbindd_domain_info_done(struct tevent_req
*subreq
);
34 struct tevent_req
*winbindd_domain_info_send(
36 struct tevent_context
*ev
,
37 struct winbindd_cli_state
*cli
,
38 struct winbindd_request
*request
)
40 struct tevent_req
*req
, *subreq
;
41 struct winbindd_domain_info_state
*state
;
43 req
= tevent_req_create(mem_ctx
, &state
,
44 struct winbindd_domain_info_state
);
49 DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli
->pid
,
50 cli
->request
->domain_name
));
52 state
->domain
= find_domain_from_name_noinit(
53 cli
->request
->domain_name
);
55 if (state
->domain
== NULL
) {
56 DEBUG(3, ("Did not find domain [%s]\n",
57 cli
->request
->domain_name
));
58 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
59 return tevent_req_post(req
, ev
);
62 if (state
->domain
->initialized
) {
64 return tevent_req_post(req
, ev
);
68 * Send a ping down. This implicitly initializes the domain.
73 subreq
= dcerpc_wbint_Ping_send(state
,
74 global_event_context(),
75 dom_child_handle(state
->domain
),
78 if (tevent_req_nomem(subreq
, req
)) {
79 return tevent_req_post(req
, ev
);
81 tevent_req_set_callback(subreq
, winbindd_domain_info_done
, req
);
86 static void winbindd_domain_info_done(struct tevent_req
*subreq
)
88 struct tevent_req
*req
= tevent_req_callback_data(
89 subreq
, struct tevent_req
);
90 struct winbindd_domain_info_state
*state
= tevent_req_data(
91 req
, struct winbindd_domain_info_state
);
92 NTSTATUS status
, result
;
94 status
= dcerpc_wbint_Ping_recv(subreq
, state
, &result
);
96 if (tevent_req_nterror(req
, status
)) {
97 DBG_NOTICE("dcerpc_wbint_Ping call failed: %s\n",
102 if (tevent_req_nterror(req
, result
)) {
103 DBG_NOTICE("dcerpc_wbint_Ping failed: %s\n",
108 if (!state
->domain
->initialized
) {
109 DBG_INFO("dcerpc_wbint_Ping did not initialize domain %s\n",
110 state
->domain
->name
);
111 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
115 tevent_req_done(req
);
118 NTSTATUS
winbindd_domain_info_recv(struct tevent_req
*req
,
119 struct winbindd_response
*response
)
121 struct winbindd_domain_info_state
*state
= tevent_req_data(
122 req
, struct winbindd_domain_info_state
);
123 struct winbindd_domain
*domain
= state
->domain
;
126 if (tevent_req_is_nterror(req
, &status
)) {
127 DBG_NOTICE("winbindd_domain_info failed: %s\n",
132 fstrcpy(response
->data
.domain_info
.name
, domain
->name
);
133 fstrcpy(response
->data
.domain_info
.alt_name
, domain
->alt_name
);
134 sid_to_fstring(response
->data
.domain_info
.sid
, &domain
->sid
);
136 response
->data
.domain_info
.native_mode
= domain
->native_mode
;
137 response
->data
.domain_info
.active_directory
= domain
->active_directory
;
138 response
->data
.domain_info
.primary
= domain
->primary
;