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