2 Unix SMB/Netbios implementation.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1999
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1999
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 extern int DEBUGLEVEL;
36 extern struct cli_state *smb_cli;
41 /****************************************************************************
43 ****************************************************************************/
44 BOOL net_srv_get_info(struct client_info *info,
53 fstrcpy(dest_srv, "\\\\");
54 fstrcat(dest_srv, info->dest_host);
57 DEBUG(4,("net_srv_get_info: server:%s info level: %d\n",
58 dest_srv, (int)info_level));
60 /* open LSARPC session. */
61 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
63 /* send info level: receive requested info. hopefully. */
64 res = res ? do_srv_net_srv_get_info(smb_cli, fnum,
65 dest_srv, info_level, ctr) : False;
67 /* close the session */
68 cli_nt_session_close(smb_cli, fnum);
73 /****************************************************************************
75 ****************************************************************************/
76 void cmd_srv_query_info(struct client_info *info)
78 uint32 info_level = 101;
82 bzero(&ctr, sizeof(ctr));
84 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
86 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
89 DEBUG(5, ("cmd_srv_query_info: smb_cli->fd:%d\n", smb_cli->fd));
91 if (net_srv_get_info(info, info_level, &ctr))
93 DEBUG(5,("cmd_srv_query_info: query succeeded\n"));
95 display_srv_info_ctr(out_hnd, ACTION_HEADER , &ctr);
96 display_srv_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
97 display_srv_info_ctr(out_hnd, ACTION_FOOTER , &ctr);
101 DEBUG(5,("cmd_srv_query_info: query failed\n"));
105 /****************************************************************************
106 server enum transports
107 ****************************************************************************/
108 BOOL msrpc_srv_enum_tprt(struct cli_state *cli,
109 const char* dest_srv,
111 SRV_TPRT_INFO_CTR *ctr,
112 TPRT_INFO_FN(tprt_fn))
124 /* open srvsvc session. */
125 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
127 /* enumerate transports on server */
128 res1 = res ? do_srv_net_srv_tprt_enum(smb_cli, fnum,
130 info_level, ctr, 0xffffffff, &hnd) : False;
132 /* close the session */
133 cli_nt_session_close(smb_cli, fnum);
137 free_srv_tprt_ctr(ctr);
142 static void srv_display_tprt_ctr(const SRV_TPRT_INFO_CTR *ctr)
144 display_srv_tprt_info_ctr(out_hnd, ACTION_HEADER , ctr);
145 display_srv_tprt_info_ctr(out_hnd, ACTION_ENUMERATE, ctr);
146 display_srv_tprt_info_ctr(out_hnd, ACTION_FOOTER , ctr);
149 /****************************************************************************
150 server enum transports
151 ****************************************************************************/
152 void cmd_srv_enum_tprt(struct client_info *info)
156 SRV_TPRT_INFO_CTR ctr;
157 uint32 info_level = 0;
159 bzero(&ctr, sizeof(ctr));
161 fstrcpy(dest_srv, "\\\\");
162 fstrcat(dest_srv, info->dest_host);
165 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
167 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
170 DEBUG(4,("cmd_srv_enum_tprt: server:%s info level: %d\n",
171 dest_srv, (int)info_level));
173 DEBUG(5, ("cmd_srv_enum_tprt: smb_cli->fd:%d\n", smb_cli->fd));
175 /* enumerate transports on server */
176 msrpc_srv_enum_tprt(smb_cli, dest_srv,
178 srv_display_tprt_ctr);
181 /****************************************************************************
182 server enum connections
183 ****************************************************************************/
184 void cmd_srv_enum_conn(struct client_info *info)
190 SRV_CONN_INFO_CTR ctr;
192 uint32 info_level = 0;
196 bzero(&ctr, sizeof(ctr));
198 fstrcpy(qual_srv, "\\\\");
199 fstrcat(qual_srv, info->myhostname);
202 fstrcpy(dest_srv, "\\\\");
203 fstrcat(dest_srv, info->dest_host);
206 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
208 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
211 DEBUG(4,("cmd_srv_enum_conn: server:%s info level: %d\n",
212 dest_srv, (int)info_level));
214 DEBUG(5, ("cmd_srv_enum_conn: smb_cli->fd:%d\n", smb_cli->fd));
216 /* open srvsvc session. */
217 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
222 /* enumerate connections on server */
223 res = res ? do_srv_net_srv_conn_enum(smb_cli, fnum,
225 info_level, &ctr, 0xffffffff, &hnd) : False;
229 display_srv_conn_info_ctr(out_hnd, ACTION_HEADER , &ctr);
230 display_srv_conn_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
231 display_srv_conn_info_ctr(out_hnd, ACTION_FOOTER , &ctr);
234 /* close the session */
235 cli_nt_session_close(smb_cli, fnum);
239 DEBUG(5,("cmd_srv_enum_conn: query succeeded\n"));
243 DEBUG(5,("cmd_srv_enum_conn: query failed\n"));
247 /****************************************************************************
249 ****************************************************************************/
250 void cmd_srv_enum_shares(struct client_info *info)
255 SRV_SHARE_INFO_CTR ctr;
257 uint32 info_level = 1;
261 bzero(&ctr, sizeof(ctr));
263 fstrcpy(dest_srv, "\\\\");
264 fstrcat(dest_srv, info->dest_host);
267 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
269 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
272 DEBUG(4,("cmd_srv_enum_shares: server:%s info level: %d\n",
273 dest_srv, (int)info_level));
275 DEBUG(5, ("cmd_srv_enum_shares: smb_cli->fd:%d\n", smb_cli->fd));
277 /* open srvsvc session. */
278 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
283 /* enumerate shares_files on server */
284 res = res ? do_srv_net_srv_share_enum(smb_cli, fnum,
286 info_level, &ctr, 0xffffffff, &hnd) : False;
290 display_srv_share_info_ctr(out_hnd, ACTION_HEADER , &ctr);
291 display_srv_share_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
292 display_srv_share_info_ctr(out_hnd, ACTION_FOOTER , &ctr);
295 /* close the session */
296 cli_nt_session_close(smb_cli, fnum);
300 DEBUG(5,("cmd_srv_enum_shares: query succeeded\n"));
304 DEBUG(5,("cmd_srv_enum_shares: query failed\n"));
308 /****************************************************************************
310 ****************************************************************************/
311 void cmd_srv_enum_sess(struct client_info *info)
316 SRV_SESS_INFO_CTR ctr;
318 uint32 info_level = 0;
322 bzero(&ctr, sizeof(ctr));
324 fstrcpy(dest_srv, "\\\\");
325 fstrcat(dest_srv, info->dest_host);
328 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
330 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
333 DEBUG(4,("cmd_srv_enum_sess: server:%s info level: %d\n",
334 dest_srv, (int)info_level));
336 DEBUG(5, ("cmd_srv_enum_sess: smb_cli->fd:%d\n", smb_cli->fd));
338 /* open srvsvc session. */
339 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
344 /* enumerate sessions on server */
345 res = res ? do_srv_net_srv_sess_enum(smb_cli, fnum,
346 dest_srv, NULL, NULL, info_level, &ctr, 0x1000, &hnd) : False;
350 display_srv_sess_info_ctr(out_hnd, ACTION_HEADER , &ctr);
351 display_srv_sess_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
352 display_srv_sess_info_ctr(out_hnd, ACTION_FOOTER , &ctr);
355 /* close the session */
356 cli_nt_session_close(smb_cli, fnum);
360 DEBUG(5,("cmd_srv_enum_sess: query succeeded\n"));
364 DEBUG(5,("cmd_srv_enum_sess: query failed\n"));
368 /****************************************************************************
370 ****************************************************************************/
371 void cmd_srv_enum_files(struct client_info *info)
376 SRV_FILE_INFO_CTR ctr;
378 uint32 info_level = 3;
382 bzero(&ctr, sizeof(ctr));
384 fstrcpy(dest_srv, "\\\\");
385 fstrcat(dest_srv, info->dest_host);
388 if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
390 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
393 DEBUG(4,("cmd_srv_enum_files: server:%s info level: %d\n",
394 dest_srv, (int)info_level));
396 DEBUG(5, ("cmd_srv_enum_files: smb_cli->fd:%d\n", smb_cli->fd));
398 /* open srvsvc session. */
399 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
404 /* enumerate files on server */
405 res = res ? do_srv_net_srv_file_enum(smb_cli, fnum,
406 dest_srv, NULL, 0, info_level, &ctr, 0x1000, &hnd) : False;
410 display_srv_file_info_ctr(out_hnd, ACTION_HEADER , &ctr);
411 display_srv_file_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
412 display_srv_file_info_ctr(out_hnd, ACTION_FOOTER , &ctr);
415 /* close the session */
416 cli_nt_session_close(smb_cli, fnum);
420 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
424 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
428 /****************************************************************************
430 ****************************************************************************/
431 void cmd_time(struct client_info *info)
435 TIME_OF_DAY_INFO tod;
438 fstrcpy(dest_srv, "\\\\");
439 fstrcat(dest_srv, info->dest_host);
442 DEBUG(4,("cmd_time: server:%s\n", dest_srv));
444 /* open srvsvc session. */
445 res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &fnum) : False;
447 /* enumerate files on server */
448 res = res ? do_srv_net_remote_tod(smb_cli, fnum,
449 dest_srv, &tod) : False;
453 fprintf(out_hnd, "\tRemote Time:\t%s\n\n",
454 http_timestring(tod.elapsedt));
457 /* Close the session */
458 cli_nt_session_close(smb_cli, fnum);
462 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
466 DEBUG(5,("cmd_srv_enum_files: query failed\n"));