Use vfs_cifs as a basis for vfs_proxy
[Samba/vfs_proxy.git] / source3 / lib / netapi / serverinfo.c
blobb2a134b0afc4e47a5c1ca096ac7217eaa240ea32
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 cli_state *cli = NULL;
165 struct rpc_pipe_client *pipe_cli = NULL;
166 NTSTATUS status;
167 WERROR werr;
168 union srvsvc_NetSrvInfo info;
170 if (!r->out.buffer) {
171 return WERR_INVALID_PARAM;
174 switch (r->in.level) {
175 case 100:
176 case 101:
177 case 102:
178 case 1005:
179 break;
180 default:
181 return WERR_UNKNOWN_LEVEL;
184 werr = libnetapi_open_pipe(ctx, r->in.server_name,
185 &ndr_table_srvsvc.syntax_id,
186 &cli,
187 &pipe_cli);
188 if (!W_ERROR_IS_OK(werr)) {
189 goto done;
192 status = rpccli_srvsvc_NetSrvGetInfo(pipe_cli, ctx,
193 r->in.server_name,
194 r->in.level,
195 &info,
196 &werr);
197 if (!NT_STATUS_IS_OK(status)) {
198 werr = ntstatus_to_werror(status);
199 goto done;
202 status = map_server_info_to_SERVER_INFO_buffer(ctx, r->in.level, &info,
203 r->out.buffer);
204 if (!NT_STATUS_IS_OK(status)) {
205 werr = ntstatus_to_werror(status);
206 goto done;
209 done:
210 return werr;
213 /****************************************************************
214 ****************************************************************/
216 static WERROR NetServerSetInfo_l_1005(struct libnetapi_ctx *ctx,
217 struct NetServerSetInfo *r)
219 WERROR werr;
220 struct smbconf_ctx *conf_ctx;
221 struct srvsvc_NetSrvInfo1005 *info1005;
223 if (!r->in.buffer) {
224 *r->out.parm_error = 1005; /* sure here ? */
225 return WERR_INVALID_PARAM;
228 info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
230 if (!info1005->comment) {
231 *r->out.parm_error = 1005;
232 return WERR_INVALID_PARAM;
235 if (!lp_config_backend_is_registry()) {
236 libnetapi_set_error_string(ctx,
237 "Configuration manipulation requested but not "
238 "supported by backend");
239 return WERR_NOT_SUPPORTED;
242 werr = smbconf_init_reg(ctx, &conf_ctx, NULL);
243 if (!W_ERROR_IS_OK(werr)) {
244 goto done;
247 werr = smbconf_set_global_parameter(conf_ctx, "server string",
248 info1005->comment);
250 done:
251 smbconf_shutdown(conf_ctx);
252 return werr;
255 /****************************************************************
256 ****************************************************************/
258 WERROR NetServerSetInfo_l(struct libnetapi_ctx *ctx,
259 struct NetServerSetInfo *r)
261 switch (r->in.level) {
262 case 1005:
263 return NetServerSetInfo_l_1005(ctx, r);
264 default:
265 return WERR_UNKNOWN_LEVEL;
268 return WERR_UNKNOWN_LEVEL;
271 /****************************************************************
272 ****************************************************************/
274 WERROR NetServerSetInfo_r(struct libnetapi_ctx *ctx,
275 struct NetServerSetInfo *r)
277 struct cli_state *cli = NULL;
278 struct rpc_pipe_client *pipe_cli = NULL;
279 NTSTATUS status;
280 WERROR werr;
281 union srvsvc_NetSrvInfo info;
283 werr = libnetapi_open_pipe(ctx, r->in.server_name,
284 &ndr_table_srvsvc.syntax_id,
285 &cli,
286 &pipe_cli);
287 if (!W_ERROR_IS_OK(werr)) {
288 goto done;
291 switch (r->in.level) {
292 case 1005:
293 info.info1005 = (struct srvsvc_NetSrvInfo1005 *)r->in.buffer;
294 break;
295 default:
296 werr = WERR_NOT_SUPPORTED;
297 goto done;
300 status = rpccli_srvsvc_NetSrvSetInfo(pipe_cli, ctx,
301 r->in.server_name,
302 r->in.level,
303 &info,
304 r->out.parm_error,
305 &werr);
306 if (!NT_STATUS_IS_OK(status)) {
307 werr = ntstatus_to_werror(status);
308 goto done;
311 done:
312 return werr;
315 /****************************************************************
316 ****************************************************************/
318 WERROR NetRemoteTOD_r(struct libnetapi_ctx *ctx,
319 struct NetRemoteTOD *r)
321 struct cli_state *cli = NULL;
322 struct rpc_pipe_client *pipe_cli = NULL;
323 NTSTATUS status;
324 WERROR werr;
325 struct srvsvc_NetRemoteTODInfo *info = NULL;
327 werr = libnetapi_open_pipe(ctx, r->in.server_name,
328 &ndr_table_srvsvc.syntax_id,
329 &cli,
330 &pipe_cli);
331 if (!W_ERROR_IS_OK(werr)) {
332 goto done;
335 status = rpccli_srvsvc_NetRemoteTOD(pipe_cli, ctx,
336 r->in.server_name,
337 &info,
338 &werr);
339 if (!NT_STATUS_IS_OK(status)) {
340 werr = ntstatus_to_werror(status);
341 goto done;
344 *r->out.buffer = (uint8_t *)talloc_memdup(ctx, info,
345 sizeof(struct srvsvc_NetRemoteTODInfo));
346 W_ERROR_HAVE_NO_MEMORY(*r->out.buffer);
348 done:
349 return werr;
352 /****************************************************************
353 ****************************************************************/
355 WERROR NetRemoteTOD_l(struct libnetapi_ctx *ctx,
356 struct NetRemoteTOD *r)
358 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetRemoteTOD);