4d4fb791a9254a23dfa0b9b812f8807408a4e02c
[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 void cmd_srv_query_info(struct client_info *info)
45 {
46         fstring dest_srv;
47         fstring tmp;
48         SRV_INFO_CTR ctr;
49         uint32 info_level = 101;
50
51         BOOL res = True;
52
53         bzero(&ctr, sizeof(ctr));
54
55         fstrcpy(dest_srv, "\\\\");
56         fstrcat(dest_srv, info->dest_host);
57         strupper(dest_srv);
58
59         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
60         {
61                 info_level = strtoul(tmp, (char**)NULL, 10);
62         }
63
64         DEBUG(4,("cmd_srv_query_info: server:%s info level: %d\n",
65                                 dest_srv, (int)info_level));
66
67         DEBUG(5, ("cmd_srv_query_info: smb_cli->fd:%d\n", smb_cli->fd));
68
69         /* open LSARPC session. */
70         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False;
71
72         /* send info level: receive requested info.  hopefully. */
73         res = res ? do_srv_net_srv_get_info(smb_cli,
74                                 dest_srv, info_level, &ctr) : False;
75
76         /* close the session */
77         cli_nt_session_close(smb_cli);
78
79         if (res)
80         {
81                 DEBUG(5,("cmd_srv_query_info: query succeeded\n"));
82
83                 display_srv_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
84                 display_srv_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
85                 display_srv_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
86         }
87         else
88         {
89                 DEBUG(5,("cmd_srv_query_info: query failed\n"));
90         }
91 }
92
93 /****************************************************************************
94 server enum connections
95 ****************************************************************************/
96 void cmd_srv_enum_conn(struct client_info *info)
97 {
98         fstring dest_srv;
99         fstring qual_srv;
100         fstring tmp;
101         SRV_CONN_INFO_CTR ctr;
102         ENUM_HND hnd;
103         uint32 info_level = 0;
104
105         BOOL res = True;
106
107         bzero(&ctr, sizeof(ctr));
108
109         fstrcpy(qual_srv, "\\\\");
110         fstrcat(qual_srv, info->myhostname);
111         strupper(qual_srv);
112
113         fstrcpy(dest_srv, "\\\\");
114         fstrcat(dest_srv, info->dest_host);
115         strupper(dest_srv);
116
117         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
118         {
119                 info_level = strtoul(tmp, (char**)NULL, 10);
120         }
121
122         DEBUG(4,("cmd_srv_enum_conn: server:%s info level: %d\n",
123                                 dest_srv, (int)info_level));
124
125         DEBUG(5, ("cmd_srv_enum_conn: smb_cli->fd:%d\n", smb_cli->fd));
126
127         /* open srvsvc session. */
128         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False;
129
130         hnd.ptr_hnd = 1;
131         hnd.handle = 0;
132
133         /* enumerate connections on server */
134         res = res ? do_srv_net_srv_conn_enum(smb_cli,
135                                 dest_srv, qual_srv,
136                     info_level, &ctr, 0xffffffff, &hnd) : False;
137
138         if (res)
139         {
140                 display_srv_conn_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
141                 display_srv_conn_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
142                 display_srv_conn_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
143         }
144
145         /* close the session */
146         cli_nt_session_close(smb_cli);
147
148         if (res)
149         {
150                 DEBUG(5,("cmd_srv_enum_conn: query succeeded\n"));
151         }
152         else
153         {
154                 DEBUG(5,("cmd_srv_enum_conn: query failed\n"));
155         }
156 }
157
158 /****************************************************************************
159 server enum shares
160 ****************************************************************************/
161 void cmd_srv_enum_shares(struct client_info *info)
162 {
163         fstring dest_srv;
164         fstring tmp;
165         SRV_SHARE_INFO_CTR ctr;
166         ENUM_HND hnd;
167         uint32 info_level = 1;
168
169         BOOL res = True;
170
171         bzero(&ctr, sizeof(ctr));
172
173         fstrcpy(dest_srv, "\\\\");
174         fstrcat(dest_srv, info->dest_host);
175         strupper(dest_srv);
176
177         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
178         {
179                 info_level = strtoul(tmp, (char**)NULL, 10);
180         }
181
182         DEBUG(4,("cmd_srv_enum_shares: server:%s info level: %d\n",
183                                 dest_srv, (int)info_level));
184
185         DEBUG(5, ("cmd_srv_enum_shares: smb_cli->fd:%d\n", smb_cli->fd));
186
187         /* open srvsvc session. */
188         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False;
189
190         hnd.ptr_hnd = 0;
191         hnd.handle = 0;
192
193         /* enumerate shares_files on server */
194         res = res ? do_srv_net_srv_share_enum(smb_cli,
195                                 dest_srv, 
196                     info_level, &ctr, 0xffffffff, &hnd) : False;
197
198         if (res)
199         {
200                 display_srv_share_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
201                 display_srv_share_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
202                 display_srv_share_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
203         }
204
205         /* close the session */
206         cli_nt_session_close(smb_cli);
207
208         if (res)
209         {
210                 DEBUG(5,("cmd_srv_enum_shares: query succeeded\n"));
211         }
212         else
213         {
214                 DEBUG(5,("cmd_srv_enum_shares: query failed\n"));
215         }
216 }
217
218 /****************************************************************************
219 server enum sessions
220 ****************************************************************************/
221 void cmd_srv_enum_sess(struct client_info *info)
222 {
223         fstring dest_srv;
224         fstring tmp;
225         SRV_SESS_INFO_CTR ctr;
226         ENUM_HND hnd;
227         uint32 info_level = 0;
228
229         BOOL res = True;
230
231         bzero(&ctr, sizeof(ctr));
232
233         fstrcpy(dest_srv, "\\\\");
234         fstrcat(dest_srv, info->dest_host);
235         strupper(dest_srv);
236
237         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
238         {
239                 info_level = strtoul(tmp, (char**)NULL, 10);
240         }
241
242         DEBUG(4,("cmd_srv_enum_sess: server:%s info level: %d\n",
243                                 dest_srv, (int)info_level));
244
245         DEBUG(5, ("cmd_srv_enum_sess: smb_cli->fd:%d\n", smb_cli->fd));
246
247         /* open srvsvc session. */
248         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False;
249
250         hnd.ptr_hnd = 1;
251         hnd.handle = 0;
252
253         /* enumerate sessions on server */
254         res = res ? do_srv_net_srv_sess_enum(smb_cli,
255                                 dest_srv, NULL, info_level, &ctr, 0x1000, &hnd) : False;
256
257         /* close the session */
258         cli_nt_session_close(smb_cli);
259
260         if (res)
261         {
262                 DEBUG(5,("cmd_srv_enum_sess: query succeeded\n"));
263         }
264         else
265         {
266                 DEBUG(5,("cmd_srv_enum_sess: query failed\n"));
267         }
268 }
269
270 /****************************************************************************
271 server enum files
272 ****************************************************************************/
273 void cmd_srv_enum_files(struct client_info *info)
274 {
275         fstring dest_srv;
276         fstring tmp;
277         SRV_FILE_INFO_CTR ctr;
278         ENUM_HND hnd;
279         uint32 info_level = 3;
280
281         BOOL res = True;
282
283         bzero(&ctr, sizeof(ctr));
284
285         fstrcpy(dest_srv, "\\\\");
286         fstrcat(dest_srv, info->dest_host);
287         strupper(dest_srv);
288
289         if (next_token(NULL, tmp, NULL, sizeof(tmp)-1))
290         {
291                 info_level = strtoul(tmp, (char**)NULL, 10);
292         }
293
294         DEBUG(4,("cmd_srv_enum_files: server:%s info level: %d\n",
295                                 dest_srv, (int)info_level));
296
297         DEBUG(5, ("cmd_srv_enum_files: smb_cli->fd:%d\n", smb_cli->fd));
298
299         /* open srvsvc session. */
300         res = res ? cli_nt_session_open(smb_cli, PIPE_SRVSVC, False) : False;
301
302         hnd.ptr_hnd = 1;
303         hnd.handle = 0;
304
305         /* enumerate files on server */
306         res = res ? do_srv_net_srv_file_enum(smb_cli,
307                                 dest_srv, NULL, info_level, &ctr, 0x1000, &hnd) : False;
308
309         if (res)
310         {
311                 display_srv_file_info_ctr(out_hnd, ACTION_HEADER   , &ctr);
312                 display_srv_file_info_ctr(out_hnd, ACTION_ENUMERATE, &ctr);
313                 display_srv_file_info_ctr(out_hnd, ACTION_FOOTER   , &ctr);
314         }
315
316         /* close the session */
317         cli_nt_session_close(smb_cli);
318
319         if (res)
320         {
321                 DEBUG(5,("cmd_srv_enum_files: query succeeded\n"));
322         }
323         else
324         {
325                 DEBUG(5,("cmd_srv_enum_files: query failed\n"));
326         }
327 }
328