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(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(SRV_INFO_101
*sv101
)
144 unistr2_to_ascii(name
, &sv101
->uni_name
, sizeof(name
));
145 unistr2_to_ascii(comment
, &sv101
->uni_comment
, sizeof(comment
));
147 display_server(name
, sv101
->srv_type
, comment
);
149 printf("\tplatform_id :\t%d\n", sv101
->platform_id
);
150 printf("\tos version :\t%d.%d\n", sv101
->ver_major
,
153 printf("\tserver type :\t0x%x\n", sv101
->srv_type
);
156 static void display_srv_info_102(SRV_INFO_102
*sv102
)
162 unistr2_to_ascii(name
, &sv102
->uni_name
, sizeof(name
));
163 unistr2_to_ascii(comment
, &sv102
->uni_comment
, sizeof(comment
));
164 unistr2_to_ascii(usr_path
, &sv102
->uni_usr_path
, sizeof(usr_path
));
166 display_server(name
, sv102
->srv_type
, comment
);
168 printf("\tplatform_id :\t%d\n", sv102
->platform_id
);
169 printf("\tos version :\t%d.%d\n", sv102
->ver_major
,
172 printf("\tusers :\t%x\n", sv102
->users
);
173 printf("\tdisc, hidden :\t%x, %x\n", sv102
->disc
, sv102
->hidden
);
174 printf("\tannounce, delta :\t%d, %d\n", sv102
->announce
,
176 printf("\tlicenses :\t%d\n", sv102
->licenses
);
177 printf("\tuser path :\t%s\n", usr_path
);
180 /* Server query info */
181 static WERROR
cmd_srvsvc_srv_query_info(struct rpc_pipe_client
*cli
,
183 int argc
, const char **argv
)
185 uint32 info_level
= 101;
190 printf("Usage: %s [infolevel]\n", argv
[0]);
195 info_level
= atoi(argv
[1]);
197 result
= rpccli_srvsvc_net_srv_get_info(cli
, mem_ctx
, info_level
,
200 if (!W_ERROR_IS_OK(result
)) {
204 /* Display results */
206 switch (info_level
) {
208 display_srv_info_101(&ctr
.srv
.sv101
);
211 display_srv_info_102(&ctr
.srv
.sv102
);
214 printf("unsupported info level %d\n", info_level
);
222 static void display_share_info_1(SRV_SHARE_INFO_1
*info1
)
224 fstring netname
= "", remark
= "";
226 rpcstr_pull_unistr2_fstring(netname
, &info1
->info_1_str
.uni_netname
);
227 rpcstr_pull_unistr2_fstring(remark
, &info1
->info_1_str
.uni_remark
);
229 printf("netname: %s\n", netname
);
230 printf("\tremark:\t%s\n", remark
);
233 static void display_share_info_2(SRV_SHARE_INFO_2
*info2
)
235 fstring netname
= "", remark
= "", path
= "", passwd
= "";
237 rpcstr_pull_unistr2_fstring(netname
, &info2
->info_2_str
.uni_netname
);
238 rpcstr_pull_unistr2_fstring(remark
, &info2
->info_2_str
.uni_remark
);
239 rpcstr_pull_unistr2_fstring(path
, &info2
->info_2_str
.uni_path
);
240 rpcstr_pull_unistr2_fstring(passwd
, &info2
->info_2_str
.uni_passwd
);
242 printf("netname: %s\n", netname
);
243 printf("\tremark:\t%s\n", remark
);
244 printf("\tpath:\t%s\n", path
);
245 printf("\tpassword:\t%s\n", passwd
);
248 static void display_share_info_502(SRV_SHARE_INFO_502
*info502
)
250 fstring netname
= "", remark
= "", path
= "", passwd
= "";
252 rpcstr_pull_unistr2_fstring(netname
, &info502
->info_502_str
.uni_netname
);
253 rpcstr_pull_unistr2_fstring(remark
, &info502
->info_502_str
.uni_remark
);
254 rpcstr_pull_unistr2_fstring(path
, &info502
->info_502_str
.uni_path
);
255 rpcstr_pull_unistr2_fstring(passwd
, &info502
->info_502_str
.uni_passwd
);
257 printf("netname: %s\n", netname
);
258 printf("\tremark:\t%s\n", remark
);
259 printf("\tpath:\t%s\n", path
);
260 printf("\tpassword:\t%s\n", passwd
);
262 printf("\ttype:\t0x%x\n", info502
->info_502
.type
);
263 printf("\tperms:\t%d\n", info502
->info_502
.perms
);
264 printf("\tmax_uses:\t%d\n", info502
->info_502
.max_uses
);
265 printf("\tnum_uses:\t%d\n", info502
->info_502
.num_uses
);
267 if (info502
->info_502_str
.sd
)
268 display_sec_desc(info502
->info_502_str
.sd
);
272 static WERROR
cmd_srvsvc_net_share_enum(struct rpc_pipe_client
*cli
,
274 int argc
, const char **argv
)
276 uint32 info_level
= 2;
277 SRV_SHARE_INFO_CTR ctr
;
280 uint32 preferred_len
= 0xffffffff, i
;
283 printf("Usage: %s [infolevel]\n", argv
[0]);
288 info_level
= atoi(argv
[1]);
290 init_enum_hnd(&hnd
, 0);
292 result
= rpccli_srvsvc_net_share_enum(
293 cli
, mem_ctx
, info_level
, &ctr
, preferred_len
, &hnd
);
295 if (!W_ERROR_IS_OK(result
) || !ctr
.num_entries
)
298 /* Display results */
300 switch (info_level
) {
302 for (i
= 0; i
< ctr
.num_entries
; i
++)
303 display_share_info_1(&ctr
.share
.info1
[i
]);
306 for (i
= 0; i
< ctr
.num_entries
; i
++)
307 display_share_info_2(&ctr
.share
.info2
[i
]);
310 for (i
= 0; i
< ctr
.num_entries
; i
++)
311 display_share_info_502(&ctr
.share
.info502
[i
]);
314 printf("unsupported info level %d\n", info_level
);
322 static WERROR
cmd_srvsvc_net_share_get_info(struct rpc_pipe_client
*cli
,
324 int argc
, const char **argv
)
326 uint32 info_level
= 502;
331 printf("Usage: %s [sharename] [infolevel]\n", argv
[0]);
336 info_level
= atoi(argv
[2]);
338 result
= rpccli_srvsvc_net_share_get_info(cli
, mem_ctx
, argv
[1], info_level
, &info
);
340 if (!W_ERROR_IS_OK(result
))
343 /* Display results */
345 switch (info_level
) {
347 display_share_info_1(&info
.share
.info1
);
350 display_share_info_2(&info
.share
.info2
);
353 display_share_info_502(&info
.share
.info502
);
356 printf("unsupported info level %d\n", info_level
);
364 static WERROR
cmd_srvsvc_net_share_set_info(struct rpc_pipe_client
*cli
,
366 int argc
, const char **argv
)
368 uint32 info_level
= 502;
369 SRV_SHARE_INFO info_get
;
373 printf("Usage: %s [sharename] [comment]\n", argv
[0]);
377 /* retrieve share info */
378 result
= rpccli_srvsvc_net_share_get_info(cli
, mem_ctx
, argv
[1], info_level
, &info_get
);
379 if (!W_ERROR_IS_OK(result
))
382 info_get
.switch_value
= info_level
;
383 info_get
.ptr_share_ctr
= 1;
384 init_unistr2(&(info_get
.share
.info502
.info_502_str
.uni_remark
), argv
[2], UNI_STR_TERMINATE
);
387 result
= rpccli_srvsvc_net_share_set_info(cli
, mem_ctx
, argv
[1], info_level
, &info_get
);
389 if (!W_ERROR_IS_OK(result
))
392 /* re-retrieve share info and display */
393 result
= rpccli_srvsvc_net_share_get_info(cli
, mem_ctx
, argv
[1], info_level
, &info_get
);
394 if (!W_ERROR_IS_OK(result
))
397 display_share_info_502(&info_get
.share
.info502
);
403 static WERROR
cmd_srvsvc_net_remote_tod(struct rpc_pipe_client
*cli
,
405 int argc
, const char **argv
)
407 TIME_OF_DAY_INFO tod
;
408 fstring srv_name_slash
;
412 printf("Usage: %s\n", argv
[0]);
416 fstr_sprintf(srv_name_slash
, "\\\\%s", cli
->cli
->desthost
);
417 result
= rpccli_srvsvc_net_remote_tod(
418 cli
, mem_ctx
, srv_name_slash
, &tod
);
420 if (!W_ERROR_IS_OK(result
))
427 static WERROR
cmd_srvsvc_net_file_enum(struct rpc_pipe_client
*cli
,
429 int argc
, const char **argv
)
431 uint32 info_level
= 3;
432 SRV_FILE_INFO_CTR ctr
;
435 uint32 preferred_len
= 0xffff;
438 printf("Usage: %s [infolevel]\n", argv
[0]);
443 info_level
= atoi(argv
[1]);
445 init_enum_hnd(&hnd
, 0);
449 result
= rpccli_srvsvc_net_file_enum(
450 cli
, mem_ctx
, info_level
, NULL
, &ctr
, preferred_len
, &hnd
);
452 if (!W_ERROR_IS_OK(result
))
459 /* List of commands exported by this module */
461 struct cmd_set srvsvc_commands
[] = {
465 { "srvinfo", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_srv_query_info
, PI_SRVSVC
, NULL
, "Server query info", "" },
466 { "netshareenum",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_enum
, PI_SRVSVC
, NULL
, "Enumerate shares", "" },
467 { "netsharegetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_get_info
, PI_SRVSVC
, NULL
, "Get Share Info", "" },
468 { "netsharesetinfo",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_share_set_info
, PI_SRVSVC
, NULL
, "Set Share Info", "" },
469 { "netfileenum", RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_file_enum
, PI_SRVSVC
, NULL
, "Enumerate open files", "" },
470 { "netremotetod",RPC_RTYPE_WERROR
, NULL
, cmd_srvsvc_net_remote_tod
, PI_SRVSVC
, NULL
, "Fetch remote time of day", "" },