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);
207 while ((opt = getopt(argc, argv,"i")) != EOF)
219 report(out_hnd,"Services\n");
220 report(out_hnd,"--------\n");
222 msrpc_svc_enum(srv_name, &svcs, &num_svcs,
223 request_info ? NULL : svc_display_svc_info,
224 request_info ? svc_display_query_svc_cfg : NULL);
232 /****************************************************************************
234 ****************************************************************************/
235 void cmd_svc_stop(struct client_info *info, int argc, char *argv[])
246 fstrcpy(srv_name, "\\\\");
247 fstrcat(srv_name, info->dest_host);
250 DEBUG(4,("cmd_svc_stop: server:%s\n", srv_name));
254 report(out_hnd,"svcstop <service name>\n");
260 /* open service control manager receive a policy handle */
261 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000000,
264 res1 = res ? svc_open_service( &pol_scm,
265 svc_name, 0x00000020,
267 res2 = res1 ? svc_stop_service(&pol_svc, 0x1) : False;
269 res1 = res1 ? svc_close(&pol_svc) : False;
270 res = res ? svc_close(&pol_scm) : False;
274 report(out_hnd,"Stopped Service %s\n", svc_name);
275 DEBUG(5,("cmd_svc_stop: succeeded\n"));
278 report(out_hnd,"Failed Service Stopped (%s)\n", svc_name);
280 DEBUG(5,("cmd_svc_stop: failed\n"));
284 /****************************************************************************
286 ****************************************************************************/
287 void cmd_svc_start(struct client_info *info, int argc, char *argv[])
298 fstrcpy(srv_name, "\\\\");
299 fstrcat(srv_name, info->dest_host);
302 DEBUG(4,("cmd_svc_start: server:%s\n", srv_name));
306 report(out_hnd,"svcstart <service name> [arg 0] [arg 1]...]\n");
318 /* open service control manager receive a policy handle */
319 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000000,
322 res1 = res ? svc_open_service( &pol_scm,
323 svc_name, 0x80000010,
325 res2 = res1 ? svc_start_service( &pol_svc, argc, argv) : False;
327 res1 = res1 ? svc_close(&pol_svc) : False;
328 res = res ? svc_close(&pol_scm) : False;
332 report(out_hnd,"Started Service %s\n", svc_name);
333 DEBUG(5,("cmd_svc_start: succeeded\n"));
336 report(out_hnd,"Failed Service Startup (%s)\n", svc_name);
338 DEBUG(5,("cmd_svc_start: failed\n"));
342 /****************************************************************************
344 ****************************************************************************/
345 void cmd_svc_set(struct client_info *info, int argc, char *argv[])
351 QUERY_SERVICE_CONFIG cfg;
352 uint32 svc_buf_size = 0x8000;
360 fstrcpy(srv_name, "\\\\");
361 fstrcat(srv_name, info->dest_host);
364 DEBUG(4,("cmd_svc_set: server:%s\n", srv_name));
368 report(out_hnd,"svcset <service name>\n");
374 /* open service control manager receive a policy handle */
375 res = res ? svc_open_sc_man( srv_name, NULL, 0x80000004,
378 res2 = res ? svc_open_service( &pol_scm,
379 svc_name, 0x80000001,
381 res3 = res2 ? svc_query_svc_cfg( &pol_svc, &cfg,
382 &svc_buf_size) : False;
386 res3 = svc_change_svc_cfg(&pol_svc,
393 NULL, "administrator", NULL, NULL);
397 res2 = res2 ? svc_close(&pol_svc) : False;
399 res = res ? svc_close(&pol_scm) : False;
403 DEBUG(5,("cmd_svc_set: change succeeded\n"));
407 DEBUG(5,("cmd_svc_set: change failed\n"));