3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1998,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
8 * Copyright (C) Paul Ashton 1997-1998.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 extern int DEBUGLEVEL;
34 /****************************************************************************
36 ****************************************************************************/
37 BOOL svc_open_sc_man( const char *srv_name, char *db_name,
43 SVC_Q_OPEN_SC_MAN q_o;
44 BOOL valid_pol = False;
46 struct cli_connection *con = NULL;
48 if (!cli_connection_init(srv_name, PIPE_SVCCTL, &con))
53 if (hnd == NULL) return False;
55 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
56 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
58 /* create and send a MSRPC command with api SVC_OPEN_SC_MAN */
60 DEBUG(4,("SVC Open SC_MAN\n"));
62 make_svc_q_open_sc_man(&q_o, srv_name, db_name, des_access);
64 /* turn parameters into data stream */
65 svc_io_q_open_sc_man("", &q_o, &buf, 0);
67 /* send the data on \PIPE\ */
68 if (rpc_con_pipe_req(con, SVC_OPEN_SC_MAN, &buf, &rbuf))
70 SVC_R_OPEN_SC_MAN r_o;
75 svc_io_r_open_sc_man("", &r_o, &rbuf, 0);
78 if (p && r_o.status != 0)
80 /* report error code */
81 DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
87 /* ok, at last: we're happy. return the policy handle */
88 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
90 valid_pol = register_policy_hnd(hnd) &&
91 set_policy_con(hnd, con,
92 cli_connection_unlink);
103 /****************************************************************************
104 do a SVC Open Service
105 ****************************************************************************/
106 BOOL svc_open_service( POLICY_HND *scm_hnd,
107 const char *srv_name,
113 SVC_Q_OPEN_SERVICE q_o;
114 BOOL valid_pol = False;
116 struct cli_connection *con = NULL;
118 if (!cli_connection_get(scm_hnd, &con))
123 if (hnd == NULL || scm_hnd == NULL) return False;
125 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
126 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
128 /* create and send a MSRPC command with api SVC_OPEN_SERVICE */
130 DEBUG(4,("SVC Open Service\n"));
132 make_svc_q_open_service(&q_o, scm_hnd, srv_name, des_access);
134 /* turn parameters into data stream */
135 svc_io_q_open_service("", &q_o, &buf, 0);
137 /* send the data on \PIPE\ */
138 if (rpc_con_pipe_req(con, SVC_OPEN_SERVICE, &buf, &rbuf))
140 SVC_R_OPEN_SERVICE r_o;
145 svc_io_r_open_service("", &r_o, &rbuf, 0);
146 p = rbuf.offset != 0;
148 if (p && r_o.status != 0)
150 /* report error code */
151 DEBUG(1,("SVC_OPEN_SC_MAN: %s\n", get_nt_error_msg(r_o.status)));
157 /* ok, at last: we're happy. return the policy handle */
158 memcpy(hnd, r_o.pol.data, sizeof(hnd->data));
159 valid_pol = register_policy_hnd(hnd) &&
160 set_policy_con(hnd, con, NULL);
171 /****************************************************************************
172 do a SVC Enumerate Services
173 ****************************************************************************/
174 BOOL svc_enum_svcs( POLICY_HND *hnd,
175 uint32 services_type, uint32 services_state,
176 uint32 *buf_size, uint32 *resume_hnd,
178 ENUM_SRVC_STATUS **svcs, uint32 *num_svcs)
182 SVC_Q_ENUM_SVCS_STATUS q_o;
183 BOOL valid_pol = False;
185 struct cli_connection *con = NULL;
187 if (!cli_connection_get(hnd, &con))
192 if (hnd == NULL || buf_size == NULL || dos_error == NULL || num_svcs == NULL)
197 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
198 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
200 /* create and send a MSRPC command with api SVC_ENUM_SVCS_STATUS */
202 DEBUG(4,("SVC Enum Services Status\n"));
204 make_svc_q_enum_svcs_status(&q_o, hnd,
205 services_type, services_state,
206 *buf_size, *resume_hnd);
208 /* turn parameters into data stream */
209 svc_io_q_enum_svcs_status("", &q_o, &buf, 0);
211 /* send the data on \PIPE\ */
212 if (rpc_con_pipe_req(con, SVC_ENUM_SVCS_STATUS, &buf, &rbuf))
214 SVC_R_ENUM_SVCS_STATUS r_o;
219 svc_io_r_enum_svcs_status("", &r_o, &rbuf, 0);
220 p = rbuf.offset != 0;
222 if (p && r_o.dos_status != 0)
226 if (r_o.dos_status != ERRmoredata)
228 smb_safe_err_msg(ERRDOS, r_o.dos_status,
229 errmsg, sizeof(errmsg));
230 /* report error code */
231 DEBUG(1,("SVC_ENUM_SVCS_STATUS: %s\n", errmsg));
233 p = r_o.dos_status == ERRmoredata;
239 (*num_svcs) = r_o.num_svcs;
240 (*resume_hnd) = get_enum_hnd(&r_o.resume_hnd);
241 (*buf_size) = r_o.more_buf_size;
242 (*dos_error) = r_o.dos_status;
254 /****************************************************************************
255 do a SVC Stop Service
256 ****************************************************************************/
257 BOOL svc_stop_service( POLICY_HND *hnd,
262 SVC_Q_STOP_SERVICE q_c;
263 BOOL valid_cfg = False;
265 struct cli_connection *con = NULL;
267 if (!cli_connection_get(hnd, &con))
272 if (hnd == NULL) return False;
274 /* create and send a MSRPC command with api SVC_STOP_SERVICE */
276 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
277 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
279 DEBUG(4,("SVC Stop Service\n"));
281 /* store the parameters */
282 make_svc_q_stop_service(&q_c, hnd, unknown);
284 /* turn parameters into data stream */
285 svc_io_q_stop_service("", &q_c, &buf, 0);
287 /* send the data on \PIPE\ */
288 if (rpc_con_pipe_req(con, SVC_STOP_SERVICE, &buf, &rbuf))
290 SVC_R_STOP_SERVICE r_c;
295 svc_io_r_stop_service("", &r_c, &rbuf, 0);
296 p = rbuf.offset != 0;
298 if (p && r_c.status != 0)
300 /* report error code */
301 DEBUG(1,("SVC_START_SERVICE: %s\n", get_nt_error_msg(r_c.status)));
318 /****************************************************************************
319 do a SVC Start Service
320 ****************************************************************************/
321 BOOL svc_start_service( POLICY_HND *hnd,
327 SVC_Q_START_SERVICE q_c;
328 BOOL valid_cfg = False;
330 struct cli_connection *con = NULL;
332 if (!cli_connection_get(hnd, &con))
337 if (hnd == NULL) return False;
339 /* create and send a MSRPC command with api SVC_START_SERVICE */
341 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
342 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
344 DEBUG(4,("SVC Start Service\n"));
346 /* store the parameters */
347 make_svc_q_start_service(&q_c, hnd, argc, argv);
349 /* turn parameters into data stream */
350 svc_io_q_start_service("", &q_c, &buf, 0);
352 /* send the data on \PIPE\ */
353 if (rpc_con_pipe_req(con, SVC_START_SERVICE, &buf, &rbuf))
355 SVC_R_START_SERVICE r_c;
360 svc_io_r_start_service("", &r_c, &rbuf, 0);
361 p = rbuf.offset != 0;
363 if (p && r_c.status != 0)
365 /* report error code */
366 DEBUG(1,("SVC_START_SERVICE: %s\n", get_nt_error_msg(r_c.status)));
383 /****************************************************************************
384 do a SVC Query Service Config
385 ****************************************************************************/
386 BOOL svc_query_svc_cfg( POLICY_HND *hnd,
387 QUERY_SERVICE_CONFIG *cfg,
392 SVC_Q_QUERY_SVC_CONFIG q_c;
393 BOOL valid_cfg = False;
395 struct cli_connection *con = NULL;
397 if (!cli_connection_get(hnd, &con))
402 if (hnd == NULL || buf_size == NULL) return False;
404 /* create and send a MSRPC command with api SVC_QUERY_SVC_CONFIG */
406 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
407 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
409 DEBUG(4,("SVC Query Service Config\n"));
411 /* store the parameters */
412 make_svc_q_query_svc_config(&q_c, hnd, *buf_size);
414 /* turn parameters into data stream */
415 svc_io_q_query_svc_config("", &q_c, &buf, 0);
417 /* send the data on \PIPE\ */
418 if (rpc_con_pipe_req(con, SVC_QUERY_SVC_CONFIG, &buf, &rbuf))
420 SVC_R_QUERY_SVC_CONFIG r_c;
428 svc_io_r_query_svc_config("", &r_c, &rbuf, 0);
429 p = rbuf.offset != 0;
431 if (p && r_c.status != 0)
433 /* report error code */
434 DEBUG(1,("SVC_QUERY_SVC_CONFIG: %s\n", get_nt_error_msg(r_c.status)));
440 valid_cfg = r_c.buf_size != 0;
451 /****************************************************************************
453 ****************************************************************************/
454 BOOL svc_close(POLICY_HND *hnd)
459 BOOL valid_close = False;
461 struct cli_connection *con = NULL;
463 if (!cli_connection_get(hnd, &con))
468 if (hnd == NULL) return False;
470 /* create and send a MSRPC command with api SVC_CLOSE */
472 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
473 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
475 DEBUG(4,("SVC Close\n"));
477 /* store the parameters */
478 make_svc_q_close(&q_c, hnd);
480 /* turn parameters into data stream */
481 svc_io_q_close("", &q_c, &buf, 0);
483 /* send the data on \PIPE\ */
484 if (rpc_con_pipe_req(con, SVC_CLOSE, &buf, &rbuf))
491 svc_io_r_close("", &r_c, &rbuf, 0);
492 p = rbuf.offset != 0;
494 if (p && r_c.status != 0)
496 /* report error code */
497 DEBUG(1,("SVC_CLOSE: %s\n", get_nt_error_msg(r_c.status)));
503 /* check that the returned policy handle is all zeros */
507 for (i = 0; i < sizeof(r_c.pol.data); i++)
509 if (r_c.pol.data[i] != 0)
517 DEBUG(1,("SVC_CLOSE: non-zero handle returned\n"));
522 close_policy_hnd(hnd);
530 /****************************************************************************
531 do a SVC Change Service Config
532 ****************************************************************************/
533 BOOL svc_change_svc_cfg( POLICY_HND *hnd,
534 uint32 service_type, uint32 start_type,
536 uint32 error_control,
537 char* bin_path_name, char* load_order_grp,
539 char* dependencies, char* service_start_name,
545 SVC_Q_CHANGE_SVC_CONFIG q_c;
546 BOOL valid_cfg = False;
548 struct cli_connection *con = NULL;
550 if (!cli_connection_get(hnd, &con))
555 if (hnd == NULL) return False;
557 /* create and send a MSRPC command with api SVC_CHANGE_SVC_CONFIG */
559 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
560 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
562 DEBUG(4,("SVC Change Service Config\n"));
564 /* store the parameters */
565 make_svc_q_change_svc_config(&q_c, hnd,
566 service_type, start_type,
567 unknown_0, error_control,
568 bin_path_name, load_order_grp,
570 dependencies, service_start_name,
571 password, disp_name);
573 /* turn parameters into data stream */
574 svc_io_q_change_svc_config("", &q_c, &buf, 0);
576 /* send the data on \PIPE\ */
577 if (rpc_con_pipe_req(con, SVC_CHANGE_SVC_CONFIG, &buf, &rbuf))
579 SVC_R_CHANGE_SVC_CONFIG r_c;
584 svc_io_r_change_svc_config("", &r_c, &rbuf, 0);
585 p = rbuf.offset != 0;
587 if (p && r_c.status != 0)
589 /* report error code */
590 DEBUG(1,("SVC_CHANGE_SVC_CONFIG: %s\n", get_nt_error_msg(r_c.status)));