2 Unix SMB/CIFS implementation.
3 async implementation of WINBINDD_PING_DC
4 Copyright (C) Volker Lendecke 2009
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 "librpc/gen_ndr/ndr_wbint_c.h"
24 struct winbindd_ping_dc_state
{
29 static void winbindd_ping_dc_done(struct tevent_req
*subreq
);
31 struct tevent_req
*winbindd_ping_dc_send(TALLOC_CTX
*mem_ctx
,
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_ping_dc_state
*state
;
38 struct winbindd_domain
*domain
;
40 req
= tevent_req_create(mem_ctx
, &state
,
41 struct winbindd_ping_dc_state
);
46 if (request
->domain_name
[0] == '\0') {
47 /* preserve old behavior, when no domain name is given */
48 domain
= find_our_domain();
50 domain
= find_domain_from_name(request
->domain_name
);
53 tevent_req_nterror(req
, NT_STATUS_NO_SUCH_DOMAIN
);
54 return tevent_req_post(req
, ev
);
56 if (domain
->internal
) {
58 * Internal domains are passdb based, we can always
62 return tevent_req_post(req
, ev
);
65 subreq
= dcerpc_wbint_PingDc_send(state
, ev
, dom_child_handle(domain
),
67 if (tevent_req_nomem(subreq
, req
)) {
68 return tevent_req_post(req
, ev
);
70 tevent_req_set_callback(subreq
, winbindd_ping_dc_done
, req
);
74 static void winbindd_ping_dc_done(struct tevent_req
*subreq
)
76 struct tevent_req
*req
= tevent_req_callback_data(
77 subreq
, struct tevent_req
);
78 struct winbindd_ping_dc_state
*state
= tevent_req_data(
79 req
, struct winbindd_ping_dc_state
);
80 NTSTATUS status
, result
;
82 status
= dcerpc_wbint_PingDc_recv(subreq
, state
, &result
);
83 state
->result
= result
;
84 if (any_nt_status_not_ok(status
, result
, &status
)) {
85 tevent_req_nterror(req
, status
);
91 NTSTATUS
winbindd_ping_dc_recv(struct tevent_req
*req
,
92 struct winbindd_response
*presp
)
94 struct winbindd_ping_dc_state
*state
= tevent_req_data(
95 req
, struct winbindd_ping_dc_state
);
97 if (!NT_STATUS_IS_OK(state
->result
)) {
98 set_auth_errors(presp
, state
->result
);
102 presp
->extra_data
.data
= talloc_strdup(presp
, state
->dcname
);
103 presp
->length
+= strlen((char *)presp
->extra_data
.data
) + 1;
106 return tevent_req_simple_recv_ntstatus(req
);