1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
|
/*
Unix SMB/CIFS implementation.
RPC pipe client
Copyright (C) Andrew Tridgell 1992-1999
Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
Copyright (C) Tim Potter 2000,2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "rpcclient.h"
#include "../librpc/gen_ndr/ndr_srvsvc.h"
#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
#include "../libcli/security/display_sec.h"
/* Display server query info */
static char *get_server_type_str(uint32 type)
{
static fstring typestr;
int i;
if (type == SV_TYPE_ALL) {
fstrcpy(typestr, "All");
return typestr;
}
typestr[0] = 0;
for (i = 0; i < 32; i++) {
if (type & (1 << i)) {
switch (1 << i) {
case SV_TYPE_WORKSTATION:
fstrcat(typestr, "Wk ");
break;
case SV_TYPE_SERVER:
fstrcat(typestr, "Sv ");
break;
case SV_TYPE_SQLSERVER:
fstrcat(typestr, "Sql ");
break;
case SV_TYPE_DOMAIN_CTRL:
fstrcat(typestr, "PDC ");
break;
case SV_TYPE_DOMAIN_BAKCTRL:
fstrcat(typestr, "BDC ");
break;
case SV_TYPE_TIME_SOURCE:
fstrcat(typestr, "Tim ");
break;
case SV_TYPE_AFP:
fstrcat(typestr, "AFP ");
break;
case SV_TYPE_NOVELL:
fstrcat(typestr, "Nov ");
break;
case SV_TYPE_DOMAIN_MEMBER:
fstrcat(typestr, "Dom ");
break;
case SV_TYPE_PRINTQ_SERVER:
fstrcat(typestr, "PrQ ");
break;
case SV_TYPE_DIALIN_SERVER:
fstrcat(typestr, "Din ");
break;
case SV_TYPE_SERVER_UNIX:
fstrcat(typestr, "Unx ");
break;
case SV_TYPE_NT:
fstrcat(typestr, "NT ");
break;
case SV_TYPE_WFW:
fstrcat(typestr, "Wfw ");
break;
case SV_TYPE_SERVER_MFPN:
fstrcat(typestr, "Mfp ");
break;
case SV_TYPE_SERVER_NT:
fstrcat(typestr, "SNT ");
break;
case SV_TYPE_POTENTIAL_BROWSER:
fstrcat(typestr, "PtB ");
break;
case SV_TYPE_BACKUP_BROWSER:
fstrcat(typestr, "BMB ");
break;
case SV_TYPE_MASTER_BROWSER:
fstrcat(typestr, "LMB ");
break;
case SV_TYPE_DOMAIN_MASTER:
fstrcat(typestr, "DMB ");
break;
case SV_TYPE_SERVER_OSF:
fstrcat(typestr, "OSF ");
break;
case SV_TYPE_SERVER_VMS:
fstrcat(typestr, "VMS ");
break;
case SV_TYPE_WIN95_PLUS:
fstrcat(typestr, "W95 ");
break;
case SV_TYPE_ALTERNATE_XPORT:
fstrcat(typestr, "Xpt ");
break;
case SV_TYPE_LOCAL_LIST_ONLY:
fstrcat(typestr, "Dom ");
break;
case SV_TYPE_DOMAIN_ENUM:
fstrcat(typestr, "Loc ");
break;
}
}
}
i = strlen(typestr) - 1;
if (typestr[i] == ' ')
typestr[i] = 0;
return typestr;
}
static void display_server(const char *sname, uint32 type, const char *comment)
{
printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type),
comment);
}
static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
{
display_server(r->server_name, r->server_type, r->comment);
printf("\tplatform_id :\t%d\n", r->platform_id);
printf("\tos version :\t%d.%d\n",
r->version_major, r->version_minor);
printf("\tserver type :\t0x%x\n", r->server_type);
}
static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
{
display_server(r->server_name, r->server_type, r->comment);
printf("\tplatform_id :\t%d\n", r->platform_id);
printf("\tos version :\t%d.%d\n",
r->version_major, r->version_minor);
printf("\tserver type :\t0x%x\n", r->server_type);
printf("\tusers :\t%x\n", r->users);
printf("\tdisc, hidden :\t%x, %x\n", r->disc, r->hidden);
printf("\tannounce, delta :\t%d, %d\n", r->announce,
r->anndelta);
printf("\tlicenses :\t%d\n", r->licenses);
printf("\tuser path :\t%s\n", r->userpath);
}
/* Server query info */
static WERROR cmd_srvsvc_srv_query_info(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 101;
union srvsvc_NetSrvInfo info;
WERROR result;
NTSTATUS status;
const char *server_unc = cli->srv_name_slash;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 3) {
printf("Usage: %s [infolevel] [server_unc]\n", argv[0]);
return WERR_OK;
}
if (argc >= 2) {
info_level = atoi(argv[1]);
}
if (argc >= 3) {
server_unc = argv[2];
}
status = dcerpc_srvsvc_NetSrvGetInfo(b, mem_ctx,
server_unc,
info_level,
&info,
&result);
if (!NT_STATUS_IS_OK(status)) {
return ntstatus_to_werror(status);
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
/* Display results */
switch (info_level) {
case 101:
display_srv_info_101(info.info101);
break;
case 102:
display_srv_info_102(info.info102);
break;
default:
printf("unsupported info level %d\n", info_level);
break;
}
done:
return result;
}
static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
{
printf("netname: %s\n", r->name);
printf("\tremark:\t%s\n", r->comment);
}
static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
{
printf("netname: %s\n", r->name);
printf("\tremark:\t%s\n", r->comment);
printf("\tpath:\t%s\n", r->path);
printf("\tpassword:\t%s\n", r->password);
}
static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
{
printf("netname: %s\n", r->name);
printf("\tremark:\t%s\n", r->comment);
printf("\tpath:\t%s\n", r->path);
printf("\tpassword:\t%s\n", r->password);
printf("\ttype:\t0x%x\n", r->type);
printf("\tperms:\t%d\n", r->permissions);
printf("\tmax_uses:\t%d\n", r->max_users);
printf("\tnum_uses:\t%d\n", r->current_users);
if (r->sd_buf.sd)
display_sec_desc(r->sd_buf.sd);
}
static WERROR cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv,
uint32_t opcode)
{
uint32 info_level = 2;
struct srvsvc_NetShareInfoCtr info_ctr;
struct srvsvc_NetShareCtr0 ctr0;
struct srvsvc_NetShareCtr1 ctr1;
struct srvsvc_NetShareCtr2 ctr2;
struct srvsvc_NetShareCtr501 ctr501;
struct srvsvc_NetShareCtr502 ctr502;
struct srvsvc_NetShareCtr1004 ctr1004;
struct srvsvc_NetShareCtr1005 ctr1005;
struct srvsvc_NetShareCtr1006 ctr1006;
struct srvsvc_NetShareCtr1007 ctr1007;
struct srvsvc_NetShareCtr1501 ctr1501;
WERROR result;
NTSTATUS status;
uint32_t totalentries = 0;
uint32_t resume_handle = 0;
uint32_t *resume_handle_p = NULL;
uint32 preferred_len = 0xffffffff, i;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 3) {
printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
return WERR_OK;
}
if (argc >= 2) {
info_level = atoi(argv[1]);
}
if (argc == 3) {
resume_handle = atoi(argv[2]);
resume_handle_p = &resume_handle;
}
ZERO_STRUCT(info_ctr);
info_ctr.level = info_level;
switch (info_level) {
case 0:
ZERO_STRUCT(ctr0);
info_ctr.ctr.ctr0 = &ctr0;
break;
case 1:
ZERO_STRUCT(ctr1);
info_ctr.ctr.ctr1 = &ctr1;
break;
case 2:
ZERO_STRUCT(ctr2);
info_ctr.ctr.ctr2 = &ctr2;
break;
case 501:
ZERO_STRUCT(ctr501);
info_ctr.ctr.ctr501 = &ctr501;
break;
case 502:
ZERO_STRUCT(ctr502);
info_ctr.ctr.ctr502 = &ctr502;
break;
case 1004:
ZERO_STRUCT(ctr1004);
info_ctr.ctr.ctr1004 = &ctr1004;
break;
case 1005:
ZERO_STRUCT(ctr1005);
info_ctr.ctr.ctr1005 = &ctr1005;
break;
case 1006:
ZERO_STRUCT(ctr1006);
info_ctr.ctr.ctr1006 = &ctr1006;
break;
case 1007:
ZERO_STRUCT(ctr1007);
info_ctr.ctr.ctr1007 = &ctr1007;
break;
case 1501:
ZERO_STRUCT(ctr1501);
info_ctr.ctr.ctr1501 = &ctr1501;
break;
}
switch (opcode) {
case NDR_SRVSVC_NETSHAREENUM:
status = dcerpc_srvsvc_NetShareEnum(b, mem_ctx,
cli->desthost,
&info_ctr,
preferred_len,
&totalentries,
resume_handle_p,
&result);
break;
case NDR_SRVSVC_NETSHAREENUMALL:
status = dcerpc_srvsvc_NetShareEnumAll(b, mem_ctx,
cli->desthost,
&info_ctr,
preferred_len,
&totalentries,
resume_handle_p,
&result);
break;
default:
return WERR_INVALID_PARAM;
}
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
/* Display results */
switch (info_level) {
case 1:
for (i = 0; i < totalentries; i++)
display_share_info_1(&info_ctr.ctr.ctr1->array[i]);
break;
case 2:
for (i = 0; i < totalentries; i++)
display_share_info_2(&info_ctr.ctr.ctr2->array[i]);
break;
case 502:
for (i = 0; i < totalentries; i++)
display_share_info_502(&info_ctr.ctr.ctr502->array[i]);
break;
default:
printf("unsupported info level %d\n", info_level);
break;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
argc, argv,
NDR_SRVSVC_NETSHAREENUM);
}
static WERROR cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
argc, argv,
NDR_SRVSVC_NETSHAREENUMALL);
}
static WERROR cmd_srvsvc_net_share_get_info(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 502;
union srvsvc_NetShareInfo info;
WERROR result;
NTSTATUS status;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc < 2 || argc > 3) {
printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
return WERR_OK;
}
if (argc == 3)
info_level = atoi(argv[2]);
status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
cli->desthost,
argv[1],
info_level,
&info,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
/* Display results */
switch (info_level) {
case 1:
display_share_info_1(info.info1);
break;
case 2:
display_share_info_2(info.info2);
break;
case 502:
display_share_info_502(info.info502);
break;
default:
printf("unsupported info level %d\n", info_level);
break;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_share_set_info(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 502;
union srvsvc_NetShareInfo info_get;
WERROR result;
NTSTATUS status;
uint32_t parm_err = 0;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 3) {
printf("Usage: %s [sharename] [comment]\n", argv[0]);
return WERR_OK;
}
/* retrieve share info */
status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
cli->desthost,
argv[1],
info_level,
&info_get,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
info_get.info502->comment = argv[2];
/* set share info */
status = dcerpc_srvsvc_NetShareSetInfo(b, mem_ctx,
cli->desthost,
argv[1],
info_level,
&info_get,
&parm_err,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
/* re-retrieve share info and display */
status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
cli->desthost,
argv[1],
info_level,
&info_get,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
display_share_info_502(info_get.info502);
done:
return result;
}
static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
struct srvsvc_NetRemoteTODInfo *tod = NULL;
WERROR result;
NTSTATUS status;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 1) {
printf("Usage: %s\n", argv[0]);
return WERR_OK;
}
status = dcerpc_srvsvc_NetRemoteTOD(b, mem_ctx,
cli->srv_name_slash,
&tod,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result))
goto done;
done:
return result;
}
static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
uint32 info_level = 3;
struct srvsvc_NetFileInfoCtr info_ctr;
struct srvsvc_NetFileCtr3 ctr3;
WERROR result;
NTSTATUS status;
uint32 preferred_len = 0xffff;
uint32_t total_entries = 0;
uint32_t resume_handle = 0;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 2) {
printf("Usage: %s [infolevel]\n", argv[0]);
return WERR_OK;
}
if (argc == 2)
info_level = atoi(argv[1]);
ZERO_STRUCT(info_ctr);
ZERO_STRUCT(ctr3);
info_ctr.level = info_level;
info_ctr.ctr.ctr3 = &ctr3;
status = dcerpc_srvsvc_NetFileEnum(b, mem_ctx,
cli->desthost,
NULL,
NULL,
&info_ctr,
preferred_len,
&total_entries,
&resume_handle,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
WERROR result;
NTSTATUS status;
uint32_t name_type = 9;
uint32_t flags = 0;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc < 2 || argc > 3) {
printf("Usage: %s [sharename] [type]\n", argv[0]);
return WERR_OK;
}
if (argc == 3) {
name_type = atoi(argv[2]);
}
status = dcerpc_srvsvc_NetNameValidate(b, mem_ctx,
cli->desthost,
argv[1],
name_type,
flags,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result))
goto done;
done:
return result;
}
static WERROR cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
WERROR result;
NTSTATUS status;
struct sec_desc_buf *sd_buf = NULL;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc < 2 || argc > 4) {
printf("Usage: %s [sharename] [file]\n", argv[0]);
return WERR_OK;
}
status = dcerpc_srvsvc_NetGetFileSecurity(b, mem_ctx,
cli->desthost,
argv[1],
argv[2],
SECINFO_DACL,
&sd_buf,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
display_sec_desc(sd_buf->sd);
done:
return result;
}
static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
WERROR result;
NTSTATUS status;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc < 2 || argc > 4) {
printf("Usage: %s [client] [user]\n", argv[0]);
return WERR_OK;
}
status = dcerpc_srvsvc_NetSessDel(b, mem_ctx,
cli->desthost,
argv[1],
argv[2],
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
WERROR result;
NTSTATUS status;
struct srvsvc_NetSessInfoCtr info_ctr;
struct srvsvc_NetSessCtr0 ctr0;
struct srvsvc_NetSessCtr1 ctr1;
struct srvsvc_NetSessCtr2 ctr2;
struct srvsvc_NetSessCtr10 ctr10;
struct srvsvc_NetSessCtr502 ctr502;
uint32_t total_entries = 0;
uint32_t resume_handle = 0;
uint32_t *resume_handle_p = NULL;
uint32_t level = 1;
const char *client = NULL;
const char *user = NULL;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 6) {
printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
return WERR_OK;
}
if (argc >= 2) {
client = argv[1];
}
if (argc >= 3) {
user = argv[2];
}
if (argc >= 4) {
level = atoi(argv[3]);
}
if (argc >= 5) {
resume_handle = atoi(argv[4]);
resume_handle_p = &resume_handle;
}
ZERO_STRUCT(info_ctr);
info_ctr.level = level;
d_printf("trying level: %d\n", level);
switch (level) {
case 0:
ZERO_STRUCT(ctr0);
info_ctr.ctr.ctr0 = &ctr0;
break;
case 1:
ZERO_STRUCT(ctr1);
info_ctr.ctr.ctr1 = &ctr1;
break;
case 2:
ZERO_STRUCT(ctr2);
info_ctr.ctr.ctr2 = &ctr2;
break;
case 10:
ZERO_STRUCT(ctr10);
info_ctr.ctr.ctr10 = &ctr10;
break;
case 502:
ZERO_STRUCT(ctr502);
info_ctr.ctr.ctr502 = &ctr502;
break;
}
status = dcerpc_srvsvc_NetSessEnum(b, mem_ctx,
cli->desthost,
client,
user,
&info_ctr,
0xffffffff,
&total_entries,
resume_handle_p,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
struct srvsvc_NetDiskInfo info;
WERROR result;
NTSTATUS status;
uint32_t total_entries = 0;
uint32_t resume_handle = 0;
uint32_t level = 0;
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 4) {
printf("Usage: %s [level] [resume_handle]\n", argv[0]);
return WERR_OK;
}
if (argc >= 2) {
level = atoi(argv[1]);
}
if (argc >= 3) {
resume_handle = atoi(argv[2]);
}
ZERO_STRUCT(info);
status = dcerpc_srvsvc_NetDiskEnum(b, mem_ctx,
cli->desthost,
level,
&info,
0xffffffff,
&total_entries,
&resume_handle,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
done:
return result;
}
static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
TALLOC_CTX *mem_ctx,
int argc, const char **argv)
{
struct srvsvc_NetConnInfoCtr info_ctr;
struct srvsvc_NetConnCtr0 ctr0;
struct srvsvc_NetConnCtr1 ctr1;
WERROR result;
NTSTATUS status;
uint32_t total_entries = 0;
uint32_t resume_handle = 0;
uint32_t *resume_handle_p = NULL;
uint32_t level = 1;
const char *path = "IPC$";
struct dcerpc_binding_handle *b = cli->binding_handle;
if (argc > 4) {
printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
return WERR_OK;
}
if (argc >= 2) {
level = atoi(argv[1]);
}
if (argc >= 3) {
path = argv[2];
}
if (argc >= 4) {
resume_handle = atoi(argv[3]);
resume_handle_p = &resume_handle;
}
ZERO_STRUCT(info_ctr);
info_ctr.level = level;
switch (level) {
case 0:
ZERO_STRUCT(ctr0);
info_ctr.ctr.ctr0 = &ctr0;
break;
case 1:
ZERO_STRUCT(ctr1);
info_ctr.ctr.ctr1 = &ctr1;
break;
default:
return WERR_INVALID_PARAM;
}
status = dcerpc_srvsvc_NetConnEnum(b, mem_ctx,
cli->desthost,
path,
&info_ctr,
0xffffffff,
&total_entries,
resume_handle_p,
&result);
if (!NT_STATUS_IS_OK(status)) {
result = ntstatus_to_werror(status);
goto done;
}
if (!W_ERROR_IS_OK(result)) {
goto done;
}
done:
return result;
}
/* List of commands exported by this module */
struct cmd_set srvsvc_commands[] = {
{ "SRVSVC" },
{ "srvinfo", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_srv_query_info, &ndr_table_srvsvc, NULL, "Server query info", "" },
{ "netshareenum",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum, &ndr_table_srvsvc, NULL, "Enumerate shares", "" },
{ "netshareenumall",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_enum_all, &ndr_table_srvsvc, NULL, "Enumerate all shares", "" },
{ "netsharegetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_get_info, &ndr_table_srvsvc, NULL, "Get Share Info", "" },
{ "netsharesetinfo",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_share_set_info, &ndr_table_srvsvc, NULL, "Set Share Info", "" },
{ "netfileenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_enum, &ndr_table_srvsvc, NULL, "Enumerate open files", "" },
{ "netremotetod",RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_remote_tod, &ndr_table_srvsvc, NULL, "Fetch remote time of day", "" },
{ "netnamevalidate", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_name_validate, &ndr_table_srvsvc, NULL, "Validate sharename", "" },
{ "netfilegetsec", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_file_get_sec, &ndr_table_srvsvc, NULL, "Get File security", "" },
{ "netsessdel", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_del, &ndr_table_srvsvc, NULL, "Delete Session", "" },
{ "netsessenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_sess_enum, &ndr_table_srvsvc, NULL, "Enumerate Sessions", "" },
{ "netdiskenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_disk_enum, &ndr_table_srvsvc, NULL, "Enumerate Disks", "" },
{ "netconnenum", RPC_RTYPE_WERROR, NULL, cmd_srvsvc_net_conn_enum, &ndr_table_srvsvc, NULL, "Enumerate Connections", "" },
{ NULL }
};
|