display of session enum info
[samba.git] / source / rpcclient / cmd_srvsvc.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    NT Domain Authentication SMB / MSRPC client
5    Copyright (C) Andrew Tridgell 1994-1997
6    Copyright (C) Luke Kenneth Casson Leighton 1996-1997
7    
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.
12    
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.
17    
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.
21 */
22
23
24
25 #ifdef SYSLOG
26 #undef SYSLOG
27 #endif
28
29 #include "includes.h"
30 #include "nterr.h"
31
32 extern int DEBUGLEVEL;
33
34 #define DEBUG_TESTING
35
36 extern struct cli_state *smb_cli;
37
38 extern FILE* out_hnd;
39
40
41 /****************************************************************************
42 server get info query
43 ****************************************************************************/
44 void cmd_srv_query_info(struct client_info *info)
45 {
46         uint16 nt_pipe_fnum;
47         fstring dest_srv;
48         fstring tmp;
49         SRV_INFO_CTR ctr;
50         uint32 info_level = 101;
51
52         BOOL res = True;
53
54         bzero(&ctr, sizeof(ctr));
55
56         fstrcpy(dest_srv, "\\\\");
57         fstrcat(dest_srv, info->dest_host);
58         strupper(dest_srv);
59
60         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
61         {
62                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
63         }
64
65         DEBUG(4,("cmd_srv_query_info: server:%s info level: %d\n",
66                                 dest_srv, (int)info_level));
67
68         DEBUG(5, ("cmd_srv_query_info: smb_cli->fd:%d\n", smb_cli->fd));
69
70         /* open LSARPC session. */
71         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
72
73         /* send info level: receive requested info.  hopefully. */
74         res = res ? do_srv_net_srv_get_info(smb_cli, nt_pipe_fnum,
75                                 dest_srv, info_level, &ctr) : False;
76
77         /* close the session */
78         cli_nt_session_close(smb_cli, nt_pipe_fnum);
79
80         if (res)
81         {
82                 DEBUG(5,("cmd_srv_query_info: query succeeded\n"));
83
84                 display_srv_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
85                 display_srv_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
86                 display_srv_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
87         }
88         else
89         {
90                 DEBUG(5,("cmd_srv_query_info: query failed\n"));
91         }
92 }
93
94 /****************************************************************************
95 server enum connections
96 ****************************************************************************/
97 void cmd_srv_enum_conn(struct client_info *info)
98 {
99         uint16 nt_pipe_fnum;
100         fstring dest_srv;
101         fstring qual_srv;
102         fstring tmp;
103         SRV_CONN_INFO_CTR ctr;
104         ENUM_HND hnd;
105         uint32 info_level = 0;
106
107         BOOL res = True;
108
109         bzero(&ctr, sizeof(ctr));
110
111         fstrcpy(qual_srv, "\\\\");
112         fstrcat(qual_srv, info->myhostname);
113         strupper(qual_srv);
114
115         fstrcpy(dest_srv, "\\\\");
116         fstrcat(dest_srv, info->dest_host);
117         strupper(dest_srv);
118
119         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
120         {
121                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
122         }
123
124         DEBUG(4,("cmd_srv_enum_conn: server:%s info level: %d\n",
125                                 dest_srv, (int)info_level));
126
127         DEBUG(5, ("cmd_srv_enum_conn: smb_cli->fd:%d\n", smb_cli->fd));
128
129         /* open srvsvc session. */
130         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
131
132         hnd.ptr_hnd = 1;
133         hnd.handle = 0;
134
135         /* enumerate connections on server */
136         res = res ? do_srv_net_srv_conn_enum(smb_cli, nt_pipe_fnum,
137                                 dest_srv, qual_srv,
138                     info_level, &ctr, 0xffffffff, &hnd) : False;
139
140         if (res)
141         {
142                 display_srv_conn_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
143                 display_srv_conn_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
144                 display_srv_conn_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
145         }
146
147         /* close the session */
148         cli_nt_session_close(smb_cli, nt_pipe_fnum);
149
150         if (res)
151         {
152                 DEBUG(5,("cmd_srv_enum_conn: query succeeded\n"));
153         }
154         else
155         {
156                 DEBUG(5,("cmd_srv_enum_conn: query failed\n"));
157         }
158 }
159
160 /****************************************************************************
161 server enum shares
162 ****************************************************************************/
163 void cmd_srv_enum_shares(struct client_info *info)
164 {
165         uint16 nt_pipe_fnum;
166         fstring dest_srv;
167         fstring tmp;
168         SRV_SHARE_INFO_CTR ctr;
169         ENUM_HND hnd;
170         uint32 info_level = 1;
171
172         BOOL res = True;
173
174         bzero(&ctr, sizeof(ctr));
175
176         fstrcpy(dest_srv, "\\\\");
177         fstrcat(dest_srv, info->dest_host);
178         strupper(dest_srv);
179
180         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
181         {
182                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
183         }
184
185         DEBUG(4,("cmd_srv_enum_shares: server:%s info level: %d\n",
186                                 dest_srv, (int)info_level));
187
188         DEBUG(5, ("cmd_srv_enum_shares: smb_cli->fd:%d\n", smb_cli->fd));
189
190         /* open srvsvc session. */
191         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
192
193         hnd.ptr_hnd = 0;
194         hnd.handle = 0;
195
196         /* enumerate shares_files on server */
197         res = res ? do_srv_net_srv_share_enum(smb_cli, nt_pipe_fnum,
198                                 dest_srv, 
199                     info_level, &ctr, 0xffffffff, &hnd) : False;
200
201         if (res)
202         {
203                 display_srv_share_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
204                 display_srv_share_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
205                 display_srv_share_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
206         }
207
208         /* close the session */
209         cli_nt_session_close(smb_cli, nt_pipe_fnum);
210
211         if (res)
212         {
213                 DEBUG(5,("cmd_srv_enum_shares: query succeeded\n"));
214         }
215         else
216         {
217                 DEBUG(5,("cmd_srv_enum_shares: query failed\n"));
218         }
219 }
220
221 /****************************************************************************
222 server enum sessions
223 ****************************************************************************/
224 void cmd_srv_enum_sess(struct client_info *info)
225 {
226         uint16 nt_pipe_fnum;
227         fstring dest_srv;
228         fstring tmp;
229         SRV_SESS_INFO_CTR ctr;
230         ENUM_HND hnd;
231         uint32 info_level = 0;
232
233         BOOL res = True;
234
235         bzero(&ctr, sizeof(ctr));
236
237         fstrcpy(dest_srv, "\\\\");
238         fstrcat(dest_srv, info->dest_host);
239         strupper(dest_srv);
240
241         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
242         {
243                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
244         }
245
246         DEBUG(4,("cmd_srv_enum_sess: server:%s info level: %d\n",
247                                 dest_srv, (int)info_level));
248
249         DEBUG(5, ("cmd_srv_enum_sess: smb_cli->fd:%d\n", smb_cli->fd));
250
251         /* open srvsvc session. */
252         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
253
254         hnd.ptr_hnd = 1;
255         hnd.handle = 0;
256
257         /* enumerate sessions on server */
258         res = res ? do_srv_net_srv_sess_enum(smb_cli, nt_pipe_fnum,
259                                 dest_srv, NULL, NULL, info_level, &ctr, 0x1000, &hnd) : False;
260
261         if (res)
262         {
263                 display_srv_sess_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
264                 display_srv_sess_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
265                 display_srv_sess_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
266         }
267
268         /* close the session */
269         cli_nt_session_close(smb_cli, nt_pipe_fnum);
270
271         if (res)
272         {
273                 DEBUG(5,("cmd_srv_enum_sess: query succeeded\n"));
274         }
275         else
276         {
277                 DEBUG(5,("cmd_srv_enum_sess: query failed\n"));
278         }
279 }
280
281 /****************************************************************************
282 server enum files
283 ****************************************************************************/
284 void cmd_srv_enum_files(struct client_info *info)
285 {
286         uint16 nt_pipe_fnum;
287         fstring dest_srv;
288         fstring tmp;
289         SRV_FILE_INFO_CTR ctr;
290         ENUM_HND hnd;
291         uint32 info_level = 3;
292
293         BOOL res = True;
294
295         bzero(&ctr, sizeof(ctr));
296
297         fstrcpy(dest_srv, "\\\\");
298         fstrcat(dest_srv, info->dest_host);
299         strupper(dest_srv);
300
301         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
302         {
303                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
304         }
305
306         DEBUG(4,("cmd_srv_enum_files: server:%s info level: %d\n",
307                                 dest_srv, (int)info_level));
308
309         DEBUG(5, ("cmd_srv_enum_files: smb_cli->fd:%d\n", smb_cli->fd));
310
311         /* open srvsvc session. */
312         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
313
314         hnd.ptr_hnd = 1;
315         hnd.handle = 0;
316
317         /* enumerate files on server */
318         res = res ? do_srv_net_srv_file_enum(smb_cli, nt_pipe_fnum,
319                                 dest_srv, NULL, 0, info_level, &ctr, 0x1000, &hnd) : False;
320
321         if (res)
322         {
323                 display_srv_file_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
324                 display_srv_file_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
325                 display_srv_file_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
326         }
327
328         /* close the session */
329         cli_nt_session_close(smb_cli, nt_pipe_fnum);
330
331         if (res)
332         {
333                 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
334         }
335         else
336         {
337                 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
338         }
339 }
340
341 /****************************************************************************
342 display remote time
343 ****************************************************************************/
344 void cmd_time(struct client_info *info)
345 {
346         uint16 nt_pipe_fnum;
347         fstring dest_srv;
348         TIME_OF_DAY_INFO tod;
349         BOOL res = True;
350
351         fstrcpy(dest_srv, "\\\\");
352         fstrcat(dest_srv, info->dest_host);
353         strupper(dest_srv);
354
355         DEBUG(4,("cmd_time: server:%s\n", dest_srv));
356
357         /* open srvsvc session. */
358         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
359
360         /* enumerate files on server */
361         res = res ? do_srv_net_remote_tod(smb_cli, nt_pipe_fnum,
362                                           dest_srv, &tod) : False;
363
364         if (res)
365         {
366                 fprintf(out_hnd, "\tRemote Time:\t%s\n\n",
367                         http_timestring(tod.elapsedt));
368         }
369
370         /* Close the session */
371         cli_nt_session_close(smb_cli, nt_pipe_fnum);
372
373         if (res)
374         {
375                 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
376         }
377         else
378         {
379                 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
380         }
381 }