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_ref 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
;
42 struct winbindd_domain
*domain
= NULL
;
44 req
= tevent_req_create(mem_ctx
, &state
,
45 struct winbindd_domain_info_state
);
50 DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli
->pid
,
51 cli
->request
->domain_name
));
53 domain
= find_domain_from_name_noinit(
54 cli
->request
->domain_name
);
57 DEBUG(3, ("Did not find domain [%s]\n",
58 cli
->request
->domain_name
));
59 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
60 return tevent_req_post(req
, ev
);
62 winbindd_domain_ref_set(&state
->domain
, domain
);
64 if (domain
->initialized
) {
66 return tevent_req_post(req
, ev
);
70 * Send a ping down. This implicitly initializes the domain.
75 subreq
= dcerpc_wbint_Ping_send(state
,
76 global_event_context(),
77 dom_child_handle(domain
),
80 if (tevent_req_nomem(subreq
, req
)) {
81 return tevent_req_post(req
, ev
);
83 tevent_req_set_callback(subreq
, winbindd_domain_info_done
, req
);
88 static void winbindd_domain_info_done(struct tevent_req
*subreq
)
90 struct tevent_req
*req
= tevent_req_callback_data(
91 subreq
, struct tevent_req
);
92 struct winbindd_domain_info_state
*state
= tevent_req_data(
93 req
, struct winbindd_domain_info_state
);
94 NTSTATUS status
, result
;
95 struct winbindd_domain
*domain
= NULL
;
98 status
= dcerpc_wbint_Ping_recv(subreq
, state
, &result
);
100 if (tevent_req_nterror(req
, status
)) {
101 DBG_NOTICE("dcerpc_wbint_Ping call failed: %s\n",
106 if (tevent_req_nterror(req
, result
)) {
107 DBG_NOTICE("dcerpc_wbint_Ping failed: %s\n",
112 valid
= winbindd_domain_ref_get(&state
->domain
, &domain
);
115 * winbindd_domain_ref_get() already generated
116 * a debug message for the stale domain!
118 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
122 if (!domain
->initialized
) {
123 DBG_INFO("dcerpc_wbint_Ping did not initialize domain %s\n",
125 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
129 tevent_req_done(req
);
132 NTSTATUS
winbindd_domain_info_recv(struct tevent_req
*req
,
133 struct winbindd_response
*response
)
135 struct winbindd_domain_info_state
*state
= tevent_req_data(
136 req
, struct winbindd_domain_info_state
);
137 struct winbindd_domain
*domain
= NULL
;
141 if (tevent_req_is_nterror(req
, &status
)) {
142 DBG_NOTICE("winbindd_domain_info failed: %s\n",
147 valid
= winbindd_domain_ref_get(&state
->domain
, &domain
);
150 * winbindd_domain_ref_get() already generated
151 * a debug message for the stale domain!
153 return NT_STATUS_NO_SUCH_DOMAIN
;
156 fstrcpy(response
->data
.domain_info
.name
, domain
->name
);
157 fstrcpy(response
->data
.domain_info
.alt_name
, domain
->alt_name
);
158 sid_to_fstring(response
->data
.domain_info
.sid
, &domain
->sid
);
160 response
->data
.domain_info
.native_mode
= domain
->active_directory
;
161 response
->data
.domain_info
.active_directory
= domain
->active_directory
;
162 response
->data
.domain_info
.primary
= domain
->primary
;