2 Unix SMB/Netbios implementation.
4 NT Domain Authentication SMB / MSRPC client
5 Copyright (C) Andrew Tridgell 1994-1997
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997
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.
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.
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.
32 extern int DEBUGLEVEL;
36 void svc_display_query_svc_cfg(const QUERY_SERVICE_CONFIG *cfg)
38 display_query_svc_cfg(out_hnd, ACTION_HEADER , cfg);
39 display_query_svc_cfg(out_hnd, ACTION_ENUMERATE, cfg);
40 display_query_svc_cfg(out_hnd, ACTION_FOOTER , cfg);
43 BOOL svc_query_service( POLICY_HND *pol_scm,
45 SVC_QUERY_FN(svc_query_fn))
50 QUERY_SERVICE_CONFIG cfg;
51 uint32 svc_buf_size = 0x8000;
53 res2 = res2 ? svc_open_service( pol_scm,
56 res3 = res2 ? svc_query_svc_cfg( &pol_svc, &cfg,
57 &svc_buf_size) : False;
59 if (res3 && svc_query_fn != NULL)
64 res2 = res2 ? svc_close(&pol_svc) : False;
69 /****************************************************************************
71 ****************************************************************************/
72 void cmd_svc_info(struct client_info *info, int argc, char *argv[])
82 fstrcpy(srv_name, "\\\\");
83 fstrcat(srv_name, info->dest_host);
86 DEBUG(4,("cmd_svc_info: server:%s\n", srv_name));
90 report(out_hnd,"svcinfo <service name>\n");
96 /* open service control manager receive a policy handle */
97 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000004,
100 res1 = svc_query_service(&pol_scm, svc_name,
101 svc_display_query_svc_cfg);
103 res = res ? svc_close(&pol_scm) : False;
107 DEBUG(5,("cmd_svc_info: query succeeded\n"));
111 DEBUG(5,("cmd_svc_info: query failed\n"));
115 static void svc_display_svc_info(const ENUM_SRVC_STATUS *svc)
117 display_svc_info(out_hnd, ACTION_HEADER , svc);
118 display_svc_info(out_hnd, ACTION_ENUMERATE, svc);
119 display_svc_info(out_hnd, ACTION_FOOTER , svc);
122 /****************************************************************************
124 ****************************************************************************/
125 BOOL msrpc_svc_enum(const char* srv_name,
126 ENUM_SRVC_STATUS **svcs,
128 SVC_INFO_FN(info_fn),
129 SVC_QUERY_FN(query_fn))
134 uint32 resume_hnd = 0;
136 uint32 dos_error = 0;
143 /* open service control manager receive a policy handle */
144 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000004,
158 /* enumerate services */
159 res1 = res ? svc_enum_svcs( &pol_scm,
160 0x00000030, 0x00000003,
161 &buf_size, &resume_hnd, &dos_error,
162 svcs, num_svcs) : False;
164 } while (res1 && dos_error == ERRmoredata);
166 for (i = 0; i < (*num_svcs) && (*svcs) != NULL && res1; i++)
170 unistr_to_ascii(svc_name, (*svcs)[i].uni_srvc_name.buffer,
173 if (query_fn != NULL)
175 res1 = svc_query_service(&pol_scm,
178 else if (info_fn != NULL)
180 info_fn(&(*svcs)[i]);
184 res = res ? svc_close(&pol_scm) : False;
189 /****************************************************************************
191 ****************************************************************************/
192 void cmd_svc_enum(struct client_info *info, int argc, char *argv[])
194 ENUM_SRVC_STATUS *svcs = NULL;
196 BOOL request_info = False;
200 fstrcpy(srv_name, "\\\\");
201 fstrcat(srv_name, info->dest_host);
204 while ((opt = getopt(argc, argv,"i")) != EOF)
216 report(out_hnd,"Services\n");
217 report(out_hnd,"--------\n");
219 msrpc_svc_enum(srv_name, &svcs, &num_svcs,
220 request_info ? NULL : svc_display_svc_info,
221 request_info ? svc_display_query_svc_cfg : NULL);
229 /****************************************************************************
231 ****************************************************************************/
232 void cmd_svc_stop(struct client_info *info, int argc, char *argv[])
243 fstrcpy(srv_name, "\\\\");
244 fstrcat(srv_name, info->dest_host);
247 DEBUG(4,("cmd_svc_stop: server:%s\n", srv_name));
251 report(out_hnd,"svcstop <service name>\n");
257 /* open service control manager receive a policy handle */
258 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000000,
261 res1 = res ? svc_open_service( &pol_scm,
262 svc_name, 0x00000020,
264 res2 = res1 ? svc_stop_service(&pol_svc, 0x1) : False;
266 res1 = res1 ? svc_close(&pol_svc) : False;
267 res = res ? svc_close(&pol_scm) : False;
271 report(out_hnd,"Stopped Service %s\n", svc_name);
272 DEBUG(5,("cmd_svc_stop: succeeded\n"));
275 report(out_hnd,"Failed Service Stopped (%s)\n", svc_name);
277 DEBUG(5,("cmd_svc_stop: failed\n"));
281 /****************************************************************************
283 ****************************************************************************/
284 void cmd_svc_start(struct client_info *info, int argc, char *argv[])
295 fstrcpy(srv_name, "\\\\");
296 fstrcat(srv_name, info->dest_host);
299 DEBUG(4,("cmd_svc_start: server:%s\n", srv_name));
303 report(out_hnd,"svcstart <service name> [arg 0] [arg 1]...]\n");
315 /* open service control manager receive a policy handle */
316 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000000,
319 res1 = res ? svc_open_service( &pol_scm,
320 svc_name, 0x80000010,
322 res2 = res1 ? svc_start_service( &pol_svc, argc, argv) : False;
324 res1 = res1 ? svc_close(&pol_svc) : False;
325 res = res ? svc_close(&pol_scm) : False;
329 report(out_hnd,"Started Service %s\n", svc_name);
330 DEBUG(5,("cmd_svc_start: succeeded\n"));
333 report(out_hnd,"Failed Service Startup (%s)\n", svc_name);
335 DEBUG(5,("cmd_svc_start: failed\n"));
339 /****************************************************************************
341 ****************************************************************************/
342 void cmd_svc_set(struct client_info *info, int argc, char *argv[])
348 QUERY_SERVICE_CONFIG cfg;
349 uint32 svc_buf_size = 0x8000;
357 fstrcpy(srv_name, "\\\\");
358 fstrcat(srv_name, info->dest_host);
361 DEBUG(4,("cmd_svc_set: server:%s\n", srv_name));
365 report(out_hnd,"svcset <service name>\n");
371 /* open service control manager receive a policy handle */
372 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000004,
375 res2 = res ? svc_open_service( &pol_scm,
376 svc_name, 0x80000001,
378 res3 = res2 ? svc_query_svc_cfg( &pol_svc, &cfg,
379 &svc_buf_size) : False;
383 res3 = svc_change_svc_cfg(&pol_svc,
390 NULL, "administrator", NULL, NULL);
394 res2 = res2 ? svc_close(&pol_svc) : False;
396 res = res ? svc_close(&pol_scm) : False;
400 DEBUG(5,("cmd_svc_set: change succeeded\n"));
404 DEBUG(5,("cmd_svc_set: change failed\n"));