idmap_tdb_common: fix a debug message in idmap_tdb_common_unixid_to_sid()
[Samba/wip.git] / source3 / lib / netapi / getdc.c
blobae976f1f02d3febfd71ba5a630ac7ec6d52c1552
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"
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)
43 NTSTATUS status;
44 WERROR werr;
45 struct dcerpc_binding_handle *b;
46 const char *dcname;
47 void *buffer;
49 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
50 &ndr_table_netlogon,
51 &b);
52 if (!W_ERROR_IS_OK(werr)) {
53 goto done;
56 status = dcerpc_netr_GetDcName(b, talloc_tos(),
57 r->in.server_name,
58 r->in.domain_name,
59 &dcname,
60 &werr);
62 if (!NT_STATUS_IS_OK(status)) {
63 werr = ntstatus_to_werror(status);
64 goto done;
67 if (!W_ERROR_IS_OK(werr)) {
68 goto done;
71 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
72 werr = WERR_NOMEM;
73 goto done;
75 memcpy(buffer, dcname, strlen_m_term(dcname));
76 *r->out.buffer = buffer;
77 done:
79 return werr;
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)
97 NTSTATUS status;
98 WERROR werr;
99 struct dcerpc_binding_handle *b;
100 const char *dcname;
101 void *buffer;
103 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
104 &ndr_table_netlogon,
105 &b);
106 if (!W_ERROR_IS_OK(werr)) {
107 goto done;
110 status = dcerpc_netr_GetAnyDCName(b, talloc_tos(),
111 r->in.server_name,
112 r->in.domain_name,
113 &dcname,
114 &werr);
115 if (!NT_STATUS_IS_OK(status)) {
116 werr = ntstatus_to_werror(status);
117 goto done;
120 if (!W_ERROR_IS_OK(werr)) {
121 goto done;
124 if (NetApiBufferAllocate(strlen_m_term(dcname), &buffer)) {
125 werr = WERR_NOMEM;
126 goto done;
128 memcpy(buffer, dcname, strlen_m_term(dcname));
129 *r->out.buffer = buffer;
131 done:
133 return werr;
137 /********************************************************************
138 ********************************************************************/
140 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
141 struct DsGetDcName *r)
143 NTSTATUS status;
144 struct libnetapi_private_ctx *priv;
146 priv = talloc_get_type_abort(ctx->private_data,
147 struct libnetapi_private_ctx);
149 status = dsgetdcname(ctx,
150 priv->msg_ctx,
151 r->in.domain_name,
152 r->in.domain_guid,
153 r->in.site_name,
154 r->in.flags,
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)
171 WERROR werr;
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,
176 &ndr_table_netlogon,
177 &b);
178 if (!W_ERROR_IS_OK(werr)) {
179 goto done;
182 status = dcerpc_netr_DsRGetDCNameEx(b,
183 ctx,
184 r->in.server_name,
185 r->in.domain_name,
186 r->in.domain_guid,
187 r->in.site_name,
188 r->in.flags,
189 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
190 &werr);
191 if (NT_STATUS_IS_OK(status) && W_ERROR_IS_OK(werr)) {
192 goto done;
195 status = dcerpc_netr_DsRGetDCName(b,
196 ctx,
197 r->in.server_name,
198 r->in.domain_name,
199 r->in.domain_guid,
200 NULL,
201 r->in.flags,
202 (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
203 &werr);
204 if (!NT_STATUS_IS_OK(status)) {
205 werr = ntstatus_to_werror(status);
206 goto done;
209 done:
210 return werr;