ctdb-server: Clean up connection tracking functions
[samba4-gss.git] / source3 / lib / netapi / getdc.c
blob7e5fab3ff63739729e030c53e1bcad4867fe1975
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/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)
44 NTSTATUS status;
45 WERROR werr;
46 struct dcerpc_binding_handle *b;
47 const char *dcname;
48 void *buffer;
50 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
51 &ndr_table_netlogon,
52 &b);
53 if (!W_ERROR_IS_OK(werr)) {
54 goto done;
57 status = dcerpc_netr_GetDcName(b, talloc_tos(),
58 r->in.server_name,
59 r->in.domain_name,
60 &dcname,
61 &werr);
63 if (!NT_STATUS_IS_OK(status)) {
64 werr = ntstatus_to_werror(status);
65 goto done;
68 if (!W_ERROR_IS_OK(werr)) {
69 goto done;
72 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
73 werr = WERR_NOT_ENOUGH_MEMORY;
74 goto done;
76 memcpy(buffer, dcname, strlen_m_term(dcname));
77 *r->out.buffer = buffer;
78 done:
80 return werr;
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)
98 NTSTATUS status;
99 WERROR werr;
100 struct dcerpc_binding_handle *b;
101 const char *dcname;
102 void *buffer;
104 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
105 &ndr_table_netlogon,
106 &b);
107 if (!W_ERROR_IS_OK(werr)) {
108 goto done;
111 status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
112 r->in.server_name,
113 r->in.domain_name,
114 &dcname,
115 &werr);
116 if (!NT_STATUS_IS_OK(status)) {
117 werr = ntstatus_to_werror(status);
118 goto done;
121 if (!W_ERROR_IS_OK(werr)) {
122 goto done;
125 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
126 werr = WERR_NOT_ENOUGH_MEMORY;
127 goto done;
129 memcpy(buffer, dcname, strlen_m_term(dcname));
130 *r->out.buffer = buffer;
132 done:
134 return werr;
138 /********************************************************************
139 ********************************************************************/
141 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
142 struct DsGetDcName *r)
144 NTSTATUS status;
145 struct libnetapi_private_ctx *priv;
147 priv = talloc_get_type_abort(ctx->private_data,
148 struct libnetapi_private_ctx);
150 status = dsgetdcname(ctx,
151 priv->msg_ctx,
152 r->in.domain_name,
153 r->in.domain_guid,
154 r->in.site_name,
155 r->in.flags,
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)
172 WERROR werr;
173 NTSTATUS status;
174 struct dcerpc_binding_handle *b;
176 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
177 &ndr_table_netlogon,
178 &b);
179 if (!W_ERROR_IS_OK(werr)) {
180 goto done;
183 status = dcerpc_netr_DsRGetDCNameEx(b,
184 ctx,
185 r->in.server_name,
186 r->in.domain_name,
187 r->in.domain_guid,
188 r->in.site_name,
189 r->in.flags,
190 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
191 &werr);
192 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
193 goto done;
196 status = dcerpc_netr_DsRGetDCName(b,
197 ctx,
198 r->in.server_name,
199 r->in.domain_name,
200 r->in.domain_guid,
201 NULL,
202 r->in.flags,
203 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
204 &werr);
205 if (!NT_STATUS_IS_OK(status)) {
206 werr = ntstatus_to_werror(status);
207 goto done;
210 done:
211 return werr;