2 * Unix SMB/CIFS implementation.
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/>.
22 #include "lib/netapi/netapi.h"
23 #include "libnet/libnet.h"
25 /********************************************************************
26 ********************************************************************/
28 static WERROR NetGetDCNameLocal(struct libnetapi_ctx *ctx,
29 const char *server_name,
30 const char *domain_name,
33 return WERR_NOT_SUPPORTED;
36 /********************************************************************
37 ********************************************************************/
39 static WERROR NetGetDCNameRemote(struct libnetapi_ctx *ctx,
40 const char *server_name,
41 const char *domain_name,
44 struct cli_state *cli = NULL;
45 struct rpc_pipe_client *pipe_cli = NULL;
49 status = cli_full_connection(&cli, NULL, server_name,
57 if (!NT_STATUS_IS_OK(status)) {
58 werr = ntstatus_to_werror(status);
62 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
65 werr = ntstatus_to_werror(status);
69 status = rpccli_netr_GetDcName(pipe_cli, ctx,
72 (const char **)buffer,
82 /********************************************************************
83 ********************************************************************/
85 static WERROR libnetapi_NetGetDCName(struct libnetapi_ctx *ctx,
86 const char *server_name,
87 const char *domain_name,
90 if (!server_name || is_myname_or_ipaddr(server_name)) {
91 return NetGetDCNameLocal(ctx,
97 return NetGetDCNameRemote(ctx,
103 /****************************************************************
105 ****************************************************************/
107 NET_API_STATUS NetGetDCName(const char *server_name,
108 const char *domain_name,
111 struct libnetapi_ctx *ctx = NULL;
112 NET_API_STATUS status;
115 status = libnetapi_getctx(&ctx);
120 werr = libnetapi_NetGetDCName(ctx,
124 if (!W_ERROR_IS_OK(werr)) {
125 return W_ERROR_V(werr);
128 return NET_API_STATUS_SUCCESS;
131 /********************************************************************
132 ********************************************************************/
134 static WERROR NetGetAnyDCNameLocal(struct libnetapi_ctx *ctx,
135 const char *server_name,
136 const char *domain_name,
139 return WERR_NOT_SUPPORTED;
142 /********************************************************************
143 ********************************************************************/
145 static WERROR NetGetAnyDCNameRemote(struct libnetapi_ctx *ctx,
146 const char *server_name,
147 const char *domain_name,
150 struct cli_state *cli = NULL;
151 struct rpc_pipe_client *pipe_cli = NULL;
155 status = cli_full_connection(&cli, NULL, server_name,
163 if (!NT_STATUS_IS_OK(status)) {
164 werr = ntstatus_to_werror(status);
168 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_NETLOGON,
171 werr = ntstatus_to_werror(status);
175 status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
178 (const char **)buffer,
180 if (!NT_STATUS_IS_OK(status)) {
192 /********************************************************************
193 ********************************************************************/
195 static WERROR libnetapi_NetGetAnyDCName(struct libnetapi_ctx *ctx,
196 const char *server_name,
197 const char *domain_name,
200 if (!server_name || is_myname_or_ipaddr(server_name)) {
201 return NetGetAnyDCNameLocal(ctx,
207 return NetGetAnyDCNameRemote(ctx,
213 /****************************************************************
215 ****************************************************************/
217 NET_API_STATUS NetGetAnyDCName(const char *server_name,
218 const char *domain_name,
221 struct libnetapi_ctx *ctx = NULL;
222 NET_API_STATUS status;
225 status = libnetapi_getctx(&ctx);
230 werr = libnetapi_NetGetAnyDCName(ctx,
234 if (!W_ERROR_IS_OK(werr)) {
235 return W_ERROR_V(werr);
238 return NET_API_STATUS_SUCCESS;