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