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)
153 struct libnet_conf_ctx *conf_ctx;
156 struct srvsvc_NetSrvInfo1005 *info1005;
159 *parm_error = 1005; /* sure here ? */
160 return WERR_INVALID_PARAM;
163 info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
165 if (!info1005->comment) {
167 return WERR_INVALID_PARAM;
170 if (!lp_include_registry_globals()) {
171 return WERR_NOT_SUPPORTED;
174 mem_ctx = talloc_stackframe();
175 werr = libnet_conf_open(mem_ctx, &conf_ctx);
176 if (!W_ERROR_IS_OK(werr)) {
180 werr = libnet_conf_set_global_parameter(conf_ctx,
185 libnet_conf_close(conf_ctx);
186 TALLOC_FREE(mem_ctx);
190 static WERROR NetServerSetInfoLocal(struct libnetapi_ctx *ctx,
191 const char *server_name,
194 uint32_t *parm_error)
198 return NetServerSetInfoLocal_1005(ctx, buffer, parm_error);
200 return WERR_UNKNOWN_LEVEL;
203 return WERR_UNKNOWN_LEVEL;
206 static WERROR NetServerSetInfoRemote(struct libnetapi_ctx *ctx,
207 const char *server_name,
210 uint32_t *parm_error)
212 struct cli_state *cli = NULL;
213 struct rpc_pipe_client *pipe_cli = NULL;
216 union srvsvc_NetSrvInfo info;
218 status = cli_full_connection(&cli, NULL, server_name,
226 if (!NT_STATUS_IS_OK(status)) {
227 werr = ntstatus_to_werror(status);
231 pipe_cli = cli_rpc_pipe_open_noauth(cli, PI_SRVSVC,
234 werr = ntstatus_to_werror(status);
240 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)buffer;
243 werr = WERR_NOT_SUPPORTED;
247 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
253 if (!NT_STATUS_IS_OK(status)) {
254 werr = ntstatus_to_werror(status);
266 static WERROR libnetapi_NetServerSetInfo(struct libnetapi_ctx *ctx,
267 const char *server_name,
270 uint32_t *parm_error)
272 if (!server_name || is_myname_or_ipaddr(server_name)) {
273 return NetServerSetInfoLocal(ctx,
280 return NetServerSetInfoRemote(ctx,
288 NET_API_STATUS NetServerSetInfo(const char *server_name,
291 uint32_t *parm_error)
293 struct libnetapi_ctx *ctx = NULL;
294 NET_API_STATUS status;
297 status = libnetapi_getctx(&ctx);
302 werr = libnetapi_NetServerSetInfo(ctx,
307 if (!W_ERROR_IS_OK(werr)) {
308 return W_ERROR_V(werr);