libnetapi: fix a C++ warning by making implicit cast explicit
[Samba/ekacnet.git] / source3 / lib / netapi / serverinfo.c
blobdd7a8808b4100b406c512330efba3694e9a30310
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 "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"
28 /****************************************************************
29 ****************************************************************/
31 static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
32 uint8_t **buffer)
34 struct SERVER_INFO_1005 info1005;
36 info1005.sv1005_comment = lp_serverstring();
37 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
38 if (!*buffer) {
39 return WERR_NOMEM;
42 return WERR_OK;
45 /****************************************************************
46 ****************************************************************/
48 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
49 struct NetServerGetInfo *r)
51 switch (r->in.level) {
52 case 1005:
53 return NetServerGetInfo_l_1005(ctx, r->out.buffer);
54 default:
55 return WERR_UNKNOWN_LEVEL;
58 return WERR_UNKNOWN_LEVEL;
61 /****************************************************************
62 ****************************************************************/
64 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
65 struct NetServerGetInfo *r)
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;
73 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
74 if (!W_ERROR_IS_OK(werr)) {
75 goto done;
78 werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli);
79 if (!W_ERROR_IS_OK(werr)) {
80 goto done;
83 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
84 r->in.server_name,
85 r->in.level,
86 &info,
87 &werr);
88 if (!NT_STATUS_IS_OK(status)) {
89 werr = ntstatus_to_werror(status);
90 goto done;
93 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, &info, sizeof(info));
94 if (!*r->out.buffer) {
95 werr = WERR_NOMEM;
96 goto done;
99 done:
100 return werr;
103 /****************************************************************
104 ****************************************************************/
106 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
107 struct NetServerSetInfo *r)
109 WERROR werr;
110 struct smbconf_ctx *conf_ctx;
111 struct srvsvc_NetSrvInfo1005 *info1005;
113 if (!r->in.buffer) {
114 *r->out.parm_error = 1005; /* sure here ? */
115 return WERR_INVALID_PARAM;
118 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
120 if (!info1005->comment) {
121 *r->out.parm_error = 1005;
122 return WERR_INVALID_PARAM;
125 if (!lp_config_backend_is_registry()) {
126 libnetapi_set_error_string(ctx,
127 "Configuration manipulation requested but not "
128 "supported by backend");
129 return WERR_NOT_SUPPORTED;
132 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
133 if (!W_ERROR_IS_OK(werr)) {
134 goto done;
137 werr = smbconf_set_global_parameter(conf_ctx, "server string",
138 info1005->comment);
140 done:
141 smbconf_shutdown(conf_ctx);
142 return werr;
145 /****************************************************************
146 ****************************************************************/
148 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
149 struct NetServerSetInfo *r)
151 switch (r->in.level) {
152 case 1005:
153 return NetServerSetInfo_l_1005(ctx, r);
154 default:
155 return WERR_UNKNOWN_LEVEL;
158 return WERR_UNKNOWN_LEVEL;
161 /****************************************************************
162 ****************************************************************/
164 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
165 struct NetServerSetInfo *r)
167 struct cli_state *cli = NULL;
168 struct rpc_pipe_client *pipe_cli = NULL;
169 NTSTATUS status;
170 WERROR werr;
171 union srvsvc_NetSrvInfo info;
173 werr = libnetapi_open_ipc_connection(ctx, r->in.server_name, &cli);
174 if (!W_ERROR_IS_OK(werr)) {
175 goto done;
178 werr = libnetapi_open_pipe(ctx, cli, PI_SRVSVC, &pipe_cli);
179 if (!W_ERROR_IS_OK(werr)) {
180 goto done;
183 switch (r->in.level) {
184 case 1005:
185 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
186 break;
187 default:
188 werr = WERR_NOT_SUPPORTED;
189 goto done;
192 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
193 r->in.server_name,
194 r->in.level,
195 &info,
196 r->out.parm_error,
197 &werr);
198 if (!NT_STATUS_IS_OK(status)) {
199 werr = ntstatus_to_werror(status);
200 goto done;
203 done:
204 return werr;