s3: Use dbwrap_parse_record in fetch_share_mode_unlocked
[kai/samba.git] / source3 / rpcclient / cmd_srvsvc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    RPC pipe client
4
5    Copyright (C) Andrew Tridgell 1992-1999
6    Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7    Copyright (C) Tim Potter 2000,2002
8
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.
13    
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.
18    
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/>.
21 */
22
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"
28
29 /* Display server query info */
30
31 static char *get_server_type_str(uint32 type)
32 {
33         static fstring typestr;
34         int i;
35
36         if (type == SV_TYPE_ALL) {
37                 fstrcpy(typestr, "All");
38                 return typestr;
39         }
40                 
41         typestr[0] = 0;
42
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;
124                         }
125                 }
126         }
127
128         i = strlen(typestr) - 1;
129
130         if (typestr[i] == ' ')
131                 typestr[i] = 0;
132         
133         return typestr;
134 }
135
136 static void display_server(const char *sname, uint32 type, const char *comment)
137 {
138         printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type), 
139                comment);
140 }
141
142 static void display_srv_info_101(struct srvsvc_NetSrvInfo101 *r)
143 {
144         display_server(r->server_name, r->server_type, r->comment);
145
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);
150 }
151
152 static void display_srv_info_102(struct srvsvc_NetSrvInfo102 *r)
153 {
154         display_server(r->server_name, r->server_type, r->comment);
155
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);
160
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);
167 }
168
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)
173 {
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;
180
181         if (argc > 3) {
182                 printf("Usage: %s [infolevel] [server_unc]\n", argv[0]);
183                 return WERR_OK;
184         }
185
186         if (argc >= 2) {
187                 info_level = atoi(argv[1]);
188         }
189
190         if (argc >= 3) {
191                 server_unc = argv[2];
192         }
193
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);
201         }
202
203         if (!W_ERROR_IS_OK(result)) {
204                 goto done;
205         }
206
207         /* Display results */
208
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;
219         }
220
221  done:
222         return result;
223 }
224
225 static void display_share_info_1(struct srvsvc_NetShareInfo1 *r)
226 {
227         printf("netname: %s\n", r->name);
228         printf("\tremark:\t%s\n", r->comment);
229 }
230
231 static void display_share_info_2(struct srvsvc_NetShareInfo2 *r)
232 {
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);
237 }
238
239 static void display_share_info_502(struct srvsvc_NetShareInfo502 *r)
240 {
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);
245
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);
250
251         if (r->sd_buf.sd)
252                 display_sec_desc(r->sd_buf.sd);
253
254 }
255
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)
260 {
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;
280
281         if (argc > 3) {
282                 printf("Usage: %s [infolevel] [resume_handle]\n", argv[0]);
283                 return WERR_OK;
284         }
285
286         if (argc >= 2) {
287                 info_level = atoi(argv[1]);
288         }
289
290         if (argc == 3) {
291                 resume_handle = atoi(argv[2]);
292                 resume_handle_p = &resume_handle;
293         }
294
295         ZERO_STRUCT(info_ctr);
296
297         info_ctr.level = info_level;
298
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;
340         }
341
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;
363         }
364
365         if (!NT_STATUS_IS_OK(status)) {
366                 result = ntstatus_to_werror(status);
367                 goto done;
368         }
369         if (!W_ERROR_IS_OK(result)) {
370                 goto done;
371         }
372
373         /* Display results */
374
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;
391         }
392
393  done:
394         return result;
395 }
396
397 static WERROR cmd_srvsvc_net_share_enum(struct rpc_pipe_client *cli,
398                                         TALLOC_CTX *mem_ctx,
399                                         int argc, const char **argv)
400 {
401         return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
402                                              argc, argv,
403                                              NDR_SRVSVC_NETSHAREENUM);
404 }
405
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)
409 {
410         return cmd_srvsvc_net_share_enum_int(cli, mem_ctx,
411                                              argc, argv,
412                                              NDR_SRVSVC_NETSHAREENUMALL);
413 }
414
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)
418 {
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;
424
425         if (argc < 2 || argc > 3) {
426                 printf("Usage: %s [sharename] [infolevel]\n", argv[0]);
427                 return WERR_OK;
428         }
429
430         if (argc == 3)
431                 info_level = atoi(argv[2]);
432
433         status = dcerpc_srvsvc_NetShareGetInfo(b, mem_ctx,
434                                                cli->desthost,
435                                                argv[1],
436                                                info_level,
437                                                &info,
438                                                &result);
439
440         if (!NT_STATUS_IS_OK(status)) {
441                 result = ntstatus_to_werror(status);
442                 goto done;
443         }
444         if (!W_ERROR_IS_OK(result)) {
445                 goto done;
446         }
447
448         /* Display results */
449
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;
463         }
464
465  done:
466         return result;
467 }
468
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)
472 {
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;
479
480         if (argc > 3) {
481                 printf("Usage: %s [sharename] [comment]\n", argv[0]);
482                 return WERR_OK;
483         }
484
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);
492
493         if (!NT_STATUS_IS_OK(status)) {
494                 result = ntstatus_to_werror(status);
495                 goto done;
496         }
497         if (!W_ERROR_IS_OK(result)) {
498                 goto done;
499         }
500
501         info_get.info502->comment = argv[2];
502
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);
511
512         if (!NT_STATUS_IS_OK(status)) {
513                 result = ntstatus_to_werror(status);
514                 goto done;
515         }
516         if (!W_ERROR_IS_OK(result)) {
517                 goto done;
518         }
519
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;
530         }
531         if (!W_ERROR_IS_OK(result)) {
532                 goto done;
533         }
534
535         display_share_info_502(info_get.info502);
536
537  done:
538         return result;
539 }
540
541 static WERROR cmd_srvsvc_net_remote_tod(struct rpc_pipe_client *cli, 
542                                           TALLOC_CTX *mem_ctx,
543                                           int argc, const char **argv)
544 {
545         struct srvsvc_NetRemoteTODInfo *tod = NULL;
546         WERROR result;
547         NTSTATUS status;
548         struct dcerpc_binding_handle *b = cli->binding_handle;
549
550         if (argc > 1) {
551                 printf("Usage: %s\n", argv[0]);
552                 return WERR_OK;
553         }
554
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;
562         }
563
564         if (!W_ERROR_IS_OK(result))
565                 goto done;
566
567  done:
568         return result;
569 }
570
571 static WERROR cmd_srvsvc_net_file_enum(struct rpc_pipe_client *cli, 
572                                          TALLOC_CTX *mem_ctx,
573                                          int argc, const char **argv)
574 {
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;
584
585         if (argc > 2) {
586                 printf("Usage: %s [infolevel]\n", argv[0]);
587                 return WERR_OK;
588         }
589
590         if (argc == 2)
591                 info_level = atoi(argv[1]);
592
593         ZERO_STRUCT(info_ctr);
594         ZERO_STRUCT(ctr3);
595
596         info_ctr.level = info_level;
597         info_ctr.ctr.ctr3 = &ctr3;
598
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;
611         }
612
613         if (!W_ERROR_IS_OK(result)) {
614                 goto done;
615         }
616
617  done:
618         return result;
619 }
620
621 static WERROR cmd_srvsvc_net_name_validate(struct rpc_pipe_client *cli,
622                                            TALLOC_CTX *mem_ctx,
623                                            int argc, const char **argv)
624 {
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;
630
631         if (argc < 2 || argc > 3) {
632                 printf("Usage: %s [sharename] [type]\n", argv[0]);
633                 return WERR_OK;
634         }
635
636         if (argc == 3) {
637                 name_type = atoi(argv[2]);
638         }
639
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;
649         }
650
651         if (!W_ERROR_IS_OK(result))
652                 goto done;
653
654  done:
655         return result;
656 }
657
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)
661 {
662         WERROR result;
663         NTSTATUS status;
664         struct sec_desc_buf *sd_buf = NULL;
665         struct dcerpc_binding_handle *b = cli->binding_handle;
666
667         if (argc < 2 || argc > 4) {
668                 printf("Usage: %s [sharename] [file]\n", argv[0]);
669                 return WERR_OK;
670         }
671
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;
682         }
683
684         if (!W_ERROR_IS_OK(result)) {
685                 goto done;
686         }
687
688         display_sec_desc(sd_buf->sd);
689
690  done:
691         return result;
692 }
693
694 static WERROR cmd_srvsvc_net_sess_del(struct rpc_pipe_client *cli,
695                                       TALLOC_CTX *mem_ctx,
696                                       int argc, const char **argv)
697 {
698         WERROR result;
699         NTSTATUS status;
700         struct dcerpc_binding_handle *b = cli->binding_handle;
701
702         if (argc < 2 || argc > 4) {
703                 printf("Usage: %s [client] [user]\n", argv[0]);
704                 return WERR_OK;
705         }
706
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;
715         }
716
717         if (!W_ERROR_IS_OK(result)) {
718                 goto done;
719         }
720
721  done:
722         return result;
723 }
724
725 static WERROR cmd_srvsvc_net_sess_enum(struct rpc_pipe_client *cli,
726                                        TALLOC_CTX *mem_ctx,
727                                        int argc, const char **argv)
728 {
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;
744
745         if (argc > 6) {
746                 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv[0]);
747                 return WERR_OK;
748         }
749
750         if (argc >= 2) {
751                 client = argv[1];
752         }
753
754         if (argc >= 3) {
755                 user = argv[2];
756         }
757
758         if (argc >= 4) {
759                 level = atoi(argv[3]);
760         }
761
762         if (argc >= 5) {
763                 resume_handle = atoi(argv[4]);
764                 resume_handle_p = &resume_handle;
765         }
766
767         ZERO_STRUCT(info_ctr);
768
769         info_ctr.level = level;
770
771         d_printf("trying level: %d\n", level);
772
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;
794         }
795
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);
805
806         if (!NT_STATUS_IS_OK(status)) {
807                 result = ntstatus_to_werror(status);
808                 goto done;
809         }
810
811         if (!W_ERROR_IS_OK(result)) {
812                 goto done;
813         }
814
815  done:
816         return result;
817 }
818
819 static WERROR cmd_srvsvc_net_disk_enum(struct rpc_pipe_client *cli,
820                                        TALLOC_CTX *mem_ctx,
821                                        int argc, const char **argv)
822 {
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;
830
831         if (argc > 4) {
832                 printf("Usage: %s [level] [resume_handle]\n", argv[0]);
833                 return WERR_OK;
834         }
835
836         if (argc >= 2) {
837                 level = atoi(argv[1]);
838         }
839
840         if (argc >= 3) {
841                 resume_handle = atoi(argv[2]);
842         }
843
844         ZERO_STRUCT(info);
845
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;
857         }
858
859         if (!W_ERROR_IS_OK(result)) {
860                 goto done;
861         }
862
863  done:
864         return result;
865 }
866
867 static WERROR cmd_srvsvc_net_conn_enum(struct rpc_pipe_client *cli,
868                                        TALLOC_CTX *mem_ctx,
869                                        int argc, const char **argv)
870 {
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;
882
883         if (argc > 4) {
884                 printf("Usage: %s [level] [path] [resume_handle]\n", argv[0]);
885                 return WERR_OK;
886         }
887
888         if (argc >= 2) {
889                 level = atoi(argv[1]);
890         }
891
892         if (argc >= 3) {
893                 path = argv[2];
894         }
895
896         if (argc >= 4) {
897                 resume_handle = atoi(argv[3]);
898                 resume_handle_p = &resume_handle;
899         }
900
901         ZERO_STRUCT(info_ctr);
902
903         info_ctr.level = level;
904
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;
916         }
917
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);
926
927         if (!NT_STATUS_IS_OK(status)) {
928                 result = ntstatus_to_werror(status);
929                 goto done;
930         }
931
932         if (!W_ERROR_IS_OK(result)) {
933                 goto done;
934         }
935
936  done:
937         return result;
938 }
939
940
941 /* List of commands exported by this module */
942
943 struct cmd_set srvsvc_commands[] = {
944
945         { "SRVSVC" },
946
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", "" },
960
961         { NULL }
962 };