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"
26 /* Display server query info */
28 static char *get_server_type_str(uint32 type
)
30 static fstring typestr
;
33 if (type
== SV_TYPE_ALL
) {
34 fstrcpy(typestr
, "All");
40 for (i
= 0; i
< 32; i
++) {
41 if (type
& (1 << i
)) {
43 case SV_TYPE_WORKSTATION
:
44 fstrcat(typestr
, "Wk ");
47 fstrcat(typestr
, "Sv ");
49 case SV_TYPE_SQLSERVER
:
50 fstrcat(typestr
, "Sql ");
52 case SV_TYPE_DOMAIN_CTRL
:
53 fstrcat(typestr
, "PDC ");
55 case SV_TYPE_DOMAIN_BAKCTRL
:
56 fstrcat(typestr
, "BDC ");
58 case SV_TYPE_TIME_SOURCE
:
59 fstrcat(typestr
, "Tim ");
62 fstrcat(typestr
, "AFP ");
65 fstrcat(typestr
, "Nov ");
67 case SV_TYPE_DOMAIN_MEMBER
:
68 fstrcat(typestr
, "Dom ");
70 case SV_TYPE_PRINTQ_SERVER
:
71 fstrcat(typestr
, "PrQ ");
73 case SV_TYPE_DIALIN_SERVER
:
74 fstrcat(typestr
, "Din ");
76 case SV_TYPE_SERVER_UNIX
:
77 fstrcat(typestr
, "Unx ");
80 fstrcat(typestr
, "NT ");
83 fstrcat(typestr
, "Wfw ");
85 case SV_TYPE_SERVER_MFPN
:
86 fstrcat(typestr
, "Mfp ");
88 case SV_TYPE_SERVER_NT
:
89 fstrcat(typestr
, "SNT ");
91 case SV_TYPE_POTENTIAL_BROWSER
:
92 fstrcat(typestr
, "PtB ");
94 case SV_TYPE_BACKUP_BROWSER
:
95 fstrcat(typestr
, "BMB ");
97 case SV_TYPE_MASTER_BROWSER
:
98 fstrcat(typestr
, "LMB ");
100 case SV_TYPE_DOMAIN_MASTER
:
101 fstrcat(typestr
, "DMB ");
103 case SV_TYPE_SERVER_OSF
:
104 fstrcat(typestr
, "OSF ");
106 case SV_TYPE_SERVER_VMS
:
107 fstrcat(typestr
, "VMS ");
109 case SV_TYPE_WIN95_PLUS
:
110 fstrcat(typestr
, "W95 ");
112 case SV_TYPE_ALTERNATE_XPORT
:
113 fstrcat(typestr
, "Xpt ");
115 case SV_TYPE_LOCAL_LIST_ONLY
:
116 fstrcat(typestr
, "Dom ");
118 case SV_TYPE_DOMAIN_ENUM
:
119 fstrcat(typestr
, "Loc ");
125 i
= strlen(typestr
) - 1;
127 if (typestr
[i
] == ' ')
133 static void display_server(const char *sname
, uint32 type
, const char *comment
)
135 printf("\t%-15.15s%-20s %s\n", sname
, get_server_type_str(type
),
139 static void display_srv_info_101(struct srvsvc_NetSrvInfo101
*r
)
141 display_server(r
->server_name
, r
->server_type
, r
->comment
);
143 printf("\tplatform_id :\t%d\n", r
->platform_id
);
144 printf("\tos version :\t%d.%d\n",
145 r
->version_major
, r
->version_minor
);
146 printf("\tserver type :\t0x%x\n", r
->server_type
);
149 static void display_srv_info_102(struct srvsvc_NetSrvInfo102
*r
)
151 display_server(r
->server_name
, r
->server_type
, r
->comment
);
153 printf("\tplatform_id :\t%d\n", r
->platform_id
);
154 printf("\tos version :\t%d.%d\n",
155 r
->version_major
, r
->version_minor
);
156 printf("\tserver type :\t0x%x\n", r
->server_type
);
158 printf("\tusers :\t%x\n", r
->users
);
159 printf("\tdisc, hidden :\t%x, %x\n", r
->disc
, r
->hidden
);
160 printf("\tannounce, delta :\t%d, %d\n", r
->announce
,
162 printf("\tlicenses :\t%d\n", r
->licenses
);
163 printf("\tuser path :\t%s\n", r
->userpath
);
166 /* Server query info */
167 static WERROR
cmd_srvsvc_srv_query_info(struct rpc_pipe_client
*cli
,
169 int argc
, const char **argv
)
171 uint32 info_level
= 101;
172 union srvsvc_NetSrvInfo info
;
177 printf("Usage: %s [infolevel]\n", argv
[0]);
182 info_level
= atoi(argv
[1]);
184 status
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
,
189 if (!NT_STATUS_IS_OK(status
)) {
190 return ntstatus_to_werror(status
);
193 if (!W_ERROR_IS_OK(result
)) {
197 /* Display results */
199 switch (info_level
) {
201 display_srv_info_101(info
.info101
);
204 display_srv_info_102(info
.info102
);
207 printf("unsupported info level %d\n", info_level
);
215 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
217 printf("netname: %s\n", r
->name
);
218 printf("\tremark:\t%s\n", r
->comment
);
221 static void display_share_info_2(struct srvsvc_NetShareInfo2
*r
)
223 printf("netname: %s\n", r
->name
);
224 printf("\tremark:\t%s\n", r
->comment
);
225 printf("\tpath:\t%s\n", r
->path
);
226 printf("\tpassword:\t%s\n", r
->password
);
229 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
231 printf("netname: %s\n", r
->name
);
232 printf("\tremark:\t%s\n", r
->comment
);
233 printf("\tpath:\t%s\n", r
->path
);
234 printf("\tpassword:\t%s\n", r
->password
);
236 printf("\ttype:\t0x%x\n", r
->type
);
237 printf("\tperms:\t%d\n", r
->permissions
);
238 printf("\tmax_uses:\t%d\n", r
->max_users
);
239 printf("\tnum_uses:\t%d\n", r
->current_users
);
242 display_sec_desc(r
->sd_buf
.sd
);
246 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
248 int argc
, const char **argv
,
251 uint32 info_level
= 2;
252 struct srvsvc_NetShareInfoCtr info_ctr
;
253 struct srvsvc_NetShareCtr0 ctr0
;
254 struct srvsvc_NetShareCtr1 ctr1
;
255 struct srvsvc_NetShareCtr2 ctr2
;
256 struct srvsvc_NetShareCtr501 ctr501
;
257 struct srvsvc_NetShareCtr502 ctr502
;
258 struct srvsvc_NetShareCtr1004 ctr1004
;
259 struct srvsvc_NetShareCtr1005 ctr1005
;
260 struct srvsvc_NetShareCtr1006 ctr1006
;
261 struct srvsvc_NetShareCtr1007 ctr1007
;
262 struct srvsvc_NetShareCtr1501 ctr1501
;
265 uint32_t totalentries
= 0;
266 uint32_t resume_handle
= 0;
267 uint32_t *resume_handle_p
= NULL
;
268 uint32 preferred_len
= 0xffffffff, i
;
271 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
276 info_level
= atoi(argv
[1]);
280 resume_handle
= atoi(argv
[2]);
281 resume_handle_p
= &resume_handle
;
284 ZERO_STRUCT(info_ctr
);
286 info_ctr
.level
= info_level
;
288 switch (info_level
) {
291 info_ctr
.ctr
.ctr0
= &ctr0
;
295 info_ctr
.ctr
.ctr1
= &ctr1
;
299 info_ctr
.ctr
.ctr2
= &ctr2
;
303 info_ctr
.ctr
.ctr501
= &ctr501
;
307 info_ctr
.ctr
.ctr502
= &ctr502
;
310 ZERO_STRUCT(ctr1004
);
311 info_ctr
.ctr
.ctr1004
= &ctr1004
;
314 ZERO_STRUCT(ctr1005
);
315 info_ctr
.ctr
.ctr1005
= &ctr1005
;
318 ZERO_STRUCT(ctr1006
);
319 info_ctr
.ctr
.ctr1006
= &ctr1006
;
322 ZERO_STRUCT(ctr1007
);
323 info_ctr
.ctr
.ctr1007
= &ctr1007
;
326 ZERO_STRUCT(ctr1501
);
327 info_ctr
.ctr
.ctr1501
= &ctr1501
;
332 case NDR_SRVSVC_NETSHAREENUM
:
333 status
= rpccli_srvsvc_NetShareEnum(cli
, mem_ctx
,
341 case NDR_SRVSVC_NETSHAREENUMALL
:
342 status
= rpccli_srvsvc_NetShareEnumAll(cli
, mem_ctx
,
351 return WERR_INVALID_PARAM
;
354 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
358 /* Display results */
360 switch (info_level
) {
362 for (i
= 0; i
< totalentries
; i
++)
363 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
366 for (i
= 0; i
< totalentries
; i
++)
367 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
370 for (i
= 0; i
< totalentries
; i
++)
371 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
374 printf("unsupported info level %d\n", info_level
);
382 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
384 int argc
, const char **argv
)
386 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
388 NDR_SRVSVC_NETSHAREENUM
);
391 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
393 int argc
, const char **argv
)
395 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
397 NDR_SRVSVC_NETSHAREENUMALL
);
400 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
402 int argc
, const char **argv
)
404 uint32 info_level
= 502;
405 union srvsvc_NetShareInfo info
;
409 if (argc
< 2 || argc
> 3) {
410 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
415 info_level
= atoi(argv
[2]);
417 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
424 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
428 /* Display results */
430 switch (info_level
) {
432 display_share_info_1(info
.info1
);
435 display_share_info_2(info
.info2
);
438 display_share_info_502(info
.info502
);
441 printf("unsupported info level %d\n", info_level
);
449 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
451 int argc
, const char **argv
)
453 uint32 info_level
= 502;
454 union srvsvc_NetShareInfo info_get
;
457 uint32_t parm_err
= 0;
460 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
464 /* retrieve share info */
465 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
472 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
476 info_get
.info502
->comment
= argv
[2];
479 status
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
,
487 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
491 /* re-retrieve share info and display */
492 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
499 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
503 display_share_info_502(info_get
.info502
);
509 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
511 int argc
, const char **argv
)
513 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
518 printf("Usage: %s\n", argv
[0]);
522 status
= rpccli_srvsvc_NetRemoteTOD(cli
, mem_ctx
,
526 if (!NT_STATUS_IS_OK(status
)) {
527 result
= ntstatus_to_werror(status
);
531 if (!W_ERROR_IS_OK(result
))
538 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
540 int argc
, const char **argv
)
542 uint32 info_level
= 3;
543 struct srvsvc_NetFileInfoCtr info_ctr
;
544 struct srvsvc_NetFileCtr3 ctr3
;
547 uint32 preferred_len
= 0xffff;
548 uint32_t total_entries
= 0;
549 uint32_t resume_handle
= 0;
552 printf("Usage: %s [infolevel]\n", argv
[0]);
557 info_level
= atoi(argv
[1]);
559 ZERO_STRUCT(info_ctr
);
562 info_ctr
.level
= info_level
;
563 info_ctr
.ctr
.ctr3
= &ctr3
;
565 status
= rpccli_srvsvc_NetFileEnum(cli
, mem_ctx
,
575 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
582 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
584 int argc
, const char **argv
)
588 uint32_t name_type
= 9;
591 if (argc
< 2 || argc
> 3) {
592 printf("Usage: %s [sharename] [type]\n", argv
[0]);
597 name_type
= atoi(argv
[2]);
600 status
= rpccli_srvsvc_NetNameValidate(cli
, mem_ctx
,
607 if (!W_ERROR_IS_OK(result
))
614 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
616 int argc
, const char **argv
)
620 struct sec_desc_buf
*sd_buf
= NULL
;
622 if (argc
< 2 || argc
> 4) {
623 printf("Usage: %s [sharename] [file]\n", argv
[0]);
627 status
= rpccli_srvsvc_NetGetFileSecurity(cli
, mem_ctx
,
635 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
639 display_sec_desc(sd_buf
->sd
);
645 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
647 int argc
, const char **argv
)
652 if (argc
< 2 || argc
> 4) {
653 printf("Usage: %s [client] [user]\n", argv
[0]);
657 status
= rpccli_srvsvc_NetSessDel(cli
, mem_ctx
,
663 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
671 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
673 int argc
, const char **argv
)
677 struct srvsvc_NetSessInfoCtr info_ctr
;
678 struct srvsvc_NetSessCtr0 ctr0
;
679 struct srvsvc_NetSessCtr1 ctr1
;
680 struct srvsvc_NetSessCtr2 ctr2
;
681 struct srvsvc_NetSessCtr10 ctr10
;
682 struct srvsvc_NetSessCtr502 ctr502
;
683 uint32_t total_entries
= 0;
684 uint32_t resume_handle
= 0;
685 uint32_t *resume_handle_p
= NULL
;
687 const char *client
= NULL
;
688 const char *user
= NULL
;
691 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
704 level
= atoi(argv
[3]);
708 resume_handle
= atoi(argv
[4]);
709 resume_handle_p
= &resume_handle
;
712 ZERO_STRUCT(info_ctr
);
714 info_ctr
.level
= level
;
716 d_printf("trying level: %d\n", level
);
721 info_ctr
.ctr
.ctr0
= &ctr0
;
725 info_ctr
.ctr
.ctr1
= &ctr1
;
729 info_ctr
.ctr
.ctr2
= &ctr2
;
733 info_ctr
.ctr
.ctr10
= &ctr10
;
737 info_ctr
.ctr
.ctr502
= &ctr502
;
741 status
= rpccli_srvsvc_NetSessEnum(cli
, mem_ctx
,
751 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
759 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
761 int argc
, const char **argv
)
763 struct srvsvc_NetDiskInfo info
;
766 uint32_t total_entries
= 0;
767 uint32_t resume_handle
= 0;
771 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
776 level
= atoi(argv
[1]);
780 resume_handle
= atoi(argv
[2]);
785 status
= rpccli_srvsvc_NetDiskEnum(cli
, mem_ctx
,
794 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
802 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
804 int argc
, const char **argv
)
806 struct srvsvc_NetConnInfoCtr info_ctr
;
807 struct srvsvc_NetConnCtr0 ctr0
;
808 struct srvsvc_NetConnCtr1 ctr1
;
811 uint32_t total_entries
= 0;
812 uint32_t resume_handle
= 0;
813 uint32_t *resume_handle_p
= NULL
;
815 const char *path
= "IPC$";
818 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
823 level
= atoi(argv
[1]);
831 resume_handle
= atoi(argv
[3]);
832 resume_handle_p
= &resume_handle
;
835 ZERO_STRUCT(info_ctr
);
837 info_ctr
.level
= level
;
842 info_ctr
.ctr
.ctr0
= &ctr0
;
846 info_ctr
.ctr
.ctr1
= &ctr1
;
849 return WERR_INVALID_PARAM
;
852 status
= rpccli_srvsvc_NetConnEnum(cli
, mem_ctx
,
861 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
870 /* List of commands exported by this module */
872 struct cmd_set srvsvc_commands
[] = {
876 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Server query info", "" },
877 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate shares", "" },
878 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate all shares", "" },
879 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get Share Info", "" },
880 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Set Share Info", "" },
881 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate open files", "" },
882 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Fetch remote time of day", "" },
883 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Validate sharename", "" },
884 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get File security", "" },
885 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Delete Session", "" },
886 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Sessions", "" },
887 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Disks", "" },
888 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Connections", "" },