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