1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * NetApi GetDC Support
|
---|
4 | * Copyright (C) Guenther Deschner 2007
|
---|
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 |
|
---|
22 | #include "librpc/gen_ndr/libnetapi.h"
|
---|
23 | #include "lib/netapi/netapi.h"
|
---|
24 | #include "lib/netapi/netapi_private.h"
|
---|
25 | #include "lib/netapi/libnetapi.h"
|
---|
26 | #include "libnet/libnet.h"
|
---|
27 |
|
---|
28 | /********************************************************************
|
---|
29 | ********************************************************************/
|
---|
30 |
|
---|
31 | WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
|
---|
32 | struct NetGetDCName *r)
|
---|
33 | {
|
---|
34 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /********************************************************************
|
---|
38 | ********************************************************************/
|
---|
39 |
|
---|
40 | WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
|
---|
41 | struct NetGetDCName *r)
|
---|
42 | {
|
---|
43 | struct cli_state *cli = NULL;
|
---|
44 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
45 | NTSTATUS status;
|
---|
46 | WERROR werr;
|
---|
47 |
|
---|
48 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
49 | &ndr_table_netlogon.syntax_id,
|
---|
50 | &cli,
|
---|
51 | &pipe_cli);
|
---|
52 | if (!W_ERROR_IS_OK(werr)) {
|
---|
53 | goto done;
|
---|
54 | }
|
---|
55 |
|
---|
56 | status = rpccli_netr_GetDcName(pipe_cli, ctx,
|
---|
57 | r->in.server_name,
|
---|
58 | r->in.domain_name,
|
---|
59 | (const char **)r->out.buffer,
|
---|
60 | &werr);
|
---|
61 |
|
---|
62 | if (!NT_STATUS_IS_OK(status)) {
|
---|
63 | werr = ntstatus_to_werror(status);
|
---|
64 | }
|
---|
65 |
|
---|
66 | done:
|
---|
67 |
|
---|
68 | return werr;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /********************************************************************
|
---|
72 | ********************************************************************/
|
---|
73 |
|
---|
74 | WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
|
---|
75 | struct NetGetAnyDCName *r)
|
---|
76 | {
|
---|
77 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
|
---|
78 | }
|
---|
79 |
|
---|
80 | /********************************************************************
|
---|
81 | ********************************************************************/
|
---|
82 |
|
---|
83 | WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
|
---|
84 | struct NetGetAnyDCName *r)
|
---|
85 | {
|
---|
86 | struct cli_state *cli = NULL;
|
---|
87 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
88 | NTSTATUS status;
|
---|
89 | WERROR werr;
|
---|
90 |
|
---|
91 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
92 | &ndr_table_netlogon.syntax_id,
|
---|
93 | &cli,
|
---|
94 | &pipe_cli);
|
---|
95 | if (!W_ERROR_IS_OK(werr)) {
|
---|
96 | goto done;
|
---|
97 | }
|
---|
98 |
|
---|
99 | status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
|
---|
100 | r->in.server_name,
|
---|
101 | r->in.domain_name,
|
---|
102 | (const char **)r->out.buffer,
|
---|
103 | &werr);
|
---|
104 | if (!NT_STATUS_IS_OK(status)) {
|
---|
105 | goto done;
|
---|
106 | }
|
---|
107 | done:
|
---|
108 |
|
---|
109 | return werr;
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 | /********************************************************************
|
---|
114 | ********************************************************************/
|
---|
115 |
|
---|
116 | WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
|
---|
117 | struct DsGetDcName *r)
|
---|
118 | {
|
---|
119 | NTSTATUS status;
|
---|
120 |
|
---|
121 | status = dsgetdcname(ctx,
|
---|
122 | NULL,
|
---|
123 | r->in.domain_name,
|
---|
124 | r->in.domain_guid,
|
---|
125 | r->in.site_name,
|
---|
126 | r->in.flags,
|
---|
127 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
|
---|
128 | if (!NT_STATUS_IS_OK(status)) {
|
---|
129 | libnetapi_set_error_string(ctx,
|
---|
130 | "failed to find DC: %s",
|
---|
131 | get_friendly_nt_error_msg(status));
|
---|
132 | }
|
---|
133 |
|
---|
134 | return ntstatus_to_werror(status);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /********************************************************************
|
---|
138 | ********************************************************************/
|
---|
139 |
|
---|
140 | WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
|
---|
141 | struct DsGetDcName *r)
|
---|
142 | {
|
---|
143 | WERROR werr;
|
---|
144 | NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
|
---|
145 | struct cli_state *cli = NULL;
|
---|
146 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
147 |
|
---|
148 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
149 | &ndr_table_netlogon.syntax_id,
|
---|
150 | &cli,
|
---|
151 | &pipe_cli);
|
---|
152 | if (!W_ERROR_IS_OK(werr)) {
|
---|
153 | goto done;
|
---|
154 | }
|
---|
155 |
|
---|
156 | status = rpccli_netr_DsRGetDCName(pipe_cli,
|
---|
157 | ctx,
|
---|
158 | r->in.server_name,
|
---|
159 | r->in.domain_name,
|
---|
160 | r->in.domain_guid,
|
---|
161 | NULL,
|
---|
162 | r->in.flags,
|
---|
163 | (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
|
---|
164 | &werr);
|
---|
165 | if (!NT_STATUS_IS_OK(status)) {
|
---|
166 | werr = ntstatus_to_werror(status);
|
---|
167 | goto done;
|
---|
168 | }
|
---|
169 |
|
---|
170 | done:
|
---|
171 | return werr;
|
---|
172 | }
|
---|