Rework of VFS is_offline() function to only return boolean offline/online result...
[Samba.git] / source3 / rpcclient / cmd_srvsvc.c
blob572609981dd8641cd91edf16af49bbe8e65eaa8d
1 /*
2 Unix SMB/CIFS implementation.
3 RPC pipe client
5 Copyright (C) Andrew Tridgell 1992-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7 Copyright (C) Tim Potter 2000,2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "includes.h"
24 #include "rpcclient.h"
26 /* Display server query info */
28 static char *get_server_type_str(uint32 type)
30 static fstring typestr;
31 int i;
33 if (type == SV_TYPE_ALL) {
34 fstrcpy(typestr, "All");
35 return typestr;
38 typestr[0] = 0;
40 for (i = 0; i < 32; i++) {
41 if (type & (1 << i)) {
42 switch (1 << i) {
43 case SV_TYPE_WORKSTATION:
44 fstrcat(typestr, "Wk ");
45 break;
46 case SV_TYPE_SERVER:
47 fstrcat(typestr, "Sv ");
48 break;
49 case SV_TYPE_SQLSERVER:
50 fstrcat(typestr, "Sql ");
51 break;
52 case SV_TYPE_DOMAIN_CTRL:
53 fstrcat(typestr, "PDC ");
54 break;
55 case SV_TYPE_DOMAIN_BAKCTRL:
56 fstrcat(typestr, "BDC ");
57 break;
58 case SV_TYPE_TIME_SOURCE:
59 fstrcat(typestr, "Tim ");
60 break;
61 case SV_TYPE_AFP:
62 fstrcat(typestr, "AFP ");
63 break;
64 case SV_TYPE_NOVELL:
65 fstrcat(typestr, "Nov ");
66 break;
67 case SV_TYPE_DOMAIN_MEMBER:
68 fstrcat(typestr, "Dom ");
69 break;
70 case SV_TYPE_PRINTQ_SERVER:
71 fstrcat(typestr, "PrQ ");
72 break;
73 case SV_TYPE_DIALIN_SERVER:
74 fstrcat(typestr, "Din ");
75 break;
76 case SV_TYPE_SERVER_UNIX:
77 fstrcat(typestr, "Unx ");
78 break;
79 case SV_TYPE_NT:
80 fstrcat(typestr, "NT ");
81 break;
82 case SV_TYPE_WFW:
83 fstrcat(typestr, "Wfw ");
84 break;
85 case SV_TYPE_SERVER_MFPN:
86 fstrcat(typestr, "Mfp ");
87 break;
88 case SV_TYPE_SERVER_NT:
89 fstrcat(typestr, "SNT ");
90 break;
91 case SV_TYPE_POTENTIAL_BROWSER:
92 fstrcat(typestr, "PtB ");
93 break;
94 case SV_TYPE_BACKUP_BROWSER:
95 fstrcat(typestr, "BMB ");
96 break;
97 case SV_TYPE_MASTER_BROWSER:
98 fstrcat(typestr, "LMB ");
99 break;
100 case SV_TYPE_DOMAIN_MASTER:
101 fstrcat(typestr, "DMB ");
102 break;
103 case SV_TYPE_SERVER_OSF:
104 fstrcat(typestr, "OSF ");
105 break;
106 case SV_TYPE_SERVER_VMS:
107 fstrcat(typestr, "VMS ");
108 break;
109 case SV_TYPE_WIN95_PLUS:
110 fstrcat(typestr, "W95 ");
111 break;
112 case SV_TYPE_ALTERNATE_XPORT:
113 fstrcat(typestr, "Xpt ");
114 break;
115 case SV_TYPE_LOCAL_LIST_ONLY:
116 fstrcat(typestr, "Dom ");
117 break;
118 case SV_TYPE_DOMAIN_ENUM:
119 fstrcat(typestr, "Loc ");
120 break;
125 i = strlen(typestr) - 1;
127 if (typestr[i] == ' ')
128 typestr[i] = 0;
130 return typestr;
133 static void display_server(char *sname, uint32 type, const char *comment)
135 printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
136 comment);
139 static void display_srv_info_101(SRV_INFO_101 *sv101)
141 fstring name;
142 fstring comment;
144 unistr2_to_ascii(name, &sv101->uni_name, sizeof(name));
145 unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment));
147 display_server(name, sv101->srv_type, comment);
149 printf("\tplatform_id :\t%d\n", sv101->platform_id);
150 printf("\tos version :\t%d.%d\n", sv101->ver_major,
151 sv101->ver_minor);
153 printf("\tserver type :\t0x%x\n", sv101->srv_type);
156 static void display_srv_info_102(SRV_INFO_102 *sv102)
158 fstring name;
159 fstring comment;
160 fstring usr_path;
162 unistr2_to_ascii(name, &sv102->uni_name, sizeof(name));
163 unistr2_to_ascii(comment, &sv102->uni_comment, sizeof(comment));
164 unistr2_to_ascii(usr_path, &sv102->uni_usr_path, sizeof(usr_path));
166 display_server(name, sv102->srv_type, comment);
168 printf("\tplatform_id :\t%d\n", sv102->platform_id);
169 printf("\tos version :\t%d.%d\n", sv102->ver_major,
170 sv102->ver_minor);
172 printf("\tusers :\t%x\n", sv102->users);
173 printf("\tdisc, hidden :\t%x, %x\n", sv102->disc, sv102->hidden);
174 printf("\tannounce, delta :\t%d, %d\n", sv102->announce,
175 sv102->ann_delta);
176 printf("\tlicenses :\t%d\n", sv102->licenses);
177 printf("\tuser path :\t%s\n", usr_path);
180 /* Server query info */
181 static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
182 TALLOC_CTX *mem_ctx,
183 int argc, const char **argv)
185 uint32 info_level = 101;
186 SRV_INFO_CTR ctr;
187 WERROR result;
189 if (argc > 2) {
190 printf("Usage: %s [infolevel]\n", argv[0]);
191 return WERR_OK;
194 if (argc == 2)
195 info_level = atoi(argv[1]);
197 result = rpccli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
198 &ctr);
200 if (!W_ERROR_IS_OK(result)) {
201 goto done;
204 /* Display results */
206 switch (info_level) {
207 case 101:
208 display_srv_info_101(&ctr.srv.sv101);
209 break;
210 case 102:
211 display_srv_info_102(&ctr.srv.sv102);
212 break;
213 default:
214 printf("unsupported info level %d\n", info_level);
215 break;
218 done:
219 return result;
222 static void display_share_info_1(SRV_SHARE_INFO_1 *info1)
224 fstring netname = "", remark = "";
226 rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname);
227 rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark);
229 printf("netname: %s\n", netname);
230 printf("\tremark:\t%s\n", remark);
233 static void display_share_info_2(SRV_SHARE_INFO_2 *info2)
235 fstring netname = "", remark = "", path = "", passwd = "";
237 rpcstr_pull_unistr2_fstring(netname, &info2->info_2_str.uni_netname);
238 rpcstr_pull_unistr2_fstring(remark, &info2->info_2_str.uni_remark);
239 rpcstr_pull_unistr2_fstring(path, &info2->info_2_str.uni_path);
240 rpcstr_pull_unistr2_fstring(passwd, &info2->info_2_str.uni_passwd);
242 printf("netname: %s\n", netname);
243 printf("\tremark:\t%s\n", remark);
244 printf("\tpath:\t%s\n", path);
245 printf("\tpassword:\t%s\n", passwd);
248 static void display_share_info_502(SRV_SHARE_INFO_502 *info502)
250 fstring netname = "", remark = "", path = "", passwd = "";
252 rpcstr_pull_unistr2_fstring(netname, &info502->info_502_str.uni_netname);
253 rpcstr_pull_unistr2_fstring(remark, &info502->info_502_str.uni_remark);
254 rpcstr_pull_unistr2_fstring(path, &info502->info_502_str.uni_path);
255 rpcstr_pull_unistr2_fstring(passwd, &info502->info_502_str.uni_passwd);
257 printf("netname: %s\n", netname);
258 printf("\tremark:\t%s\n", remark);
259 printf("\tpath:\t%s\n", path);
260 printf("\tpassword:\t%s\n", passwd);
262 printf("\ttype:\t0x%x\n", info502->info_502.type);
263 printf("\tperms:\t%d\n", info502->info_502.perms);
264 printf("\tmax_uses:\t%d\n", info502->info_502.max_uses);
265 printf("\tnum_uses:\t%d\n", info502->info_502.num_uses);
267 if (info502->info_502_str.sd)
268 display_sec_desc(info502->info_502_str.sd);
272 static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
273 TALLOC_CTX *mem_ctx,
274 int argc, const char **argv)
276 uint32 info_level = 2;
277 SRV_SHARE_INFO_CTR ctr;
278 WERROR result;
279 ENUM_HND hnd;
280 uint32 preferred_len = 0xffffffff, i;
282 if (argc > 2) {
283 printf("Usage: %s [infolevel]\n", argv[0]);
284 return WERR_OK;
287 if (argc == 2)
288 info_level = atoi(argv[1]);
290 init_enum_hnd(&hnd, 0);
292 result = rpccli_srvsvc_net_share_enum(
293 cli, mem_ctx, info_level, &ctr, preferred_len, &hnd);
295 if (!W_ERROR_IS_OK(result) || !ctr.num_entries)
296 goto done;
298 /* Display results */
300 switch (info_level) {
301 case 1:
302 for (i = 0; i < ctr.num_entries; i++)
303 display_share_info_1(&ctr.share.info1[i]);
304 break;
305 case 2:
306 for (i = 0; i < ctr.num_entries; i++)
307 display_share_info_2(&ctr.share.info2[i]);
308 break;
309 case 502:
310 for (i = 0; i < ctr.num_entries; i++)
311 display_share_info_502(&ctr.share.info502[i]);
312 break;
313 default:
314 printf("unsupported info level %d\n", info_level);
315 break;
318 done:
319 return result;
322 static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
323 TALLOC_CTX *mem_ctx,
324 int argc, const char **argv)
326 uint32 info_level = 502;
327 SRV_SHARE_INFO info;
328 WERROR result;
330 if (argc > 3) {
331 printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
332 return WERR_OK;
335 if (argc == 3)
336 info_level = atoi(argv[2]);
338 result = rpccli_srvsvc_net_share_get_info(cli, mem_ctx, argv[1], info_level, &info);
340 if (!W_ERROR_IS_OK(result))
341 goto done;
343 /* Display results */
345 switch (info_level) {
346 case 1:
347 display_share_info_1(&info.share.info1);
348 break;
349 case 2:
350 display_share_info_2(&info.share.info2);
351 break;
352 case 502:
353 display_share_info_502(&info.share.info502);
354 break;
355 default:
356 printf("unsupported info level %d\n", info_level);
357 break;
360 done:
361 return result;
364 static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
365 TALLOC_CTX *mem_ctx,
366 int argc, const char **argv)
368 uint32 info_level = 502;
369 SRV_SHARE_INFO info_get;
370 WERROR result;
372 if (argc > 3) {
373 printf("Usage: %s [sharename] [comment]\n", argv[0]);
374 return WERR_OK;
377 /* retrieve share info */
378 result = rpccli_srvsvc_net_share_get_info(cli, mem_ctx, argv[1], info_level, &info_get);
379 if (!W_ERROR_IS_OK(result))
380 goto done;
382 info_get.switch_value = info_level;
383 info_get.ptr_share_ctr = 1;
384 init_unistr2(&(info_get.share.info502.info_502_str.uni_remark), argv[2], UNI_STR_TERMINATE);
386 /* set share info */
387 result = rpccli_srvsvc_net_share_set_info(cli, mem_ctx, argv[1], info_level, &info_get);
389 if (!W_ERROR_IS_OK(result))
390 goto done;
392 /* re-retrieve share info and display */
393 result = rpccli_srvsvc_net_share_get_info(cli, mem_ctx, argv[1], info_level, &info_get);
394 if (!W_ERROR_IS_OK(result))
395 goto done;
397 display_share_info_502(&info_get.share.info502);
399 done:
400 return result;
403 static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli,
404 TALLOC_CTX *mem_ctx,
405 int argc, const char **argv)
407 TIME_OF_DAY_INFO tod;
408 fstring srv_name_slash;
409 WERROR result;
411 if (argc > 1) {
412 printf("Usage: %s\n", argv[0]);
413 return WERR_OK;
416 fstr_sprintf(srv_name_slash, "\\\\%s", cli->cli->desthost);
417 result = rpccli_srvsvc_net_remote_tod(
418 cli, mem_ctx, srv_name_slash, &tod);
420 if (!W_ERROR_IS_OK(result))
421 goto done;
423 done:
424 return result;
427 static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
428 TALLOC_CTX *mem_ctx,
429 int argc, const char **argv)
431 uint32 info_level = 3;
432 SRV_FILE_INFO_CTR ctr;
433 WERROR result;
434 ENUM_HND hnd;
435 uint32 preferred_len = 0xffff;
437 if (argc > 2) {
438 printf("Usage: %s [infolevel]\n", argv[0]);
439 return WERR_OK;
442 if (argc == 2)
443 info_level = atoi(argv[1]);
445 init_enum_hnd(&hnd, 0);
447 ZERO_STRUCT(ctr);
449 result = rpccli_srvsvc_net_file_enum(
450 cli, mem_ctx, info_level, NULL, &ctr, preferred_len, &hnd);
452 if (!W_ERROR_IS_OK(result))
453 goto done;
455 done:
456 return result;
459 /* List of commands exported by this module */
461 struct cmd_set srvsvc_commands[] = {
463 { "SRVSVC" },
465 { "srvinfo", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, PI_SRVSVC, NULL, "Server query info", "" },
466 { "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, PI_SRVSVC, NULL, "Enumerate shares", "" },
467 { "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, PI_SRVSVC, NULL, "Get Share Info", "" },
468 { "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, PI_SRVSVC, NULL, "Set Share Info", "" },
469 { "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum, PI_SRVSVC, NULL, "Enumerate open files", "" },
470 { "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, PI_SRVSVC, NULL, "Fetch remote time of day", "" },
472 { NULL }