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;
276 uint32_t resume_handle
= 0;
277 uint32_t *resume_handle_p
= NULL
;
278 uint32 preferred_len
= 0xffffffff, i
;
279 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
282 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
287 info_level
= atoi(argv
[1]);
291 resume_handle
= atoi(argv
[2]);
292 resume_handle_p
= &resume_handle
;
295 ZERO_STRUCT(info_ctr
);
297 info_ctr
.level
= info_level
;
299 switch (info_level
) {
302 info_ctr
.ctr
.ctr0
= &ctr0
;
306 info_ctr
.ctr
.ctr1
= &ctr1
;
310 info_ctr
.ctr
.ctr2
= &ctr2
;
314 info_ctr
.ctr
.ctr501
= &ctr501
;
318 info_ctr
.ctr
.ctr502
= &ctr502
;
321 ZERO_STRUCT(ctr1004
);
322 info_ctr
.ctr
.ctr1004
= &ctr1004
;
325 ZERO_STRUCT(ctr1005
);
326 info_ctr
.ctr
.ctr1005
= &ctr1005
;
329 ZERO_STRUCT(ctr1006
);
330 info_ctr
.ctr
.ctr1006
= &ctr1006
;
333 ZERO_STRUCT(ctr1007
);
334 info_ctr
.ctr
.ctr1007
= &ctr1007
;
337 ZERO_STRUCT(ctr1501
);
338 info_ctr
.ctr
.ctr1501
= &ctr1501
;
343 case NDR_SRVSVC_NETSHAREENUM
:
344 status
= dcerpc_srvsvc_NetShareEnum(b
, mem_ctx
,
352 case NDR_SRVSVC_NETSHAREENUMALL
:
353 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
362 return WERR_INVALID_PARAM
;
365 if (!NT_STATUS_IS_OK(status
)) {
366 result
= ntstatus_to_werror(status
);
369 if (!W_ERROR_IS_OK(result
)) {
373 /* Display results */
375 switch (info_level
) {
377 for (i
= 0; i
< totalentries
; i
++)
378 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
381 for (i
= 0; i
< totalentries
; i
++)
382 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
385 for (i
= 0; i
< totalentries
; i
++)
386 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
389 printf("unsupported info level %d\n", info_level
);
397 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
399 int argc
, const char **argv
)
401 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
403 NDR_SRVSVC_NETSHAREENUM
);
406 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
408 int argc
, const char **argv
)
410 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
412 NDR_SRVSVC_NETSHAREENUMALL
);
415 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
417 int argc
, const char **argv
)
419 uint32 info_level
= 502;
420 union srvsvc_NetShareInfo info
;
423 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
425 if (argc
< 2 || argc
> 3) {
426 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
431 info_level
= atoi(argv
[2]);
433 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
440 if (!NT_STATUS_IS_OK(status
)) {
441 result
= ntstatus_to_werror(status
);
444 if (!W_ERROR_IS_OK(result
)) {
448 /* Display results */
450 switch (info_level
) {
452 display_share_info_1(info
.info1
);
455 display_share_info_2(info
.info2
);
458 display_share_info_502(info
.info502
);
461 printf("unsupported info level %d\n", info_level
);
469 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
471 int argc
, const char **argv
)
473 uint32 info_level
= 502;
474 union srvsvc_NetShareInfo info_get
;
477 uint32_t parm_err
= 0;
478 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
481 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
485 /* retrieve share info */
486 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
493 if (!NT_STATUS_IS_OK(status
)) {
494 result
= ntstatus_to_werror(status
);
497 if (!W_ERROR_IS_OK(result
)) {
501 info_get
.info502
->comment
= argv
[2];
504 status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
512 if (!NT_STATUS_IS_OK(status
)) {
513 result
= ntstatus_to_werror(status
);
516 if (!W_ERROR_IS_OK(result
)) {
520 /* re-retrieve share info and display */
521 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
527 if (!NT_STATUS_IS_OK(status
)) {
528 result
= ntstatus_to_werror(status
);
531 if (!W_ERROR_IS_OK(result
)) {
535 display_share_info_502(info_get
.info502
);
541 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
543 int argc
, const char **argv
)
545 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
548 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
551 printf("Usage: %s\n", argv
[0]);
555 status
= dcerpc_srvsvc_NetRemoteTOD(b
, mem_ctx
,
559 if (!NT_STATUS_IS_OK(status
)) {
560 result
= ntstatus_to_werror(status
);
564 if (!W_ERROR_IS_OK(result
))
571 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
573 int argc
, const char **argv
)
575 uint32 info_level
= 3;
576 struct srvsvc_NetFileInfoCtr info_ctr
;
577 struct srvsvc_NetFileCtr3 ctr3
;
580 uint32 preferred_len
= 0xffff;
581 uint32_t total_entries
= 0;
582 uint32_t resume_handle
= 0;
583 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
586 printf("Usage: %s [infolevel]\n", argv
[0]);
591 info_level
= atoi(argv
[1]);
593 ZERO_STRUCT(info_ctr
);
596 info_ctr
.level
= info_level
;
597 info_ctr
.ctr
.ctr3
= &ctr3
;
599 status
= dcerpc_srvsvc_NetFileEnum(b
, mem_ctx
,
608 if (!NT_STATUS_IS_OK(status
)) {
609 result
= ntstatus_to_werror(status
);
613 if (!W_ERROR_IS_OK(result
)) {
621 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
623 int argc
, const char **argv
)
627 uint32_t name_type
= 9;
629 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
631 if (argc
< 2 || argc
> 3) {
632 printf("Usage: %s [sharename] [type]\n", argv
[0]);
637 name_type
= atoi(argv
[2]);
640 status
= dcerpc_srvsvc_NetNameValidate(b
, mem_ctx
,
646 if (!NT_STATUS_IS_OK(status
)) {
647 result
= ntstatus_to_werror(status
);
651 if (!W_ERROR_IS_OK(result
))
658 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
660 int argc
, const char **argv
)
664 struct sec_desc_buf
*sd_buf
= NULL
;
665 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
667 if (argc
< 2 || argc
> 4) {
668 printf("Usage: %s [sharename] [file]\n", argv
[0]);
672 status
= dcerpc_srvsvc_NetGetFileSecurity(b
, mem_ctx
,
679 if (!NT_STATUS_IS_OK(status
)) {
680 result
= ntstatus_to_werror(status
);
684 if (!W_ERROR_IS_OK(result
)) {
688 display_sec_desc(sd_buf
->sd
);
694 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
696 int argc
, const char **argv
)
700 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
702 if (argc
< 2 || argc
> 4) {
703 printf("Usage: %s [client] [user]\n", argv
[0]);
707 status
= dcerpc_srvsvc_NetSessDel(b
, mem_ctx
,
712 if (!NT_STATUS_IS_OK(status
)) {
713 result
= ntstatus_to_werror(status
);
717 if (!W_ERROR_IS_OK(result
)) {
725 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
727 int argc
, const char **argv
)
731 struct srvsvc_NetSessInfoCtr info_ctr
;
732 struct srvsvc_NetSessCtr0 ctr0
;
733 struct srvsvc_NetSessCtr1 ctr1
;
734 struct srvsvc_NetSessCtr2 ctr2
;
735 struct srvsvc_NetSessCtr10 ctr10
;
736 struct srvsvc_NetSessCtr502 ctr502
;
737 uint32_t total_entries
= 0;
738 uint32_t resume_handle
= 0;
739 uint32_t *resume_handle_p
= NULL
;
741 const char *client
= NULL
;
742 const char *user
= NULL
;
743 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
746 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
759 level
= atoi(argv
[3]);
763 resume_handle
= atoi(argv
[4]);
764 resume_handle_p
= &resume_handle
;
767 ZERO_STRUCT(info_ctr
);
769 info_ctr
.level
= level
;
771 d_printf("trying level: %d\n", level
);
776 info_ctr
.ctr
.ctr0
= &ctr0
;
780 info_ctr
.ctr
.ctr1
= &ctr1
;
784 info_ctr
.ctr
.ctr2
= &ctr2
;
788 info_ctr
.ctr
.ctr10
= &ctr10
;
792 info_ctr
.ctr
.ctr502
= &ctr502
;
796 status
= dcerpc_srvsvc_NetSessEnum(b
, mem_ctx
,
806 if (!NT_STATUS_IS_OK(status
)) {
807 result
= ntstatus_to_werror(status
);
811 if (!W_ERROR_IS_OK(result
)) {
819 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
821 int argc
, const char **argv
)
823 struct srvsvc_NetDiskInfo info
;
826 uint32_t total_entries
= 0;
827 uint32_t resume_handle
= 0;
829 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
832 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
837 level
= atoi(argv
[1]);
841 resume_handle
= atoi(argv
[2]);
846 status
= dcerpc_srvsvc_NetDiskEnum(b
, mem_ctx
,
854 if (!NT_STATUS_IS_OK(status
)) {
855 result
= ntstatus_to_werror(status
);
859 if (!W_ERROR_IS_OK(result
)) {
867 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
869 int argc
, const char **argv
)
871 struct srvsvc_NetConnInfoCtr info_ctr
;
872 struct srvsvc_NetConnCtr0 ctr0
;
873 struct srvsvc_NetConnCtr1 ctr1
;
876 uint32_t total_entries
= 0;
877 uint32_t resume_handle
= 0;
878 uint32_t *resume_handle_p
= NULL
;
880 const char *path
= "IPC$";
881 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
884 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
889 level
= atoi(argv
[1]);
897 resume_handle
= atoi(argv
[3]);
898 resume_handle_p
= &resume_handle
;
901 ZERO_STRUCT(info_ctr
);
903 info_ctr
.level
= level
;
908 info_ctr
.ctr
.ctr0
= &ctr0
;
912 info_ctr
.ctr
.ctr1
= &ctr1
;
915 return WERR_INVALID_PARAM
;
918 status
= dcerpc_srvsvc_NetConnEnum(b
, mem_ctx
,
927 if (!NT_STATUS_IS_OK(status
)) {
928 result
= ntstatus_to_werror(status
);
932 if (!W_ERROR_IS_OK(result
)) {
941 /* List of commands exported by this module */
943 struct cmd_set srvsvc_commands
[] = {
947 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
, NULL
, "Server query info", "" },
948 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate shares", "" },
949 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
, NULL
, "Enumerate all shares", "" },
950 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
, NULL
, "Get Share Info", "" },
951 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
, NULL
, "Set Share Info", "" },
952 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate open files", "" },
953 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
, NULL
, "Fetch remote time of day", "" },
954 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
, NULL
, "Validate sharename", "" },
955 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
, NULL
, "Get File security", "" },
956 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
, NULL
, "Delete Session", "" },
957 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Sessions", "" },
958 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Disks", "" },
959 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
, NULL
, "Enumerate Connections", "" },