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"
28 /********************************************************************
29 ********************************************************************/
31 WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
32 struct NetGetDCName *r)
34 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
37 /********************************************************************
38 ********************************************************************/
40 WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
41 struct NetGetDCName *r)
45 struct dcerpc_binding_handle *b;
49 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
52 if (!W_ERROR_IS_OK(werr)) {
56 status = dcerpc_netr_GetDcName(b, talloc_tos(),
62 if (!NT_STATUS_IS_OK(status)) {
63 werr = ntstatus_to_werror(status);
67 if (!W_ERROR_IS_OK(werr)) {
71 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
72 werr = WERR_NOT_ENOUGH_MEMORY;
75 memcpy(buffer, dcname, strlen_m_term(dcname));
76 *r->out.buffer = buffer;
82 /********************************************************************
83 ********************************************************************/
85 WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
86 struct NetGetAnyDCName *r)
88 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
91 /********************************************************************
92 ********************************************************************/
94 WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
95 struct NetGetAnyDCName *r)
99 struct dcerpc_binding_handle *b;
103 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
106 if (!W_ERROR_IS_OK(werr)) {
110 status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
115 if (!NT_STATUS_IS_OK(status)) {
116 werr = ntstatus_to_werror(status);
120 if (!W_ERROR_IS_OK(werr)) {
124 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
125 werr = WERR_NOT_ENOUGH_MEMORY;
128 memcpy(buffer, dcname, strlen_m_term(dcname));
129 *r->out.buffer = buffer;
137 /********************************************************************
138 ********************************************************************/
140 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
141 struct DsGetDcName *r)
144 struct libnetapi_private_ctx *priv;
146 priv = talloc_get_type_abort(ctx->private_data,
147 struct libnetapi_private_ctx);
149 status = dsgetdcname(ctx,
155 (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
156 if (!NT_STATUS_IS_OK(status)) {
157 libnetapi_set_error_string(ctx,
158 "failed to find DC: %s",
159 get_friendly_nt_error_msg(status));
162 return ntstatus_to_werror(status);
165 /********************************************************************
166 ********************************************************************/
168 WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
169 struct DsGetDcName *r)
172 NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
173 struct dcerpc_binding_handle *b;
175 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
178 if (!W_ERROR_IS_OK(werr)) {
182 status = dcerpc_netr_DsRGetDCNameEx(b,
189 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
191 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
195 status = dcerpc_netr_DsRGetDCName(b,
202 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
204 if (!NT_STATUS_IS_OK(status)) {
205 werr = ntstatus_to_werror(status);