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/cli_srvsvc.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
;
180 printf("Usage: %s [infolevel] [server_unc]\n", argv
[0]);
185 info_level
= atoi(argv
[1]);
189 server_unc
= argv
[2];
192 status
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
,
197 if (!NT_STATUS_IS_OK(status
)) {
198 return ntstatus_to_werror(status
);
201 if (!W_ERROR_IS_OK(result
)) {
205 /* Display results */
207 switch (info_level
) {
209 display_srv_info_101(info
.info101
);
212 display_srv_info_102(info
.info102
);
215 printf("unsupported info level %d\n", info_level
);
223 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
225 printf("netname: %s\n", r
->name
);
226 printf("\tremark:\t%s\n", r
->comment
);
229 static void display_share_info_2(struct srvsvc_NetShareInfo2
*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
);
237 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
239 printf("netname: %s\n", r
->name
);
240 printf("\tremark:\t%s\n", r
->comment
);
241 printf("\tpath:\t%s\n", r
->path
);
242 printf("\tpassword:\t%s\n", r
->password
);
244 printf("\ttype:\t0x%x\n", r
->type
);
245 printf("\tperms:\t%d\n", r
->permissions
);
246 printf("\tmax_uses:\t%d\n", r
->max_users
);
247 printf("\tnum_uses:\t%d\n", r
->current_users
);
250 display_sec_desc(r
->sd_buf
.sd
);
254 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
256 int argc
, const char **argv
,
259 uint32 info_level
= 2;
260 struct srvsvc_NetShareInfoCtr info_ctr
;
261 struct srvsvc_NetShareCtr0 ctr0
;
262 struct srvsvc_NetShareCtr1 ctr1
;
263 struct srvsvc_NetShareCtr2 ctr2
;
264 struct srvsvc_NetShareCtr501 ctr501
;
265 struct srvsvc_NetShareCtr502 ctr502
;
266 struct srvsvc_NetShareCtr1004 ctr1004
;
267 struct srvsvc_NetShareCtr1005 ctr1005
;
268 struct srvsvc_NetShareCtr1006 ctr1006
;
269 struct srvsvc_NetShareCtr1007 ctr1007
;
270 struct srvsvc_NetShareCtr1501 ctr1501
;
273 uint32_t totalentries
= 0;
274 uint32_t resume_handle
= 0;
275 uint32_t *resume_handle_p
= NULL
;
276 uint32 preferred_len
= 0xffffffff, i
;
279 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
284 info_level
= atoi(argv
[1]);
288 resume_handle
= atoi(argv
[2]);
289 resume_handle_p
= &resume_handle
;
292 ZERO_STRUCT(info_ctr
);
294 info_ctr
.level
= info_level
;
296 switch (info_level
) {
299 info_ctr
.ctr
.ctr0
= &ctr0
;
303 info_ctr
.ctr
.ctr1
= &ctr1
;
307 info_ctr
.ctr
.ctr2
= &ctr2
;
311 info_ctr
.ctr
.ctr501
= &ctr501
;
315 info_ctr
.ctr
.ctr502
= &ctr502
;
318 ZERO_STRUCT(ctr1004
);
319 info_ctr
.ctr
.ctr1004
= &ctr1004
;
322 ZERO_STRUCT(ctr1005
);
323 info_ctr
.ctr
.ctr1005
= &ctr1005
;
326 ZERO_STRUCT(ctr1006
);
327 info_ctr
.ctr
.ctr1006
= &ctr1006
;
330 ZERO_STRUCT(ctr1007
);
331 info_ctr
.ctr
.ctr1007
= &ctr1007
;
334 ZERO_STRUCT(ctr1501
);
335 info_ctr
.ctr
.ctr1501
= &ctr1501
;
340 case NDR_SRVSVC_NETSHAREENUM
:
341 status
= rpccli_srvsvc_NetShareEnum(cli
, mem_ctx
,
349 case NDR_SRVSVC_NETSHAREENUMALL
:
350 status
= rpccli_srvsvc_NetShareEnumAll(cli
, mem_ctx
,
359 return WERR_INVALID_PARAM
;
362 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
366 /* Display results */
368 switch (info_level
) {
370 for (i
= 0; i
< totalentries
; i
++)
371 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
374 for (i
= 0; i
< totalentries
; i
++)
375 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
378 for (i
= 0; i
< totalentries
; i
++)
379 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
382 printf("unsupported info level %d\n", info_level
);
390 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
392 int argc
, const char **argv
)
394 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
396 NDR_SRVSVC_NETSHAREENUM
);
399 static WERROR
cmd_srvsvc_net_share_enum_all(struct rpc_pipe_client
*cli
,
401 int argc
, const char **argv
)
403 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
405 NDR_SRVSVC_NETSHAREENUMALL
);
408 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
410 int argc
, const char **argv
)
412 uint32 info_level
= 502;
413 union srvsvc_NetShareInfo info
;
417 if (argc
< 2 || argc
> 3) {
418 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
423 info_level
= atoi(argv
[2]);
425 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
432 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
436 /* Display results */
438 switch (info_level
) {
440 display_share_info_1(info
.info1
);
443 display_share_info_2(info
.info2
);
446 display_share_info_502(info
.info502
);
449 printf("unsupported info level %d\n", info_level
);
457 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
459 int argc
, const char **argv
)
461 uint32 info_level
= 502;
462 union srvsvc_NetShareInfo info_get
;
465 uint32_t parm_err
= 0;
468 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
472 /* retrieve share info */
473 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
480 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
484 info_get
.info502
->comment
= argv
[2];
487 status
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
,
495 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
499 /* re-retrieve share info and display */
500 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
507 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
511 display_share_info_502(info_get
.info502
);
517 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
519 int argc
, const char **argv
)
521 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
526 printf("Usage: %s\n", argv
[0]);
530 status
= rpccli_srvsvc_NetRemoteTOD(cli
, mem_ctx
,
534 if (!NT_STATUS_IS_OK(status
)) {
535 result
= ntstatus_to_werror(status
);
539 if (!W_ERROR_IS_OK(result
))
546 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
548 int argc
, const char **argv
)
550 uint32 info_level
= 3;
551 struct srvsvc_NetFileInfoCtr info_ctr
;
552 struct srvsvc_NetFileCtr3 ctr3
;
555 uint32 preferred_len
= 0xffff;
556 uint32_t total_entries
= 0;
557 uint32_t resume_handle
= 0;
560 printf("Usage: %s [infolevel]\n", argv
[0]);
565 info_level
= atoi(argv
[1]);
567 ZERO_STRUCT(info_ctr
);
570 info_ctr
.level
= info_level
;
571 info_ctr
.ctr
.ctr3
= &ctr3
;
573 status
= rpccli_srvsvc_NetFileEnum(cli
, mem_ctx
,
583 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
590 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
592 int argc
, const char **argv
)
596 uint32_t name_type
= 9;
599 if (argc
< 2 || argc
> 3) {
600 printf("Usage: %s [sharename] [type]\n", argv
[0]);
605 name_type
= atoi(argv
[2]);
608 status
= rpccli_srvsvc_NetNameValidate(cli
, mem_ctx
,
615 if (!W_ERROR_IS_OK(result
))
622 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
624 int argc
, const char **argv
)
628 struct sec_desc_buf
*sd_buf
= NULL
;
630 if (argc
< 2 || argc
> 4) {
631 printf("Usage: %s [sharename] [file]\n", argv
[0]);
635 status
= rpccli_srvsvc_NetGetFileSecurity(cli
, mem_ctx
,
643 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
647 display_sec_desc(sd_buf
->sd
);
653 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
655 int argc
, const char **argv
)
660 if (argc
< 2 || argc
> 4) {
661 printf("Usage: %s [client] [user]\n", argv
[0]);
665 status
= rpccli_srvsvc_NetSessDel(cli
, mem_ctx
,
671 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
679 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
681 int argc
, const char **argv
)
685 struct srvsvc_NetSessInfoCtr info_ctr
;
686 struct srvsvc_NetSessCtr0 ctr0
;
687 struct srvsvc_NetSessCtr1 ctr1
;
688 struct srvsvc_NetSessCtr2 ctr2
;
689 struct srvsvc_NetSessCtr10 ctr10
;
690 struct srvsvc_NetSessCtr502 ctr502
;
691 uint32_t total_entries
= 0;
692 uint32_t resume_handle
= 0;
693 uint32_t *resume_handle_p
= NULL
;
695 const char *client
= NULL
;
696 const char *user
= NULL
;
699 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
712 level
= atoi(argv
[3]);
716 resume_handle
= atoi(argv
[4]);
717 resume_handle_p
= &resume_handle
;
720 ZERO_STRUCT(info_ctr
);
722 info_ctr
.level
= level
;
724 d_printf("trying level: %d\n", level
);
729 info_ctr
.ctr
.ctr0
= &ctr0
;
733 info_ctr
.ctr
.ctr1
= &ctr1
;
737 info_ctr
.ctr
.ctr2
= &ctr2
;
741 info_ctr
.ctr
.ctr10
= &ctr10
;
745 info_ctr
.ctr
.ctr502
= &ctr502
;
749 status
= rpccli_srvsvc_NetSessEnum(cli
, mem_ctx
,
759 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
767 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
769 int argc
, const char **argv
)
771 struct srvsvc_NetDiskInfo info
;
774 uint32_t total_entries
= 0;
775 uint32_t resume_handle
= 0;
779 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
784 level
= atoi(argv
[1]);
788 resume_handle
= atoi(argv
[2]);
793 status
= rpccli_srvsvc_NetDiskEnum(cli
, mem_ctx
,
802 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
810 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
812 int argc
, const char **argv
)
814 struct srvsvc_NetConnInfoCtr info_ctr
;
815 struct srvsvc_NetConnCtr0 ctr0
;
816 struct srvsvc_NetConnCtr1 ctr1
;
819 uint32_t total_entries
= 0;
820 uint32_t resume_handle
= 0;
821 uint32_t *resume_handle_p
= NULL
;
823 const char *path
= "IPC$";
826 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
831 level
= atoi(argv
[1]);
839 resume_handle
= atoi(argv
[3]);
840 resume_handle_p
= &resume_handle
;
843 ZERO_STRUCT(info_ctr
);
845 info_ctr
.level
= level
;
850 info_ctr
.ctr
.ctr0
= &ctr0
;
854 info_ctr
.ctr
.ctr1
= &ctr1
;
857 return WERR_INVALID_PARAM
;
860 status
= rpccli_srvsvc_NetConnEnum(cli
, mem_ctx
,
869 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
878 /* List of commands exported by this module */
880 struct cmd_set srvsvc_commands
[] = {
884 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Server query info", "" },
885 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate shares", "" },
886 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate all shares", "" },
887 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get Share Info", "" },
888 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Set Share Info", "" },
889 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate open files", "" },
890 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Fetch remote time of day", "" },
891 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Validate sharename", "" },
892 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Get File security", "" },
893 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Delete Session", "" },
894 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Sessions", "" },
895 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Disks", "" },
896 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, &ndr_table_srvsvc
.syntax_id
, NULL
, "Enumerate Connections", "" },