s4:rpc_srv:getncchanges: 4.5 anc emulation uses qsort(), not ldb_qsort()
[samba.git] / source3 / winbindd / winbindd_domain_info.c
blobc4364d99ad3b9275c31079f0a382e26648f6e690
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 *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;
43 req = tevent_req_create(mem_ctx, &state,
44 struct winbindd_domain_info_state);
45 if (req == NULL) {
46 return NULL;
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) {
63 tevent_req_done(req);
64 return tevent_req_post(req, ev);
68 * Send a ping down. This implicitly initializes the domain.
71 state->in = cli->pid;
72 state->out = 0;
73 subreq = dcerpc_wbint_Ping_send(state,
74 global_event_context(),
75 dom_child_handle(state->domain),
76 state->in,
77 &state->out);
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);
83 return 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);
95 TALLOC_FREE(subreq);
96 if (tevent_req_nterror(req, status)) {
97 DBG_NOTICE("dcerpc_wbint_Ping call failed: %s\n",
98 nt_errstr(status));
99 return;
102 if (tevent_req_nterror(req, result)) {
103 DBG_NOTICE("dcerpc_wbint_Ping failed: %s\n",
104 nt_errstr(result));
105 return;
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);
112 return;
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;
124 NTSTATUS status;
126 if (tevent_req_is_nterror(req, &status)) {
127 DBG_NOTICE("winbindd_domain_info failed: %s\n",
128 nt_errstr(status));
129 return status;
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;
140 return NT_STATUS_OK;