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