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 "../librpc/gen_ndr/ndr_netlogon_c.h"
23 #include "librpc/gen_ndr/libnetapi.h"
24 #include "lib/netapi/netapi.h"
25 #include "lib/netapi/netapi_private.h"
26 #include "lib/netapi/libnetapi.h"
27 #include "libsmb/dsgetdcname.h"
29 /********************************************************************
30 ********************************************************************/
32 WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
33 struct NetGetDCName *r)
35 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
38 /********************************************************************
39 ********************************************************************/
41 WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
42 struct NetGetDCName *r)
46 struct dcerpc_binding_handle *b;
50 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
53 if (!W_ERROR_IS_OK(werr)) {
57 status = dcerpc_netr_GetDcName(b, talloc_tos(),
63 if (!NT_STATUS_IS_OK(status)) {
64 werr = ntstatus_to_werror(status);
68 if (!W_ERROR_IS_OK(werr)) {
72 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
73 werr = WERR_NOT_ENOUGH_MEMORY;
76 memcpy(buffer, dcname, strlen_m_term(dcname));
77 *r->out.buffer = buffer;
83 /********************************************************************
84 ********************************************************************/
86 WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
87 struct NetGetAnyDCName *r)
89 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
92 /********************************************************************
93 ********************************************************************/
95 WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
96 struct NetGetAnyDCName *r)
100 struct dcerpc_binding_handle *b;
104 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
107 if (!W_ERROR_IS_OK(werr)) {
111 status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
116 if (!NT_STATUS_IS_OK(status)) {
117 werr = ntstatus_to_werror(status);
121 if (!W_ERROR_IS_OK(werr)) {
125 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
126 werr = WERR_NOT_ENOUGH_MEMORY;
129 memcpy(buffer, dcname, strlen_m_term(dcname));
130 *r->out.buffer = buffer;
138 /********************************************************************
139 ********************************************************************/
141 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
142 struct DsGetDcName *r)
145 struct libnetapi_private_ctx *priv;
147 priv = talloc_get_type_abort(ctx->private_data,
148 struct libnetapi_private_ctx);
150 status = dsgetdcname(ctx,
156 (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
157 if (!NT_STATUS_IS_OK(status)) {
158 libnetapi_set_error_string(ctx,
159 "failed to find DC: %s",
160 get_friendly_nt_error_msg(status));
163 return ntstatus_to_werror(status);
166 /********************************************************************
167 ********************************************************************/
169 WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
170 struct DsGetDcName *r)
173 NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
174 struct dcerpc_binding_handle *b;
176 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
179 if (!W_ERROR_IS_OK(werr)) {
183 status = dcerpc_netr_DsRGetDCNameEx(b,
190 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
192 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
196 status = dcerpc_netr_DsRGetDCName(b,
203 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
205 if (!NT_STATUS_IS_OK(status)) {
206 werr = ntstatus_to_werror(status);