drsuapi.idl: fix source_dsa spelling
[samba4-gss.git] / source3 / winbindd / winbindd_domain_info.c
blob78dc180124b542f4778a5812b6e7bdf61308e1bc
1 /*
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
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;
28 uint32_t in;
29 uint32_t out;
32 static void winbindd_domain_info_done(struct tevent_req *subreq);
34 struct tevent_req *winbindd_domain_info_send(
35 TALLOC_CTX *mem_ctx,
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);
46 if (req == NULL) {
47 return NULL;
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);
56 if (domain == NULL) {
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) {
65 tevent_req_done(req);
66 return tevent_req_post(req, ev);
70 * Send a ping down. This implicitly initializes the domain.
73 state->in = cli->pid;
74 state->out = 0;
75 subreq = dcerpc_wbint_Ping_send(state,
76 global_event_context(),
77 dom_child_handle(domain),
78 state->in,
79 &state->out);
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);
85 return 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;
96 bool valid;
98 status = dcerpc_wbint_Ping_recv(subreq, state, &result);
99 TALLOC_FREE(subreq);
100 if (tevent_req_nterror(req, status)) {
101 DBG_NOTICE("dcerpc_wbint_Ping call failed: %s\n",
102 nt_errstr(status));
103 return;
106 if (tevent_req_nterror(req, result)) {
107 DBG_NOTICE("dcerpc_wbint_Ping failed: %s\n",
108 nt_errstr(result));
109 return;
112 valid = winbindd_domain_ref_get(&state->domain, &domain);
113 if (!valid) {
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);
119 return;
122 if (!domain->initialized) {
123 DBG_INFO("dcerpc_wbint_Ping did not initialize domain %s\n",
124 domain->name);
125 tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
126 return;
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;
138 bool valid;
139 NTSTATUS status;
141 if (tevent_req_is_nterror(req, &status)) {
142 DBG_NOTICE("winbindd_domain_info failed: %s\n",
143 nt_errstr(status));
144 return status;
147 valid = winbindd_domain_ref_get(&state->domain, &domain);
148 if (!valid) {
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;
164 return NT_STATUS_OK;