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"
28 /* Display server query info */
30 static char *get_server_type_str(uint32 type
)
32 static fstring typestr
;
35 if (type
== SV_TYPE_ALL
) {
36 fstrcpy(typestr
, "All");
42 for (i
= 0; i
< 32; i
++) {
43 if (type
& (1 << i
)) {
45 case SV_TYPE_WORKSTATION
:
46 fstrcat(typestr
, "Wk ");
49 fstrcat(typestr
, "Sv ");
51 case SV_TYPE_SQLSERVER
:
52 fstrcat(typestr
, "Sql ");
54 case SV_TYPE_DOMAIN_CTRL
:
55 fstrcat(typestr
, "PDC ");
57 case SV_TYPE_DOMAIN_BAKCTRL
:
58 fstrcat(typestr
, "BDC ");
60 case SV_TYPE_TIME_SOURCE
:
61 fstrcat(typestr
, "Tim ");
64 fstrcat(typestr
, "AFP ");
67 fstrcat(typestr
, "Nov ");
69 case SV_TYPE_DOMAIN_MEMBER
:
70 fstrcat(typestr
, "Dom ");
72 case SV_TYPE_PRINTQ_SERVER
:
73 fstrcat(typestr
, "PrQ ");
75 case SV_TYPE_DIALIN_SERVER
:
76 fstrcat(typestr
, "Din ");
78 case SV_TYPE_SERVER_UNIX
:
79 fstrcat(typestr
, "Unx ");
82 fstrcat(typestr
, "NT ");
85 fstrcat(typestr
, "Wfw ");
87 case SV_TYPE_SERVER_MFPN
:
88 fstrcat(typestr
, "Mfp ");
90 case SV_TYPE_SERVER_NT
:
91 fstrcat(typestr
, "SNT ");
93 case SV_TYPE_POTENTIAL_BROWSER
:
94 fstrcat(typestr
, "PtB ");
96 case SV_TYPE_BACKUP_BROWSER
:
97 fstrcat(typestr
, "BMB ");
99 case SV_TYPE_MASTER_BROWSER
:
100 fstrcat(typestr
, "LMB ");
102 case SV_TYPE_DOMAIN_MASTER
:
103 fstrcat(typestr
, "DMB ");
105 case SV_TYPE_SERVER_OSF
:
106 fstrcat(typestr
, "OSF ");
108 case SV_TYPE_SERVER_VMS
:
109 fstrcat(typestr
, "VMS ");
111 case SV_TYPE_WIN95_PLUS
:
112 fstrcat(typestr
, "W95 ");
114 case SV_TYPE_ALTERNATE_XPORT
:
115 fstrcat(typestr
, "Xpt ");
117 case SV_TYPE_LOCAL_LIST_ONLY
:
118 fstrcat(typestr
, "Dom ");
120 case SV_TYPE_DOMAIN_ENUM
:
121 fstrcat(typestr
, "Loc ");
127 i
= strlen(typestr
) - 1;
129 if (typestr
[i
] == ' ')
135 static void display_server(const char *sname
, uint32 type
, const char *comment
)
137 printf("\t%-15.15s%-20s %s\n", sname
, get_server_type_str(type
),
141 static void display_srv_info_101(struct srvsvc_NetSrvInfo101
*r
)
143 display_server(r
->server_name
, r
->server_type
, r
->comment
);
145 printf("\tplatform_id :\t%d\n", r
->platform_id
);
146 printf("\tos version :\t%d.%d\n",
147 r
->version_major
, r
->version_minor
);
148 printf("\tserver type :\t0x%x\n", r
->server_type
);
151 static void display_srv_info_102(struct srvsvc_NetSrvInfo102
*r
)
153 display_server(r
->server_name
, r
->server_type
, r
->comment
);
155 printf("\tplatform_id :\t%d\n", r
->platform_id
);
156 printf("\tos version :\t%d.%d\n",
157 r
->version_major
, r
->version_minor
);
158 printf("\tserver type :\t0x%x\n", r
->server_type
);
160 printf("\tusers :\t%x\n", r
->users
);
161 printf("\tdisc, hidden :\t%x, %x\n", r
->disc
, r
->hidden
);
162 printf("\tannounce, delta :\t%d, %d\n", r
->announce
,
164 printf("\tlicenses :\t%d\n", r
->licenses
);
165 printf("\tuser path :\t%s\n", r
->userpath
);
168 /* Server query info */
169 static WERROR
cmd_srvsvc_srv_query_info(struct rpc_pipe_client
*cli
,
171 int argc
, const char **argv
)
173 uint32 info_level
= 101;
174 union srvsvc_NetSrvInfo info
;
177 const char *server_unc
= cli
->srv_name_slash
;
178 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
181 printf("Usage: %s [infolevel] [server_unc]\n", argv
[0]);
186 info_level
= atoi(argv
[1]);
190 server_unc
= argv
[2];
193 status
= dcerpc_srvsvc_NetSrvGetInfo(b
, mem_ctx
,
198 if (!NT_STATUS_IS_OK(status
)) {
199 return ntstatus_to_werror(status
);
202 if (!W_ERROR_IS_OK(result
)) {
206 /* Display results */
208 switch (info_level
) {
210 display_srv_info_101(info
.info101
);
213 display_srv_info_102(info
.info102
);
216 printf("unsupported info level %d\n", info_level
);
224 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
226 printf("netname: %s\n", r
->name
);
227 printf("\tremark:\t%s\n", r
->comment
);
230 static void display_share_info_2(struct srvsvc_NetShareInfo2
*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
);
238 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
240 printf("netname: %s\n", r
->name
);
241 printf("\tremark:\t%s\n", r
->comment
);
242 printf("\tpath:\t%s\n", r
->path
);
243 printf("\tpassword:\t%s\n", r
->password
);
245 printf("\ttype:\t0x%x\n", r
->type
);
246 printf("\tperms:\t%d\n", r
->permissions
);
247 printf("\tmax_uses:\t%d\n", r
->max_users
);
248 printf("\tnum_uses:\t%d\n", r
->current_users
);
251 display_sec_desc(r
->sd_buf
.sd
);
255 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
257 int argc
, const char **argv
,
260 uint32 info_level
= 2;
261 struct srvsvc_NetShareInfoCtr info_ctr
;
262 struct srvsvc_NetShareCtr0 ctr0
;
263 struct srvsvc_NetShareCtr1 ctr1
;
264 struct srvsvc_NetShareCtr2 ctr2
;
265 struct srvsvc_NetShareCtr501 ctr501
;
266 struct srvsvc_NetShareCtr502 ctr502
;
267 struct srvsvc_NetShareCtr1004 ctr1004
;
268 struct srvsvc_NetShareCtr1005 ctr1005
;
269 struct srvsvc_NetShareCtr1006 ctr1006
;
270 struct srvsvc_NetShareCtr1007 ctr1007
;
271 struct srvsvc_NetShareCtr1501 ctr1501
;
274 uint32_t totalentries
= 0;
275 uint32_t resume_handle
= 0;
276 uint32_t *resume_handle_p
= NULL
;
277 uint32 preferred_len
= 0xffffffff, i
;
278 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
281 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
286 info_level
= atoi(argv
[1]);
290 resume_handle
= atoi(argv
[2]);
291 resume_handle_p
= &resume_handle
;
294 ZERO_STRUCT(info_ctr
);
296 info_ctr
.level
= info_level
;
298 switch (info_level
) {
301 info_ctr
.ctr
.ctr0
= &ctr0
;
305 info_ctr
.ctr
.ctr1
= &ctr1
;
309 info_ctr
.ctr
.ctr2
= &ctr2
;
313 info_ctr
.ctr
.ctr501
= &ctr501
;
317 info_ctr
.ctr
.ctr502
= &ctr502
;
320 ZERO_STRUCT(ctr1004
);
321 info_ctr
.ctr
.ctr1004
= &ctr1004
;
324 ZERO_STRUCT(ctr1005
);
325 info_ctr
.ctr
.ctr1005
= &ctr1005
;
328 ZERO_STRUCT(ctr1006
);
329 info_ctr
.ctr
.ctr1006
= &ctr1006
;
332 ZERO_STRUCT(ctr1007
);
333 info_ctr
.ctr
.ctr1007
= &ctr1007
;
336 ZERO_STRUCT(ctr1501
);
337 info_ctr
.ctr
.ctr1501
= &ctr1501
;
342 case NDR_SRVSVC_NETSHAREENUM
:
343 status
= dcerpc_srvsvc_NetShareEnum(b
, mem_ctx
,
351 case NDR_SRVSVC_NETSHAREENUMALL
:
352 status
= dcerpc_srvsvc_NetShareEnumAll(b
, mem_ctx
,
361 return WERR_INVALID_PARAM
;
364 if (!NT_STATUS_IS_OK(status
)) {
365 result
= ntstatus_to_werror(status
);
368 if (!W_ERROR_IS_OK(result
)) {
372 /* Display results */
374 switch (info_level
) {
376 for (i
= 0; i
< totalentries
; i
++)
377 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
380 for (i
= 0; i
< totalentries
; i
++)
381 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
384 for (i
= 0; i
< totalentries
; i
++)
385 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
388 printf("unsupported info level %d\n", info_level
);
396 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
398 int argc
, const char **argv
)
400 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
402 NDR_SRVSVC_NETSHAREENUM
);
405 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
407 int argc
, const char **argv
)
409 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
411 NDR_SRVSVC_NETSHAREENUMALL
);
414 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
416 int argc
, const char **argv
)
418 uint32 info_level
= 502;
419 union srvsvc_NetShareInfo info
;
422 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
424 if (argc
< 2 || argc
> 3) {
425 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
430 info_level
= atoi(argv
[2]);
432 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
439 if (!NT_STATUS_IS_OK(status
)) {
440 result
= ntstatus_to_werror(status
);
443 if (!W_ERROR_IS_OK(result
)) {
447 /* Display results */
449 switch (info_level
) {
451 display_share_info_1(info
.info1
);
454 display_share_info_2(info
.info2
);
457 display_share_info_502(info
.info502
);
460 printf("unsupported info level %d\n", info_level
);
468 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
470 int argc
, const char **argv
)
472 uint32 info_level
= 502;
473 union srvsvc_NetShareInfo info_get
;
476 uint32_t parm_err
= 0;
477 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
480 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
484 /* retrieve share info */
485 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
492 if (!NT_STATUS_IS_OK(status
)) {
493 result
= ntstatus_to_werror(status
);
496 if (!W_ERROR_IS_OK(result
)) {
500 info_get
.info502
->comment
= argv
[2];
503 status
= dcerpc_srvsvc_NetShareSetInfo(b
, mem_ctx
,
511 if (!NT_STATUS_IS_OK(status
)) {
512 result
= ntstatus_to_werror(status
);
515 if (!W_ERROR_IS_OK(result
)) {
519 /* re-retrieve share info and display */
520 status
= dcerpc_srvsvc_NetShareGetInfo(b
, mem_ctx
,
526 if (!NT_STATUS_IS_OK(status
)) {
527 result
= ntstatus_to_werror(status
);
530 if (!W_ERROR_IS_OK(result
)) {
534 display_share_info_502(info_get
.info502
);
540 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
542 int argc
, const char **argv
)
544 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
547 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
550 printf("Usage: %s\n", argv
[0]);
554 status
= dcerpc_srvsvc_NetRemoteTOD(b
, mem_ctx
,
558 if (!NT_STATUS_IS_OK(status
)) {
559 result
= ntstatus_to_werror(status
);
563 if (!W_ERROR_IS_OK(result
))
570 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
572 int argc
, const char **argv
)
574 uint32 info_level
= 3;
575 struct srvsvc_NetFileInfoCtr info_ctr
;
576 struct srvsvc_NetFileCtr3 ctr3
;
579 uint32 preferred_len
= 0xffff;
580 uint32_t total_entries
= 0;
581 uint32_t resume_handle
= 0;
582 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
585 printf("Usage: %s [infolevel]\n", argv
[0]);
590 info_level
= atoi(argv
[1]);
592 ZERO_STRUCT(info_ctr
);
595 info_ctr
.level
= info_level
;
596 info_ctr
.ctr
.ctr3
= &ctr3
;
598 status
= dcerpc_srvsvc_NetFileEnum(b
, mem_ctx
,
607 if (!NT_STATUS_IS_OK(status
)) {
608 result
= ntstatus_to_werror(status
);
612 if (!W_ERROR_IS_OK(result
)) {
620 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
622 int argc
, const char **argv
)
626 uint32_t name_type
= 9;
628 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
630 if (argc
< 2 || argc
> 3) {
631 printf("Usage: %s [sharename] [type]\n", argv
[0]);
636 name_type
= atoi(argv
[2]);
639 status
= dcerpc_srvsvc_NetNameValidate(b
, mem_ctx
,
645 if (!NT_STATUS_IS_OK(status
)) {
646 result
= ntstatus_to_werror(status
);
650 if (!W_ERROR_IS_OK(result
))
657 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
659 int argc
, const char **argv
)
663 struct sec_desc_buf
*sd_buf
= NULL
;
664 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
666 if (argc
< 2 || argc
> 4) {
667 printf("Usage: %s [sharename] [file]\n", argv
[0]);
671 status
= dcerpc_srvsvc_NetGetFileSecurity(b
, mem_ctx
,
678 if (!NT_STATUS_IS_OK(status
)) {
679 result
= ntstatus_to_werror(status
);
683 if (!W_ERROR_IS_OK(result
)) {
687 display_sec_desc(sd_buf
->sd
);
693 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
695 int argc
, const char **argv
)
699 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
701 if (argc
< 2 || argc
> 4) {
702 printf("Usage: %s [client] [user]\n", argv
[0]);
706 status
= dcerpc_srvsvc_NetSessDel(b
, mem_ctx
,
711 if (!NT_STATUS_IS_OK(status
)) {
712 result
= ntstatus_to_werror(status
);
716 if (!W_ERROR_IS_OK(result
)) {
724 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
726 int argc
, const char **argv
)
730 struct srvsvc_NetSessInfoCtr info_ctr
;
731 struct srvsvc_NetSessCtr0 ctr0
;
732 struct srvsvc_NetSessCtr1 ctr1
;
733 struct srvsvc_NetSessCtr2 ctr2
;
734 struct srvsvc_NetSessCtr10 ctr10
;
735 struct srvsvc_NetSessCtr502 ctr502
;
736 uint32_t total_entries
= 0;
737 uint32_t resume_handle
= 0;
738 uint32_t *resume_handle_p
= NULL
;
740 const char *client
= NULL
;
741 const char *user
= NULL
;
742 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
745 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
758 level
= atoi(argv
[3]);
762 resume_handle
= atoi(argv
[4]);
763 resume_handle_p
= &resume_handle
;
766 ZERO_STRUCT(info_ctr
);
768 info_ctr
.level
= level
;
770 d_printf("trying level: %d\n", level
);
775 info_ctr
.ctr
.ctr0
= &ctr0
;
779 info_ctr
.ctr
.ctr1
= &ctr1
;
783 info_ctr
.ctr
.ctr2
= &ctr2
;
787 info_ctr
.ctr
.ctr10
= &ctr10
;
791 info_ctr
.ctr
.ctr502
= &ctr502
;
795 status
= dcerpc_srvsvc_NetSessEnum(b
, mem_ctx
,
805 if (!NT_STATUS_IS_OK(status
)) {
806 result
= ntstatus_to_werror(status
);
810 if (!W_ERROR_IS_OK(result
)) {
818 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
820 int argc
, const char **argv
)
822 struct srvsvc_NetDiskInfo info
;
825 uint32_t total_entries
= 0;
826 uint32_t resume_handle
= 0;
828 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
831 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
836 level
= atoi(argv
[1]);
840 resume_handle
= atoi(argv
[2]);
845 status
= dcerpc_srvsvc_NetDiskEnum(b
, mem_ctx
,
853 if (!NT_STATUS_IS_OK(status
)) {
854 result
= ntstatus_to_werror(status
);
858 if (!W_ERROR_IS_OK(result
)) {
866 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
868 int argc
, const char **argv
)
870 struct srvsvc_NetConnInfoCtr info_ctr
;
871 struct srvsvc_NetConnCtr0 ctr0
;
872 struct srvsvc_NetConnCtr1 ctr1
;
875 uint32_t total_entries
= 0;
876 uint32_t resume_handle
= 0;
877 uint32_t *resume_handle_p
= NULL
;
879 const char *path
= "IPC$";
880 struct dcerpc_binding_handle
*b
= cli
->binding_handle
;
883 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
888 level
= atoi(argv
[1]);
896 resume_handle
= atoi(argv
[3]);
897 resume_handle_p
= &resume_handle
;
900 ZERO_STRUCT(info_ctr
);
902 info_ctr
.level
= level
;
907 info_ctr
.ctr
.ctr0
= &ctr0
;
911 info_ctr
.ctr
.ctr1
= &ctr1
;
914 return WERR_INVALID_PARAM
;
917 status
= dcerpc_srvsvc_NetConnEnum(b
, mem_ctx
,
926 if (!NT_STATUS_IS_OK(status
)) {
927 result
= ntstatus_to_werror(status
);
931 if (!W_ERROR_IS_OK(result
)) {
940 /* List of commands exported by this module */
942 struct cmd_set srvsvc_commands
[] = {
946 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Server query info", "" },
947 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate shares", "" },
948 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate all shares", "" },
949 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get Share Info", "" },
950 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Set Share Info", "" },
951 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate open files", "" },
952 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Fetch remote time of day", "" },
953 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Validate sharename", "" },
954 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get File security", "" },
955 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Delete Session", "" },
956 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Sessions", "" },
957 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Disks", "" },
958 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Connections", "" },