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
;
175 const char *server_name
;
178 printf("Usage: %s [infolevel]\n", argv
[0]);
183 info_level
= atoi(argv
[1]);
185 server_name
= talloc_asprintf_strupper_m(mem_ctx
, "\\\\%s",
187 W_ERROR_HAVE_NO_MEMORY(server_name
);
189 status
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
,
194 if (!NT_STATUS_IS_OK(status
)) {
195 return ntstatus_to_werror(status
);
198 if (!W_ERROR_IS_OK(result
)) {
202 /* Display results */
204 switch (info_level
) {
206 display_srv_info_101(info
.info101
);
209 display_srv_info_102(info
.info102
);
212 printf("unsupported info level %d\n", info_level
);
220 static void display_share_info_1(struct srvsvc_NetShareInfo1
*r
)
222 printf("netname: %s\n", r
->name
);
223 printf("\tremark:\t%s\n", r
->comment
);
226 static void display_share_info_2(struct srvsvc_NetShareInfo2
*r
)
228 printf("netname: %s\n", r
->name
);
229 printf("\tremark:\t%s\n", r
->comment
);
230 printf("\tpath:\t%s\n", r
->path
);
231 printf("\tpassword:\t%s\n", r
->password
);
234 static void display_share_info_502(struct srvsvc_NetShareInfo502
*r
)
236 printf("netname: %s\n", r
->name
);
237 printf("\tremark:\t%s\n", r
->comment
);
238 printf("\tpath:\t%s\n", r
->path
);
239 printf("\tpassword:\t%s\n", r
->password
);
241 printf("\ttype:\t0x%x\n", r
->type
);
242 printf("\tperms:\t%d\n", r
->permissions
);
243 printf("\tmax_uses:\t%d\n", r
->max_users
);
244 printf("\tnum_uses:\t%d\n", r
->current_users
);
247 display_sec_desc(r
->sd_buf
.sd
);
251 static WERROR
cmd_srvsvc_net_share_enum_int(struct rpc_pipe_client
*cli
,
253 int argc
, const char **argv
,
256 uint32 info_level
= 2;
257 struct srvsvc_NetShareInfoCtr info_ctr
;
258 struct srvsvc_NetShareCtr0 ctr0
;
259 struct srvsvc_NetShareCtr1 ctr1
;
260 struct srvsvc_NetShareCtr2 ctr2
;
261 struct srvsvc_NetShareCtr501 ctr501
;
262 struct srvsvc_NetShareCtr502 ctr502
;
263 struct srvsvc_NetShareCtr1004 ctr1004
;
264 struct srvsvc_NetShareCtr1005 ctr1005
;
265 struct srvsvc_NetShareCtr1006 ctr1006
;
266 struct srvsvc_NetShareCtr1007 ctr1007
;
267 struct srvsvc_NetShareCtr1501 ctr1501
;
270 uint32_t totalentries
= 0;
271 uint32_t resume_handle
= 0;
272 uint32_t *resume_handle_p
= NULL
;
273 uint32 preferred_len
= 0xffffffff, i
;
276 printf("Usage: %s [infolevel] [resume_handle]\n", argv
[0]);
281 info_level
= atoi(argv
[1]);
285 resume_handle
= atoi(argv
[2]);
286 resume_handle_p
= &resume_handle
;
289 ZERO_STRUCT(info_ctr
);
291 info_ctr
.level
= info_level
;
293 switch (info_level
) {
296 info_ctr
.ctr
.ctr0
= &ctr0
;
300 info_ctr
.ctr
.ctr1
= &ctr1
;
304 info_ctr
.ctr
.ctr2
= &ctr2
;
308 info_ctr
.ctr
.ctr501
= &ctr501
;
312 info_ctr
.ctr
.ctr502
= &ctr502
;
315 ZERO_STRUCT(ctr1004
);
316 info_ctr
.ctr
.ctr1004
= &ctr1004
;
319 ZERO_STRUCT(ctr1005
);
320 info_ctr
.ctr
.ctr1005
= &ctr1005
;
323 ZERO_STRUCT(ctr1006
);
324 info_ctr
.ctr
.ctr1006
= &ctr1006
;
327 ZERO_STRUCT(ctr1007
);
328 info_ctr
.ctr
.ctr1007
= &ctr1007
;
331 ZERO_STRUCT(ctr1501
);
332 info_ctr
.ctr
.ctr1501
= &ctr1501
;
337 case NDR_SRVSVC_NETSHAREENUM
:
338 status
= rpccli_srvsvc_NetShareEnum(cli
, mem_ctx
,
346 case NDR_SRVSVC_NETSHAREENUMALL
:
347 status
= rpccli_srvsvc_NetShareEnumAll(cli
, mem_ctx
,
356 return WERR_INVALID_PARAM
;
359 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
363 /* Display results */
365 switch (info_level
) {
367 for (i
= 0; i
< totalentries
; i
++)
368 display_share_info_1(&info_ctr
.ctr
.ctr1
->array
[i
]);
371 for (i
= 0; i
< totalentries
; i
++)
372 display_share_info_2(&info_ctr
.ctr
.ctr2
->array
[i
]);
375 for (i
= 0; i
< totalentries
; i
++)
376 display_share_info_502(&info_ctr
.ctr
.ctr502
->array
[i
]);
379 printf("unsupported info level %d\n", info_level
);
387 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
389 int argc
, const char **argv
)
391 return cmd_srvsvc_net_share_enum_int(cli
, mem_ctx
,
393 NDR_SRVSVC_NETSHAREENUM
);
396 static WERROR
cmd_srvsvc_net_share_enum_all(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_NETSHAREENUMALL
);
405 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
407 int argc
, const char **argv
)
409 uint32 info_level
= 502;
410 union srvsvc_NetShareInfo info
;
414 if (argc
< 2 || argc
> 3) {
415 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
420 info_level
= atoi(argv
[2]);
422 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
429 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
433 /* Display results */
435 switch (info_level
) {
437 display_share_info_1(info
.info1
);
440 display_share_info_2(info
.info2
);
443 display_share_info_502(info
.info502
);
446 printf("unsupported info level %d\n", info_level
);
454 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
456 int argc
, const char **argv
)
458 uint32 info_level
= 502;
459 union srvsvc_NetShareInfo info_get
;
462 uint32_t parm_err
= 0;
465 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
469 /* retrieve share info */
470 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
477 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
481 info_get
.info502
->comment
= argv
[2];
484 status
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
,
492 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
496 /* re-retrieve share info and display */
497 status
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
,
504 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
508 display_share_info_502(info_get
.info502
);
514 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
516 int argc
, const char **argv
)
518 struct srvsvc_NetRemoteTODInfo
*tod
= NULL
;
523 printf("Usage: %s\n", argv
[0]);
527 status
= rpccli_srvsvc_NetRemoteTOD(cli
, mem_ctx
,
528 cli
->cli
->srv_name_slash
,
531 if (!NT_STATUS_IS_OK(status
)) {
532 result
= ntstatus_to_werror(status
);
536 if (!W_ERROR_IS_OK(result
))
543 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
545 int argc
, const char **argv
)
547 uint32 info_level
= 3;
548 struct srvsvc_NetFileInfoCtr info_ctr
;
549 struct srvsvc_NetFileCtr3 ctr3
;
552 uint32 preferred_len
= 0xffff;
553 uint32_t total_entries
= 0;
554 uint32_t resume_handle
= 0;
557 printf("Usage: %s [infolevel]\n", argv
[0]);
562 info_level
= atoi(argv
[1]);
564 ZERO_STRUCT(info_ctr
);
567 info_ctr
.level
= info_level
;
568 info_ctr
.ctr
.ctr3
= &ctr3
;
570 status
= rpccli_srvsvc_NetFileEnum(cli
, mem_ctx
,
580 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
))
587 static WERROR
cmd_srvsvc_net_name_validate(struct rpc_pipe_client
*cli
,
589 int argc
, const char **argv
)
593 uint32_t name_type
= 9;
596 if (argc
< 2 || argc
> 3) {
597 printf("Usage: %s [sharename] [type]\n", argv
[0]);
602 name_type
= atoi(argv
[2]);
605 status
= rpccli_srvsvc_NetNameValidate(cli
, mem_ctx
,
612 if (!W_ERROR_IS_OK(result
))
619 static WERROR
cmd_srvsvc_net_file_get_sec(struct rpc_pipe_client
*cli
,
621 int argc
, const char **argv
)
625 struct sec_desc_buf
*sd_buf
= NULL
;
627 if (argc
< 2 || argc
> 4) {
628 printf("Usage: %s [sharename] [file]\n", argv
[0]);
632 status
= rpccli_srvsvc_NetGetFileSecurity(cli
, mem_ctx
,
640 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
644 display_sec_desc(sd_buf
->sd
);
650 static WERROR
cmd_srvsvc_net_sess_del(struct rpc_pipe_client
*cli
,
652 int argc
, const char **argv
)
657 if (argc
< 2 || argc
> 4) {
658 printf("Usage: %s [client] [user]\n", argv
[0]);
662 status
= rpccli_srvsvc_NetSessDel(cli
, mem_ctx
,
668 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
676 static WERROR
cmd_srvsvc_net_sess_enum(struct rpc_pipe_client
*cli
,
678 int argc
, const char **argv
)
682 struct srvsvc_NetSessInfoCtr info_ctr
;
683 struct srvsvc_NetSessCtr0 ctr0
;
684 struct srvsvc_NetSessCtr1 ctr1
;
685 struct srvsvc_NetSessCtr2 ctr2
;
686 struct srvsvc_NetSessCtr10 ctr10
;
687 struct srvsvc_NetSessCtr502 ctr502
;
688 uint32_t total_entries
= 0;
689 uint32_t resume_handle
= 0;
690 uint32_t *resume_handle_p
= NULL
;
692 const char *client
= NULL
;
693 const char *user
= NULL
;
696 printf("Usage: %s [client] [user] [level] [resume_handle]\n", argv
[0]);
709 level
= atoi(argv
[3]);
713 resume_handle
= atoi(argv
[4]);
714 resume_handle_p
= &resume_handle
;
717 ZERO_STRUCT(info_ctr
);
719 info_ctr
.level
= level
;
721 d_printf("trying level: %d\n", level
);
726 info_ctr
.ctr
.ctr0
= &ctr0
;
730 info_ctr
.ctr
.ctr1
= &ctr1
;
734 info_ctr
.ctr
.ctr2
= &ctr2
;
738 info_ctr
.ctr
.ctr10
= &ctr10
;
742 info_ctr
.ctr
.ctr502
= &ctr502
;
746 status
= rpccli_srvsvc_NetSessEnum(cli
, mem_ctx
,
756 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
764 static WERROR
cmd_srvsvc_net_disk_enum(struct rpc_pipe_client
*cli
,
766 int argc
, const char **argv
)
768 struct srvsvc_NetDiskInfo info
;
771 uint32_t total_entries
= 0;
772 uint32_t resume_handle
= 0;
776 printf("Usage: %s [level] [resume_handle]\n", argv
[0]);
781 level
= atoi(argv
[1]);
785 resume_handle
= atoi(argv
[2]);
790 status
= rpccli_srvsvc_NetDiskEnum(cli
, mem_ctx
,
799 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
807 static WERROR
cmd_srvsvc_net_conn_enum(struct rpc_pipe_client
*cli
,
809 int argc
, const char **argv
)
811 struct srvsvc_NetConnInfoCtr info_ctr
;
812 struct srvsvc_NetConnCtr0 ctr0
;
813 struct srvsvc_NetConnCtr1 ctr1
;
816 uint32_t total_entries
= 0;
817 uint32_t resume_handle
= 0;
818 uint32_t *resume_handle_p
= NULL
;
820 const char *path
= "IPC$";
823 printf("Usage: %s [level] [path] [resume_handle]\n", argv
[0]);
828 level
= atoi(argv
[1]);
836 resume_handle
= atoi(argv
[3]);
837 resume_handle_p
= &resume_handle
;
840 ZERO_STRUCT(info_ctr
);
842 info_ctr
.level
= level
;
847 info_ctr
.ctr
.ctr0
= &ctr0
;
851 info_ctr
.ctr
.ctr1
= &ctr1
;
854 return WERR_INVALID_PARAM
;
857 status
= rpccli_srvsvc_NetConnEnum(cli
, mem_ctx
,
866 if (!NT_STATUS_IS_OK(status
) || !W_ERROR_IS_OK(result
)) {
875 /* List of commands exported by this module */
877 struct cmd_set srvsvc_commands
[] = {
881 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, PI_SRVSVC
, NULL
, "Server query info", "" },
882 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, PI_SRVSVC
, NULL
, "Enumerate shares", "" },
883 { "netshareenumall",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum_all
, PI_SRVSVC
, NULL
, "Enumerate all shares", "" },
884 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, PI_SRVSVC
, NULL
, "Get Share Info", "" },
885 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, PI_SRVSVC
, NULL
, "Set Share Info", "" },
886 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, PI_SRVSVC
, NULL
, "Enumerate open files", "" },
887 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, PI_SRVSVC
, NULL
, "Fetch remote time of day", "" },
888 { "netnamevalidate", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_name_validate
, PI_SRVSVC
, NULL
, "Validate sharename", "" },
889 { "netfilegetsec", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_get_sec
, PI_SRVSVC
, NULL
, "Get File security", "" },
890 { "netsessdel", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_del
, PI_SRVSVC
, NULL
, "Delete Session", "" },
891 { "netsessenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_sess_enum
, PI_SRVSVC
, NULL
, "Enumerate Sessions", "" },
892 { "netdiskenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_disk_enum
, PI_SRVSVC
, NULL
, "Enumerate Disks", "" },
893 { "netconnenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_conn_enum
, PI_SRVSVC
, NULL
, "Enumerate Connections", "" },