libsmbconf: add a "path" variable to the conf context.
[Samba.git] / source / lib / netapi / serverinfo.c
blobe83cc357e2fdf669d2d4f2507626da4171994096
1 /*
2 * Unix SMB/CIFS implementation.
3 * NetApi Server 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 "lib/netapi/netapi.h"
23 #include "libnet/libnet.h"
25 /****************************************************************
26 ****************************************************************/
28 static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx,
29 uint8_t **buffer)
31 struct srvsvc_NetSrvInfo1005 info1005;
33 info1005.comment = lp_serverstring();
34 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
35 if (!*buffer) {
36 return WERR_NOMEM;
39 return WERR_OK;
42 /****************************************************************
43 ****************************************************************/
45 static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx,
46 const char *server_name,
47 uint32_t level,
48 uint8_t **buffer)
50 switch (level) {
51 case 1005:
52 return NetServerGetInfoLocal_1005(ctx, buffer);
53 default:
54 return WERR_UNKNOWN_LEVEL;
57 return WERR_UNKNOWN_LEVEL;
60 /****************************************************************
61 ****************************************************************/
63 static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
64 const char *server_name,
65 uint32_t level,
66 uint8_t **buffer)
68 struct cli_state *cli = NULL;
69 struct rpc_pipe_client *pipe_cli = NULL;
70 NTSTATUS status;
71 WERROR werr;
72 union srvsvc_NetSrvInfo info;
74 status = cli_full_connection(&cli, NULL, server_name,
75 NULL, 0,
76 "IPC$", "IPC",
77 ctx->username,
78 ctx->workgroup,
79 ctx->password,
80 0, Undefined, NULL);
82 if (!NT_STATUS_IS_OK(status)) {
83 werr = ntstatus_to_werror(status);
84 goto done;
87 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
88 &status);
89 if (!pipe_cli) {
90 werr = ntstatus_to_werror(status);
91 goto done;
94 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
95 server_name,
96 level,
97 &info,
98 &werr);
99 if (!NT_STATUS_IS_OK(status)) {
100 werr = ntstatus_to_werror(status);
101 goto done;
104 *buffer = (uint8_t *)&info;
106 done:
107 if (cli) {
108 cli_shutdown(cli);
111 return werr;
114 /****************************************************************
115 ****************************************************************/
117 static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx,
118 const char *server_name,
119 uint32_t level,
120 uint8_t **buffer)
122 if (!server_name || is_myname_or_ipaddr(server_name)) {
123 return NetServerGetInfoLocal(ctx,
124 server_name,
125 level,
126 buffer);
129 return NetServerGetInfoRemote(ctx,
130 server_name,
131 level,
132 buffer);
136 /****************************************************************
137 NetServerGetInfo
138 ****************************************************************/
140 NET_API_STATUS NetServerGetInfo(const char *server_name,
141 uint32_t level,
142 uint8_t **buffer)
144 struct libnetapi_ctx *ctx = NULL;
145 NET_API_STATUS status;
146 WERROR werr;
148 status = libnetapi_getctx(&ctx);
149 if (status != 0) {
150 return status;
153 werr = libnetapi_NetServerGetInfo(ctx,
154 server_name,
155 level,
156 buffer);
157 if (!W_ERROR_IS_OK(werr)) {
158 return W_ERROR_V(werr);
161 return NET_API_STATUS_SUCCESS;
164 /****************************************************************
165 ****************************************************************/
167 static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
168 uint8_t *buffer,
169 uint32_t *parm_error)
171 WERROR werr;
172 struct smbconf_ctx *conf_ctx;
173 struct srvsvc_NetSrvInfo1005 *info1005;
175 if (!buffer) {
176 *parm_error = 1005; /* sure here ? */
177 return WERR_INVALID_PARAM;
180 info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
182 if (!info1005->comment) {
183 *parm_error = 1005;
184 return WERR_INVALID_PARAM;
187 if (!lp_config_backend_is_registry()) {
188 libnetapi_set_error_string(ctx,
189 "Configuration manipulation requested but not "
190 "supported by backend");
191 return WERR_NOT_SUPPORTED;
194 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
195 if (!W_ERROR_IS_OK(werr)) {
196 goto done;
199 werr = smbconf_set_global_parameter(conf_ctx, "server string",
200 info1005->comment);
202 done:
203 smbconf_shutdown(conf_ctx);
204 return werr;
207 /****************************************************************
208 ****************************************************************/
210 static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
211 const char *server_name,
212 uint32_t level,
213 uint8_t *buffer,
214 uint32_t *parm_error)
216 switch (level) {
217 case 1005:
218 return NetServerSetInfoLocal_1005(ctx, buffer, parm_error);
219 default:
220 return WERR_UNKNOWN_LEVEL;
223 return WERR_UNKNOWN_LEVEL;
226 /****************************************************************
227 ****************************************************************/
229 static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
230 const char *server_name,
231 uint32_t level,
232 uint8_t *buffer,
233 uint32_t *parm_error)
235 struct cli_state *cli = NULL;
236 struct rpc_pipe_client *pipe_cli = NULL;
237 NTSTATUS status;
238 WERROR werr;
239 union srvsvc_NetSrvInfo info;
241 status = cli_full_connection(&cli, NULL, server_name,
242 NULL, 0,
243 "IPC$", "IPC",
244 ctx->username,
245 ctx->workgroup,
246 ctx->password,
247 0, Undefined, NULL);
249 if (!NT_STATUS_IS_OK(status)) {
250 werr = ntstatus_to_werror(status);
251 goto done;
254 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
255 &status);
256 if (!pipe_cli) {
257 werr = ntstatus_to_werror(status);
258 goto done;
261 switch (level) {
262 case 1005:
263 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
264 break;
265 default:
266 werr = WERR_NOT_SUPPORTED;
267 goto done;
270 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
271 server_name,
272 level,
273 info,
274 parm_error,
275 &werr);
276 if (!NT_STATUS_IS_OK(status)) {
277 werr = ntstatus_to_werror(status);
278 goto done;
281 done:
282 if (cli) {
283 cli_shutdown(cli);
286 return werr;
289 /****************************************************************
290 ****************************************************************/
292 static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx,
293 const char *server_name,
294 uint32_t level,
295 uint8_t *buffer,
296 uint32_t *parm_error)
298 if (!server_name || is_myname_or_ipaddr(server_name)) {
299 return NetServerSetInfoLocal(ctx,
300 server_name,
301 level,
302 buffer,
303 parm_error);
306 return NetServerSetInfoRemote(ctx,
307 server_name,
308 level,
309 buffer,
310 parm_error);
313 /****************************************************************
314 NetServerSetInfo
315 ****************************************************************/
317 NET_API_STATUS NetServerSetInfo(const char *server_name,
318 uint32_t level,
319 uint8_t *buffer,
320 uint32_t *parm_error)
322 struct libnetapi_ctx *ctx = NULL;
323 NET_API_STATUS status;
324 WERROR werr;
326 status = libnetapi_getctx(&ctx);
327 if (status != 0) {
328 return status;
331 werr = libnetapi_NetServerSetInfo(ctx,
332 server_name,
333 level,
334 buffer,
335 parm_error);
336 if (!W_ERROR_IS_OK(werr)) {
337 return W_ERROR_V(werr);
340 return NET_API_STATUS_SUCCESS;