2 Unix SMB/CIFS implementation.
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_winbind_c.h"
24 struct wb_dsgetdcname_state
{
25 struct netr_DsRGetDCNameInfo
*dcinfo
;
28 static void wb_dsgetdcname_done(struct tevent_req
*subreq
);
30 struct tevent_req
*wb_dsgetdcname_send(TALLOC_CTX
*mem_ctx
,
31 struct tevent_context
*ev
,
32 const char *domain_name
,
33 const struct GUID
*domain_guid
,
34 const char *site_name
,
37 struct tevent_req
*req
, *subreq
;
38 struct wb_dsgetdcname_state
*state
;
39 struct winbindd_child
*child
;
41 struct GUID
*guid_ptr
= NULL
;
43 req
= tevent_req_create(mem_ctx
, &state
, struct wb_dsgetdcname_state
);
48 if (strequal(domain_name
, "BUILTIN")) {
52 tevent_req_nterror(req
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
);
53 return tevent_req_post(req
, ev
);
56 if (strequal(domain_name
, get_global_sam_name())) {
57 int role
= lp_server_role();
58 if ( role
!= ROLE_ACTIVE_DIRECTORY_DC
) {
60 * Two options here: Give back our own address, or say there's
61 * nobody around. Right now opting for the latter, one measure
62 * to prevent the loopback connects. This might change if
65 tevent_req_nterror(req
, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND
);
66 return tevent_req_post(req
, ev
);
72 * We have to figure out the DC ourselves
74 child
= locator_child();
76 struct winbindd_domain
*domain
= find_our_domain();
77 child
= choose_domain_child(domain
);
80 if (domain_guid
!= NULL
) {
81 /* work around a const issue in rpccli_ autogenerated code */
86 subreq
= dcerpc_wbint_DsGetDcName_send(
87 state
, ev
, child
->binding_handle
, domain_name
, guid_ptr
, site_name
,
88 flags
, &state
->dcinfo
);
89 if (tevent_req_nomem(subreq
, req
)) {
90 return tevent_req_post(req
, ev
);
92 tevent_req_set_callback(subreq
, wb_dsgetdcname_done
, req
);
96 static void wb_dsgetdcname_done(struct tevent_req
*subreq
)
98 struct tevent_req
*req
= tevent_req_callback_data(
99 subreq
, struct tevent_req
);
100 struct wb_dsgetdcname_state
*state
= tevent_req_data(
101 req
, struct wb_dsgetdcname_state
);
102 NTSTATUS status
, result
;
104 status
= dcerpc_wbint_DsGetDcName_recv(subreq
, state
, &result
);
106 if (any_nt_status_not_ok(status
, result
, &status
)) {
107 tevent_req_nterror(req
, status
);
110 tevent_req_done(req
);
113 NTSTATUS
wb_dsgetdcname_recv(struct tevent_req
*req
, TALLOC_CTX
*mem_ctx
,
114 struct netr_DsRGetDCNameInfo
**pdcinfo
)
116 struct wb_dsgetdcname_state
*state
= tevent_req_data(
117 req
, struct wb_dsgetdcname_state
);
120 if (tevent_req_is_nterror(req
, &status
)) {
123 *pdcinfo
= talloc_move(mem_ctx
, &state
->dcinfo
);