2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-1998,2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1998,2000,
7 * Copyright (C) Paul Ashton 1997-1998,2000,
8 * Copyright (C) Elrond 2000.
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.
27 #include "rpc_parse.h"
28 #include "rpc_client.h"
30 extern int DEBUGLEVEL
;
32 /****************************************************************************
34 ****************************************************************************/
35 BOOL
svc_open_sc_man(const char *srv_name
, char *db_name
,
36 uint32 des_access
, POLICY_HND
*hnd
)
40 SVC_Q_OPEN_SC_MAN q_o
;
41 BOOL valid_pol
= False
;
43 struct cli_connection
*con
= NULL
;
45 if (!cli_connection_init(srv_name
, PIPE_SVCCTL
, &con
))
53 prs_init(&buf
, 0, 4, False
);
54 prs_init(&rbuf
, 0, 4, True
);
56 /* create and send a MSRPC command with api SVC_OPEN_SC_MAN */
58 DEBUG(4, ("SVC Open SC_MAN\n"));
60 make_svc_q_open_sc_man(&q_o
, srv_name
, db_name
, des_access
);
62 /* turn parameters into data stream */
63 if (svc_io_q_open_sc_man("", &q_o
, &buf
, 0) &&
64 rpc_con_pipe_req(con
, SVC_OPEN_SC_MAN
, &buf
, &rbuf
))
66 SVC_R_OPEN_SC_MAN r_o
;
71 svc_io_r_open_sc_man("", &r_o
, &rbuf
, 0);
74 if (p
&& r_o
.status
!= 0)
76 /* report error code */
77 DEBUG(1, ("SVC_OPEN_SC_MAN: %s\n",
78 get_nt_error_msg(r_o
.status
)));
84 /* ok, at last: we're happy. return the policy handle */
88 register_policy_hnd(get_global_hnd_cache(),
91 && set_policy_con(get_global_hnd_cache(), hnd
,
92 con
, cli_connection_unlink
);
103 /****************************************************************************
104 do a SVC Open Service
105 ****************************************************************************/
106 BOOL
svc_open_service(POLICY_HND
*scm_hnd
, const char *srv_name
,
107 uint32 des_access
, POLICY_HND
*hnd
)
111 SVC_Q_OPEN_SERVICE q_o
;
112 BOOL valid_pol
= False
;
114 struct cli_connection
*con
= NULL
;
116 if (!cli_connection_get(scm_hnd
, &con
))
121 if (hnd
== NULL
|| scm_hnd
== NULL
)
124 prs_init(&buf
, 0, 4, False
);
125 prs_init(&rbuf
, 0, 4, True
);
127 /* create and send a MSRPC command with api SVC_OPEN_SERVICE */
129 DEBUG(4, ("SVC Open Service\n"));
131 make_svc_q_open_service(&q_o
, scm_hnd
, srv_name
, des_access
);
133 /* turn parameters into data stream */
134 if (svc_io_q_open_service("", &q_o
, &buf
, 0) &&
135 rpc_con_pipe_req(con
, SVC_OPEN_SERVICE
, &buf
, &rbuf
))
137 SVC_R_OPEN_SERVICE r_o
;
142 svc_io_r_open_service("", &r_o
, &rbuf
, 0);
143 p
= rbuf
.offset
!= 0;
145 if (p
&& r_o
.status
!= 0)
147 /* report error code */
148 DEBUG(1, ("SVC_OPEN_SC_MAN: %s\n",
149 get_nt_error_msg(r_o
.status
)));
155 /* ok, at last: we're happy. return the policy handle */
158 register_policy_hnd(get_global_hnd_cache(),
159 cli_con_sec_ctx(con
),
161 && set_policy_con(get_global_hnd_cache(), hnd
,
166 prs_free_data(&rbuf
);
167 prs_free_data(&buf
);
173 /****************************************************************************
174 do a SVC Enumerate Services
175 ****************************************************************************/
176 BOOL
svc_enum_svcs(POLICY_HND
*hnd
,
177 uint32 services_type
, uint32 services_state
,
178 uint32
*buf_size
, uint32
*resume_hnd
,
180 ENUM_SRVC_STATUS
**svcs
, uint32
*num_svcs
)
184 SVC_Q_ENUM_SVCS_STATUS q_o
;
185 BOOL valid_pol
= False
;
187 struct cli_connection
*con
= NULL
;
189 if (!cli_connection_get(hnd
, &con
))
194 if (hnd
== NULL
|| buf_size
== NULL
|| dos_error
== NULL
200 prs_init(&buf
, 0, 4, False
);
201 prs_init(&rbuf
, 0, 4, True
);
203 /* create and send a MSRPC command with api SVC_ENUM_SVCS_STATUS */
205 DEBUG(4, ("SVC Enum Services Status\n"));
207 make_svc_q_enum_svcs_status(&q_o
, hnd
,
208 services_type
, services_state
,
209 *buf_size
, *resume_hnd
);
211 /* turn parameters into data stream */
212 if (svc_io_q_enum_svcs_status("", &q_o
, &buf
, 0) &&
213 rpc_con_pipe_req(con
, SVC_ENUM_SVCS_STATUS
, &buf
, &rbuf
))
215 SVC_R_ENUM_SVCS_STATUS r_o
;
220 svc_io_r_enum_svcs_status("", &r_o
, &rbuf
, 0);
221 p
= rbuf
.offset
!= 0;
223 if (p
&& r_o
.dos_status
!= 0)
227 if (r_o
.dos_status
!= ERRmoredata
)
229 smb_safe_err_msg(ERRDOS
, r_o
.dos_status
,
230 errmsg
, sizeof(errmsg
));
231 /* report error code */
232 DEBUG(1, ("SVC_ENUM_SVCS_STATUS: %s\n",
235 p
= r_o
.dos_status
== ERRmoredata
;
241 (*num_svcs
) = r_o
.num_svcs
;
242 (*resume_hnd
) = get_enum_hnd(&r_o
.resume_hnd
);
243 (*buf_size
) = r_o
.more_buf_size
;
244 (*dos_error
) = r_o
.dos_status
;
249 prs_free_data(&rbuf
);
250 prs_free_data(&buf
);
256 /****************************************************************************
257 do a SVC Stop Service
258 ****************************************************************************/
259 BOOL
svc_stop_service(POLICY_HND
*hnd
, uint32 unknown
)
263 SVC_Q_STOP_SERVICE q_c
;
264 BOOL valid_cfg
= False
;
266 struct cli_connection
*con
= NULL
;
268 if (!cli_connection_get(hnd
, &con
))
276 /* create and send a MSRPC command with api SVC_STOP_SERVICE */
278 prs_init(&buf
, 0, 4, False
);
279 prs_init(&rbuf
, 0, 4, True
);
281 DEBUG(4, ("SVC Stop Service\n"));
283 /* store the parameters */
284 make_svc_q_stop_service(&q_c
, hnd
, unknown
);
286 /* turn parameters into data stream */
287 if (svc_io_q_stop_service("", &q_c
, &buf
, 0) &&
288 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",
302 get_nt_error_msg(r_c
.status
)));
312 prs_free_data(&rbuf
);
313 prs_free_data(&buf
);
319 /****************************************************************************
320 do a SVC Start Service
321 ****************************************************************************/
322 BOOL
svc_start_service(POLICY_HND
*hnd
, uint32 argc
, char **argv
)
326 SVC_Q_START_SERVICE q_c
;
327 BOOL valid_cfg
= False
;
329 struct cli_connection
*con
= NULL
;
331 if (!cli_connection_get(hnd
, &con
))
339 /* create and send a MSRPC command with api SVC_START_SERVICE */
341 prs_init(&buf
, 0, 4, False
);
342 prs_init(&rbuf
, 0, 4, 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 if (svc_io_q_start_service("", &q_c
, &buf
, 0) &&
351 rpc_con_pipe_req(con
, SVC_START_SERVICE
, &buf
, &rbuf
))
353 SVC_R_START_SERVICE r_c
;
358 svc_io_r_start_service("", &r_c
, &rbuf
, 0);
359 p
= rbuf
.offset
!= 0;
361 if (p
&& r_c
.status
!= 0)
363 /* report error code */
364 DEBUG(1, ("SVC_START_SERVICE: %s\n",
365 get_nt_error_msg(r_c
.status
)));
375 prs_free_data(&rbuf
);
376 prs_free_data(&buf
);
382 /****************************************************************************
383 do a SVC Query Service Config
384 ****************************************************************************/
385 BOOL
svc_query_svc_cfg(POLICY_HND
*hnd
,
386 QUERY_SERVICE_CONFIG
*cfg
, uint32
*buf_size
)
390 SVC_Q_QUERY_SVC_CONFIG q_c
;
391 BOOL valid_cfg
= False
;
393 struct cli_connection
*con
= NULL
;
395 if (!cli_connection_get(hnd
, &con
))
400 if (hnd
== NULL
|| buf_size
== NULL
)
403 /* create and send a MSRPC command with api SVC_QUERY_SVC_CONFIG */
405 prs_init(&buf
, 0, 4, False
);
406 prs_init(&rbuf
, 0, 4, True
);
408 DEBUG(4, ("SVC Query Service Config\n"));
410 /* store the parameters */
411 make_svc_q_query_svc_config(&q_c
, hnd
, *buf_size
);
413 /* turn parameters into data stream */
414 if (svc_io_q_query_svc_config("", &q_c
, &buf
, 0) &&
415 rpc_con_pipe_req(con
, SVC_QUERY_SVC_CONFIG
, &buf
, &rbuf
))
417 SVC_R_QUERY_SVC_CONFIG r_c
;
425 svc_io_r_query_svc_config("", &r_c
, &rbuf
, 0);
426 p
= rbuf
.offset
!= 0;
428 if (p
&& r_c
.status
!= 0)
430 /* report error code */
431 DEBUG(1, ("SVC_QUERY_SVC_CONFIG: %s\n",
432 get_nt_error_msg(r_c
.status
)));
438 valid_cfg
= r_c
.buf_size
!= 0;
442 prs_free_data(&rbuf
);
443 prs_free_data(&buf
);
449 /****************************************************************************
451 ****************************************************************************/
452 BOOL
svc_close(POLICY_HND
*hnd
)
457 BOOL valid_close
= False
;
459 struct cli_connection
*con
= NULL
;
461 if (!cli_connection_get(hnd
, &con
))
469 /* create and send a MSRPC command with api SVC_CLOSE */
471 prs_init(&buf
, 0, 4, False
);
472 prs_init(&rbuf
, 0, 4, True
);
474 DEBUG(4, ("SVC Close\n"));
476 /* store the parameters */
477 make_svc_q_close(&q_c
, hnd
);
479 /* turn parameters into data stream */
480 if (svc_io_q_close("", &q_c
, &buf
, 0) &&
481 rpc_con_pipe_req(con
, SVC_CLOSE
, &buf
, &rbuf
))
488 svc_io_r_close("", &r_c
, &rbuf
, 0);
489 p
= rbuf
.offset
!= 0;
491 if (p
&& r_c
.status
!= 0)
493 /* report error code */
494 DEBUG(1, ("SVC_CLOSE: %s\n",
495 get_nt_error_msg(r_c
.status
)));
505 close_policy_hnd(get_global_hnd_cache(), hnd
);
507 prs_free_data(&rbuf
);
508 prs_free_data(&buf
);
513 /****************************************************************************
514 do a SVC Change Service Config
515 ****************************************************************************/
516 BOOL
svc_change_svc_cfg(POLICY_HND
*hnd
,
517 uint32 service_type
, uint32 start_type
,
518 uint32 unknown_0
, uint32 error_control
,
519 char *bin_path_name
, char *load_order_grp
,
521 char *dependencies
, char *service_start_name
,
522 char *password
, char *disp_name
)
526 SVC_Q_CHANGE_SVC_CONFIG q_c
;
527 BOOL valid_cfg
= False
;
529 struct cli_connection
*con
= NULL
;
531 if (!cli_connection_get(hnd
, &con
))
539 /* create and send a MSRPC command with api SVC_CHANGE_SVC_CONFIG */
541 prs_init(&buf
, 0, 4, False
);
542 prs_init(&rbuf
, 0, 4, True
);
544 DEBUG(4, ("SVC Change Service Config\n"));
546 /* store the parameters */
547 make_svc_q_change_svc_config(&q_c
, hnd
,
548 service_type
, start_type
,
549 unknown_0
, error_control
,
550 bin_path_name
, load_order_grp
,
552 dependencies
, service_start_name
,
553 password
, disp_name
);
555 /* turn parameters into data stream */
556 if (svc_io_q_change_svc_config("", &q_c
, &buf
, 0) &&
557 rpc_con_pipe_req(con
, SVC_CHANGE_SVC_CONFIG
, &buf
, &rbuf
))
559 SVC_R_CHANGE_SVC_CONFIG r_c
;
564 svc_io_r_change_svc_config("", &r_c
, &rbuf
, 0);
565 p
= rbuf
.offset
!= 0;
567 if (p
&& r_c
.status
!= 0)
569 /* report error code */
570 DEBUG(1, ("SVC_CHANGE_SVC_CONFIG: %s\n",
571 get_nt_error_msg(r_c
.status
)));
581 prs_free_data(&rbuf
);
582 prs_free_data(&buf
);
587 /****************************************************************************
589 ****************************************************************************/
590 BOOL
svc_unknown_3(const POLICY_HND
*scman_hnd
, POLICY_HND
*hnd
)
595 BOOL valid_req
= False
;
597 struct cli_connection
*con
= NULL
;
599 if (scman_hnd
== NULL
)
602 if (!cli_connection_get(scman_hnd
, &con
))
607 prs_init(&buf
, 0, 4, False
);
608 prs_init(&rbuf
, 0, 4, True
);
610 DEBUG(4, ("SVC Unknown 3\n"));
612 /* store the parameters */
613 q_c
.scman_hnd
= *scman_hnd
;
615 /* turn parameters into data stream */
616 if (svc_io_q_unknown_3("", &q_c
, &buf
, 0) &&
617 rpc_con_pipe_req(con
, SVC_UNKNOWN_3
, &buf
, &rbuf
))
624 p
= svc_io_r_unknown_3("", &r_o
, &rbuf
, 0);
627 p
= (rbuf
.offset
!= 0);
629 if (p
&& r_o
.status
!= 0)
631 /* report error code */
632 DEBUG(1, ("SVC_OPEN_SC_MAN: %s\n",
633 get_nt_error_msg(r_o
.status
)));
639 /* ok, at last: we're happy. return the policy handle */
642 register_policy_hnd(get_global_hnd_cache(),
643 cli_con_sec_ctx(con
),
645 && set_policy_con(get_global_hnd_cache(), hnd
,
646 con
, cli_connection_unlink
);
649 policy_hnd_set_name(get_global_hnd_cache(),
650 hnd
, "unknown 3 handle");
655 prs_free_data(&rbuf
);
656 prs_free_data(&buf
);
661 /****************************************************************************
662 do a SVC Stop Service
663 ****************************************************************************/
664 uint32
svc_get_svc_sec(const POLICY_HND
*hnd
, uint32 sec_info
,
665 /* [in,out] */ uint32
*buf_size
,
671 BOOL status
= NT_STATUS_INVALID_PARAMETER
;
673 if (hnd
== NULL
|| buf_size
== NULL
)
674 return NT_STATUS_INVALID_PARAMETER
;
676 /* create and send a MSRPC command with api SVC_STOP_SERVICE */
678 prs_init(&buf
, 0, 4, False
);
679 prs_init(&rbuf
, 0, 4, True
);
681 DEBUG(4, ("SVC Stop Service\n"));
683 /* store the parameters */
685 q
.sec_info
= sec_info
;
686 q
.buf_size
= *buf_size
;
688 /* turn parameters into data stream */
689 if (svc_io_q_get_svc_sec("", &q
, &buf
, 0)
690 && rpc_hnd_pipe_req(hnd
, SVC_GET_SVC_SEC
, &buf
, &rbuf
))
695 if(svc_io_r_get_svc_sec("", &r
, &rbuf
, 0)
699 if(status
!= NT_STATUS_NOPROBLEMO
)
700 DEBUG(1, ("SVC_GET_SVC_SEC: %s\n",
701 get_nt_error_msg(status
)));
702 *buf_size
= r
.buf_size
;
723 prs_free_data(&rbuf
);
724 prs_free_data(&buf
);