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/>.
23 struct winbindd_domain_info_state
{
24 struct winbindd_domain
*domain
;
25 struct winbindd_request ping_request
;
28 static void winbindd_domain_info_done(struct tevent_req
*subreq
);
30 struct tevent_req
*winbindd_domain_info_send(
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_domain_info_state
*state
;
39 req
= tevent_req_create(mem_ctx
, &state
,
40 struct winbindd_domain_info_state
);
45 DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli
->pid
,
46 cli
->request
->domain_name
));
48 state
->domain
= find_domain_from_name_noinit(
49 cli
->request
->domain_name
);
51 if (state
->domain
== NULL
) {
52 DEBUG(3, ("Did not find domain [%s]\n",
53 cli
->request
->domain_name
));
54 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
55 return tevent_req_post(req
, ev
);
58 if (state
->domain
->initialized
) {
60 return tevent_req_post(req
, ev
);
63 state
->ping_request
.cmd
= WINBINDD_PING
;
66 * Send a ping down. This implicitly initializes the domain.
69 subreq
= wb_domain_request_send(state
, global_event_context(),
70 state
->domain
, &state
->ping_request
);
71 if (tevent_req_nomem(subreq
, req
)) {
72 return tevent_req_post(req
, ev
);
74 tevent_req_set_callback(subreq
, winbindd_domain_info_done
, req
);
79 static void winbindd_domain_info_done(struct tevent_req
*subreq
)
81 struct tevent_req
*req
= tevent_req_callback_data(
82 subreq
, struct tevent_req
);
83 struct winbindd_domain_info_state
*state
= tevent_req_data(
84 req
, struct winbindd_domain_info_state
);
85 struct winbindd_response
*response
;
88 ret
= wb_domain_request_recv(subreq
, state
, &response
, &err
);
91 DBG_DEBUG("wb_domain_request failed: %s\n", strerror(err
));
92 tevent_req_nterror(req
, map_nt_error_from_unix(err
));
96 if (!state
->domain
->initialized
) {
97 DBG_INFO("wb_domain_request did not initialize domain %s\n",
99 tevent_req_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
103 tevent_req_done(req
);
106 NTSTATUS
winbindd_domain_info_recv(struct tevent_req
*req
,
107 struct winbindd_response
*response
)
109 struct winbindd_domain_info_state
*state
= tevent_req_data(
110 req
, struct winbindd_domain_info_state
);
111 struct winbindd_domain
*domain
= state
->domain
;
114 if (tevent_req_is_nterror(req
, &status
)) {
115 DBG_DEBUG("winbindd_domain_info failed: %s\n",
120 fstrcpy(response
->data
.domain_info
.name
, domain
->name
);
121 fstrcpy(response
->data
.domain_info
.alt_name
, domain
->alt_name
);
122 sid_to_fstring(response
->data
.domain_info
.sid
, &domain
->sid
);
124 response
->data
.domain_info
.native_mode
= domain
->native_mode
;
125 response
->data
.domain_info
.active_directory
= domain
->active_directory
;
126 response
->data
.domain_info
.primary
= domain
->primary
;