NetServerTransportEnum parsing, client-side and rpcclient "srvtransports" added.
[samba.git] / source3 / 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 BOOL net_srv_get_info(struct client_info *info,
45                 uint32 info_level,
46                 SRV_INFO_CTR *ctr)
47 {
48         uint16 nt_pipe_fnum;
49         fstring dest_srv;
50
51         BOOL res = True;
52
53         fstrcpy(dest_srv, "\\\\");
54         fstrcat(dest_srv, info->dest_host);
55         strupper(dest_srv);
56
57         DEBUG(4,("net_srv_get_info: server:%s info level: %d\n",
58                                 dest_srv, (int)info_level));
59
60         /* open LSARPC session. */
61         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
62
63         /* send info level: receive requested info.  hopefully. */
64         res = res ? do_srv_net_srv_get_info(smb_cli, nt_pipe_fnum,
65                                 dest_srv, info_level, ctr) : False;
66
67         /* close the session */
68         cli_nt_session_close(smb_cli, nt_pipe_fnum);
69
70         return res;
71 }
72
73 /****************************************************************************
74 server get info query
75 ****************************************************************************/
76 void cmd_srv_query_info(struct client_info *info)
77 {
78         uint32 info_level = 101;
79         SRV_INFO_CTR ctr;
80         fstring tmp;
81
82         bzero(&ctr, sizeof(ctr));
83
84         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
85         {
86                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
87         }
88
89         DEBUG(5, ("cmd_srv_query_info: smb_cli->fd:%d\n", smb_cli->fd));
90
91         if (net_srv_get_info(info, info_level, &ctr))
92         {
93                 DEBUG(5,("cmd_srv_query_info: query succeeded\n"));
94
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);
98         }
99         else
100         {
101                 DEBUG(5,("cmd_srv_query_info: query failed\n"));
102         }
103 }
104
105 /****************************************************************************
106 server enum transports
107 ****************************************************************************/
108 void cmd_srv_enum_tprt(struct client_info *info)
109 {
110         uint16 nt_pipe_fnum;
111         fstring dest_srv;
112         fstring tmp;
113         SRV_TPRT_INFO_CTR ctr;
114         ENUM_HND hnd;
115         uint32 info_level = 0;
116
117         BOOL res = True;
118
119         bzero(&ctr, sizeof(ctr));
120
121         fstrcpy(dest_srv, "\\\\");
122         fstrcat(dest_srv, info->dest_host);
123         strupper(dest_srv);
124
125         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
126         {
127                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
128         }
129
130         DEBUG(4,("cmd_srv_enum_tprt: server:%s info level: %d\n",
131                                 dest_srv, (int)info_level));
132
133         DEBUG(5, ("cmd_srv_enum_tprt: smb_cli->fd:%d\n", smb_cli->fd));
134
135         /* open srvsvc session. */
136         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
137
138         hnd.ptr_hnd = 1;
139         hnd.handle = 0;
140
141         /* enumerate transports on server */
142         res = res ? do_srv_net_srv_tprt_enum(smb_cli, nt_pipe_fnum,
143                                 dest_srv, 
144                     info_level, &ctr, 0xffffffff, &hnd) : False;
145
146         if (res)
147         {
148                 display_srv_tprt_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
149                 display_srv_tprt_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
150                 display_srv_tprt_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
151         }
152
153         /* close the session */
154         cli_nt_session_close(smb_cli, nt_pipe_fnum);
155
156         if (res)
157         {
158                 DEBUG(5,("cmd_srv_enum_tprt: query succeeded\n"));
159         }
160         else
161         {
162                 DEBUG(5,("cmd_srv_enum_tprt: query failed\n"));
163         }
164 }
165
166 /****************************************************************************
167 server enum connections
168 ****************************************************************************/
169 void cmd_srv_enum_conn(struct client_info *info)
170 {
171         uint16 nt_pipe_fnum;
172         fstring dest_srv;
173         fstring qual_srv;
174         fstring tmp;
175         SRV_CONN_INFO_CTR ctr;
176         ENUM_HND hnd;
177         uint32 info_level = 0;
178
179         BOOL res = True;
180
181         bzero(&ctr, sizeof(ctr));
182
183         fstrcpy(qual_srv, "\\\\");
184         fstrcat(qual_srv, info->myhostname);
185         strupper(qual_srv);
186
187         fstrcpy(dest_srv, "\\\\");
188         fstrcat(dest_srv, info->dest_host);
189         strupper(dest_srv);
190
191         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
192         {
193                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
194         }
195
196         DEBUG(4,("cmd_srv_enum_conn: server:%s info level: %d\n",
197                                 dest_srv, (int)info_level));
198
199         DEBUG(5, ("cmd_srv_enum_conn: smb_cli->fd:%d\n", smb_cli->fd));
200
201         /* open srvsvc session. */
202         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
203
204         hnd.ptr_hnd = 1;
205         hnd.handle = 0;
206
207         /* enumerate connections on server */
208         res = res ? do_srv_net_srv_conn_enum(smb_cli, nt_pipe_fnum,
209                                 dest_srv, qual_srv,
210                     info_level, &ctr, 0xffffffff, &hnd) : False;
211
212         if (res)
213         {
214                 display_srv_conn_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
215                 display_srv_conn_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
216                 display_srv_conn_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
217         }
218
219         /* close the session */
220         cli_nt_session_close(smb_cli, nt_pipe_fnum);
221
222         if (res)
223         {
224                 DEBUG(5,("cmd_srv_enum_conn: query succeeded\n"));
225         }
226         else
227         {
228                 DEBUG(5,("cmd_srv_enum_conn: query failed\n"));
229         }
230 }
231
232 /****************************************************************************
233 server enum shares
234 ****************************************************************************/
235 void cmd_srv_enum_shares(struct client_info *info)
236 {
237         uint16 nt_pipe_fnum;
238         fstring dest_srv;
239         fstring tmp;
240         SRV_SHARE_INFO_CTR ctr;
241         ENUM_HND hnd;
242         uint32 info_level = 1;
243
244         BOOL res = True;
245
246         bzero(&ctr, sizeof(ctr));
247
248         fstrcpy(dest_srv, "\\\\");
249         fstrcat(dest_srv, info->dest_host);
250         strupper(dest_srv);
251
252         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
253         {
254                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
255         }
256
257         DEBUG(4,("cmd_srv_enum_shares: server:%s info level: %d\n",
258                                 dest_srv, (int)info_level));
259
260         DEBUG(5, ("cmd_srv_enum_shares: smb_cli->fd:%d\n", smb_cli->fd));
261
262         /* open srvsvc session. */
263         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
264
265         hnd.ptr_hnd = 0;
266         hnd.handle = 0;
267
268         /* enumerate shares_files on server */
269         res = res ? do_srv_net_srv_share_enum(smb_cli, nt_pipe_fnum,
270                                 dest_srv, 
271                     info_level, &ctr, 0xffffffff, &hnd) : False;
272
273         if (res)
274         {
275                 display_srv_share_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
276                 display_srv_share_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
277                 display_srv_share_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
278         }
279
280         /* close the session */
281         cli_nt_session_close(smb_cli, nt_pipe_fnum);
282
283         if (res)
284         {
285                 DEBUG(5,("cmd_srv_enum_shares: query succeeded\n"));
286         }
287         else
288         {
289                 DEBUG(5,("cmd_srv_enum_shares: query failed\n"));
290         }
291 }
292
293 /****************************************************************************
294 server enum sessions
295 ****************************************************************************/
296 void cmd_srv_enum_sess(struct client_info *info)
297 {
298         uint16 nt_pipe_fnum;
299         fstring dest_srv;
300         fstring tmp;
301         SRV_SESS_INFO_CTR ctr;
302         ENUM_HND hnd;
303         uint32 info_level = 0;
304
305         BOOL res = True;
306
307         bzero(&ctr, sizeof(ctr));
308
309         fstrcpy(dest_srv, "\\\\");
310         fstrcat(dest_srv, info->dest_host);
311         strupper(dest_srv);
312
313         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
314         {
315                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
316         }
317
318         DEBUG(4,("cmd_srv_enum_sess: server:%s info level: %d\n",
319                                 dest_srv, (int)info_level));
320
321         DEBUG(5, ("cmd_srv_enum_sess: smb_cli->fd:%d\n", smb_cli->fd));
322
323         /* open srvsvc session. */
324         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
325
326         hnd.ptr_hnd = 1;
327         hnd.handle = 0;
328
329         /* enumerate sessions on server */
330         res = res ? do_srv_net_srv_sess_enum(smb_cli, nt_pipe_fnum,
331                                 dest_srv, NULL, NULL, info_level, &ctr, 0x1000, &hnd) : False;
332
333         if (res)
334         {
335                 display_srv_sess_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
336                 display_srv_sess_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
337                 display_srv_sess_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
338         }
339
340         /* close the session */
341         cli_nt_session_close(smb_cli, nt_pipe_fnum);
342
343         if (res)
344         {
345                 DEBUG(5,("cmd_srv_enum_sess: query succeeded\n"));
346         }
347         else
348         {
349                 DEBUG(5,("cmd_srv_enum_sess: query failed\n"));
350         }
351 }
352
353 /****************************************************************************
354 server enum files
355 ****************************************************************************/
356 void cmd_srv_enum_files(struct client_info *info)
357 {
358         uint16 nt_pipe_fnum;
359         fstring dest_srv;
360         fstring tmp;
361         SRV_FILE_INFO_CTR ctr;
362         ENUM_HND hnd;
363         uint32 info_level = 3;
364
365         BOOL res = True;
366
367         bzero(&ctr, sizeof(ctr));
368
369         fstrcpy(dest_srv, "\\\\");
370         fstrcat(dest_srv, info->dest_host);
371         strupper(dest_srv);
372
373         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
374         {
375                 info_level = (uint32)strtol(tmp, (char**)NULL, 10);
376         }
377
378         DEBUG(4,("cmd_srv_enum_files: server:%s info level: %d\n",
379                                 dest_srv, (int)info_level));
380
381         DEBUG(5, ("cmd_srv_enum_files: smb_cli->fd:%d\n", smb_cli->fd));
382
383         /* open srvsvc session. */
384         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
385
386         hnd.ptr_hnd = 1;
387         hnd.handle = 0;
388
389         /* enumerate files on server */
390         res = res ? do_srv_net_srv_file_enum(smb_cli, nt_pipe_fnum,
391                                 dest_srv, NULL, 0, info_level, &ctr, 0x1000, &hnd) : False;
392
393         if (res)
394         {
395                 display_srv_file_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
396                 display_srv_file_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
397                 display_srv_file_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
398         }
399
400         /* close the session */
401         cli_nt_session_close(smb_cli, nt_pipe_fnum);
402
403         if (res)
404         {
405                 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
406         }
407         else
408         {
409                 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
410         }
411 }
412
413 /****************************************************************************
414 display remote time
415 ****************************************************************************/
416 void cmd_time(struct client_info *info)
417 {
418         uint16 nt_pipe_fnum;
419         fstring dest_srv;
420         TIME_OF_DAY_INFO tod;
421         BOOL res = True;
422
423         fstrcpy(dest_srv, "\\\\");
424         fstrcat(dest_srv, info->dest_host);
425         strupper(dest_srv);
426
427         DEBUG(4,("cmd_time: server:%s\n", dest_srv));
428
429         /* open srvsvc session. */
430         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, &nt_pipe_fnum) : False;
431
432         /* enumerate files on server */
433         res = res ? do_srv_net_remote_tod(smb_cli, nt_pipe_fnum,
434                                           dest_srv, &tod) : False;
435
436         if (res)
437         {
438                 fprintf(out_hnd, "\tRemote Time:\t%s\n\n",
439                         http_timestring(tod.elapsedt));
440         }
441
442         /* Close the session */
443         cli_nt_session_close(smb_cli, nt_pipe_fnum);
444
445         if (res)
446         {
447                 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
448         }
449         else
450         {
451                 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
452         }
453 }