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
;
178 printf("Usage: %s [infolevel]\n", argv
[0]);
183 info_level
= atoi(argv
[1]);
185 status
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
,
190 if (!NT_STATUS_IS_OK(status
)) {
191 return ntstatus_to_werror(status
);
194 if (!W_ERROR_IS_OK(result
)) {
198 /* Display results */
200 switch (info_level
) {
202 display_srv_info_101(info
.info101
);
205 display_srv_info_102(info
.info102
);
208 printf("unsupported info level %d\n", info_level
);
216 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
218 printf("netname: %s\n", r
->name
);
219 printf("\tremark:\t%s\n", r
->comment
);
222 static void display_share_info_2(struct srvsvc_NetShareInfo2
*r
)
224 printf("netname: %s\n", r
->name
);
225 printf("\tremark:\t%s\n", r
->comment
);
226 printf("\tpath:\t%s\n", r
->path
);
227 printf("\tpassword:\t%s\n", r
->password
);
230 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
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
);
237 printf("\ttype:\t0x%x\n", r
->type
);
238 printf("\tperms:\t%d\n", r
->permissions
);
239 printf("\tmax_uses:\t%d\n", r
->max_users
);
240 printf("\tnum_uses:\t%d\n", r
->current_users
);
243 display_sec_desc(r
->sd_buf
.sd
);
247 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
249 int argc
, const char **argv
,
252 uint32 info_level
= 2;
253 struct srvsvc_NetShareInfoCtr info_ctr
;
254 struct srvsvc_NetShareCtr0 ctr0
;
255 struct srvsvc_NetShareCtr1 ctr1
;
256 struct srvsvc_NetShareCtr2 ctr2
;
257 struct srvsvc_NetShareCtr501 ctr501
;
258 struct srvsvc_NetShareCtr502 ctr502
;
259 struct srvsvc_NetShareCtr1004 ctr1004
;
260 struct srvsvc_NetShareCtr1005 ctr1005
;
261 struct srvsvc_NetShareCtr1006 ctr1006
;
262 struct srvsvc_NetShareCtr1007 ctr1007
;
263 struct srvsvc_NetShareCtr1501 ctr1501
;
266 uint32_t totalentries
= 0;
267 uint32_t resume_handle
= 0;
268 uint32_t *resume_handle_p
= NULL
;
269 uint32 preferred_len
= 0xffffffff, i
;
272 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
277 info_level
= atoi(argv
[1]);
281 resume_handle
= atoi(argv
[2]);
282 resume_handle_p
= &resume_handle
;
285 ZERO_STRUCT(info_ctr
);
287 info_ctr
.level
= info_level
;
289 switch (info_level
) {
292 info_ctr
.ctr
.ctr0
= &ctr0
;
296 info_ctr
.ctr
.ctr1
= &ctr1
;
300 info_ctr
.ctr
.ctr2
= &ctr2
;
304 info_ctr
.ctr
.ctr501
= &ctr501
;
308 info_ctr
.ctr
.ctr502
= &ctr502
;
311 ZERO_STRUCT(ctr1004
);
312 info_ctr
.ctr
.ctr1004
= &ctr1004
;
315 ZERO_STRUCT(ctr1005
);
316 info_ctr
.ctr
.ctr1005
= &ctr1005
;
319 ZERO_STRUCT(ctr1006
);
320 info_ctr
.ctr
.ctr1006
= &ctr1006
;
323 ZERO_STRUCT(ctr1007
);
324 info_ctr
.ctr
.ctr1007
= &ctr1007
;
327 ZERO_STRUCT(ctr1501
);
328 info_ctr
.ctr
.ctr1501
= &ctr1501
;
333 case NDR_SRVSVC_NETSHAREENUM
:
334 status
= rpccli_srvsvc_NetShareEnum(cli
, mem_ctx
,
342 case NDR_SRVSVC_NETSHAREENUMALL
:
343 status
= rpccli_srvsvc_NetShareEnumAll(cli
, mem_ctx
,
352 return WERR_INVALID_PARAM
;
355 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
359 /* Display results */
361 switch (info_level
) {
363 for (i
= 0; i
< totalentries
; i
++)
364 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
367 for (i
= 0; i
< totalentries
; i
++)
368 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
371 for (i
= 0; i
< totalentries
; i
++)
372 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
375 printf("unsupported info level %d\n", info_level
);
383 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
385 int argc
, const char **argv
)
387 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
389 NDR_SRVSVC_NETSHAREENUM
);
392 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
394 int argc
, const char **argv
)
396 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
398 NDR_SRVSVC_NETSHAREENUMALL
);
401 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
403 int argc
, const char **argv
)
405 uint32 info_level
= 502;
406 union srvsvc_NetShareInfo info
;
410 if (argc
< 2 || argc
> 3) {
411 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
416 info_level
= atoi(argv
[2]);
418 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
425 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
429 /* Display results */
431 switch (info_level
) {
433 display_share_info_1(info
.info1
);
436 display_share_info_2(info
.info2
);
439 display_share_info_502(info
.info502
);
442 printf("unsupported info level %d\n", info_level
);
450 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
452 int argc
, const char **argv
)
454 uint32 info_level
= 502;
455 union srvsvc_NetShareInfo info_get
;
458 uint32_t parm_err
= 0;
461 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
465 /* retrieve share info */
466 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
473 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
477 info_get
.info502
->comment
= argv
[2];
480 status
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
,
488 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
492 /* re-retrieve share info and display */
493 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
500 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
504 display_share_info_502(info_get
.info502
);
510 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
512 int argc
, const char **argv
)
514 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
519 printf("Usage: %s\n", argv
[0]);
523 status
= rpccli_srvsvc_NetRemoteTOD(cli
, mem_ctx
,
527 if (!NT_STATUS_IS_OK(status
)) {
528 result
= ntstatus_to_werror(status
);
532 if (!W_ERROR_IS_OK(result
))
539 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
541 int argc
, const char **argv
)
543 uint32 info_level
= 3;
544 struct srvsvc_NetFileInfoCtr info_ctr
;
545 struct srvsvc_NetFileCtr3 ctr3
;
548 uint32 preferred_len
= 0xffff;
549 uint32_t total_entries
= 0;
550 uint32_t resume_handle
= 0;
553 printf("Usage: %s [infolevel]\n", argv
[0]);
558 info_level
= atoi(argv
[1]);
560 ZERO_STRUCT(info_ctr
);
563 info_ctr
.level
= info_level
;
564 info_ctr
.ctr
.ctr3
= &ctr3
;
566 status
= rpccli_srvsvc_NetFileEnum(cli
, mem_ctx
,
576 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
583 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
585 int argc
, const char **argv
)
589 uint32_t name_type
= 9;
592 if (argc
< 2 || argc
> 3) {
593 printf("Usage: %s [sharename] [type]\n", argv
[0]);
598 name_type
= atoi(argv
[2]);
601 status
= rpccli_srvsvc_NetNameValidate(cli
, mem_ctx
,
608 if (!W_ERROR_IS_OK(result
))
615 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
617 int argc
, const char **argv
)
621 struct sec_desc_buf
*sd_buf
= NULL
;
623 if (argc
< 2 || argc
> 4) {
624 printf("Usage: %s [sharename] [file]\n", argv
[0]);
628 status
= rpccli_srvsvc_NetGetFileSecurity(cli
, mem_ctx
,
636 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
640 display_sec_desc(sd_buf
->sd
);
646 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
648 int argc
, const char **argv
)
653 if (argc
< 2 || argc
> 4) {
654 printf("Usage: %s [client] [user]\n", argv
[0]);
658 status
= rpccli_srvsvc_NetSessDel(cli
, mem_ctx
,
664 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
672 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
674 int argc
, const char **argv
)
678 struct srvsvc_NetSessInfoCtr info_ctr
;
679 struct srvsvc_NetSessCtr0 ctr0
;
680 struct srvsvc_NetSessCtr1 ctr1
;
681 struct srvsvc_NetSessCtr2 ctr2
;
682 struct srvsvc_NetSessCtr10 ctr10
;
683 struct srvsvc_NetSessCtr502 ctr502
;
684 uint32_t total_entries
= 0;
685 uint32_t resume_handle
= 0;
686 uint32_t *resume_handle_p
= NULL
;
688 const char *client
= NULL
;
689 const char *user
= NULL
;
692 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
705 level
= atoi(argv
[3]);
709 resume_handle
= atoi(argv
[4]);
710 resume_handle_p
= &resume_handle
;
713 ZERO_STRUCT(info_ctr
);
715 info_ctr
.level
= level
;
717 d_printf("trying level: %d\n", level
);
722 info_ctr
.ctr
.ctr0
= &ctr0
;
726 info_ctr
.ctr
.ctr1
= &ctr1
;
730 info_ctr
.ctr
.ctr2
= &ctr2
;
734 info_ctr
.ctr
.ctr10
= &ctr10
;
738 info_ctr
.ctr
.ctr502
= &ctr502
;
742 status
= rpccli_srvsvc_NetSessEnum(cli
, mem_ctx
,
752 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
760 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
762 int argc
, const char **argv
)
764 struct srvsvc_NetDiskInfo info
;
767 uint32_t total_entries
= 0;
768 uint32_t resume_handle
= 0;
772 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
777 level
= atoi(argv
[1]);
781 resume_handle
= atoi(argv
[2]);
786 status
= rpccli_srvsvc_NetDiskEnum(cli
, mem_ctx
,
795 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
803 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
805 int argc
, const char **argv
)
807 struct srvsvc_NetConnInfoCtr info_ctr
;
808 struct srvsvc_NetConnCtr0 ctr0
;
809 struct srvsvc_NetConnCtr1 ctr1
;
812 uint32_t total_entries
= 0;
813 uint32_t resume_handle
= 0;
814 uint32_t *resume_handle_p
= NULL
;
816 const char *path
= "IPC$";
819 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
824 level
= atoi(argv
[1]);
832 resume_handle
= atoi(argv
[3]);
833 resume_handle_p
= &resume_handle
;
836 ZERO_STRUCT(info_ctr
);
838 info_ctr
.level
= level
;
843 info_ctr
.ctr
.ctr0
= &ctr0
;
847 info_ctr
.ctr
.ctr1
= &ctr1
;
850 return WERR_INVALID_PARAM
;
853 status
= rpccli_srvsvc_NetConnEnum(cli
, mem_ctx
,
862 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
871 /* List of commands exported by this module */
873 struct cmd_set srvsvc_commands
[] = {
877 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Server query info", "" },
878 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate shares", "" },
879 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate all shares", "" },
880 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get Share Info", "" },
881 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Set Share Info", "" },
882 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate open files", "" },
883 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Fetch remote time of day", "" },
884 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Validate sharename", "" },
885 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get File security", "" },
886 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Delete Session", "" },
887 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Sessions", "" },
888 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Disks", "" },
889 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Connections", "" },