2 Unix SMB/CIFS implementation.
5 Copyright (C) Andrew Tridgell 1992-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
7 Copyright (C) Tim Potter 2000,2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "rpcclient.h"
25 #include "../librpc/gen_ndr/cli_srvsvc.h"
27 /* Display server query info */
29 static char *get_server_type_str(uint32 type
)
31 static fstring typestr
;
34 if (type
== SV_TYPE_ALL
) {
35 fstrcpy(typestr
, "All");
41 for (i
= 0; i
< 32; i
++) {
42 if (type
& (1 << i
)) {
44 case SV_TYPE_WORKSTATION
:
45 fstrcat(typestr
, "Wk ");
48 fstrcat(typestr
, "Sv ");
50 case SV_TYPE_SQLSERVER
:
51 fstrcat(typestr
, "Sql ");
53 case SV_TYPE_DOMAIN_CTRL
:
54 fstrcat(typestr
, "PDC ");
56 case SV_TYPE_DOMAIN_BAKCTRL
:
57 fstrcat(typestr
, "BDC ");
59 case SV_TYPE_TIME_SOURCE
:
60 fstrcat(typestr
, "Tim ");
63 fstrcat(typestr
, "AFP ");
66 fstrcat(typestr
, "Nov ");
68 case SV_TYPE_DOMAIN_MEMBER
:
69 fstrcat(typestr
, "Dom ");
71 case SV_TYPE_PRINTQ_SERVER
:
72 fstrcat(typestr
, "PrQ ");
74 case SV_TYPE_DIALIN_SERVER
:
75 fstrcat(typestr
, "Din ");
77 case SV_TYPE_SERVER_UNIX
:
78 fstrcat(typestr
, "Unx ");
81 fstrcat(typestr
, "NT ");
84 fstrcat(typestr
, "Wfw ");
86 case SV_TYPE_SERVER_MFPN
:
87 fstrcat(typestr
, "Mfp ");
89 case SV_TYPE_SERVER_NT
:
90 fstrcat(typestr
, "SNT ");
92 case SV_TYPE_POTENTIAL_BROWSER
:
93 fstrcat(typestr
, "PtB ");
95 case SV_TYPE_BACKUP_BROWSER
:
96 fstrcat(typestr
, "BMB ");
98 case SV_TYPE_MASTER_BROWSER
:
99 fstrcat(typestr
, "LMB ");
101 case SV_TYPE_DOMAIN_MASTER
:
102 fstrcat(typestr
, "DMB ");
104 case SV_TYPE_SERVER_OSF
:
105 fstrcat(typestr
, "OSF ");
107 case SV_TYPE_SERVER_VMS
:
108 fstrcat(typestr
, "VMS ");
110 case SV_TYPE_WIN95_PLUS
:
111 fstrcat(typestr
, "W95 ");
113 case SV_TYPE_ALTERNATE_XPORT
:
114 fstrcat(typestr
, "Xpt ");
116 case SV_TYPE_LOCAL_LIST_ONLY
:
117 fstrcat(typestr
, "Dom ");
119 case SV_TYPE_DOMAIN_ENUM
:
120 fstrcat(typestr
, "Loc ");
126 i
= strlen(typestr
) - 1;
128 if (typestr
[i
] == ' ')
134 static void display_server(const char *sname
, uint32 type
, const char *comment
)
136 printf("\t%-15.15s%-20s %s\n", sname
, get_server_type_str(type
),
140 static void display_srv_info_101(struct srvsvc_NetSrvInfo101
*r
)
142 display_server(r
->server_name
, r
->server_type
, r
->comment
);
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
);
150 static void display_srv_info_102(struct srvsvc_NetSrvInfo102
*r
)
152 display_server(r
->server_name
, r
->server_type
, r
->comment
);
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
);
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
,
163 printf("\tlicenses :\t%d\n", r
->licenses
);
164 printf("\tuser path :\t%s\n", r
->userpath
);
167 /* Server query info */
168 static WERROR
cmd_srvsvc_srv_query_info(struct rpc_pipe_client
*cli
,
170 int argc
, const char **argv
)
172 uint32 info_level
= 101;
173 union srvsvc_NetSrvInfo info
;
176 const char *server_unc
= cli
->srv_name_slash
;
179 printf("Usage: %s [infolevel] [server_unc]\n", argv
[0]);
184 info_level
= atoi(argv
[1]);
188 server_unc
= argv
[2];
191 status
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
,
196 if (!NT_STATUS_IS_OK(status
)) {
197 return ntstatus_to_werror(status
);
200 if (!W_ERROR_IS_OK(result
)) {
204 /* Display results */
206 switch (info_level
) {
208 display_srv_info_101(info
.info101
);
211 display_srv_info_102(info
.info102
);
214 printf("unsupported info level %d\n", info_level
);
222 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
224 printf("netname: %s\n", r
->name
);
225 printf("\tremark:\t%s\n", r
->comment
);
228 static void display_share_info_2(struct srvsvc_NetShareInfo2
*r
)
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
);
236 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
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
);
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
);
249 display_sec_desc(r
->sd_buf
.sd
);
253 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
255 int argc
, const char **argv
,
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
;
272 uint32_t totalentries
= 0;
273 uint32_t resume_handle
= 0;
274 uint32_t *resume_handle_p
= NULL
;
275 uint32 preferred_len
= 0xffffffff, i
;
278 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
283 info_level
= atoi(argv
[1]);
287 resume_handle
= atoi(argv
[2]);
288 resume_handle_p
= &resume_handle
;
291 ZERO_STRUCT(info_ctr
);
293 info_ctr
.level
= info_level
;
295 switch (info_level
) {
298 info_ctr
.ctr
.ctr0
= &ctr0
;
302 info_ctr
.ctr
.ctr1
= &ctr1
;
306 info_ctr
.ctr
.ctr2
= &ctr2
;
310 info_ctr
.ctr
.ctr501
= &ctr501
;
314 info_ctr
.ctr
.ctr502
= &ctr502
;
317 ZERO_STRUCT(ctr1004
);
318 info_ctr
.ctr
.ctr1004
= &ctr1004
;
321 ZERO_STRUCT(ctr1005
);
322 info_ctr
.ctr
.ctr1005
= &ctr1005
;
325 ZERO_STRUCT(ctr1006
);
326 info_ctr
.ctr
.ctr1006
= &ctr1006
;
329 ZERO_STRUCT(ctr1007
);
330 info_ctr
.ctr
.ctr1007
= &ctr1007
;
333 ZERO_STRUCT(ctr1501
);
334 info_ctr
.ctr
.ctr1501
= &ctr1501
;
339 case NDR_SRVSVC_NETSHAREENUM
:
340 status
= rpccli_srvsvc_NetShareEnum(cli
, mem_ctx
,
348 case NDR_SRVSVC_NETSHAREENUMALL
:
349 status
= rpccli_srvsvc_NetShareEnumAll(cli
, mem_ctx
,
358 return WERR_INVALID_PARAM
;
361 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
365 /* Display results */
367 switch (info_level
) {
369 for (i
= 0; i
< totalentries
; i
++)
370 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
373 for (i
= 0; i
< totalentries
; i
++)
374 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
377 for (i
= 0; i
< totalentries
; i
++)
378 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
381 printf("unsupported info level %d\n", info_level
);
389 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
391 int argc
, const char **argv
)
393 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
395 NDR_SRVSVC_NETSHAREENUM
);
398 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
400 int argc
, const char **argv
)
402 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
404 NDR_SRVSVC_NETSHAREENUMALL
);
407 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
409 int argc
, const char **argv
)
411 uint32 info_level
= 502;
412 union srvsvc_NetShareInfo info
;
416 if (argc
< 2 || argc
> 3) {
417 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
422 info_level
= atoi(argv
[2]);
424 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
431 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
435 /* Display results */
437 switch (info_level
) {
439 display_share_info_1(info
.info1
);
442 display_share_info_2(info
.info2
);
445 display_share_info_502(info
.info502
);
448 printf("unsupported info level %d\n", info_level
);
456 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
458 int argc
, const char **argv
)
460 uint32 info_level
= 502;
461 union srvsvc_NetShareInfo info_get
;
464 uint32_t parm_err
= 0;
467 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
471 /* retrieve share info */
472 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
479 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
483 info_get
.info502
->comment
= argv
[2];
486 status
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
,
494 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
498 /* re-retrieve share info and display */
499 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
506 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
510 display_share_info_502(info_get
.info502
);
516 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
518 int argc
, const char **argv
)
520 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
525 printf("Usage: %s\n", argv
[0]);
529 status
= rpccli_srvsvc_NetRemoteTOD(cli
, mem_ctx
,
533 if (!NT_STATUS_IS_OK(status
)) {
534 result
= ntstatus_to_werror(status
);
538 if (!W_ERROR_IS_OK(result
))
545 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
547 int argc
, const char **argv
)
549 uint32 info_level
= 3;
550 struct srvsvc_NetFileInfoCtr info_ctr
;
551 struct srvsvc_NetFileCtr3 ctr3
;
554 uint32 preferred_len
= 0xffff;
555 uint32_t total_entries
= 0;
556 uint32_t resume_handle
= 0;
559 printf("Usage: %s [infolevel]\n", argv
[0]);
564 info_level
= atoi(argv
[1]);
566 ZERO_STRUCT(info_ctr
);
569 info_ctr
.level
= info_level
;
570 info_ctr
.ctr
.ctr3
= &ctr3
;
572 status
= rpccli_srvsvc_NetFileEnum(cli
, mem_ctx
,
582 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
589 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
591 int argc
, const char **argv
)
595 uint32_t name_type
= 9;
598 if (argc
< 2 || argc
> 3) {
599 printf("Usage: %s [sharename] [type]\n", argv
[0]);
604 name_type
= atoi(argv
[2]);
607 status
= rpccli_srvsvc_NetNameValidate(cli
, mem_ctx
,
614 if (!W_ERROR_IS_OK(result
))
621 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
623 int argc
, const char **argv
)
627 struct sec_desc_buf
*sd_buf
= NULL
;
629 if (argc
< 2 || argc
> 4) {
630 printf("Usage: %s [sharename] [file]\n", argv
[0]);
634 status
= rpccli_srvsvc_NetGetFileSecurity(cli
, mem_ctx
,
642 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
646 display_sec_desc(sd_buf
->sd
);
652 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
654 int argc
, const char **argv
)
659 if (argc
< 2 || argc
> 4) {
660 printf("Usage: %s [client] [user]\n", argv
[0]);
664 status
= rpccli_srvsvc_NetSessDel(cli
, mem_ctx
,
670 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
678 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
680 int argc
, const char **argv
)
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
;
694 const char *client
= NULL
;
695 const char *user
= NULL
;
698 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
711 level
= atoi(argv
[3]);
715 resume_handle
= atoi(argv
[4]);
716 resume_handle_p
= &resume_handle
;
719 ZERO_STRUCT(info_ctr
);
721 info_ctr
.level
= level
;
723 d_printf("trying level: %d\n", level
);
728 info_ctr
.ctr
.ctr0
= &ctr0
;
732 info_ctr
.ctr
.ctr1
= &ctr1
;
736 info_ctr
.ctr
.ctr2
= &ctr2
;
740 info_ctr
.ctr
.ctr10
= &ctr10
;
744 info_ctr
.ctr
.ctr502
= &ctr502
;
748 status
= rpccli_srvsvc_NetSessEnum(cli
, mem_ctx
,
758 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
766 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
768 int argc
, const char **argv
)
770 struct srvsvc_NetDiskInfo info
;
773 uint32_t total_entries
= 0;
774 uint32_t resume_handle
= 0;
778 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
783 level
= atoi(argv
[1]);
787 resume_handle
= atoi(argv
[2]);
792 status
= rpccli_srvsvc_NetDiskEnum(cli
, mem_ctx
,
801 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
809 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
811 int argc
, const char **argv
)
813 struct srvsvc_NetConnInfoCtr info_ctr
;
814 struct srvsvc_NetConnCtr0 ctr0
;
815 struct srvsvc_NetConnCtr1 ctr1
;
818 uint32_t total_entries
= 0;
819 uint32_t resume_handle
= 0;
820 uint32_t *resume_handle_p
= NULL
;
822 const char *path
= "IPC$";
825 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
830 level
= atoi(argv
[1]);
838 resume_handle
= atoi(argv
[3]);
839 resume_handle_p
= &resume_handle
;
842 ZERO_STRUCT(info_ctr
);
844 info_ctr
.level
= level
;
849 info_ctr
.ctr
.ctr0
= &ctr0
;
853 info_ctr
.ctr
.ctr1
= &ctr1
;
856 return WERR_INVALID_PARAM
;
859 status
= rpccli_srvsvc_NetConnEnum(cli
, mem_ctx
,
868 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
877 /* List of commands exported by this module */
879 struct cmd_set srvsvc_commands
[] = {
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", "" },