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/>.
22 #include "lib/netapi/netapi.h"
23 #include "libnet/libnet.h"
25 /****************************************************************
26 ****************************************************************/
28 static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx,
31 struct srvsvc_NetSrvInfo1005 info1005;
33 info1005.comment = lp_serverstring();
34 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
42 /****************************************************************
43 ****************************************************************/
45 static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx,
46 const char *server_name,
52 return NetServerGetInfoLocal_1005(ctx, buffer);
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,
68 struct cli_state *cli = NULL;
69 struct rpc_pipe_client *pipe_cli = NULL;
72 union srvsvc_NetSrvInfo info;
74 status = cli_full_connection(&cli, NULL, server_name,
82 if (!NT_STATUS_IS_OK(status)) {
83 werr = ntstatus_to_werror(status);
87 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
90 werr = ntstatus_to_werror(status);
94 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
99 if (!NT_STATUS_IS_OK(status)) {
100 werr = ntstatus_to_werror(status);
104 *buffer = (uint8_t *)&info;
114 /****************************************************************
115 ****************************************************************/
117 static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx,
118 const char *server_name,
122 if (!server_name || is_myname_or_ipaddr(server_name)) {
123 return NetServerGetInfoLocal(ctx,
129 return NetServerGetInfoRemote(ctx,
136 /****************************************************************
138 ****************************************************************/
140 NET_API_STATUS NetServerGetInfo(const char *server_name,
144 struct libnetapi_ctx *ctx = NULL;
145 NET_API_STATUS status;
148 status = libnetapi_getctx(&ctx);
153 werr = libnetapi_NetServerGetInfo(ctx,
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,
169 uint32_t *parm_error)
172 struct libnet_conf_ctx *conf_ctx;
173 struct srvsvc_NetSrvInfo1005 *info1005;
176 *parm_error = 1005; /* sure here ? */
177 return WERR_INVALID_PARAM;
180 info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
182 if (!info1005->comment) {
184 return WERR_INVALID_PARAM;
187 if (!lp_config_backend_is_registry()) {
188 return WERR_NOT_SUPPORTED;
191 werr = libnet_conf_open(ctx, &conf_ctx);
192 if (!W_ERROR_IS_OK(werr)) {
196 werr = libnet_conf_set_global_parameter(conf_ctx,
201 libnet_conf_close(conf_ctx);
205 /****************************************************************
206 ****************************************************************/
208 static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
209 const char *server_name,
212 uint32_t *parm_error)
216 return NetServerSetInfoLocal_1005(ctx, buffer, parm_error);
218 return WERR_UNKNOWN_LEVEL;
221 return WERR_UNKNOWN_LEVEL;
224 /****************************************************************
225 ****************************************************************/
227 static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
228 const char *server_name,
231 uint32_t *parm_error)
233 struct cli_state *cli = NULL;
234 struct rpc_pipe_client *pipe_cli = NULL;
237 union srvsvc_NetSrvInfo info;
239 status = cli_full_connection(&cli, NULL, server_name,
247 if (!NT_STATUS_IS_OK(status)) {
248 werr = ntstatus_to_werror(status);
252 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
255 werr = ntstatus_to_werror(status);
261 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
264 werr = WERR_NOT_SUPPORTED;
268 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
274 if (!NT_STATUS_IS_OK(status)) {
275 werr = ntstatus_to_werror(status);
287 /****************************************************************
288 ****************************************************************/
290 static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx,
291 const char *server_name,
294 uint32_t *parm_error)
296 if (!server_name || is_myname_or_ipaddr(server_name)) {
297 return NetServerSetInfoLocal(ctx,
304 return NetServerSetInfoRemote(ctx,
311 /****************************************************************
313 ****************************************************************/
315 NET_API_STATUS NetServerSetInfo(const char *server_name,
318 uint32_t *parm_error)
320 struct libnetapi_ctx *ctx = NULL;
321 NET_API_STATUS status;
324 status = libnetapi_getctx(&ctx);
329 werr = libnetapi_NetServerSetInfo(ctx,
334 if (!W_ERROR_IS_OK(werr)) {
335 return W_ERROR_V(werr);
338 return NET_API_STATUS_SUCCESS;