• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/samba-3.5.8/source3/lib/netapi/
1/*
2 *  Unix SMB/CIFS implementation.
3 *  NetApi GetDC Support
4 *  Copyright (C) Guenther Deschner 2007
5 *
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.
10 *
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.
15 *
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/>.
18 */
19
20#include "includes.h"
21
22#include "librpc/gen_ndr/libnetapi.h"
23#include "lib/netapi/netapi.h"
24#include "lib/netapi/netapi_private.h"
25#include "lib/netapi/libnetapi.h"
26#include "libnet/libnet.h"
27#include "../librpc/gen_ndr/cli_netlogon.h"
28
29/********************************************************************
30********************************************************************/
31
32WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
33		      struct NetGetDCName *r)
34{
35	LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
36}
37
38/********************************************************************
39********************************************************************/
40
41WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
42		      struct NetGetDCName *r)
43{
44	struct rpc_pipe_client *pipe_cli = NULL;
45	NTSTATUS status;
46	WERROR werr;
47
48	werr = libnetapi_open_pipe(ctx, r->in.server_name,
49				   &ndr_table_netlogon.syntax_id,
50				   &pipe_cli);
51	if (!W_ERROR_IS_OK(werr)) {
52		goto done;
53	}
54
55	status = rpccli_netr_GetDcName(pipe_cli, talloc_tos(),
56				       r->in.server_name,
57				       r->in.domain_name,
58				       (const char **)r->out.buffer,
59				       &werr);
60
61	if (!NT_STATUS_IS_OK(status)) {
62		werr = ntstatus_to_werror(status);
63	}
64 done:
65
66	return werr;
67}
68
69/********************************************************************
70********************************************************************/
71
72WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
73			 struct NetGetAnyDCName *r)
74{
75	LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
76}
77
78/********************************************************************
79********************************************************************/
80
81WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
82			 struct NetGetAnyDCName *r)
83{
84	struct rpc_pipe_client *pipe_cli = NULL;
85	NTSTATUS status;
86	WERROR werr;
87
88	werr = libnetapi_open_pipe(ctx, r->in.server_name,
89				   &ndr_table_netlogon.syntax_id,
90				   &pipe_cli);
91	if (!W_ERROR_IS_OK(werr)) {
92		goto done;
93	}
94
95	status = rpccli_netr_GetAnyDCName(pipe_cli, talloc_tos(),
96					  r->in.server_name,
97					  r->in.domain_name,
98					  (const char **)r->out.buffer,
99					  &werr);
100	if (!NT_STATUS_IS_OK(status)) {
101		goto done;
102	}
103 done:
104
105	return werr;
106
107}
108
109/********************************************************************
110********************************************************************/
111
112WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
113		     struct DsGetDcName *r)
114{
115	NTSTATUS status;
116
117	status = dsgetdcname(ctx,
118			     NULL,
119			     r->in.domain_name,
120			     r->in.domain_guid,
121			     r->in.site_name,
122			     r->in.flags,
123			     (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
124	if (!NT_STATUS_IS_OK(status)) {
125		libnetapi_set_error_string(ctx,
126			"failed to find DC: %s",
127			get_friendly_nt_error_msg(status));
128	}
129
130	return ntstatus_to_werror(status);
131}
132
133/********************************************************************
134********************************************************************/
135
136WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
137		     struct DsGetDcName *r)
138{
139	WERROR werr;
140	NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
141	struct rpc_pipe_client *pipe_cli = NULL;
142
143	werr = libnetapi_open_pipe(ctx, r->in.server_name,
144				   &ndr_table_netlogon.syntax_id,
145				   &pipe_cli);
146	if (!W_ERROR_IS_OK(werr)) {
147		goto done;
148	}
149
150	status = rpccli_netr_DsRGetDCName(pipe_cli,
151					  ctx,
152					  r->in.server_name,
153					  r->in.domain_name,
154					  r->in.domain_guid,
155					  NULL,
156					  r->in.flags,
157					  (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
158					  &werr);
159	if (!NT_STATUS_IS_OK(status)) {
160		werr = ntstatus_to_werror(status);
161		goto done;
162	}
163
164 done:
165	return werr;
166}
167