netapi: make libnetapi_open_ipc_connection static.
[kai/samba.git] / source3 / lib / netapi / serverinfo.c
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  NetApi Server 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 static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
32                                       uint8_t **buffer)
33 {
34         struct SERVER_INFO_1005 info1005;
35
36         info1005.sv1005_comment = lp_serverstring();
37         *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
38         if (!*buffer) {
39                 return WERR_NOMEM;
40         }
41
42         return WERR_OK;
43 }
44
45 /****************************************************************
46 ****************************************************************/
47
48 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
49                           struct NetServerGetInfo *r)
50 {
51         switch (r->in.level) {
52                 case 1005:
53                         return NetServerGetInfo_l_1005(ctx, r->out.buffer);
54                 default:
55                         return WERR_UNKNOWN_LEVEL;
56         }
57
58         return WERR_UNKNOWN_LEVEL;
59 }
60
61 /****************************************************************
62 ****************************************************************/
63
64 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
65                           struct NetServerGetInfo *r)
66 {
67         struct cli_state *cli = NULL;
68         struct rpc_pipe_client *pipe_cli = NULL;
69         NTSTATUS status;
70         WERROR werr;
71         union srvsvc_NetSrvInfo info;
72
73         werr = libnetapi_open_pipe(ctx, r->in.server_name,
74                                    &ndr_table_srvsvc.syntax_id,
75                                    &cli,
76                                    &pipe_cli);
77         if (!W_ERROR_IS_OK(werr)) {
78                 goto done;
79         }
80
81         status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
82                                              r->in.server_name,
83                                              r->in.level,
84                                              &info,
85                                              &werr);
86         if (!NT_STATUS_IS_OK(status)) {
87                 werr = ntstatus_to_werror(status);
88                 goto done;
89         }
90
91         *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info));
92         if (!*r->out.buffer) {
93                 werr = WERR_NOMEM;
94                 goto done;
95         }
96
97  done:
98         return werr;
99 }
100
101 /****************************************************************
102 ****************************************************************/
103
104 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
105                                       struct NetServerSetInfo *r)
106 {
107         WERROR werr;
108         struct smbconf_ctx *conf_ctx;
109         struct srvsvc_NetSrvInfo1005 *info1005;
110
111         if (!r->in.buffer) {
112                 *r->out.parm_error = 1005; /* sure here ? */
113                 return WERR_INVALID_PARAM;
114         }
115
116         info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
117
118         if (!info1005->comment) {
119                 *r->out.parm_error = 1005;
120                 return WERR_INVALID_PARAM;
121         }
122
123         if (!lp_config_backend_is_registry()) {
124                 libnetapi_set_error_string(ctx,
125                         "Configuration manipulation requested but not "
126                         "supported by backend");
127                 return WERR_NOT_SUPPORTED;
128         }
129
130         werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
131         if (!W_ERROR_IS_OK(werr)) {
132                 goto done;
133         }
134
135         werr = smbconf_set_global_parameter(conf_ctx, "server string",
136                                             info1005->comment);
137
138  done:
139         smbconf_shutdown(conf_ctx);
140         return werr;
141 }
142
143 /****************************************************************
144 ****************************************************************/
145
146 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
147                           struct NetServerSetInfo *r)
148 {
149         switch (r->in.level) {
150                 case 1005:
151                         return NetServerSetInfo_l_1005(ctx, r);
152                 default:
153                         return WERR_UNKNOWN_LEVEL;
154         }
155
156         return WERR_UNKNOWN_LEVEL;
157 }
158
159 /****************************************************************
160 ****************************************************************/
161
162 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
163                           struct NetServerSetInfo *r)
164 {
165         struct cli_state *cli = NULL;
166         struct rpc_pipe_client *pipe_cli = NULL;
167         NTSTATUS status;
168         WERROR werr;
169         union srvsvc_NetSrvInfo info;
170
171         werr = libnetapi_open_pipe(ctx, r->in.server_name,
172                                    &ndr_table_srvsvc.syntax_id,
173                                    &cli,
174                                    &pipe_cli);
175         if (!W_ERROR_IS_OK(werr)) {
176                 goto done;
177         }
178
179         switch (r->in.level) {
180                 case 1005:
181                         info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
182                         break;
183                 default:
184                         werr = WERR_NOT_SUPPORTED;
185                         goto done;
186         }
187
188         status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
189                                              r->in.server_name,
190                                              r->in.level,
191                                              &info,
192                                              r->out.parm_error,
193                                              &werr);
194         if (!NT_STATUS_IS_OK(status)) {
195                 werr = ntstatus_to_werror(status);
196                 goto done;
197         }
198
199  done:
200         return werr;
201 }
202
203 /****************************************************************
204 ****************************************************************/
205
206 WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
207                       struct NetRemoteTOD *r)
208 {
209         struct cli_state *cli = NULL;
210         struct rpc_pipe_client *pipe_cli = NULL;
211         NTSTATUS status;
212         WERROR werr;
213         struct srvsvc_NetRemoteTODInfo *info = NULL;
214
215         werr = libnetapi_open_pipe(ctx, r->in.server_name,
216                                    &ndr_table_srvsvc.syntax_id,
217                                    &cli,
218                                    &pipe_cli);
219         if (!W_ERROR_IS_OK(werr)) {
220                 goto done;
221         }
222
223         status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
224                                             r->in.server_name,
225                                             &info,
226                                             &werr);
227         if (!NT_STATUS_IS_OK(status)) {
228                 werr = ntstatus_to_werror(status);
229                 goto done;
230         }
231
232         *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
233                           sizeof(struct srvsvc_NetRemoteTODInfo));
234         W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
235
236  done:
237         return werr;
238 }
239
240 /****************************************************************
241 ****************************************************************/
242
243 WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
244                       struct NetRemoteTOD *r)
245 {
246         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);
247 }
248