libnetapi_open_pipe does not need to return cli_state
[Samba/gebeck_regimport.git] / source3 / lib / netapi / serverinfo.c
blobd77145eef3cc0b67a7168e0e12fa186651badded
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_101(struct libnetapi_ctx *ctx,
32 uint8_t **buffer)
34 struct SERVER_INFO_101 i;
36 i.sv101_platform_id = PLATFORM_ID_NT;
37 i.sv101_name = global_myname();
38 i.sv101_version_major = lp_major_announce_version();
39 i.sv101_version_minor = lp_minor_announce_version();
40 i.sv101_type = lp_default_server_announce();
41 i.sv101_comment = lp_serverstring();
43 *buffer = (uint8_t *)talloc_memdup(ctx, &i, sizeof(i));
44 if (!*buffer) {
45 return WERR_NOMEM;
48 return WERR_OK;
51 /****************************************************************
52 ****************************************************************/
54 static WERROR NetServerGetInfo_l_1005(struct libnetapi_ctx *ctx,
55 uint8_t **buffer)
57 struct SERVER_INFO_1005 info1005;
59 info1005.sv1005_comment = lp_serverstring();
60 *buffer = (uint8_t *)talloc_memdup(ctx, &info1005, sizeof(info1005));
61 if (!*buffer) {
62 return WERR_NOMEM;
65 return WERR_OK;
68 /****************************************************************
69 ****************************************************************/
71 WERROR NetServerGetInfo_l(struct libnetapi_ctx *ctx,
72 struct NetServerGetInfo *r)
74 switch (r->in.level) {
75 case 101:
76 return NetServerGetInfo_l_101(ctx, r->out.buffer);
77 case 1005:
78 return NetServerGetInfo_l_1005(ctx, r->out.buffer);
79 default:
80 return WERR_UNKNOWN_LEVEL;
83 return WERR_UNKNOWN_LEVEL;
86 /****************************************************************
87 ****************************************************************/
89 static NTSTATUS map_server_info_to_SERVER_INFO_buffer(TALLOC_CTX *mem_ctx,
90 uint32_t level,
91 union srvsvc_NetSrvInfo *i,
92 uint8_t **buffer)
94 struct SERVER_INFO_100 i100;
95 struct SERVER_INFO_101 i101;
96 struct SERVER_INFO_102 i102;
97 struct SERVER_INFO_1005 i1005;
99 uint32_t num_info = 0;
101 switch (level) {
102 case 100:
103 i100.sv100_platform_id = i->info100->platform_id;
104 i100.sv100_name = talloc_strdup(mem_ctx, i->info100->server_name);
106 ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_100, i100,
107 (struct SERVER_INFO_100 **)buffer,
108 &num_info);
109 break;
111 case 101:
112 i101.sv101_platform_id = i->info101->platform_id;
113 i101.sv101_name = talloc_strdup(mem_ctx, i->info101->server_name);
114 i101.sv101_version_major = i->info101->version_major;
115 i101.sv101_version_minor = i->info101->version_minor;
116 i101.sv101_type = i->info101->server_type;
117 i101.sv101_comment = talloc_strdup(mem_ctx, i->info101->comment);
119 ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_101, i101,
120 (struct SERVER_INFO_101 **)buffer,
121 &num_info);
122 break;
124 case 102:
125 i102.sv102_platform_id = i->info102->platform_id;
126 i102.sv102_name = talloc_strdup(mem_ctx, i->info102->server_name);
127 i102.sv102_version_major = i->info102->version_major;
128 i102.sv102_version_minor = i->info102->version_minor;
129 i102.sv102_type = i->info102->server_type;
130 i102.sv102_comment = talloc_strdup(mem_ctx, i->info102->comment);
131 i102.sv102_users = i->info102->users;
132 i102.sv102_disc = i->info102->disc;
133 i102.sv102_hidden = i->info102->hidden;
134 i102.sv102_announce = i->info102->announce;
135 i102.sv102_anndelta = i->info102->anndelta;
136 i102.sv102_licenses = i->info102->licenses;
137 i102.sv102_userpath = talloc_strdup(mem_ctx, i->info102->userpath);
139 ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_102, i102,
140 (struct SERVER_INFO_102 **)buffer,
141 &num_info);
142 break;
144 case 1005:
145 i1005.sv1005_comment = talloc_strdup(mem_ctx, i->info1005->comment);
147 ADD_TO_ARRAY(mem_ctx, struct SERVER_INFO_1005, i1005,
148 (struct SERVER_INFO_1005 **)buffer,
149 &num_info);
150 break;
151 default:
152 return NT_STATUS_NOT_SUPPORTED;
155 return NT_STATUS_OK;
158 /****************************************************************
159 ****************************************************************/
161 WERROR NetServerGetInfo_r(struct libnetapi_ctx *ctx,
162 struct NetServerGetInfo *r)
164 struct rpc_pipe_client *pipe_cli = NULL;
165 NTSTATUS status;
166 WERROR werr;
167 union srvsvc_NetSrvInfo info;
169 if (!r->out.buffer) {
170 return WERR_INVALID_PARAM;
173 switch (r->in.level) {
174 case 100:
175 case 101:
176 case 102:
177 case 1005:
178 break;
179 default:
180 return WERR_UNKNOWN_LEVEL;
183 werr = libnetapi_open_pipe(ctx, r->in.server_name,
184 &ndr_table_srvsvc.syntax_id,
185 &pipe_cli);
186 if (!W_ERROR_IS_OK(werr)) {
187 goto done;
190 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
191 r->in.server_name,
192 r->in.level,
193 &info,
194 &werr);
195 if (!NT_STATUS_IS_OK(status)) {
196 werr = ntstatus_to_werror(status);
197 goto done;
200 status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info,
201 r->out.buffer);
202 if (!NT_STATUS_IS_OK(status)) {
203 werr = ntstatus_to_werror(status);
204 goto done;
207 done:
208 return werr;
211 /****************************************************************
212 ****************************************************************/
214 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
215 struct NetServerSetInfo *r)
217 WERROR werr;
218 struct smbconf_ctx *conf_ctx;
219 struct srvsvc_NetSrvInfo1005 *info1005;
221 if (!r->in.buffer) {
222 *r->out.parm_error = 1005; /* sure here ? */
223 return WERR_INVALID_PARAM;
226 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
228 if (!info1005->comment) {
229 *r->out.parm_error = 1005;
230 return WERR_INVALID_PARAM;
233 if (!lp_config_backend_is_registry()) {
234 libnetapi_set_error_string(ctx,
235 "Configuration manipulation requested but not "
236 "supported by backend");
237 return WERR_NOT_SUPPORTED;
240 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
241 if (!W_ERROR_IS_OK(werr)) {
242 goto done;
245 werr = smbconf_set_global_parameter(conf_ctx, "server string",
246 info1005->comment);
248 done:
249 smbconf_shutdown(conf_ctx);
250 return werr;
253 /****************************************************************
254 ****************************************************************/
256 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
257 struct NetServerSetInfo *r)
259 switch (r->in.level) {
260 case 1005:
261 return NetServerSetInfo_l_1005(ctx, r);
262 default:
263 return WERR_UNKNOWN_LEVEL;
266 return WERR_UNKNOWN_LEVEL;
269 /****************************************************************
270 ****************************************************************/
272 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
273 struct NetServerSetInfo *r)
275 struct rpc_pipe_client *pipe_cli = NULL;
276 NTSTATUS status;
277 WERROR werr;
278 union srvsvc_NetSrvInfo info;
280 werr = libnetapi_open_pipe(ctx, r->in.server_name,
281 &ndr_table_srvsvc.syntax_id,
282 &pipe_cli);
283 if (!W_ERROR_IS_OK(werr)) {
284 goto done;
287 switch (r->in.level) {
288 case 1005:
289 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
290 break;
291 default:
292 werr = WERR_NOT_SUPPORTED;
293 goto done;
296 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
297 r->in.server_name,
298 r->in.level,
299 &info,
300 r->out.parm_error,
301 &werr);
302 if (!NT_STATUS_IS_OK(status)) {
303 werr = ntstatus_to_werror(status);
304 goto done;
307 done:
308 return werr;
311 /****************************************************************
312 ****************************************************************/
314 WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
315 struct NetRemoteTOD *r)
317 struct rpc_pipe_client *pipe_cli = NULL;
318 NTSTATUS status;
319 WERROR werr;
320 struct srvsvc_NetRemoteTODInfo *info = NULL;
322 werr = libnetapi_open_pipe(ctx, r->in.server_name,
323 &ndr_table_srvsvc.syntax_id,
324 &pipe_cli);
325 if (!W_ERROR_IS_OK(werr)) {
326 goto done;
329 status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
330 r->in.server_name,
331 &info,
332 &werr);
333 if (!NT_STATUS_IS_OK(status)) {
334 werr = ntstatus_to_werror(status);
335 goto done;
338 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
339 sizeof(struct srvsvc_NetRemoteTODInfo));
340 W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
342 done:
343 return werr;
346 /****************************************************************
347 ****************************************************************/
349 WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
350 struct NetRemoteTOD *r)
352 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);