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"
24 struct winbindd_domain_info_state {
25 struct winbindd_domain *domain;
26 struct winbindd_request ping_request;
29 static void winbindd_domain_info_done(struct tevent_req *subreq);
31 struct tevent_req *winbindd_domain_info_send(
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_domain_info_state *state;
40 req = tevent_req_create(mem_ctx, &state,
41 struct winbindd_domain_info_state);
46 DEBUG(3, ("[%5lu]: domain_info [%s]\n", (unsigned long)cli->pid,
47 cli->request->domain_name));
49 state->domain = find_domain_from_name_noinit(
50 cli->request->domain_name);
52 if (state->domain == NULL) {
53 DEBUG(3, ("Did not find domain [%s]\n",
54 cli->request->domain_name));
55 tevent_req_nterror(req, NT_STATUS_NO_SUCH_DOMAIN);
56 return tevent_req_post(req, ev);
59 if (state->domain->initialized) {
61 return tevent_req_post(req, ev);
64 state->ping_request.cmd = WINBINDD_PING;
67 * Send a ping down. This implicitly initializes the domain.
70 subreq = wb_domain_request_send(state, global_event_context(),
71 state->domain, &state->ping_request);
72 if (tevent_req_nomem(subreq, req)) {
73 return tevent_req_post(req, ev);
75 tevent_req_set_callback(subreq, winbindd_domain_info_done, req);
80 static void winbindd_domain_info_done(struct tevent_req *subreq)
82 struct tevent_req *req = tevent_req_callback_data(
83 subreq, struct tevent_req);
84 struct winbindd_domain_info_state *state = tevent_req_data(
85 req, struct winbindd_domain_info_state);
86 struct winbindd_response *response;
89 ret = wb_domain_request_recv(subreq, state, &response, &err);
92 DBG_DEBUG("wb_domain_request failed: %s\n", strerror(err));
93 tevent_req_nterror(req, map_nt_error_from_unix(err));
97 if (!state->domain->initialized) {
98 DBG_INFO("wb_domain_request did not initialize domain %s\n",
100 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
104 tevent_req_done(req);
107 NTSTATUS winbindd_domain_info_recv(struct tevent_req *req,
108 struct winbindd_response *response)
110 struct winbindd_domain_info_state *state = tevent_req_data(
111 req, struct winbindd_domain_info_state);
112 struct winbindd_domain *domain = state->domain;
115 if (tevent_req_is_nterror(req, &status)) {
116 DBG_DEBUG("winbindd_domain_info failed: %s\n",
121 fstrcpy(response->data.domain_info.name, domain->name);
122 fstrcpy(response->data.domain_info.alt_name, domain->alt_name);
123 sid_to_fstring(response->data.domain_info.sid, &domain->sid);
125 response->data.domain_info.native_mode = domain->native_mode;
126 response->data.domain_info.active_directory = domain->active_directory;
127 response->data.domain_info.primary = domain->primary;