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_winbind_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 | /*
|
---|
50 | * This makes no sense
|
---|
51 | */
|
---|
52 | tevent_req_nterror(req, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND);
|
---|
53 | return tevent_req_post(req, ev);
|
---|
54 | }
|
---|
55 |
|
---|
56 | if (strequal(domain_name, get_global_sam_name())) {
|
---|
57 | int role = lp_server_role();
|
---|
58 | if ( role != ROLE_ACTIVE_DIRECTORY_DC ) {
|
---|
59 | /*
|
---|
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
|
---|
63 | * needed.
|
---|
64 | */
|
---|
65 | tevent_req_nterror(req, NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND);
|
---|
66 | return tevent_req_post(req, ev);
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | if (IS_DC) {
|
---|
71 | /*
|
---|
72 | * We have to figure out the DC ourselves
|
---|
73 | */
|
---|
74 | child = locator_child();
|
---|
75 | } else {
|
---|
76 | struct winbindd_domain *domain = find_our_domain();
|
---|
77 | child = choose_domain_child(domain);
|
---|
78 | }
|
---|
79 |
|
---|
80 | if (domain_guid != NULL) {
|
---|
81 | /* work around a const issue in rpccli_ autogenerated code */
|
---|
82 | guid = *domain_guid;
|
---|
83 | guid_ptr = &guid;
|
---|
84 | }
|
---|
85 |
|
---|
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);
|
---|
91 | }
|
---|
92 | tevent_req_set_callback(subreq, wb_dsgetdcname_done, req);
|
---|
93 | return req;
|
---|
94 | }
|
---|
95 |
|
---|
96 | static void wb_dsgetdcname_done(struct tevent_req *subreq)
|
---|
97 | {
|
---|
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;
|
---|
103 |
|
---|
104 | status = dcerpc_wbint_DsGetDcName_recv(subreq, state, &result);
|
---|
105 | TALLOC_FREE(subreq);
|
---|
106 | if (any_nt_status_not_ok(status, result, &status)) {
|
---|
107 | tevent_req_nterror(req, status);
|
---|
108 | return;
|
---|
109 | }
|
---|
110 | tevent_req_done(req);
|
---|
111 | }
|
---|
112 |
|
---|
113 | NTSTATUS wb_dsgetdcname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
|
---|
114 | struct netr_DsRGetDCNameInfo **pdcinfo)
|
---|
115 | {
|
---|
116 | struct wb_dsgetdcname_state *state = tevent_req_data(
|
---|
117 | req, struct wb_dsgetdcname_state);
|
---|
118 | NTSTATUS status;
|
---|
119 |
|
---|
120 | if (tevent_req_is_nterror(req, &status)) {
|
---|
121 | return status;
|
---|
122 | }
|
---|
123 | *pdcinfo = talloc_move(mem_ctx, &state->dcinfo);
|
---|
124 | return NT_STATUS_OK;
|
---|
125 | }
|
---|