| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | async dsgetdcname
|
|---|
| 4 | Copyright (C) Volker Lendecke 2009
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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/>.
|
|---|
| 18 | */
|
|---|
| 19 |
|
|---|
| 20 | #include "includes.h"
|
|---|
| 21 | #include "winbindd.h"
|
|---|
| 22 | #include "librpc/gen_ndr/ndr_wbint_c.h"
|
|---|
| 23 |
|
|---|
| 24 | struct wb_dsgetdcname_state {
|
|---|
| 25 | struct netr_DsRGetDCNameInfo *dcinfo;
|
|---|
| 26 | };
|
|---|
| 27 |
|
|---|
| 28 | static void wb_dsgetdcname_done(struct tevent_req *subreq);
|
|---|
| 29 |
|
|---|
| 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)
|
|---|
| 36 | {
|
|---|
| 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;
|
|---|
| 42 |
|
|---|
| 43 | req = tevent_req_create(mem_ctx, &state, struct wb_dsgetdcname_state);
|
|---|
| 44 | if (req == NULL) {
|
|---|
| 45 | return NULL;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | if (strequal(domain_name, "BUILTIN")
|
|---|
| 49 | || strequal(domain_name, get_global_sam_name())) {
|
|---|
| 50 | /*
|
|---|
| 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.
|
|---|
| 55 | */
|
|---|
| 56 | tevent_req_nterror(req, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND);
|
|---|
| 57 | return tevent_req_post(req, ev);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | if (IS_DC) {
|
|---|
| 61 | /*
|
|---|
| 62 | * We have to figure out the DC ourselves
|
|---|
| 63 | */
|
|---|
| 64 | child = locator_child();
|
|---|
| 65 | } else {
|
|---|
| 66 | struct winbindd_domain *domain = find_our_domain();
|
|---|
| 67 | child = choose_domain_child(domain);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | if (domain_guid != NULL) {
|
|---|
| 71 | /* work around a const issue in rpccli_ autogenerated code */
|
|---|
| 72 | guid = *domain_guid;
|
|---|
| 73 | guid_ptr = &guid;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | subreq = dcerpc_wbint_DsGetDcName_send(
|
|---|
| 77 | state, ev, child->binding_handle, domain_name, guid_ptr, site_name,
|
|---|
| 78 | flags, &state->dcinfo);
|
|---|
| 79 | if (tevent_req_nomem(subreq, req)) {
|
|---|
| 80 | return tevent_req_post(req, ev);
|
|---|
| 81 | }
|
|---|
| 82 | tevent_req_set_callback(subreq, wb_dsgetdcname_done, req);
|
|---|
| 83 | return req;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | static void wb_dsgetdcname_done(struct tevent_req *subreq)
|
|---|
| 87 | {
|
|---|
| 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;
|
|---|
| 93 |
|
|---|
| 94 | status = dcerpc_wbint_DsGetDcName_recv(subreq, state, &result);
|
|---|
| 95 | TALLOC_FREE(subreq);
|
|---|
| 96 | if (any_nt_status_not_ok(status, result, &status)) {
|
|---|
| 97 | tevent_req_nterror(req, status);
|
|---|
| 98 | return;
|
|---|
| 99 | }
|
|---|
| 100 | tevent_req_done(req);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | NTSTATUS wb_dsgetdcname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
|
|---|
| 104 | struct netr_DsRGetDCNameInfo **pdcinfo)
|
|---|
| 105 | {
|
|---|
| 106 | struct wb_dsgetdcname_state *state = tevent_req_data(
|
|---|
| 107 | req, struct wb_dsgetdcname_state);
|
|---|
| 108 | NTSTATUS status;
|
|---|
| 109 |
|
|---|
| 110 | if (tevent_req_is_nterror(req, &status)) {
|
|---|
| 111 | return status;
|
|---|
| 112 | }
|
|---|
| 113 | *pdcinfo = talloc_move(mem_ctx, &state->dcinfo);
|
|---|
| 114 | return NT_STATUS_OK;
|
|---|
| 115 | }
|
|---|