lib/socket_wrapper: try to fix the build on solaris
[Samba.git] / source3 / rpcclient / cmd_srvsvc.c
blob685cdd6a3be7e8150b4b255b4c6019a7b3aa334d
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"
25 #include "../librpc/gen_ndr/ndr_srvsvc.h"
26 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
28 /* Display server query info */
30 static char *get_server_type_str(uint32 type)
32 static fstring typestr;
33 int i;
35 if (type == SV_TYPE_ALL) {
36 fstrcpy(typestr, "All");
37 return typestr;
40 typestr[0] = 0;
42 for (i = 0; i < 32; i++) {
43 if (type & (1 << i)) {
44 switch (1 << i) {
45 case SV_TYPE_WORKSTATION:
46 fstrcat(typestr, "Wk ");
47 break;
48 case SV_TYPE_SERVER:
49 fstrcat(typestr, "Sv ");
50 break;
51 case SV_TYPE_SQLSERVER:
52 fstrcat(typestr, "Sql ");
53 break;
54 case SV_TYPE_DOMAIN_CTRL:
55 fstrcat(typestr, "PDC ");
56 break;
57 case SV_TYPE_DOMAIN_BAKCTRL:
58 fstrcat(typestr, "BDC ");
59 break;
60 case SV_TYPE_TIME_SOURCE:
61 fstrcat(typestr, "Tim ");
62 break;
63 case SV_TYPE_AFP:
64 fstrcat(typestr, "AFP ");
65 break;
66 case SV_TYPE_NOVELL:
67 fstrcat(typestr, "Nov ");
68 break;
69 case SV_TYPE_DOMAIN_MEMBER:
70 fstrcat(typestr, "Dom ");
71 break;
72 case SV_TYPE_PRINTQ_SERVER:
73 fstrcat(typestr, "PrQ ");
74 break;
75 case SV_TYPE_DIALIN_SERVER:
76 fstrcat(typestr, "Din ");
77 break;
78 case SV_TYPE_SERVER_UNIX:
79 fstrcat(typestr, "Unx ");
80 break;
81 case SV_TYPE_NT:
82 fstrcat(typestr, "NT ");
83 break;
84 case SV_TYPE_WFW:
85 fstrcat(typestr, "Wfw ");
86 break;
87 case SV_TYPE_SERVER_MFPN:
88 fstrcat(typestr, "Mfp ");
89 break;
90 case SV_TYPE_SERVER_NT:
91 fstrcat(typestr, "SNT ");
92 break;
93 case SV_TYPE_POTENTIAL_BROWSER:
94 fstrcat(typestr, "PtB ");
95 break;
96 case SV_TYPE_BACKUP_BROWSER:
97 fstrcat(typestr, "BMB ");
98 break;
99 case SV_TYPE_MASTER_BROWSER:
100 fstrcat(typestr, "LMB ");
101 break;
102 case SV_TYPE_DOMAIN_MASTER:
103 fstrcat(typestr, "DMB ");
104 break;
105 case SV_TYPE_SERVER_OSF:
106 fstrcat(typestr, "OSF ");
107 break;
108 case SV_TYPE_SERVER_VMS:
109 fstrcat(typestr, "VMS ");
110 break;
111 case SV_TYPE_WIN95_PLUS:
112 fstrcat(typestr, "W95 ");
113 break;
114 case SV_TYPE_ALTERNATE_XPORT:
115 fstrcat(typestr, "Xpt ");
116 break;
117 case SV_TYPE_LOCAL_LIST_ONLY:
118 fstrcat(typestr, "Dom ");
119 break;
120 case SV_TYPE_DOMAIN_ENUM:
121 fstrcat(typestr, "Loc ");
122 break;
127 i = strlen(typestr) - 1;
129 if (typestr[i] == ' ')
130 typestr[i] = 0;
132 return typestr;
135 static void display_server(const char *sname, uint32 type, const char *comment)
137 printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
138 comment);
141 static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
143 display_server(r->server_name, r->server_type, r->comment);
145 printf("\tplatform_id :\t%d\n", r->platform_id);
146 printf("\tos version :\t%d.%d\n",
147 r->version_major, r->version_minor);
148 printf("\tserver type :\t0x%x\n", r->server_type);
151 static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
153 display_server(r->server_name, r->server_type, r->comment);
155 printf("\tplatform_id :\t%d\n", r->platform_id);
156 printf("\tos version :\t%d.%d\n",
157 r->version_major, r->version_minor);
158 printf("\tserver type :\t0x%x\n", r->server_type);
160 printf("\tusers :\t%x\n", r->users);
161 printf("\tdisc, hidden :\t%x, %x\n", r->disc, r->hidden);
162 printf("\tannounce, delta :\t%d, %d\n", r->announce,
163 r->anndelta);
164 printf("\tlicenses :\t%d\n", r->licenses);
165 printf("\tuser path :\t%s\n", r->userpath);
168 /* Server query info */
169 static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
170 TALLOC_CTX *mem_ctx,
171 int argc, const char **argv)
173 uint32 info_level = 101;
174 union srvsvc_NetSrvInfo info;
175 WERROR result;
176 NTSTATUS status;
177 const char *server_unc = cli->srv_name_slash;
178 struct dcerpc_binding_handle *b = cli->binding_handle;
180 if (argc > 3) {
181 printf("Usage: %s [infolevel] [server_unc]\n", argv[0]);
182 return WERR_OK;
185 if (argc >= 2) {
186 info_level = atoi(argv[1]);
189 if (argc >= 3) {
190 server_unc = argv[2];
193 status = dcerpc_srvsvc_NetSrvGetInfo(b, mem_ctx,
194 server_unc,
195 info_level,
196 &info,
197 &result);
198 if (!NT_STATUS_IS_OK(status)) {
199 return ntstatus_to_werror(status);
202 if (!W_ERROR_IS_OK(result)) {
203 goto done;
206 /* Display results */
208 switch (info_level) {
209 case 101:
210 display_srv_info_101(info.info101);
211 break;
212 case 102:
213 display_srv_info_102(info.info102);
214 break;
215 default:
216 printf("unsupported info level %d\n", info_level);
217 break;
220 done:
221 return result;
224 static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
226 printf("netname: %s\n", r->name);
227 printf("\tremark:\t%s\n", r->comment);
230 static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
232 printf("netname: %s\n", r->name);
233 printf("\tremark:\t%s\n", r->comment);
234 printf("\tpath:\t%s\n", r->path);
235 printf("\tpassword:\t%s\n", r->password);
238 static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
240 printf("netname: %s\n", r->name);
241 printf("\tremark:\t%s\n", r->comment);
242 printf("\tpath:\t%s\n", r->path);
243 printf("\tpassword:\t%s\n", r->password);
245 printf("\ttype:\t0x%x\n", r->type);
246 printf("\tperms:\t%d\n", r->permissions);
247 printf("\tmax_uses:\t%d\n", r->max_users);
248 printf("\tnum_uses:\t%d\n", r->current_users);
250 if (r->sd_buf.sd)
251 display_sec_desc(r->sd_buf.sd);
255 static WERROR cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client *cli,
256 TALLOC_CTX *mem_ctx,
257 int argc, const char **argv,
258 uint32_t opcode)
260 uint32 info_level = 2;
261 struct srvsvc_NetShareInfoCtr info_ctr;
262 struct srvsvc_NetShareCtr0 ctr0;
263 struct srvsvc_NetShareCtr1 ctr1;
264 struct srvsvc_NetShareCtr2 ctr2;
265 struct srvsvc_NetShareCtr501 ctr501;
266 struct srvsvc_NetShareCtr502 ctr502;
267 struct srvsvc_NetShareCtr1004 ctr1004;
268 struct srvsvc_NetShareCtr1005 ctr1005;
269 struct srvsvc_NetShareCtr1006 ctr1006;
270 struct srvsvc_NetShareCtr1007 ctr1007;
271 struct srvsvc_NetShareCtr1501 ctr1501;
272 WERROR result;
273 NTSTATUS status;
274 uint32_t totalentries = 0;
275 uint32_t resume_handle = 0;
276 uint32_t *resume_handle_p = NULL;
277 uint32 preferred_len = 0xffffffff, i;
278 struct dcerpc_binding_handle *b = cli->binding_handle;
280 if (argc > 3) {
281 printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
282 return WERR_OK;
285 if (argc >= 2) {
286 info_level = atoi(argv[1]);
289 if (argc == 3) {
290 resume_handle = atoi(argv[2]);
291 resume_handle_p = &resume_handle;
294 ZERO_STRUCT(info_ctr);
296 info_ctr.level = info_level;
298 switch (info_level) {
299 case 0:
300 ZERO_STRUCT(ctr0);
301 info_ctr.ctr.ctr0 = &ctr0;
302 break;
303 case 1:
304 ZERO_STRUCT(ctr1);
305 info_ctr.ctr.ctr1 = &ctr1;
306 break;
307 case 2:
308 ZERO_STRUCT(ctr2);
309 info_ctr.ctr.ctr2 = &ctr2;
310 break;
311 case 501:
312 ZERO_STRUCT(ctr501);
313 info_ctr.ctr.ctr501 = &ctr501;
314 break;
315 case 502:
316 ZERO_STRUCT(ctr502);
317 info_ctr.ctr.ctr502 = &ctr502;
318 break;
319 case 1004:
320 ZERO_STRUCT(ctr1004);
321 info_ctr.ctr.ctr1004 = &ctr1004;
322 break;
323 case 1005:
324 ZERO_STRUCT(ctr1005);
325 info_ctr.ctr.ctr1005 = &ctr1005;
326 break;
327 case 1006:
328 ZERO_STRUCT(ctr1006);
329 info_ctr.ctr.ctr1006 = &ctr1006;
330 break;
331 case 1007:
332 ZERO_STRUCT(ctr1007);
333 info_ctr.ctr.ctr1007 = &ctr1007;
334 break;
335 case 1501:
336 ZERO_STRUCT(ctr1501);
337 info_ctr.ctr.ctr1501 = &ctr1501;
338 break;
341 switch (opcode) {
342 case NDR_SRVSVC_NETSHAREENUM:
343 status = dcerpc_srvsvc_NetShareEnum(b, mem_ctx,
344 cli->desthost,
345 &info_ctr,
346 preferred_len,
347 &totalentries,
348 resume_handle_p,
349 &result);
350 break;
351 case NDR_SRVSVC_NETSHAREENUMALL:
352 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
353 cli->desthost,
354 &info_ctr,
355 preferred_len,
356 &totalentries,
357 resume_handle_p,
358 &result);
359 break;
360 default:
361 return WERR_INVALID_PARAM;
364 if (!NT_STATUS_IS_OK(status)) {
365 result = ntstatus_to_werror(status);
366 goto done;
368 if (!W_ERROR_IS_OK(result)) {
369 goto done;
372 /* Display results */
374 switch (info_level) {
375 case 1:
376 for (i = 0; i < totalentries; i++)
377 display_share_info_1(&info_ctr.ctr.ctr1->array[i]);
378 break;
379 case 2:
380 for (i = 0; i < totalentries; i++)
381 display_share_info_2(&info_ctr.ctr.ctr2->array[i]);
382 break;
383 case 502:
384 for (i = 0; i < totalentries; i++)
385 display_share_info_502(&info_ctr.ctr.ctr502->array[i]);
386 break;
387 default:
388 printf("unsupported info level %d\n", info_level);
389 break;
392 done:
393 return result;
396 static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
397 TALLOC_CTX *mem_ctx,
398 int argc, const char **argv)
400 return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
401 argc, argv,
402 NDR_SRVSVC_NETSHAREENUM);
405 static WERROR cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client *cli,
406 TALLOC_CTX *mem_ctx,
407 int argc, const char **argv)
409 return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
410 argc, argv,
411 NDR_SRVSVC_NETSHAREENUMALL);
414 static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
415 TALLOC_CTX *mem_ctx,
416 int argc, const char **argv)
418 uint32 info_level = 502;
419 union srvsvc_NetShareInfo info;
420 WERROR result;
421 NTSTATUS status;
422 struct dcerpc_binding_handle *b = cli->binding_handle;
424 if (argc < 2 || argc > 3) {
425 printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
426 return WERR_OK;
429 if (argc == 3)
430 info_level = atoi(argv[2]);
432 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
433 cli->desthost,
434 argv[1],
435 info_level,
436 &info,
437 &result);
439 if (!NT_STATUS_IS_OK(status)) {
440 result = ntstatus_to_werror(status);
441 goto done;
443 if (!W_ERROR_IS_OK(result)) {
444 goto done;
447 /* Display results */
449 switch (info_level) {
450 case 1:
451 display_share_info_1(info.info1);
452 break;
453 case 2:
454 display_share_info_2(info.info2);
455 break;
456 case 502:
457 display_share_info_502(info.info502);
458 break;
459 default:
460 printf("unsupported info level %d\n", info_level);
461 break;
464 done:
465 return result;
468 static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
469 TALLOC_CTX *mem_ctx,
470 int argc, const char **argv)
472 uint32 info_level = 502;
473 union srvsvc_NetShareInfo info_get;
474 WERROR result;
475 NTSTATUS status;
476 uint32_t parm_err = 0;
477 struct dcerpc_binding_handle *b = cli->binding_handle;
479 if (argc > 3) {
480 printf("Usage: %s [sharename] [comment]\n", argv[0]);
481 return WERR_OK;
484 /* retrieve share info */
485 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
486 cli->desthost,
487 argv[1],
488 info_level,
489 &info_get,
490 &result);
492 if (!NT_STATUS_IS_OK(status)) {
493 result = ntstatus_to_werror(status);
494 goto done;
496 if (!W_ERROR_IS_OK(result)) {
497 goto done;
500 info_get.info502->comment = argv[2];
502 /* set share info */
503 status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
504 cli->desthost,
505 argv[1],
506 info_level,
507 &info_get,
508 &parm_err,
509 &result);
511 if (!NT_STATUS_IS_OK(status)) {
512 result = ntstatus_to_werror(status);
513 goto done;
515 if (!W_ERROR_IS_OK(result)) {
516 goto done;
519 /* re-retrieve share info and display */
520 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
521 cli->desthost,
522 argv[1],
523 info_level,
524 &info_get,
525 &result);
526 if (!NT_STATUS_IS_OK(status)) {
527 result = ntstatus_to_werror(status);
528 goto done;
530 if (!W_ERROR_IS_OK(result)) {
531 goto done;
534 display_share_info_502(info_get.info502);
536 done:
537 return result;
540 static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli,
541 TALLOC_CTX *mem_ctx,
542 int argc, const char **argv)
544 struct srvsvc_NetRemoteTODInfo *tod = NULL;
545 WERROR result;
546 NTSTATUS status;
547 struct dcerpc_binding_handle *b = cli->binding_handle;
549 if (argc > 1) {
550 printf("Usage: %s\n", argv[0]);
551 return WERR_OK;
554 status = dcerpc_srvsvc_NetRemoteTOD(b, mem_ctx,
555 cli->srv_name_slash,
556 &tod,
557 &result);
558 if (!NT_STATUS_IS_OK(status)) {
559 result = ntstatus_to_werror(status);
560 goto done;
563 if (!W_ERROR_IS_OK(result))
564 goto done;
566 done:
567 return result;
570 static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
571 TALLOC_CTX *mem_ctx,
572 int argc, const char **argv)
574 uint32 info_level = 3;
575 struct srvsvc_NetFileInfoCtr info_ctr;
576 struct srvsvc_NetFileCtr3 ctr3;
577 WERROR result;
578 NTSTATUS status;
579 uint32 preferred_len = 0xffff;
580 uint32_t total_entries = 0;
581 uint32_t resume_handle = 0;
582 struct dcerpc_binding_handle *b = cli->binding_handle;
584 if (argc > 2) {
585 printf("Usage: %s [infolevel]\n", argv[0]);
586 return WERR_OK;
589 if (argc == 2)
590 info_level = atoi(argv[1]);
592 ZERO_STRUCT(info_ctr);
593 ZERO_STRUCT(ctr3);
595 info_ctr.level = info_level;
596 info_ctr.ctr.ctr3 = &ctr3;
598 status = dcerpc_srvsvc_NetFileEnum(b, mem_ctx,
599 cli->desthost,
600 NULL,
601 NULL,
602 &info_ctr,
603 preferred_len,
604 &total_entries,
605 &resume_handle,
606 &result);
607 if (!NT_STATUS_IS_OK(status)) {
608 result = ntstatus_to_werror(status);
609 goto done;
612 if (!W_ERROR_IS_OK(result)) {
613 goto done;
616 done:
617 return result;
620 static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
621 TALLOC_CTX *mem_ctx,
622 int argc, const char **argv)
624 WERROR result;
625 NTSTATUS status;
626 uint32_t name_type = 9;
627 uint32_t flags = 0;
628 struct dcerpc_binding_handle *b = cli->binding_handle;
630 if (argc < 2 || argc > 3) {
631 printf("Usage: %s [sharename] [type]\n", argv[0]);
632 return WERR_OK;
635 if (argc == 3) {
636 name_type = atoi(argv[2]);
639 status = dcerpc_srvsvc_NetNameValidate(b, mem_ctx,
640 cli->desthost,
641 argv[1],
642 name_type,
643 flags,
644 &result);
645 if (!NT_STATUS_IS_OK(status)) {
646 result = ntstatus_to_werror(status);
647 goto done;
650 if (!W_ERROR_IS_OK(result))
651 goto done;
653 done:
654 return result;
657 static WERROR cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client *cli,
658 TALLOC_CTX *mem_ctx,
659 int argc, const char **argv)
661 WERROR result;
662 NTSTATUS status;
663 struct sec_desc_buf *sd_buf = NULL;
664 struct dcerpc_binding_handle *b = cli->binding_handle;
666 if (argc < 2 || argc > 4) {
667 printf("Usage: %s [sharename] [file]\n", argv[0]);
668 return WERR_OK;
671 status = dcerpc_srvsvc_NetGetFileSecurity(b, mem_ctx,
672 cli->desthost,
673 argv[1],
674 argv[2],
675 SECINFO_DACL,
676 &sd_buf,
677 &result);
678 if (!NT_STATUS_IS_OK(status)) {
679 result = ntstatus_to_werror(status);
680 goto done;
683 if (!W_ERROR_IS_OK(result)) {
684 goto done;
687 display_sec_desc(sd_buf->sd);
689 done:
690 return result;
693 static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
694 TALLOC_CTX *mem_ctx,
695 int argc, const char **argv)
697 WERROR result;
698 NTSTATUS status;
699 struct dcerpc_binding_handle *b = cli->binding_handle;
701 if (argc < 2 || argc > 4) {
702 printf("Usage: %s [client] [user]\n", argv[0]);
703 return WERR_OK;
706 status = dcerpc_srvsvc_NetSessDel(b, mem_ctx,
707 cli->desthost,
708 argv[1],
709 argv[2],
710 &result);
711 if (!NT_STATUS_IS_OK(status)) {
712 result = ntstatus_to_werror(status);
713 goto done;
716 if (!W_ERROR_IS_OK(result)) {
717 goto done;
720 done:
721 return result;
724 static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
725 TALLOC_CTX *mem_ctx,
726 int argc, const char **argv)
728 WERROR result;
729 NTSTATUS status;
730 struct srvsvc_NetSessInfoCtr info_ctr;
731 struct srvsvc_NetSessCtr0 ctr0;
732 struct srvsvc_NetSessCtr1 ctr1;
733 struct srvsvc_NetSessCtr2 ctr2;
734 struct srvsvc_NetSessCtr10 ctr10;
735 struct srvsvc_NetSessCtr502 ctr502;
736 uint32_t total_entries = 0;
737 uint32_t resume_handle = 0;
738 uint32_t *resume_handle_p = NULL;
739 uint32_t level = 1;
740 const char *client = NULL;
741 const char *user = NULL;
742 struct dcerpc_binding_handle *b = cli->binding_handle;
744 if (argc > 6) {
745 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
746 return WERR_OK;
749 if (argc >= 2) {
750 client = argv[1];
753 if (argc >= 3) {
754 user = argv[2];
757 if (argc >= 4) {
758 level = atoi(argv[3]);
761 if (argc >= 5) {
762 resume_handle = atoi(argv[4]);
763 resume_handle_p = &resume_handle;
766 ZERO_STRUCT(info_ctr);
768 info_ctr.level = level;
770 d_printf("trying level: %d\n", level);
772 switch (level) {
773 case 0:
774 ZERO_STRUCT(ctr0);
775 info_ctr.ctr.ctr0 = &ctr0;
776 break;
777 case 1:
778 ZERO_STRUCT(ctr1);
779 info_ctr.ctr.ctr1 = &ctr1;
780 break;
781 case 2:
782 ZERO_STRUCT(ctr2);
783 info_ctr.ctr.ctr2 = &ctr2;
784 break;
785 case 10:
786 ZERO_STRUCT(ctr10);
787 info_ctr.ctr.ctr10 = &ctr10;
788 break;
789 case 502:
790 ZERO_STRUCT(ctr502);
791 info_ctr.ctr.ctr502 = &ctr502;
792 break;
795 status = dcerpc_srvsvc_NetSessEnum(b, mem_ctx,
796 cli->desthost,
797 client,
798 user,
799 &info_ctr,
800 0xffffffff,
801 &total_entries,
802 resume_handle_p,
803 &result);
805 if (!NT_STATUS_IS_OK(status)) {
806 result = ntstatus_to_werror(status);
807 goto done;
810 if (!W_ERROR_IS_OK(result)) {
811 goto done;
814 done:
815 return result;
818 static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
819 TALLOC_CTX *mem_ctx,
820 int argc, const char **argv)
822 struct srvsvc_NetDiskInfo info;
823 WERROR result;
824 NTSTATUS status;
825 uint32_t total_entries = 0;
826 uint32_t resume_handle = 0;
827 uint32_t level = 0;
828 struct dcerpc_binding_handle *b = cli->binding_handle;
830 if (argc > 4) {
831 printf("Usage: %s [level] [resume_handle]\n", argv[0]);
832 return WERR_OK;
835 if (argc >= 2) {
836 level = atoi(argv[1]);
839 if (argc >= 3) {
840 resume_handle = atoi(argv[2]);
843 ZERO_STRUCT(info);
845 status = dcerpc_srvsvc_NetDiskEnum(b, mem_ctx,
846 cli->desthost,
847 level,
848 &info,
849 0xffffffff,
850 &total_entries,
851 &resume_handle,
852 &result);
853 if (!NT_STATUS_IS_OK(status)) {
854 result = ntstatus_to_werror(status);
855 goto done;
858 if (!W_ERROR_IS_OK(result)) {
859 goto done;
862 done:
863 return result;
866 static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
867 TALLOC_CTX *mem_ctx,
868 int argc, const char **argv)
870 struct srvsvc_NetConnInfoCtr info_ctr;
871 struct srvsvc_NetConnCtr0 ctr0;
872 struct srvsvc_NetConnCtr1 ctr1;
873 WERROR result;
874 NTSTATUS status;
875 uint32_t total_entries = 0;
876 uint32_t resume_handle = 0;
877 uint32_t *resume_handle_p = NULL;
878 uint32_t level = 1;
879 const char *path = "IPC$";
880 struct dcerpc_binding_handle *b = cli->binding_handle;
882 if (argc > 4) {
883 printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
884 return WERR_OK;
887 if (argc >= 2) {
888 level = atoi(argv[1]);
891 if (argc >= 3) {
892 path = argv[2];
895 if (argc >= 4) {
896 resume_handle = atoi(argv[3]);
897 resume_handle_p = &resume_handle;
900 ZERO_STRUCT(info_ctr);
902 info_ctr.level = level;
904 switch (level) {
905 case 0:
906 ZERO_STRUCT(ctr0);
907 info_ctr.ctr.ctr0 = &ctr0;
908 break;
909 case 1:
910 ZERO_STRUCT(ctr1);
911 info_ctr.ctr.ctr1 = &ctr1;
912 break;
913 default:
914 return WERR_INVALID_PARAM;
917 status = dcerpc_srvsvc_NetConnEnum(b, mem_ctx,
918 cli->desthost,
919 path,
920 &info_ctr,
921 0xffffffff,
922 &total_entries,
923 resume_handle_p,
924 &result);
926 if (!NT_STATUS_IS_OK(status)) {
927 result = ntstatus_to_werror(status);
928 goto done;
931 if (!W_ERROR_IS_OK(result)) {
932 goto done;
935 done:
936 return result;
940 /* List of commands exported by this module */
942 struct cmd_set srvsvc_commands[] = {
944 { "SRVSVC" },
946 { "srvinfo", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, &ndr_table_srvsvc.syntax_id, NULL, "Server query info", "" },
947 { "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate shares", "" },
948 { "netshareenumall",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum_all, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate all shares", "" },
949 { "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, &ndr_table_srvsvc.syntax_id, NULL, "Get Share Info", "" },
950 { "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, &ndr_table_srvsvc.syntax_id, NULL, "Set Share Info", "" },
951 { "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate open files", "" },
952 { "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, &ndr_table_srvsvc.syntax_id, NULL, "Fetch remote time of day", "" },
953 { "netnamevalidate", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_name_validate, &ndr_table_srvsvc.syntax_id, NULL, "Validate sharename", "" },
954 { "netfilegetsec", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_get_sec, &ndr_table_srvsvc.syntax_id, NULL, "Get File security", "" },
955 { "netsessdel", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_del, &ndr_table_srvsvc.syntax_id, NULL, "Delete Session", "" },
956 { "netsessenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_enum, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate Sessions", "" },
957 { "netdiskenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_disk_enum, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate Disks", "" },
958 { "netconnenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_conn_enum, &ndr_table_srvsvc.syntax_id, NULL, "Enumerate Connections", "" },
960 { NULL }