netapi: make libnetapi_open_ipc_connection static.
[kai/samba.git] / source3 / lib / netapi / getdc.c
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
28 /********************************************************************
29 ********************************************************************/
30
31 WERROR NetGetDCName_l(struct libnetapi_ctx *ctx,
32                       struct NetGetDCName *r)
33 {
34         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetDCName);
35 }
36
37 /********************************************************************
38 ********************************************************************/
39
40 WERROR NetGetDCName_r(struct libnetapi_ctx *ctx,
41                       struct NetGetDCName *r)
42 {
43         struct cli_state *cli = NULL;
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                                    &cli,
51                                    &pipe_cli);
52         if (!W_ERROR_IS_OK(werr)) {
53                 goto done;
54         }
55
56         status = rpccli_netr_GetDcName(pipe_cli, ctx,
57                                        r->in.server_name,
58                                        r->in.domain_name,
59                                        (const char **)r->out.buffer,
60                                        &werr);
61  done:
62
63         return werr;
64 }
65
66 /********************************************************************
67 ********************************************************************/
68
69 WERROR NetGetAnyDCName_l(struct libnetapi_ctx *ctx,
70                          struct NetGetAnyDCName *r)
71 {
72         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetGetAnyDCName);
73 }
74
75 /********************************************************************
76 ********************************************************************/
77
78 WERROR NetGetAnyDCName_r(struct libnetapi_ctx *ctx,
79                          struct NetGetAnyDCName *r)
80 {
81         struct cli_state *cli = NULL;
82         struct rpc_pipe_client *pipe_cli = NULL;
83         NTSTATUS status;
84         WERROR werr;
85
86         werr = libnetapi_open_pipe(ctx, r->in.server_name,
87                                    &ndr_table_netlogon.syntax_id,
88                                    &cli,
89                                    &pipe_cli);
90         if (!W_ERROR_IS_OK(werr)) {
91                 goto done;
92         }
93
94         status = rpccli_netr_GetAnyDCName(pipe_cli, ctx,
95                                           r->in.server_name,
96                                           r->in.domain_name,
97                                           (const char **)r->out.buffer,
98                                           &werr);
99         if (!NT_STATUS_IS_OK(status)) {
100                 goto done;
101         }
102  done:
103
104         return werr;
105
106 }
107
108 /********************************************************************
109 ********************************************************************/
110
111 WERROR DsGetDcName_l(struct libnetapi_ctx *ctx,
112                      struct DsGetDcName *r)
113 {
114         NTSTATUS status;
115
116         status = dsgetdcname(ctx,
117                              NULL,
118                              r->in.domain_name,
119                              r->in.domain_guid,
120                              r->in.site_name,
121                              r->in.flags,
122                              (struct netr_DsRGetDCNameInfo **)r->out.dc_info);
123         if (!NT_STATUS_IS_OK(status)) {
124                 libnetapi_set_error_string(ctx,
125                         "failed to find DC: %s",
126                         get_friendly_nt_error_msg(status));
127         }
128
129         return ntstatus_to_werror(status);
130 }
131
132 /********************************************************************
133 ********************************************************************/
134
135 WERROR DsGetDcName_r(struct libnetapi_ctx *ctx,
136                      struct DsGetDcName *r)
137 {
138         WERROR werr;
139         NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
140         struct cli_state *cli = NULL;
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                                    &cli,
146                                    &pipe_cli);
147         if (!W_ERROR_IS_OK(werr)) {
148                 goto done;
149         }
150
151         status = rpccli_netr_DsRGetDCName(pipe_cli,
152                                           ctx,
153                                           r->in.server_name,
154                                           r->in.domain_name,
155                                           r->in.domain_guid,
156                                           NULL,
157                                           r->in.flags,
158                                           (struct netr_DsRGetDCNameInfo **)r->out.dc_info,
159                                           &werr);
160         if (!NT_STATUS_IS_OK(status)) {
161                 werr = ntstatus_to_werror(status);
162                 goto done;
163         }
164
165  done:
166         return werr;
167 }