s4:upgradeprovision Rework script, and reset machine account pw
[Samba/cd1.git] / source3 / winbindd / wb_dsgetdcname.c
blob994d14e264422075299c02e7f50f596c97e2760a
1 /*
2 Unix SMB/CIFS implementation.
3 async dsgetdcname
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/>.
20 #include "includes.h"
21 #include "winbindd.h"
22 #include "librpc/gen_ndr/cli_wbint.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,
35 uint32_t flags)
37 struct tevent_req *req, *subreq;
38 struct wb_dsgetdcname_state *state;
39 struct winbindd_child *child;
40 struct GUID guid;
41 struct GUID *guid_ptr = NULL;
43 req = tevent_req_create(mem_ctx, &state, struct wb_dsgetdcname_state);
44 if (req == NULL) {
45 return NULL;
48 if (strequal(domain_name, "BUILTIN")
49 || strequal(domain_name, get_global_sam_name())) {
51 * Two options here: Give back our own address, or say there's
52 * nobody around. Right now opting for the latter, one measure
53 * to prevent the loopback connects. This might change if
54 * needed.
56 tevent_req_nterror(req, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND);
57 return tevent_req_post(req, ev);
60 if (IS_DC) {
62 * We have to figure out the DC ourselves
64 child = locator_child();
65 } else {
66 struct winbindd_domain *domain = find_our_domain();
67 child = &domain->child;
70 if (domain_guid != NULL) {
71 /* work around a const issue in rpccli_ autogenerated code */
72 guid = *domain_guid;
73 guid_ptr = &guid;
76 subreq = rpccli_wbint_DsGetDcName_send(
77 state, ev, child->rpccli, domain_name, guid_ptr, site_name,
78 flags, &state->dcinfo);
79 if (tevent_req_nomem(subreq, req)) {
80 return tevent_req_post(req, ev);
82 tevent_req_set_callback(subreq, wb_dsgetdcname_done, req);
83 return req;
86 static void wb_dsgetdcname_done(struct tevent_req *subreq)
88 struct tevent_req *req = tevent_req_callback_data(
89 subreq, struct tevent_req);
90 struct wb_dsgetdcname_state *state = tevent_req_data(
91 req, struct wb_dsgetdcname_state);
92 NTSTATUS status, result;
94 status = rpccli_wbint_DsGetDcName_recv(subreq, state, &result);
95 TALLOC_FREE(subreq);
96 if (!NT_STATUS_IS_OK(status)) {
97 tevent_req_nterror(req, status);
98 return;
100 tevent_req_done(req);
103 NTSTATUS wb_dsgetdcname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
104 struct netr_DsRGetDCNameInfo **pdcinfo)
106 struct wb_dsgetdcname_state *state = tevent_req_data(
107 req, struct wb_dsgetdcname_state);
108 NTSTATUS status;
110 if (tevent_req_is_nterror(req, &status)) {
111 return status;
113 *pdcinfo = talloc_move(mem_ctx, &state->dcinfo);
114 return NT_STATUS_OK;