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/ndr_srvsvc.h"
26 #include "../librpc/gen_ndr/ndr_srvsvc_c.h"
27 #include "../libcli/security/display_sec.h"
29 /* Display server query info */
31 static char *get_server_type_str(uint32 type
)
33 static fstring typestr
;
36 if (type
== SV_TYPE_ALL
) {
37 fstrcpy(typestr
, "All");
43 for (i
= 0; i
< 32; i
++) {
44 if (type
& (1 << i
)) {
46 case SV_TYPE_WORKSTATION
:
47 fstrcat(typestr
, "Wk ");
50 fstrcat(typestr
, "Sv ");
52 case SV_TYPE_SQLSERVER
:
53 fstrcat(typestr
, "Sql ");
55 case SV_TYPE_DOMAIN_CTRL
:
56 fstrcat(typestr
, "PDC ");
58 case SV_TYPE_DOMAIN_BAKCTRL
:
59 fstrcat(typestr
, "BDC ");
61 case SV_TYPE_TIME_SOURCE
:
62 fstrcat(typestr
, "Tim ");
65 fstrcat(typestr
, "AFP ");
68 fstrcat(typestr
, "Nov ");
70 case SV_TYPE_DOMAIN_MEMBER
:
71 fstrcat(typestr
, "Dom ");
73 case SV_TYPE_PRINTQ_SERVER
:
74 fstrcat(typestr
, "PrQ ");
76 case SV_TYPE_DIALIN_SERVER
:
77 fstrcat(typestr
, "Din ");
79 case SV_TYPE_SERVER_UNIX
:
80 fstrcat(typestr
, "Unx ");
83 fstrcat(typestr
, "NT ");
86 fstrcat(typestr
, "Wfw ");
88 case SV_TYPE_SERVER_MFPN
:
89 fstrcat(typestr
, "Mfp ");
91 case SV_TYPE_SERVER_NT
:
92 fstrcat(typestr
, "SNT ");
94 case SV_TYPE_POTENTIAL_BROWSER
:
95 fstrcat(typestr
, "PtB ");
97 case SV_TYPE_BACKUP_BROWSER
:
98 fstrcat(typestr
, "BMB ");
100 case SV_TYPE_MASTER_BROWSER
:
101 fstrcat(typestr
, "LMB ");
103 case SV_TYPE_DOMAIN_MASTER
:
104 fstrcat(typestr
, "DMB ");
106 case SV_TYPE_SERVER_OSF
:
107 fstrcat(typestr
, "OSF ");
109 case SV_TYPE_SERVER_VMS
:
110 fstrcat(typestr
, "VMS ");
112 case SV_TYPE_WIN95_PLUS
:
113 fstrcat(typestr
, "W95 ");
115 case SV_TYPE_ALTERNATE_XPORT
:
116 fstrcat(typestr
, "Xpt ");
118 case SV_TYPE_LOCAL_LIST_ONLY
:
119 fstrcat(typestr
, "Dom ");
121 case SV_TYPE_DOMAIN_ENUM
:
122 fstrcat(typestr
, "Loc ");
128 i
= strlen(typestr
) - 1;
130 if (typestr
[i
] == ' ')
136 static void display_server(const char *sname
, uint32 type
, const char *comment
)
138 printf("\t%-15.15s%-20s %s\n", sname
, get_server_type_str(type
),
142 static void display_srv_info_101(struct srvsvc_NetSrvInfo101
*r
)
144 display_server(r
->server_name
, r
->server_type
, r
->comment
);
146 printf("\tplatform_id :\t%d\n", r
->platform_id
);
147 printf("\tos version :\t%d.%d\n",
148 r
->version_major
, r
->version_minor
);
149 printf("\tserver type :\t0x%x\n", r
->server_type
);
152 static void display_srv_info_102(struct srvsvc_NetSrvInfo102
*r
)
154 display_server(r
->server_name
, r
->server_type
, r
->comment
);
156 printf("\tplatform_id :\t%d\n", r
->platform_id
);
157 printf("\tos version :\t%d.%d\n",
158 r
->version_major
, r
->version_minor
);
159 printf("\tserver type :\t0x%x\n", r
->server_type
);
161 printf("\tusers :\t%x\n", r
->users
);
162 printf("\tdisc, hidden :\t%x, %x\n", r
->disc
, r
->hidden
);
163 printf("\tannounce, delta :\t%d, %d\n", r
->announce
,
165 printf("\tlicenses :\t%d\n", r
->licenses
);
166 printf("\tuser path :\t%s\n", r
->userpath
);
169 /* Server query info */
170 static WERROR
cmd_srvsvc_srv_query_info(struct rpc_pipe_client
*cli
,
172 int argc
, const char **argv
)
174 uint32 info_level
= 101;
175 union srvsvc_NetSrvInfo info
;
178 const char *server_unc
= cli
->srv_name_slash
;
179 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
182 printf("Usage: %s [infolevel] [server_unc]\n", argv
[0]);
187 info_level
= atoi(argv
[1]);
191 server_unc
= argv
[2];
194 status
= dcerpc_srvsvc_NetSrvGetInfo(b
, mem_ctx
,
199 if (!NT_STATUS_IS_OK(status
)) {
200 return ntstatus_to_werror(status
);
203 if (!W_ERROR_IS_OK(result
)) {
207 /* Display results */
209 switch (info_level
) {
211 display_srv_info_101(info
.info101
);
214 display_srv_info_102(info
.info102
);
217 printf("unsupported info level %d\n", info_level
);
225 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
227 printf("netname: %s\n", r
->name
);
228 printf("\tremark:\t%s\n", r
->comment
);
231 static void display_share_info_2(struct srvsvc_NetShareInfo2
*r
)
233 printf("netname: %s\n", r
->name
);
234 printf("\tremark:\t%s\n", r
->comment
);
235 printf("\tpath:\t%s\n", r
->path
);
236 printf("\tpassword:\t%s\n", r
->password
);
239 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
241 printf("netname: %s\n", r
->name
);
242 printf("\tremark:\t%s\n", r
->comment
);
243 printf("\tpath:\t%s\n", r
->path
);
244 printf("\tpassword:\t%s\n", r
->password
);
246 printf("\ttype:\t0x%x\n", r
->type
);
247 printf("\tperms:\t%d\n", r
->permissions
);
248 printf("\tmax_uses:\t%d\n", r
->max_users
);
249 printf("\tnum_uses:\t%d\n", r
->current_users
);
252 display_sec_desc(r
->sd_buf
.sd
);
256 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
258 int argc
, const char **argv
,
261 uint32 info_level
= 2;
262 struct srvsvc_NetShareInfoCtr info_ctr
;
263 struct srvsvc_NetShareCtr0 ctr0
;
264 struct srvsvc_NetShareCtr1 ctr1
;
265 struct srvsvc_NetShareCtr2 ctr2
;
266 struct srvsvc_NetShareCtr501 ctr501
;
267 struct srvsvc_NetShareCtr502 ctr502
;
268 struct srvsvc_NetShareCtr1004 ctr1004
;
269 struct srvsvc_NetShareCtr1005 ctr1005
;
270 struct srvsvc_NetShareCtr1006 ctr1006
;
271 struct srvsvc_NetShareCtr1007 ctr1007
;
272 struct srvsvc_NetShareCtr1501 ctr1501
;
275 uint32_t totalentries
= 0;
277 uint32_t resume_handle
= 0;
278 uint32_t *resume_handle_p
= NULL
;
279 uint32 preferred_len
= 0xffffffff, i
;
280 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
283 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
288 info_level
= atoi(argv
[1]);
292 resume_handle
= atoi(argv
[2]);
293 resume_handle_p
= &resume_handle
;
296 ZERO_STRUCT(info_ctr
);
298 info_ctr
.level
= info_level
;
300 switch (info_level
) {
303 info_ctr
.ctr
.ctr0
= &ctr0
;
307 info_ctr
.ctr
.ctr1
= &ctr1
;
311 info_ctr
.ctr
.ctr2
= &ctr2
;
315 info_ctr
.ctr
.ctr501
= &ctr501
;
319 info_ctr
.ctr
.ctr502
= &ctr502
;
322 ZERO_STRUCT(ctr1004
);
323 info_ctr
.ctr
.ctr1004
= &ctr1004
;
326 ZERO_STRUCT(ctr1005
);
327 info_ctr
.ctr
.ctr1005
= &ctr1005
;
330 ZERO_STRUCT(ctr1006
);
331 info_ctr
.ctr
.ctr1006
= &ctr1006
;
334 ZERO_STRUCT(ctr1007
);
335 info_ctr
.ctr
.ctr1007
= &ctr1007
;
338 ZERO_STRUCT(ctr1501
);
339 info_ctr
.ctr
.ctr1501
= &ctr1501
;
344 case NDR_SRVSVC_NETSHAREENUM
:
345 status
= dcerpc_srvsvc_NetShareEnum(b
, mem_ctx
,
353 case NDR_SRVSVC_NETSHAREENUMALL
:
354 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
363 return WERR_INVALID_PARAM
;
366 if (!NT_STATUS_IS_OK(status
)) {
367 result
= ntstatus_to_werror(status
);
370 if (!W_ERROR_IS_OK(result
)) {
374 /* Display results */
376 switch (info_level
) {
378 count
= info_ctr
.ctr
.ctr1
->count
;
379 for (i
= 0; i
< count
; i
++)
380 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
383 count
= info_ctr
.ctr
.ctr2
->count
;
384 for (i
= 0; i
< count
; i
++)
385 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
388 count
= info_ctr
.ctr
.ctr502
->count
;
389 for (i
= 0; i
< count
; i
++)
390 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
393 printf("unsupported info level %d\n", info_level
);
401 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
403 int argc
, const char **argv
)
405 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
407 NDR_SRVSVC_NETSHAREENUM
);
410 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
412 int argc
, const char **argv
)
414 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
416 NDR_SRVSVC_NETSHAREENUMALL
);
419 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
421 int argc
, const char **argv
)
423 uint32 info_level
= 502;
424 union srvsvc_NetShareInfo info
;
427 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
429 if (argc
< 2 || argc
> 3) {
430 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
435 info_level
= atoi(argv
[2]);
437 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
444 if (!NT_STATUS_IS_OK(status
)) {
445 result
= ntstatus_to_werror(status
);
448 if (!W_ERROR_IS_OK(result
)) {
452 /* Display results */
454 switch (info_level
) {
456 display_share_info_1(info
.info1
);
459 display_share_info_2(info
.info2
);
462 display_share_info_502(info
.info502
);
465 printf("unsupported info level %d\n", info_level
);
473 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
475 int argc
, const char **argv
)
477 uint32 info_level
= 502;
478 union srvsvc_NetShareInfo info_get
;
481 uint32_t parm_err
= 0;
482 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
485 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
489 /* retrieve share info */
490 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
497 if (!NT_STATUS_IS_OK(status
)) {
498 result
= ntstatus_to_werror(status
);
501 if (!W_ERROR_IS_OK(result
)) {
505 info_get
.info502
->comment
= argv
[2];
508 status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
516 if (!NT_STATUS_IS_OK(status
)) {
517 result
= ntstatus_to_werror(status
);
520 if (!W_ERROR_IS_OK(result
)) {
524 /* re-retrieve share info and display */
525 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
531 if (!NT_STATUS_IS_OK(status
)) {
532 result
= ntstatus_to_werror(status
);
535 if (!W_ERROR_IS_OK(result
)) {
539 display_share_info_502(info_get
.info502
);
545 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
547 int argc
, const char **argv
)
549 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
552 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
555 printf("Usage: %s\n", argv
[0]);
559 status
= dcerpc_srvsvc_NetRemoteTOD(b
, mem_ctx
,
563 if (!NT_STATUS_IS_OK(status
)) {
564 result
= ntstatus_to_werror(status
);
568 if (!W_ERROR_IS_OK(result
))
575 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
577 int argc
, const char **argv
)
579 uint32 info_level
= 3;
580 struct srvsvc_NetFileInfoCtr info_ctr
;
581 struct srvsvc_NetFileCtr3 ctr3
;
584 uint32 preferred_len
= 0xffff;
585 uint32_t total_entries
= 0;
586 uint32_t resume_handle
= 0;
587 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
590 printf("Usage: %s [infolevel]\n", argv
[0]);
595 info_level
= atoi(argv
[1]);
597 ZERO_STRUCT(info_ctr
);
600 info_ctr
.level
= info_level
;
601 info_ctr
.ctr
.ctr3
= &ctr3
;
603 status
= dcerpc_srvsvc_NetFileEnum(b
, mem_ctx
,
612 if (!NT_STATUS_IS_OK(status
)) {
613 result
= ntstatus_to_werror(status
);
617 if (!W_ERROR_IS_OK(result
)) {
625 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
627 int argc
, const char **argv
)
631 uint32_t name_type
= 9;
633 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
635 if (argc
< 2 || argc
> 3) {
636 printf("Usage: %s [sharename] [type]\n", argv
[0]);
641 name_type
= atoi(argv
[2]);
644 status
= dcerpc_srvsvc_NetNameValidate(b
, mem_ctx
,
650 if (!NT_STATUS_IS_OK(status
)) {
651 result
= ntstatus_to_werror(status
);
655 if (!W_ERROR_IS_OK(result
))
662 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
664 int argc
, const char **argv
)
668 struct sec_desc_buf
*sd_buf
= NULL
;
669 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
671 if (argc
< 2 || argc
> 4) {
672 printf("Usage: %s [sharename] [file]\n", argv
[0]);
676 status
= dcerpc_srvsvc_NetGetFileSecurity(b
, mem_ctx
,
683 if (!NT_STATUS_IS_OK(status
)) {
684 result
= ntstatus_to_werror(status
);
688 if (!W_ERROR_IS_OK(result
)) {
692 display_sec_desc(sd_buf
->sd
);
698 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
700 int argc
, const char **argv
)
704 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
706 if (argc
< 2 || argc
> 4) {
707 printf("Usage: %s [client] [user]\n", argv
[0]);
711 status
= dcerpc_srvsvc_NetSessDel(b
, mem_ctx
,
716 if (!NT_STATUS_IS_OK(status
)) {
717 result
= ntstatus_to_werror(status
);
721 if (!W_ERROR_IS_OK(result
)) {
729 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
731 int argc
, const char **argv
)
735 struct srvsvc_NetSessInfoCtr info_ctr
;
736 struct srvsvc_NetSessCtr0 ctr0
;
737 struct srvsvc_NetSessCtr1 ctr1
;
738 struct srvsvc_NetSessCtr2 ctr2
;
739 struct srvsvc_NetSessCtr10 ctr10
;
740 struct srvsvc_NetSessCtr502 ctr502
;
741 uint32_t total_entries
= 0;
742 uint32_t resume_handle
= 0;
743 uint32_t *resume_handle_p
= NULL
;
745 const char *client
= NULL
;
746 const char *user
= NULL
;
747 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
750 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
763 level
= atoi(argv
[3]);
767 resume_handle
= atoi(argv
[4]);
768 resume_handle_p
= &resume_handle
;
771 ZERO_STRUCT(info_ctr
);
773 info_ctr
.level
= level
;
775 d_printf("trying level: %d\n", level
);
780 info_ctr
.ctr
.ctr0
= &ctr0
;
784 info_ctr
.ctr
.ctr1
= &ctr1
;
788 info_ctr
.ctr
.ctr2
= &ctr2
;
792 info_ctr
.ctr
.ctr10
= &ctr10
;
796 info_ctr
.ctr
.ctr502
= &ctr502
;
800 status
= dcerpc_srvsvc_NetSessEnum(b
, mem_ctx
,
810 if (!NT_STATUS_IS_OK(status
)) {
811 result
= ntstatus_to_werror(status
);
815 if (!W_ERROR_IS_OK(result
)) {
823 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
825 int argc
, const char **argv
)
827 struct srvsvc_NetDiskInfo info
;
830 uint32_t total_entries
= 0;
831 uint32_t resume_handle
= 0;
833 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
836 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
841 level
= atoi(argv
[1]);
845 resume_handle
= atoi(argv
[2]);
850 status
= dcerpc_srvsvc_NetDiskEnum(b
, mem_ctx
,
858 if (!NT_STATUS_IS_OK(status
)) {
859 result
= ntstatus_to_werror(status
);
863 if (!W_ERROR_IS_OK(result
)) {
871 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
873 int argc
, const char **argv
)
875 struct srvsvc_NetConnInfoCtr info_ctr
;
876 struct srvsvc_NetConnCtr0 ctr0
;
877 struct srvsvc_NetConnCtr1 ctr1
;
880 uint32_t total_entries
= 0;
881 uint32_t resume_handle
= 0;
882 uint32_t *resume_handle_p
= NULL
;
884 const char *path
= "IPC$";
885 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
888 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
893 level
= atoi(argv
[1]);
901 resume_handle
= atoi(argv
[3]);
902 resume_handle_p
= &resume_handle
;
905 ZERO_STRUCT(info_ctr
);
907 info_ctr
.level
= level
;
912 info_ctr
.ctr
.ctr0
= &ctr0
;
916 info_ctr
.ctr
.ctr1
= &ctr1
;
919 return WERR_INVALID_PARAM
;
922 status
= dcerpc_srvsvc_NetConnEnum(b
, mem_ctx
,
931 if (!NT_STATUS_IS_OK(status
)) {
932 result
= ntstatus_to_werror(status
);
936 if (!W_ERROR_IS_OK(result
)) {
945 /* List of commands exported by this module */
947 struct cmd_set srvsvc_commands
[] = {
951 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
, NULL
, "Server query info", "" },
952 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate shares", "" },
953 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
, NULL
, "Enumerate all shares", "" },
954 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
, NULL
, "Get Share Info", "" },
955 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
, NULL
, "Set Share Info", "" },
956 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate open files", "" },
957 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
, NULL
, "Fetch remote time of day", "" },
958 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
, NULL
, "Validate sharename", "" },
959 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
, NULL
, "Get File security", "" },
960 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
, NULL
, "Delete Session", "" },
961 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Sessions", "" },
962 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Disks", "" },
963 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Connections", "" },