s3:lib: remove function connections_forall()
[Samba/gebeck_regimport.git] / source3 / rpcclient / cmd_srvsvc.c
blob0d67639959fc7490f3bd3a0f9017ae4a024647f7
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"
27 #include "../libcli/security/display_sec.h"
29 /* Display server query info */
31 static char *get_server_type_str(uint32 type)
33 static fstring typestr;
34 int i;
36 if (type == SV_TYPE_ALL) {
37 fstrcpy(typestr, "All");
38 return typestr;
41 typestr[0] = 0;
43 for (i = 0; i < 32; i++) {
44 if (type & (1 << i)) {
45 switch (1 << i) {
46 case SV_TYPE_WORKSTATION:
47 fstrcat(typestr, "Wk ");
48 break;
49 case SV_TYPE_SERVER:
50 fstrcat(typestr, "Sv ");
51 break;
52 case SV_TYPE_SQLSERVER:
53 fstrcat(typestr, "Sql ");
54 break;
55 case SV_TYPE_DOMAIN_CTRL:
56 fstrcat(typestr, "PDC ");
57 break;
58 case SV_TYPE_DOMAIN_BAKCTRL:
59 fstrcat(typestr, "BDC ");
60 break;
61 case SV_TYPE_TIME_SOURCE:
62 fstrcat(typestr, "Tim ");
63 break;
64 case SV_TYPE_AFP:
65 fstrcat(typestr, "AFP ");
66 break;
67 case SV_TYPE_NOVELL:
68 fstrcat(typestr, "Nov ");
69 break;
70 case SV_TYPE_DOMAIN_MEMBER:
71 fstrcat(typestr, "Dom ");
72 break;
73 case SV_TYPE_PRINTQ_SERVER:
74 fstrcat(typestr, "PrQ ");
75 break;
76 case SV_TYPE_DIALIN_SERVER:
77 fstrcat(typestr, "Din ");
78 break;
79 case SV_TYPE_SERVER_UNIX:
80 fstrcat(typestr, "Unx ");
81 break;
82 case SV_TYPE_NT:
83 fstrcat(typestr, "NT ");
84 break;
85 case SV_TYPE_WFW:
86 fstrcat(typestr, "Wfw ");
87 break;
88 case SV_TYPE_SERVER_MFPN:
89 fstrcat(typestr, "Mfp ");
90 break;
91 case SV_TYPE_SERVER_NT:
92 fstrcat(typestr, "SNT ");
93 break;
94 case SV_TYPE_POTENTIAL_BROWSER:
95 fstrcat(typestr, "PtB ");
96 break;
97 case SV_TYPE_BACKUP_BROWSER:
98 fstrcat(typestr, "BMB ");
99 break;
100 case SV_TYPE_MASTER_BROWSER:
101 fstrcat(typestr, "LMB ");
102 break;
103 case SV_TYPE_DOMAIN_MASTER:
104 fstrcat(typestr, "DMB ");
105 break;
106 case SV_TYPE_SERVER_OSF:
107 fstrcat(typestr, "OSF ");
108 break;
109 case SV_TYPE_SERVER_VMS:
110 fstrcat(typestr, "VMS ");
111 break;
112 case SV_TYPE_WIN95_PLUS:
113 fstrcat(typestr, "W95 ");
114 break;
115 case SV_TYPE_ALTERNATE_XPORT:
116 fstrcat(typestr, "Xpt ");
117 break;
118 case SV_TYPE_LOCAL_LIST_ONLY:
119 fstrcat(typestr, "Dom ");
120 break;
121 case SV_TYPE_DOMAIN_ENUM:
122 fstrcat(typestr, "Loc ");
123 break;
128 i = strlen(typestr) - 1;
130 if (typestr[i] == ' ')
131 typestr[i] = 0;
133 return typestr;
136 static void display_server(const char *sname, uint32 type, const char *comment)
138 printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
139 comment);
142 static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
144 display_server(r->server_name, r->server_type, r->comment);
146 printf("\tplatform_id :\t%d\n", r->platform_id);
147 printf("\tos version :\t%d.%d\n",
148 r->version_major, r->version_minor);
149 printf("\tserver type :\t0x%x\n", r->server_type);
152 static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
154 display_server(r->server_name, r->server_type, r->comment);
156 printf("\tplatform_id :\t%d\n", r->platform_id);
157 printf("\tos version :\t%d.%d\n",
158 r->version_major, r->version_minor);
159 printf("\tserver type :\t0x%x\n", r->server_type);
161 printf("\tusers :\t%x\n", r->users);
162 printf("\tdisc, hidden :\t%x, %x\n", r->disc, r->hidden);
163 printf("\tannounce, delta :\t%d, %d\n", r->announce,
164 r->anndelta);
165 printf("\tlicenses :\t%d\n", r->licenses);
166 printf("\tuser path :\t%s\n", r->userpath);
169 /* Server query info */
170 static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
171 TALLOC_CTX *mem_ctx,
172 int argc, const char **argv)
174 uint32 info_level = 101;
175 union srvsvc_NetSrvInfo info;
176 WERROR result;
177 NTSTATUS status;
178 const char *server_unc = cli->srv_name_slash;
179 struct dcerpc_binding_handle *b = cli->binding_handle;
181 if (argc > 3) {
182 printf("Usage: %s [infolevel] [server_unc]\n", argv[0]);
183 return WERR_OK;
186 if (argc >= 2) {
187 info_level = atoi(argv[1]);
190 if (argc >= 3) {
191 server_unc = argv[2];
194 status = dcerpc_srvsvc_NetSrvGetInfo(b, mem_ctx,
195 server_unc,
196 info_level,
197 &info,
198 &result);
199 if (!NT_STATUS_IS_OK(status)) {
200 return ntstatus_to_werror(status);
203 if (!W_ERROR_IS_OK(result)) {
204 goto done;
207 /* Display results */
209 switch (info_level) {
210 case 101:
211 display_srv_info_101(info.info101);
212 break;
213 case 102:
214 display_srv_info_102(info.info102);
215 break;
216 default:
217 printf("unsupported info level %d\n", info_level);
218 break;
221 done:
222 return result;
225 static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
227 printf("netname: %s\n", r->name);
228 printf("\tremark:\t%s\n", r->comment);
231 static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
233 printf("netname: %s\n", r->name);
234 printf("\tremark:\t%s\n", r->comment);
235 printf("\tpath:\t%s\n", r->path);
236 printf("\tpassword:\t%s\n", r->password);
239 static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
241 printf("netname: %s\n", r->name);
242 printf("\tremark:\t%s\n", r->comment);
243 printf("\tpath:\t%s\n", r->path);
244 printf("\tpassword:\t%s\n", r->password);
246 printf("\ttype:\t0x%x\n", r->type);
247 printf("\tperms:\t%d\n", r->permissions);
248 printf("\tmax_uses:\t%d\n", r->max_users);
249 printf("\tnum_uses:\t%d\n", r->current_users);
251 if (r->sd_buf.sd)
252 display_sec_desc(r->sd_buf.sd);
256 static WERROR cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client *cli,
257 TALLOC_CTX *mem_ctx,
258 int argc, const char **argv,
259 uint32_t opcode)
261 uint32 info_level = 2;
262 struct srvsvc_NetShareInfoCtr info_ctr;
263 struct srvsvc_NetShareCtr0 ctr0;
264 struct srvsvc_NetShareCtr1 ctr1;
265 struct srvsvc_NetShareCtr2 ctr2;
266 struct srvsvc_NetShareCtr501 ctr501;
267 struct srvsvc_NetShareCtr502 ctr502;
268 struct srvsvc_NetShareCtr1004 ctr1004;
269 struct srvsvc_NetShareCtr1005 ctr1005;
270 struct srvsvc_NetShareCtr1006 ctr1006;
271 struct srvsvc_NetShareCtr1007 ctr1007;
272 struct srvsvc_NetShareCtr1501 ctr1501;
273 WERROR result;
274 NTSTATUS status;
275 uint32_t totalentries = 0;
276 uint32_t resume_handle = 0;
277 uint32_t *resume_handle_p = NULL;
278 uint32 preferred_len = 0xffffffff, i;
279 struct dcerpc_binding_handle *b = cli->binding_handle;
281 if (argc > 3) {
282 printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
283 return WERR_OK;
286 if (argc >= 2) {
287 info_level = atoi(argv[1]);
290 if (argc == 3) {
291 resume_handle = atoi(argv[2]);
292 resume_handle_p = &resume_handle;
295 ZERO_STRUCT(info_ctr);
297 info_ctr.level = info_level;
299 switch (info_level) {
300 case 0:
301 ZERO_STRUCT(ctr0);
302 info_ctr.ctr.ctr0 = &ctr0;
303 break;
304 case 1:
305 ZERO_STRUCT(ctr1);
306 info_ctr.ctr.ctr1 = &ctr1;
307 break;
308 case 2:
309 ZERO_STRUCT(ctr2);
310 info_ctr.ctr.ctr2 = &ctr2;
311 break;
312 case 501:
313 ZERO_STRUCT(ctr501);
314 info_ctr.ctr.ctr501 = &ctr501;
315 break;
316 case 502:
317 ZERO_STRUCT(ctr502);
318 info_ctr.ctr.ctr502 = &ctr502;
319 break;
320 case 1004:
321 ZERO_STRUCT(ctr1004);
322 info_ctr.ctr.ctr1004 = &ctr1004;
323 break;
324 case 1005:
325 ZERO_STRUCT(ctr1005);
326 info_ctr.ctr.ctr1005 = &ctr1005;
327 break;
328 case 1006:
329 ZERO_STRUCT(ctr1006);
330 info_ctr.ctr.ctr1006 = &ctr1006;
331 break;
332 case 1007:
333 ZERO_STRUCT(ctr1007);
334 info_ctr.ctr.ctr1007 = &ctr1007;
335 break;
336 case 1501:
337 ZERO_STRUCT(ctr1501);
338 info_ctr.ctr.ctr1501 = &ctr1501;
339 break;
342 switch (opcode) {
343 case NDR_SRVSVC_NETSHAREENUM:
344 status = dcerpc_srvsvc_NetShareEnum(b, mem_ctx,
345 cli->desthost,
346 &info_ctr,
347 preferred_len,
348 &totalentries,
349 resume_handle_p,
350 &result);
351 break;
352 case NDR_SRVSVC_NETSHAREENUMALL:
353 status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
354 cli->desthost,
355 &info_ctr,
356 preferred_len,
357 &totalentries,
358 resume_handle_p,
359 &result);
360 break;
361 default:
362 return WERR_INVALID_PARAM;
365 if (!NT_STATUS_IS_OK(status)) {
366 result = ntstatus_to_werror(status);
367 goto done;
369 if (!W_ERROR_IS_OK(result)) {
370 goto done;
373 /* Display results */
375 switch (info_level) {
376 case 1:
377 for (i = 0; i < totalentries; i++)
378 display_share_info_1(&info_ctr.ctr.ctr1->array[i]);
379 break;
380 case 2:
381 for (i = 0; i < totalentries; i++)
382 display_share_info_2(&info_ctr.ctr.ctr2->array[i]);
383 break;
384 case 502:
385 for (i = 0; i < totalentries; i++)
386 display_share_info_502(&info_ctr.ctr.ctr502->array[i]);
387 break;
388 default:
389 printf("unsupported info level %d\n", info_level);
390 break;
393 done:
394 return result;
397 static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
398 TALLOC_CTX *mem_ctx,
399 int argc, const char **argv)
401 return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
402 argc, argv,
403 NDR_SRVSVC_NETSHAREENUM);
406 static WERROR cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client *cli,
407 TALLOC_CTX *mem_ctx,
408 int argc, const char **argv)
410 return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
411 argc, argv,
412 NDR_SRVSVC_NETSHAREENUMALL);
415 static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
416 TALLOC_CTX *mem_ctx,
417 int argc, const char **argv)
419 uint32 info_level = 502;
420 union srvsvc_NetShareInfo info;
421 WERROR result;
422 NTSTATUS status;
423 struct dcerpc_binding_handle *b = cli->binding_handle;
425 if (argc < 2 || argc > 3) {
426 printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
427 return WERR_OK;
430 if (argc == 3)
431 info_level = atoi(argv[2]);
433 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
434 cli->desthost,
435 argv[1],
436 info_level,
437 &info,
438 &result);
440 if (!NT_STATUS_IS_OK(status)) {
441 result = ntstatus_to_werror(status);
442 goto done;
444 if (!W_ERROR_IS_OK(result)) {
445 goto done;
448 /* Display results */
450 switch (info_level) {
451 case 1:
452 display_share_info_1(info.info1);
453 break;
454 case 2:
455 display_share_info_2(info.info2);
456 break;
457 case 502:
458 display_share_info_502(info.info502);
459 break;
460 default:
461 printf("unsupported info level %d\n", info_level);
462 break;
465 done:
466 return result;
469 static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
470 TALLOC_CTX *mem_ctx,
471 int argc, const char **argv)
473 uint32 info_level = 502;
474 union srvsvc_NetShareInfo info_get;
475 WERROR result;
476 NTSTATUS status;
477 uint32_t parm_err = 0;
478 struct dcerpc_binding_handle *b = cli->binding_handle;
480 if (argc > 3) {
481 printf("Usage: %s [sharename] [comment]\n", argv[0]);
482 return WERR_OK;
485 /* retrieve share info */
486 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
487 cli->desthost,
488 argv[1],
489 info_level,
490 &info_get,
491 &result);
493 if (!NT_STATUS_IS_OK(status)) {
494 result = ntstatus_to_werror(status);
495 goto done;
497 if (!W_ERROR_IS_OK(result)) {
498 goto done;
501 info_get.info502->comment = argv[2];
503 /* set share info */
504 status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
505 cli->desthost,
506 argv[1],
507 info_level,
508 &info_get,
509 &parm_err,
510 &result);
512 if (!NT_STATUS_IS_OK(status)) {
513 result = ntstatus_to_werror(status);
514 goto done;
516 if (!W_ERROR_IS_OK(result)) {
517 goto done;
520 /* re-retrieve share info and display */
521 status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
522 cli->desthost,
523 argv[1],
524 info_level,
525 &info_get,
526 &result);
527 if (!NT_STATUS_IS_OK(status)) {
528 result = ntstatus_to_werror(status);
529 goto done;
531 if (!W_ERROR_IS_OK(result)) {
532 goto done;
535 display_share_info_502(info_get.info502);
537 done:
538 return result;
541 static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli,
542 TALLOC_CTX *mem_ctx,
543 int argc, const char **argv)
545 struct srvsvc_NetRemoteTODInfo *tod = NULL;
546 WERROR result;
547 NTSTATUS status;
548 struct dcerpc_binding_handle *b = cli->binding_handle;
550 if (argc > 1) {
551 printf("Usage: %s\n", argv[0]);
552 return WERR_OK;
555 status = dcerpc_srvsvc_NetRemoteTOD(b, mem_ctx,
556 cli->srv_name_slash,
557 &tod,
558 &result);
559 if (!NT_STATUS_IS_OK(status)) {
560 result = ntstatus_to_werror(status);
561 goto done;
564 if (!W_ERROR_IS_OK(result))
565 goto done;
567 done:
568 return result;
571 static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
572 TALLOC_CTX *mem_ctx,
573 int argc, const char **argv)
575 uint32 info_level = 3;
576 struct srvsvc_NetFileInfoCtr info_ctr;
577 struct srvsvc_NetFileCtr3 ctr3;
578 WERROR result;
579 NTSTATUS status;
580 uint32 preferred_len = 0xffff;
581 uint32_t total_entries = 0;
582 uint32_t resume_handle = 0;
583 struct dcerpc_binding_handle *b = cli->binding_handle;
585 if (argc > 2) {
586 printf("Usage: %s [infolevel]\n", argv[0]);
587 return WERR_OK;
590 if (argc == 2)
591 info_level = atoi(argv[1]);
593 ZERO_STRUCT(info_ctr);
594 ZERO_STRUCT(ctr3);
596 info_ctr.level = info_level;
597 info_ctr.ctr.ctr3 = &ctr3;
599 status = dcerpc_srvsvc_NetFileEnum(b, mem_ctx,
600 cli->desthost,
601 NULL,
602 NULL,
603 &info_ctr,
604 preferred_len,
605 &total_entries,
606 &resume_handle,
607 &result);
608 if (!NT_STATUS_IS_OK(status)) {
609 result = ntstatus_to_werror(status);
610 goto done;
613 if (!W_ERROR_IS_OK(result)) {
614 goto done;
617 done:
618 return result;
621 static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
622 TALLOC_CTX *mem_ctx,
623 int argc, const char **argv)
625 WERROR result;
626 NTSTATUS status;
627 uint32_t name_type = 9;
628 uint32_t flags = 0;
629 struct dcerpc_binding_handle *b = cli->binding_handle;
631 if (argc < 2 || argc > 3) {
632 printf("Usage: %s [sharename] [type]\n", argv[0]);
633 return WERR_OK;
636 if (argc == 3) {
637 name_type = atoi(argv[2]);
640 status = dcerpc_srvsvc_NetNameValidate(b, mem_ctx,
641 cli->desthost,
642 argv[1],
643 name_type,
644 flags,
645 &result);
646 if (!NT_STATUS_IS_OK(status)) {
647 result = ntstatus_to_werror(status);
648 goto done;
651 if (!W_ERROR_IS_OK(result))
652 goto done;
654 done:
655 return result;
658 static WERROR cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client *cli,
659 TALLOC_CTX *mem_ctx,
660 int argc, const char **argv)
662 WERROR result;
663 NTSTATUS status;
664 struct sec_desc_buf *sd_buf = NULL;
665 struct dcerpc_binding_handle *b = cli->binding_handle;
667 if (argc < 2 || argc > 4) {
668 printf("Usage: %s [sharename] [file]\n", argv[0]);
669 return WERR_OK;
672 status = dcerpc_srvsvc_NetGetFileSecurity(b, mem_ctx,
673 cli->desthost,
674 argv[1],
675 argv[2],
676 SECINFO_DACL,
677 &sd_buf,
678 &result);
679 if (!NT_STATUS_IS_OK(status)) {
680 result = ntstatus_to_werror(status);
681 goto done;
684 if (!W_ERROR_IS_OK(result)) {
685 goto done;
688 display_sec_desc(sd_buf->sd);
690 done:
691 return result;
694 static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
695 TALLOC_CTX *mem_ctx,
696 int argc, const char **argv)
698 WERROR result;
699 NTSTATUS status;
700 struct dcerpc_binding_handle *b = cli->binding_handle;
702 if (argc < 2 || argc > 4) {
703 printf("Usage: %s [client] [user]\n", argv[0]);
704 return WERR_OK;
707 status = dcerpc_srvsvc_NetSessDel(b, mem_ctx,
708 cli->desthost,
709 argv[1],
710 argv[2],
711 &result);
712 if (!NT_STATUS_IS_OK(status)) {
713 result = ntstatus_to_werror(status);
714 goto done;
717 if (!W_ERROR_IS_OK(result)) {
718 goto done;
721 done:
722 return result;
725 static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
726 TALLOC_CTX *mem_ctx,
727 int argc, const char **argv)
729 WERROR result;
730 NTSTATUS status;
731 struct srvsvc_NetSessInfoCtr info_ctr;
732 struct srvsvc_NetSessCtr0 ctr0;
733 struct srvsvc_NetSessCtr1 ctr1;
734 struct srvsvc_NetSessCtr2 ctr2;
735 struct srvsvc_NetSessCtr10 ctr10;
736 struct srvsvc_NetSessCtr502 ctr502;
737 uint32_t total_entries = 0;
738 uint32_t resume_handle = 0;
739 uint32_t *resume_handle_p = NULL;
740 uint32_t level = 1;
741 const char *client = NULL;
742 const char *user = NULL;
743 struct dcerpc_binding_handle *b = cli->binding_handle;
745 if (argc > 6) {
746 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
747 return WERR_OK;
750 if (argc >= 2) {
751 client = argv[1];
754 if (argc >= 3) {
755 user = argv[2];
758 if (argc >= 4) {
759 level = atoi(argv[3]);
762 if (argc >= 5) {
763 resume_handle = atoi(argv[4]);
764 resume_handle_p = &resume_handle;
767 ZERO_STRUCT(info_ctr);
769 info_ctr.level = level;
771 d_printf("trying level: %d\n", level);
773 switch (level) {
774 case 0:
775 ZERO_STRUCT(ctr0);
776 info_ctr.ctr.ctr0 = &ctr0;
777 break;
778 case 1:
779 ZERO_STRUCT(ctr1);
780 info_ctr.ctr.ctr1 = &ctr1;
781 break;
782 case 2:
783 ZERO_STRUCT(ctr2);
784 info_ctr.ctr.ctr2 = &ctr2;
785 break;
786 case 10:
787 ZERO_STRUCT(ctr10);
788 info_ctr.ctr.ctr10 = &ctr10;
789 break;
790 case 502:
791 ZERO_STRUCT(ctr502);
792 info_ctr.ctr.ctr502 = &ctr502;
793 break;
796 status = dcerpc_srvsvc_NetSessEnum(b, mem_ctx,
797 cli->desthost,
798 client,
799 user,
800 &info_ctr,
801 0xffffffff,
802 &total_entries,
803 resume_handle_p,
804 &result);
806 if (!NT_STATUS_IS_OK(status)) {
807 result = ntstatus_to_werror(status);
808 goto done;
811 if (!W_ERROR_IS_OK(result)) {
812 goto done;
815 done:
816 return result;
819 static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
820 TALLOC_CTX *mem_ctx,
821 int argc, const char **argv)
823 struct srvsvc_NetDiskInfo info;
824 WERROR result;
825 NTSTATUS status;
826 uint32_t total_entries = 0;
827 uint32_t resume_handle = 0;
828 uint32_t level = 0;
829 struct dcerpc_binding_handle *b = cli->binding_handle;
831 if (argc > 4) {
832 printf("Usage: %s [level] [resume_handle]\n", argv[0]);
833 return WERR_OK;
836 if (argc >= 2) {
837 level = atoi(argv[1]);
840 if (argc >= 3) {
841 resume_handle = atoi(argv[2]);
844 ZERO_STRUCT(info);
846 status = dcerpc_srvsvc_NetDiskEnum(b, mem_ctx,
847 cli->desthost,
848 level,
849 &info,
850 0xffffffff,
851 &total_entries,
852 &resume_handle,
853 &result);
854 if (!NT_STATUS_IS_OK(status)) {
855 result = ntstatus_to_werror(status);
856 goto done;
859 if (!W_ERROR_IS_OK(result)) {
860 goto done;
863 done:
864 return result;
867 static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
868 TALLOC_CTX *mem_ctx,
869 int argc, const char **argv)
871 struct srvsvc_NetConnInfoCtr info_ctr;
872 struct srvsvc_NetConnCtr0 ctr0;
873 struct srvsvc_NetConnCtr1 ctr1;
874 WERROR result;
875 NTSTATUS status;
876 uint32_t total_entries = 0;
877 uint32_t resume_handle = 0;
878 uint32_t *resume_handle_p = NULL;
879 uint32_t level = 1;
880 const char *path = "IPC$";
881 struct dcerpc_binding_handle *b = cli->binding_handle;
883 if (argc > 4) {
884 printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
885 return WERR_OK;
888 if (argc >= 2) {
889 level = atoi(argv[1]);
892 if (argc >= 3) {
893 path = argv[2];
896 if (argc >= 4) {
897 resume_handle = atoi(argv[3]);
898 resume_handle_p = &resume_handle;
901 ZERO_STRUCT(info_ctr);
903 info_ctr.level = level;
905 switch (level) {
906 case 0:
907 ZERO_STRUCT(ctr0);
908 info_ctr.ctr.ctr0 = &ctr0;
909 break;
910 case 1:
911 ZERO_STRUCT(ctr1);
912 info_ctr.ctr.ctr1 = &ctr1;
913 break;
914 default:
915 return WERR_INVALID_PARAM;
918 status = dcerpc_srvsvc_NetConnEnum(b, mem_ctx,
919 cli->desthost,
920 path,
921 &info_ctr,
922 0xffffffff,
923 &total_entries,
924 resume_handle_p,
925 &result);
927 if (!NT_STATUS_IS_OK(status)) {
928 result = ntstatus_to_werror(status);
929 goto done;
932 if (!W_ERROR_IS_OK(result)) {
933 goto done;
936 done:
937 return result;
941 /* List of commands exported by this module */
943 struct cmd_set srvsvc_commands[] = {
945 { "SRVSVC" },
947 { "srvinfo", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, &ndr_table_srvsvc, NULL, "Server query info", "" },
948 { "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, &ndr_table_srvsvc, NULL, "Enumerate shares", "" },
949 { "netshareenumall",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum_all, &ndr_table_srvsvc, NULL, "Enumerate all shares", "" },
950 { "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, &ndr_table_srvsvc, NULL, "Get Share Info", "" },
951 { "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, &ndr_table_srvsvc, NULL, "Set Share Info", "" },
952 { "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum, &ndr_table_srvsvc, NULL, "Enumerate open files", "" },
953 { "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, &ndr_table_srvsvc, NULL, "Fetch remote time of day", "" },
954 { "netnamevalidate", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_name_validate, &ndr_table_srvsvc, NULL, "Validate sharename", "" },
955 { "netfilegetsec", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_get_sec, &ndr_table_srvsvc, NULL, "Get File security", "" },
956 { "netsessdel", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_del, &ndr_table_srvsvc, NULL, "Delete Session", "" },
957 { "netsessenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_enum, &ndr_table_srvsvc, NULL, "Enumerate Sessions", "" },
958 { "netdiskenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_disk_enum, &ndr_table_srvsvc, NULL, "Enumerate Disks", "" },
959 { "netconnenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_conn_enum, &ndr_table_srvsvc, NULL, "Enumerate Connections", "" },
961 { NULL }