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 static WERROR NetServerGetInfoLocal_1005(struct libnetapi_ctx *ctx,
28 struct srvsvc_NetSrvInfo1005 info1005;
30 info1005.comment = lp_serverstring();
31 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
39 static WERROR NetServerGetInfoLocal(struct libnetapi_ctx *ctx,
40 const char *server_name,
46 return NetServerGetInfoLocal_1005(ctx, buffer);
48 return WERR_UNKNOWN_LEVEL;
51 return WERR_UNKNOWN_LEVEL;
54 static WERROR NetServerGetInfoRemote(struct libnetapi_ctx *ctx,
55 const char *server_name,
59 struct cli_state *cli = NULL;
60 struct rpc_pipe_client *pipe_cli = NULL;
63 union srvsvc_NetSrvInfo info;
65 status = cli_full_connection(&cli, NULL, server_name,
73 if (!NT_STATUS_IS_OK(status)) {
74 werr = ntstatus_to_werror(status);
78 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
81 werr = ntstatus_to_werror(status);
85 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
90 if (!NT_STATUS_IS_OK(status)) {
91 werr = ntstatus_to_werror(status);
95 *buffer = (uint8_t *)&info;
105 static WERROR libnetapi_NetServerGetInfo(struct libnetapi_ctx *ctx,
106 const char *server_name,
110 if (!server_name || is_myname_or_ipaddr(server_name)) {
111 return NetServerGetInfoLocal(ctx,
117 return NetServerGetInfoRemote(ctx,
124 NET_API_STATUS NetServerGetInfo(const char *server_name,
128 struct libnetapi_ctx *ctx = NULL;
129 NET_API_STATUS status;
132 status = libnetapi_getctx(&ctx);
137 werr = libnetapi_NetServerGetInfo(ctx,
141 if (!W_ERROR_IS_OK(werr)) {
142 return W_ERROR_V(werr);
148 static WERROR NetServerSetInfoLocal_1005(struct libnetapi_ctx *ctx,
150 uint32_t *parm_error)
152 struct srvsvc_NetSrvInfo1005 *info1005;
155 *parm_error = 1005; /* sure here ? */
156 return WERR_INVALID_PARAM;
159 info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
161 if (!info1005->comment) {
163 return WERR_INVALID_PARAM;
166 if (!lp_include_registry_globals()) {
167 return WERR_NOT_SUPPORTED;
170 return libnet_conf_set_global_parameter("server string",
174 static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
175 const char *server_name,
178 uint32_t *parm_error)
182 return NetServerSetInfoLocal_1005(ctx, buffer, parm_error);
184 return WERR_UNKNOWN_LEVEL;
187 return WERR_UNKNOWN_LEVEL;
190 static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
191 const char *server_name,
194 uint32_t *parm_error)
196 struct cli_state *cli = NULL;
197 struct rpc_pipe_client *pipe_cli = NULL;
200 union srvsvc_NetSrvInfo info;
202 status = cli_full_connection(&cli, NULL, server_name,
210 if (!NT_STATUS_IS_OK(status)) {
211 werr = ntstatus_to_werror(status);
215 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
218 werr = ntstatus_to_werror(status);
224 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
227 werr = WERR_NOT_SUPPORTED;
231 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
237 if (!NT_STATUS_IS_OK(status)) {
238 werr = ntstatus_to_werror(status);
250 static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx,
251 const char *server_name,
254 uint32_t *parm_error)
256 if (!server_name || is_myname_or_ipaddr(server_name)) {
257 return NetServerSetInfoLocal(ctx,
264 return NetServerSetInfoRemote(ctx,
272 NET_API_STATUS NetServerSetInfo(const char *server_name,
275 uint32_t *parm_error)
277 struct libnetapi_ctx *ctx = NULL;
278 NET_API_STATUS status;
281 status = libnetapi_getctx(&ctx);
286 werr = libnetapi_NetServerSetInfo(ctx,
291 if (!W_ERROR_IS_OK(werr)) {
292 return W_ERROR_V(werr);