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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "rpcclient.h"
27 /* Display server query info */
29 static char *get_server_type_str(uint32 type
)
31 static fstring typestr
;
34 if (type
== SV_TYPE_ALL
) {
35 fstrcpy(typestr
, "All");
41 for (i
= 0; i
< 32; i
++) {
42 if (type
& (1 << i
)) {
44 case SV_TYPE_WORKSTATION
:
45 fstrcat(typestr
, "Wk ");
48 fstrcat(typestr
, "Sv ");
50 case SV_TYPE_SQLSERVER
:
51 fstrcat(typestr
, "Sql ");
53 case SV_TYPE_DOMAIN_CTRL
:
54 fstrcat(typestr
, "PDC ");
56 case SV_TYPE_DOMAIN_BAKCTRL
:
57 fstrcat(typestr
, "BDC ");
59 case SV_TYPE_TIME_SOURCE
:
60 fstrcat(typestr
, "Tim ");
63 fstrcat(typestr
, "AFP ");
66 fstrcat(typestr
, "Nov ");
68 case SV_TYPE_DOMAIN_MEMBER
:
69 fstrcat(typestr
, "Dom ");
71 case SV_TYPE_PRINTQ_SERVER
:
72 fstrcat(typestr
, "PrQ ");
74 case SV_TYPE_DIALIN_SERVER
:
75 fstrcat(typestr
, "Din ");
77 case SV_TYPE_SERVER_UNIX
:
78 fstrcat(typestr
, "Unx ");
81 fstrcat(typestr
, "NT ");
84 fstrcat(typestr
, "Wfw ");
86 case SV_TYPE_SERVER_MFPN
:
87 fstrcat(typestr
, "Mfp ");
89 case SV_TYPE_SERVER_NT
:
90 fstrcat(typestr
, "SNT ");
92 case SV_TYPE_POTENTIAL_BROWSER
:
93 fstrcat(typestr
, "PtB ");
95 case SV_TYPE_BACKUP_BROWSER
:
96 fstrcat(typestr
, "BMB ");
98 case SV_TYPE_MASTER_BROWSER
:
99 fstrcat(typestr
, "LMB ");
101 case SV_TYPE_DOMAIN_MASTER
:
102 fstrcat(typestr
, "DMB ");
104 case SV_TYPE_SERVER_OSF
:
105 fstrcat(typestr
, "OSF ");
107 case SV_TYPE_SERVER_VMS
:
108 fstrcat(typestr
, "VMS ");
110 case SV_TYPE_WIN95_PLUS
:
111 fstrcat(typestr
, "W95 ");
113 case SV_TYPE_ALTERNATE_XPORT
:
114 fstrcat(typestr
, "Xpt ");
116 case SV_TYPE_LOCAL_LIST_ONLY
:
117 fstrcat(typestr
, "Dom ");
119 case SV_TYPE_DOMAIN_ENUM
:
120 fstrcat(typestr
, "Loc ");
126 i
= strlen(typestr
) - 1;
128 if (typestr
[i
] == ' ')
134 static void display_server(const char *sname
, uint32 type
, const char *comment
)
136 printf("\t%-15.15s%-20s %s\n", sname
, get_server_type_str(type
),
140 static void display_srv_info_101(struct srvsvc_NetSrvInfo101
*sv101
)
142 display_server(sv101
->server_name
, sv101
->server_type
, sv101
->comment
);
144 printf("\tplatform_id :\t%d\n", sv101
->platform_id
);
145 printf("\tos version :\t%d.%d\n", sv101
->version_major
,
146 sv101
->version_minor
);
148 printf("\tserver type :\t0x%x\n", sv101
->server_type
);
151 static void display_srv_info_102(struct srvsvc_NetSrvInfo102
*sv102
)
153 display_server(sv102
->server_name
, sv102
->server_type
,
156 printf("\tplatform_id :\t%d\n", sv102
->platform_id
);
157 printf("\tos version :\t%d.%d\n", sv102
->version_major
,
158 sv102
->version_minor
);
160 printf("\tusers :\t%x\n", sv102
->users
);
161 printf("\tdisc, hidden :\t%x, %x\n", sv102
->disc
, sv102
->hidden
);
162 printf("\tannounce, delta :\t%d, %d\n", sv102
->announce
,
164 printf("\tlicenses :\t%d\n", sv102
->licenses
);
165 printf("\tuser path :\t%s\n", sv102
->userpath
);
168 /* Server query info */
169 static NTSTATUS
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 ctr
;
178 printf("Usage: %s [infolevel]\n", argv
[0]);
183 info_level
= atoi(argv
[1]);
185 result
= rpccli_srvsvc_NetSrvGetInfo(cli
, mem_ctx
, NULL
, info_level
,
188 if (!NT_STATUS_IS_OK(result
)) {
192 /* Display results */
194 switch (info_level
) {
196 display_srv_info_101(ctr
.info101
);
199 display_srv_info_102(ctr
.info102
);
202 printf("unsupported info level %d\n", info_level
);
210 static void display_share_info_1(struct srvsvc_NetShareInfo1
*info1
)
212 printf("netname: %s\n", info1
->name
);
213 printf("\tremark:\t%s\n", info1
->comment
);
216 static void display_share_info_2(struct srvsvc_NetShareInfo2
*info2
)
218 printf("netname: %s\n", info2
->name
);
219 printf("\tremark:\t%s\n", info2
->comment
);
220 printf("\tpath:\t%s\n", info2
->path
);
221 printf("\tpassword:\t%s\n", info2
->password
);
224 static void display_share_info_502(struct srvsvc_NetShareInfo502
*info502
)
226 printf("netname: %s\n", info502
->name
);
227 printf("\tremark:\t%s\n", info502
->comment
);
228 printf("\tpath:\t%s\n", info502
->path
);
229 printf("\tpassword:\t%s\n", info502
->password
);
231 printf("\ttype:\t0x%x\n", info502
->type
);
232 printf("\tperms:\t%d\n", info502
->permissions
);
233 printf("\tmax_uses:\t%d\n", info502
->max_users
);
234 printf("\tnum_uses:\t%d\n", info502
->current_users
);
237 display_sec_desc(info502
->sd
);
241 static NTSTATUS
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
243 int argc
, const char **argv
)
245 uint32 info_level
= 2;
246 struct srvsvc_NetShareCtr1 ctr1
;
247 struct srvsvc_NetShareCtr2 ctr2
;
248 struct srvsvc_NetShareCtr502 ctr502
;
249 union srvsvc_NetShareCtr ctr
;
252 uint32 preferred_len
= 0xffffffff, i
;
258 printf("Usage: %s [infolevel]\n", argv
[0]);
263 info_level
= atoi(argv
[1]);
267 switch (info_level
) {
281 ctr
.ctr502
= &ctr502
;
289 result
= rpccli_srvsvc_NetShareEnum(
290 cli
, mem_ctx
, cli
->cli
->desthost
, &info_level
, &ctr
, preferred_len
, &numentries
,
293 if (!NT_STATUS_IS_OK(result
) || !numentries
)
296 /* Display results */
298 switch (info_level
) {
300 for (i
= 0; i
< numentries
; i
++)
301 display_share_info_1(&ctr
.ctr1
->array
[i
]);
304 for (i
= 0; i
< numentries
; i
++)
305 display_share_info_2(&ctr
.ctr2
->array
[i
]);
308 for (i
= 0; i
< numentries
; i
++)
309 display_share_info_502(&ctr
.ctr502
->array
[i
]);
312 printf("unsupported info level %d\n", info_level
);
320 static NTSTATUS
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
322 int argc
, const char **argv
)
324 uint32 info_level
= 502;
325 union srvsvc_NetShareInfo info
;
329 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
334 info_level
= atoi(argv
[2]);
336 result
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
, NULL
, argv
[1], info_level
, &info
);
338 if (!NT_STATUS_IS_OK(result
))
341 /* Display results */
343 switch (info_level
) {
345 display_share_info_1(info
.info1
);
348 display_share_info_2(info
.info2
);
351 display_share_info_502(info
.info502
);
354 printf("unsupported info level %d\n", info_level
);
362 static NTSTATUS
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
364 int argc
, const char **argv
)
366 uint32 info_level
= 502;
367 union srvsvc_NetShareInfo info_get
;
372 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
376 /* retrieve share info */
377 result
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
, NULL
, argv
[1], info_level
, &info_get
);
378 if (!NT_STATUS_IS_OK(result
))
382 result
= rpccli_srvsvc_NetShareSetInfo(cli
, mem_ctx
, NULL
, argv
[1], info_level
, info_get
, &parm_error
);
384 if (!NT_STATUS_IS_OK(result
))
387 /* re-retrieve share info and display */
388 result
= rpccli_srvsvc_NetShareGetInfo(cli
, mem_ctx
, NULL
, argv
[1], info_level
, &info_get
);
389 if (!NT_STATUS_IS_OK(result
))
392 display_share_info_502(info_get
.info502
);
398 static NTSTATUS
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
400 int argc
, const char **argv
)
402 fstring srv_name_slash
;
404 struct srvsvc_NetRemoteTODInfo tod
;
407 printf("Usage: %s\n", argv
[0]);
411 fstr_sprintf(srv_name_slash
, "\\\\%s", cli
->cli
->desthost
);
412 result
= rpccli_srvsvc_NetRemoteTOD(
413 cli
, mem_ctx
, srv_name_slash
, &tod
);
415 if (!NT_STATUS_IS_OK(result
))
422 static NTSTATUS
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
424 int argc
, const char **argv
)
426 uint32 info_level
= 3;
427 union srvsvc_NetFileCtr ctr
;
430 uint32 preferred_len
= 0xffff;
434 printf("Usage: %s [infolevel]\n", argv
[0]);
439 info_level
= atoi(argv
[1]);
445 result
= rpccli_srvsvc_NetFileEnum(
446 cli
, mem_ctx
, NULL
, NULL
, NULL
, &info_level
, &ctr
, preferred_len
, &numentries
, &hnd
);
448 if (!NT_STATUS_IS_OK(result
))
455 /* List of commands exported by this module */
457 struct cmd_set srvsvc_commands
[] = {
461 { "srvinfo", RPC_RTYPE_NTSTATUS
, cmd_srvsvc_srv_query_info
, NULL
, PI_SRVSVC
, NULL
, "Server query info", "" },
462 { "netshareenum",RPC_RTYPE_NTSTATUS
, cmd_srvsvc_net_share_enum
, NULL
, PI_SRVSVC
, NULL
, "Enumerate shares", "" },
463 { "netsharegetinfo",RPC_RTYPE_NTSTATUS
, cmd_srvsvc_net_share_get_info
, NULL
, PI_SRVSVC
, NULL
, "Get Share Info", "" },
464 { "netsharesetinfo",RPC_RTYPE_NTSTATUS
, cmd_srvsvc_net_share_set_info
, NULL
, PI_SRVSVC
, NULL
, "Set Share Info", "" },
465 { "netfileenum", RPC_RTYPE_NTSTATUS
, cmd_srvsvc_net_file_enum
, NULL
, PI_SRVSVC
, NULL
, "Enumerate open files", "" },
466 { "netremotetod",RPC_RTYPE_NTSTATUS
, cmd_srvsvc_net_remote_tod
, NULL
, PI_SRVSVC
, NULL
, "Fetch remote time of day", "" },