Use libnetapi_open_ipc_connection in libnetapi.
[Samba/gebeck_regimport.git] / source3 / lib / netapi / getdc.c
blob8f882941b3786115df743051527a411018524762
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetApi GetDC Support
4 * Copyright (C) Guenther Deschner 2007
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"
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"
28 /********************************************************************
29 ********************************************************************/
31 WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
32 struct NetGetDCName *r)
34 return WERR_NOT_SUPPORTED;
37 /********************************************************************
38 ********************************************************************/
40 WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
41 struct NetGetDCName *r)
43 struct cli_state *cli = NULL;
44 struct rpc_pipe_client *pipe_cli = NULL;
45 NTSTATUS status;
46 WERROR werr;
48 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
49 if (!W_ERROR_IS_OK(werr)) {
50 goto done;
53 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
54 &status);
55 if (!pipe_cli) {
56 werr = ntstatus_to_werror(status);
57 goto done;
60 status = rpccli_netr_GetDcName(pipe_cli, ctx,
61 r->in.server_name,
62 r->in.domain_name,
63 (const char **)r->out.buffer,
64 &werr);
65 done:
67 return werr;
70 /********************************************************************
71 ********************************************************************/
73 WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
74 struct NetGetAnyDCName *r)
76 return WERR_NOT_SUPPORTED;
79 /********************************************************************
80 ********************************************************************/
82 WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
83 struct NetGetAnyDCName *r)
85 struct cli_state *cli = NULL;
86 struct rpc_pipe_client *pipe_cli = NULL;
87 NTSTATUS status;
88 WERROR werr;
90 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
91 if (!W_ERROR_IS_OK(werr)) {
92 goto done;
95 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
96 &status);
97 if (!pipe_cli) {
98 werr = ntstatus_to_werror(status);
99 goto done;
102 status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
103 r->in.server_name,
104 r->in.domain_name,
105 (const char **)r->out.buffer,
106 &werr);
107 if (!NT_STATUS_IS_OK(status)) {
108 goto done;
110 done:
112 return werr;
116 /********************************************************************
117 ********************************************************************/
119 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
120 struct DsGetDcName *r)
122 NTSTATUS status;
124 status = dsgetdcname(ctx,
125 r->in.domain_name,
126 r->in.domain_guid,
127 r->in.site_name,
128 r->in.flags,
129 (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
130 if (!NT_STATUS_IS_OK(status)) {
131 libnetapi_set_error_string(ctx,
132 "failed to find DC: %s",
133 get_friendly_nt_error_msg(status));
136 return ntstatus_to_werror(status);
139 /********************************************************************
140 ********************************************************************/
142 WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
143 struct DsGetDcName *r)
145 WERROR werr;
146 NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
147 struct cli_state *cli = NULL;
148 struct rpc_pipe_client *pipe_cli = NULL;
150 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
151 if (!W_ERROR_IS_OK(werr)) {
152 goto done;
155 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
156 &status);
157 if (!pipe_cli) {
158 werr = ntstatus_to_werror(status);
159 goto done;
162 status = rpccli_netr_DsRGetDCName(pipe_cli,
163 ctx,
164 r->in.server_name,
165 r->in.domain_name,
166 r->in.domain_guid,
167 NULL,
168 r->in.flags,
169 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
170 &werr);
171 if (!NT_STATUS_IS_OK(status)) {
172 werr = ntstatus_to_werror(status);
173 goto done;
176 done:
177 return werr;