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