2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (C) Marcin Krzysztof Porwit 2005.
7 * Largely Rewritten (Again) by:
8 * Copyright (C) Gerald (Jerry) Carter 2005.
9 * Copyright (C) Guenther Deschner 2008,2009.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #define DBGC_CLASS DBGC_RPC_SRV
30 struct service_control_op
{
32 SERVICE_CONTROL_OPS
*ops
;
35 /* handle external services */
36 extern SERVICE_CONTROL_OPS rcinit_svc_ops
;
38 /* builtin services (see service_db.c and services/svc_*.c */
39 extern SERVICE_CONTROL_OPS spoolss_svc_ops
;
40 extern SERVICE_CONTROL_OPS netlogon_svc_ops
;
41 extern SERVICE_CONTROL_OPS winreg_svc_ops
;
42 extern SERVICE_CONTROL_OPS wins_svc_ops
;
44 /* make sure this number patches the number of builtin
45 SERVICE_CONTROL_OPS structure listed above */
47 #define SVCCTL_NUM_INTERNAL_SERVICES 4
49 struct service_control_op
*svcctl_ops
;
51 static const struct generic_mapping scm_generic_map
=
52 { SC_MANAGER_READ_ACCESS
, SC_MANAGER_WRITE_ACCESS
, SC_MANAGER_EXECUTE_ACCESS
, SC_MANAGER_ALL_ACCESS
};
53 static const struct generic_mapping svc_generic_map
=
54 { SERVICE_READ_ACCESS
, SERVICE_WRITE_ACCESS
, SERVICE_EXECUTE_ACCESS
, SERVICE_ALL_ACCESS
};
57 /********************************************************************
58 ********************************************************************/
60 bool init_service_op_table( void )
62 const char **service_list
= lp_svcctl_list();
63 int num_services
= SVCCTL_NUM_INTERNAL_SERVICES
+ str_list_length( service_list
);
66 if ( !(svcctl_ops
= TALLOC_ARRAY( NULL
, struct service_control_op
, num_services
+1)) ) {
67 DEBUG(0,("init_service_op_table: talloc() failed!\n"));
71 /* services listed in smb.conf get the rc.init interface */
73 for ( i
=0; service_list
&& service_list
[i
]; i
++ ) {
74 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, service_list
[i
] );
75 svcctl_ops
[i
].ops
= &rcinit_svc_ops
;
78 /* add builtin services */
80 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "Spooler" );
81 svcctl_ops
[i
].ops
= &spoolss_svc_ops
;
84 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "NETLOGON" );
85 svcctl_ops
[i
].ops
= &netlogon_svc_ops
;
88 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "RemoteRegistry" );
89 svcctl_ops
[i
].ops
= &winreg_svc_ops
;
92 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "WINS" );
93 svcctl_ops
[i
].ops
= &wins_svc_ops
;
96 /* NULL terminate the array */
98 svcctl_ops
[i
].name
= NULL
;
99 svcctl_ops
[i
].ops
= NULL
;
104 /********************************************************************
105 ********************************************************************/
107 static struct service_control_op
* find_service_by_name( const char *name
)
111 for ( i
=0; svcctl_ops
[i
].name
; i
++ ) {
112 if ( strequal( name
, svcctl_ops
[i
].name
) )
113 return &svcctl_ops
[i
];
118 /********************************************************************
119 ********************************************************************/
121 static NTSTATUS
svcctl_access_check( SEC_DESC
*sec_desc
, NT_USER_TOKEN
*token
,
122 uint32 access_desired
, uint32
*access_granted
)
124 if ( geteuid() == sec_initial_uid() ) {
125 DEBUG(5,("svcctl_access_check: using root's token\n"));
126 token
= get_root_nt_token();
129 return se_access_check( sec_desc
, token
, access_desired
, access_granted
);
132 /********************************************************************
133 ********************************************************************/
135 static SEC_DESC
* construct_scm_sd( TALLOC_CTX
*ctx
)
143 /* basic access for Everyone */
145 init_sec_ace(&ace
[i
++], &global_sid_World
,
146 SEC_ACE_TYPE_ACCESS_ALLOWED
, SC_MANAGER_READ_ACCESS
, 0);
148 /* Full Access 'BUILTIN\Administrators' */
150 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
,
151 SEC_ACE_TYPE_ACCESS_ALLOWED
, SC_MANAGER_ALL_ACCESS
, 0);
154 /* create the security descriptor */
156 if ( !(theacl
= make_sec_acl(ctx
, NT4_ACL_REVISION
, i
, ace
)) )
159 if ( !(sd
= make_sec_desc(ctx
, SECURITY_DESCRIPTOR_REVISION_1
,
160 SEC_DESC_SELF_RELATIVE
, NULL
, NULL
, NULL
,
167 /******************************************************************
168 Find a registry key handle and return a SERVICE_INFO
169 *****************************************************************/
171 static SERVICE_INFO
*find_service_info_by_hnd(pipes_struct
*p
, struct policy_handle
*hnd
)
173 SERVICE_INFO
*service_info
= NULL
;
175 if( !find_policy_by_hnd( p
, hnd
, (void **)(void *)&service_info
) ) {
176 DEBUG(2,("find_service_info_by_hnd: handle not found\n"));
183 /******************************************************************
184 *****************************************************************/
186 static WERROR
create_open_service_handle( pipes_struct
*p
, struct policy_handle
*handle
, uint32 type
,
187 const char *service
, uint32 access_granted
)
189 SERVICE_INFO
*info
= NULL
;
190 WERROR result
= WERR_OK
;
191 struct service_control_op
*s_op
;
193 if ( !(info
= TALLOC_ZERO_P( NULL
, SERVICE_INFO
)) )
196 /* the Service Manager has a NULL name */
198 info
->type
= SVC_HANDLE_IS_SCM
;
201 case SVC_HANDLE_IS_SCM
:
202 info
->type
= SVC_HANDLE_IS_SCM
;
205 case SVC_HANDLE_IS_DBLOCK
:
206 info
->type
= SVC_HANDLE_IS_DBLOCK
;
209 case SVC_HANDLE_IS_SERVICE
:
210 info
->type
= SVC_HANDLE_IS_SERVICE
;
212 /* lookup the SERVICE_CONTROL_OPS */
214 if ( !(s_op
= find_service_by_name( service
)) ) {
215 result
= WERR_NO_SUCH_SERVICE
;
219 info
->ops
= s_op
->ops
;
221 if ( !(info
->name
= talloc_strdup( info
, s_op
->name
)) ) {
228 result
= WERR_NO_SUCH_SERVICE
;
232 info
->access_granted
= access_granted
;
234 /* store the SERVICE_INFO and create an open handle */
236 if ( !create_policy_hnd( p
, handle
, info
) ) {
237 result
= WERR_ACCESS_DENIED
;
242 if ( !W_ERROR_IS_OK(result
) )
248 /********************************************************************
249 _svcctl_OpenSCManagerW
250 ********************************************************************/
252 WERROR
_svcctl_OpenSCManagerW(pipes_struct
*p
,
253 struct svcctl_OpenSCManagerW
*r
)
256 uint32 access_granted
= 0;
259 /* perform access checks */
261 if ( !(sec_desc
= construct_scm_sd( p
->mem_ctx
)) )
264 se_map_generic( &r
->in
.access_mask
, &scm_generic_map
);
265 status
= svcctl_access_check( sec_desc
, p
->server_info
->ptok
,
266 r
->in
.access_mask
, &access_granted
);
267 if ( !NT_STATUS_IS_OK(status
) )
268 return ntstatus_to_werror( status
);
270 return create_open_service_handle( p
, r
->out
.handle
, SVC_HANDLE_IS_SCM
, NULL
, access_granted
);
273 /********************************************************************
275 ********************************************************************/
277 WERROR
_svcctl_OpenServiceW(pipes_struct
*p
,
278 struct svcctl_OpenServiceW
*r
)
281 uint32 access_granted
= 0;
283 const char *service
= NULL
;
285 service
= r
->in
.ServiceName
;
289 DEBUG(5, ("_svcctl_OpenServiceW: Attempting to open Service [%s], \n", service
));
291 /* based on my tests you can open a service if you have a valid scm handle */
293 if ( !find_service_info_by_hnd( p
, r
->in
.scmanager_handle
) )
296 /* perform access checks. Use the root token in order to ensure that we
297 retrieve the security descriptor */
299 if ( !(sec_desc
= svcctl_get_secdesc( p
->mem_ctx
, service
, get_root_nt_token() )) )
302 se_map_generic( &r
->in
.access_mask
, &svc_generic_map
);
303 status
= svcctl_access_check( sec_desc
, p
->server_info
->ptok
,
304 r
->in
.access_mask
, &access_granted
);
305 if ( !NT_STATUS_IS_OK(status
) )
306 return ntstatus_to_werror( status
);
308 return create_open_service_handle( p
, r
->out
.handle
, SVC_HANDLE_IS_SERVICE
, service
, access_granted
);
311 /********************************************************************
312 _svcctl_CloseServiceHandle
313 ********************************************************************/
315 WERROR
_svcctl_CloseServiceHandle(pipes_struct
*p
,
316 struct svcctl_CloseServiceHandle
*r
)
318 if ( !close_policy_hnd( p
, r
->in
.handle
) )
321 ZERO_STRUCTP(r
->out
.handle
);
326 /********************************************************************
327 _svcctl_GetServiceDisplayNameW
328 ********************************************************************/
330 WERROR
_svcctl_GetServiceDisplayNameW(pipes_struct
*p
,
331 struct svcctl_GetServiceDisplayNameW
*r
)
334 const char *display_name
;
335 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
337 /* can only use an SCM handle here */
339 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
342 service
= r
->in
.service_name
;
344 display_name
= svcctl_lookup_dispname(p
->mem_ctx
, service
,
345 p
->server_info
->ptok
);
350 *r
->out
.display_name
= display_name
;
351 *r
->out
.display_name_length
= strlen(display_name
);
356 /********************************************************************
357 _svcctl_QueryServiceStatus
358 ********************************************************************/
360 WERROR
_svcctl_QueryServiceStatus(pipes_struct
*p
,
361 struct svcctl_QueryServiceStatus
*r
)
363 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
365 /* perform access checks */
367 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
370 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
371 return WERR_ACCESS_DENIED
;
373 /* try the service specific status call */
375 return info
->ops
->service_status( info
->name
, r
->out
.service_status
);
378 /********************************************************************
379 ********************************************************************/
381 static int enumerate_status( TALLOC_CTX
*ctx
, struct ENUM_SERVICE_STATUSW
**status
, NT_USER_TOKEN
*token
)
383 int num_services
= 0;
385 struct ENUM_SERVICE_STATUSW
*st
;
386 const char *display_name
;
389 while ( svcctl_ops
[num_services
].name
)
392 if ( !(st
= TALLOC_ARRAY( ctx
, struct ENUM_SERVICE_STATUSW
, num_services
)) ) {
393 DEBUG(0,("enumerate_status: talloc() failed!\n"));
397 for ( i
=0; i
<num_services
; i
++ ) {
398 st
[i
].service_name
= talloc_strdup(st
, svcctl_ops
[i
].name
);
400 display_name
= svcctl_lookup_dispname(ctx
, svcctl_ops
[i
].name
, token
);
401 st
[i
].display_name
= talloc_strdup(st
, display_name
? display_name
: "");
403 svcctl_ops
[i
].ops
->service_status( svcctl_ops
[i
].name
, &st
[i
].status
);
411 /********************************************************************
412 _svcctl_EnumServicesStatusW
413 ********************************************************************/
415 WERROR
_svcctl_EnumServicesStatusW(pipes_struct
*p
,
416 struct svcctl_EnumServicesStatusW
*r
)
418 struct ENUM_SERVICE_STATUSW
*services
= NULL
;
421 size_t buffer_size
= 0;
422 WERROR result
= WERR_OK
;
423 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
424 NT_USER_TOKEN
*token
= p
->server_info
->ptok
;
425 DATA_BLOB blob
= data_blob_null
;
427 /* perform access checks */
429 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
432 if ( !(info
->access_granted
& SC_RIGHT_MGR_ENUMERATE_SERVICE
) ) {
433 return WERR_ACCESS_DENIED
;
436 num_services
= enumerate_status( p
->mem_ctx
, &services
, token
);
437 if (num_services
== -1 ) {
441 for ( i
=0; i
<num_services
; i
++ ) {
442 buffer_size
+= ndr_size_ENUM_SERVICE_STATUSW(&services
[i
], NULL
, 0);
445 buffer_size
+= buffer_size
% 4;
447 if (buffer_size
> r
->in
.offered
) {
449 result
= WERR_MORE_DATA
;
452 if ( W_ERROR_IS_OK(result
) ) {
454 enum ndr_err_code ndr_err
;
455 struct ndr_push
*ndr
;
457 ndr
= ndr_push_init_ctx(p
->mem_ctx
, NULL
);
459 return WERR_INVALID_PARAM
;
462 ndr_err
= ndr_push_ENUM_SERVICE_STATUSW_array(
463 ndr
, num_services
, services
);
464 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
465 return ntstatus_to_werror(ndr_map_error2ntstatus(ndr_err
));
468 blob
= ndr_push_blob(ndr
);
469 memcpy(r
->out
.service
, blob
.data
, r
->in
.offered
);
472 *r
->out
.needed
= (buffer_size
> r
->in
.offered
) ? buffer_size
: r
->in
.offered
;
473 *r
->out
.services_returned
= (uint32
)num_services
;
474 *r
->out
.resume_handle
= 0x0;
479 /********************************************************************
480 _svcctl_StartServiceW
481 ********************************************************************/
483 WERROR
_svcctl_StartServiceW(pipes_struct
*p
,
484 struct svcctl_StartServiceW
*r
)
486 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
488 /* perform access checks */
490 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
493 if ( !(info
->access_granted
& SC_RIGHT_SVC_START
) )
494 return WERR_ACCESS_DENIED
;
496 return info
->ops
->start_service( info
->name
);
499 /********************************************************************
500 _svcctl_ControlService
501 ********************************************************************/
503 WERROR
_svcctl_ControlService(pipes_struct
*p
,
504 struct svcctl_ControlService
*r
)
506 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
508 /* perform access checks */
510 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
513 switch ( r
->in
.control
) {
514 case SVCCTL_CONTROL_STOP
:
515 if ( !(info
->access_granted
& SC_RIGHT_SVC_STOP
) )
516 return WERR_ACCESS_DENIED
;
518 return info
->ops
->stop_service( info
->name
,
519 r
->out
.service_status
);
521 case SVCCTL_CONTROL_INTERROGATE
:
522 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
523 return WERR_ACCESS_DENIED
;
525 return info
->ops
->service_status( info
->name
,
526 r
->out
.service_status
);
528 return WERR_ACCESS_DENIED
;
532 /********************************************************************
533 _svcctl_EnumDependentServicesW
534 ********************************************************************/
536 WERROR
_svcctl_EnumDependentServicesW(pipes_struct
*p
,
537 struct svcctl_EnumDependentServicesW
*r
)
539 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.service
);
541 /* perform access checks */
543 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
546 if ( !(info
->access_granted
& SC_RIGHT_SVC_ENUMERATE_DEPENDENTS
) )
547 return WERR_ACCESS_DENIED
;
549 /* we have to set the outgoing buffer size to the same as the
550 incoming buffer size (even in the case of failure */
551 /* this is done in the autogenerated server already - gd */
553 *r
->out
.needed
= r
->in
.offered
;
555 /* no dependent services...basically a stub function */
556 *r
->out
.services_returned
= 0;
561 /********************************************************************
562 _svcctl_QueryServiceStatusEx
563 ********************************************************************/
565 WERROR
_svcctl_QueryServiceStatusEx(pipes_struct
*p
,
566 struct svcctl_QueryServiceStatusEx
*r
)
568 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
571 /* perform access checks */
573 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
576 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
577 return WERR_ACCESS_DENIED
;
579 /* we have to set the outgoing buffer size to the same as the
580 incoming buffer size (even in the case of failure) */
581 *r
->out
.needed
= r
->in
.offered
;
583 switch ( r
->in
.info_level
) {
584 case SVC_STATUS_PROCESS_INFO
:
586 struct SERVICE_STATUS_PROCESS svc_stat_proc
;
587 enum ndr_err_code ndr_err
;
590 /* Get the status of the service.. */
591 info
->ops
->service_status( info
->name
, &svc_stat_proc
.status
);
592 svc_stat_proc
.process_id
= sys_getpid();
593 svc_stat_proc
.service_flags
= 0x0;
595 ndr_err
= ndr_push_struct_blob(&blob
, p
->mem_ctx
, NULL
,
597 (ndr_push_flags_fn_t
)ndr_push_SERVICE_STATUS_PROCESS
);
598 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
599 return WERR_INVALID_PARAM
;
602 r
->out
.buffer
= blob
.data
;
603 buffer_size
= sizeof(struct SERVICE_STATUS_PROCESS
);
608 return WERR_UNKNOWN_LEVEL
;
612 buffer_size
+= buffer_size
% 4;
613 *r
->out
.needed
= (buffer_size
> r
->in
.offered
) ? buffer_size
: r
->in
.offered
;
615 if (buffer_size
> r
->in
.offered
) {
616 return WERR_INSUFFICIENT_BUFFER
;
622 /********************************************************************
623 ********************************************************************/
625 static WERROR
fill_svc_config( TALLOC_CTX
*ctx
, const char *name
,
626 struct QUERY_SERVICE_CONFIG
*config
,
627 NT_USER_TOKEN
*token
)
632 /* retrieve the registry values for this service */
634 if ( !(values
= svcctl_fetch_regvalues( name
, token
)) )
635 return WERR_REG_CORRUPT
;
637 /* now fill in the individual values */
639 if ( (val
= regval_ctr_getvalue( values
, "DisplayName" )) != NULL
)
640 config
->displayname
= regval_sz(val
);
642 config
->displayname
= name
;
644 if ( (val
= regval_ctr_getvalue( values
, "ObjectName" )) != NULL
) {
645 config
->startname
= regval_sz(val
);
648 if ( (val
= regval_ctr_getvalue( values
, "ImagePath" )) != NULL
) {
649 config
->executablepath
= regval_sz(val
);
652 /* a few hard coded values */
653 /* loadordergroup and dependencies are empty */
655 config
->tag_id
= 0x00000000; /* unassigned loadorder group */
656 config
->service_type
= SERVICE_TYPE_WIN32_OWN_PROCESS
;
657 config
->error_control
= SVCCTL_SVC_ERROR_NORMAL
;
659 /* set the start type. NetLogon and WINS are disabled to prevent
660 the client from showing the "Start" button (if of course the services
663 if ( strequal( name
, "NETLOGON" ) && ( lp_servicenumber(name
) == -1 ) )
664 config
->start_type
= SVCCTL_DISABLED
;
665 else if ( strequal( name
, "WINS" ) && ( !lp_wins_support() ))
666 config
->start_type
= SVCCTL_DISABLED
;
668 config
->start_type
= SVCCTL_DEMAND_START
;
671 TALLOC_FREE( values
);
676 /********************************************************************
677 _svcctl_QueryServiceConfigW
678 ********************************************************************/
680 WERROR
_svcctl_QueryServiceConfigW(pipes_struct
*p
,
681 struct svcctl_QueryServiceConfigW
*r
)
683 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
687 /* perform access checks */
689 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
692 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_CONFIG
) )
693 return WERR_ACCESS_DENIED
;
695 /* we have to set the outgoing buffer size to the same as the
696 incoming buffer size (even in the case of failure */
698 *r
->out
.needed
= r
->in
.offered
;
700 wresult
= fill_svc_config( p
->mem_ctx
, info
->name
, r
->out
.query
,
701 p
->server_info
->ptok
);
702 if ( !W_ERROR_IS_OK(wresult
) )
705 buffer_size
= ndr_size_QUERY_SERVICE_CONFIG(r
->out
.query
, NULL
, 0);
706 *r
->out
.needed
= (buffer_size
> r
->in
.offered
) ? buffer_size
: r
->in
.offered
;
708 if (buffer_size
> r
->in
.offered
) {
709 ZERO_STRUCTP(r
->out
.query
);
710 return WERR_INSUFFICIENT_BUFFER
;
716 /********************************************************************
717 _svcctl_QueryServiceConfig2W
718 ********************************************************************/
720 WERROR
_svcctl_QueryServiceConfig2W(pipes_struct
*p
,
721 struct svcctl_QueryServiceConfig2W
*r
)
723 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
726 /* perform access checks */
728 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
731 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_CONFIG
) )
732 return WERR_ACCESS_DENIED
;
734 /* we have to set the outgoing buffer size to the same as the
735 incoming buffer size (even in the case of failure */
736 *r
->out
.needed
= r
->in
.offered
;
738 switch ( r
->in
.info_level
) {
739 case SERVICE_CONFIG_DESCRIPTION
:
741 struct SERVICE_DESCRIPTION desc_buf
;
742 const char *description
;
743 enum ndr_err_code ndr_err
;
746 description
= svcctl_lookup_description(
747 p
->mem_ctx
, info
->name
, p
->server_info
->ptok
);
749 desc_buf
.description
= description
;
751 ndr_err
= ndr_push_struct_blob(&blob
, p
->mem_ctx
, NULL
,
753 (ndr_push_flags_fn_t
)ndr_push_SERVICE_DESCRIPTION
);
754 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
755 return WERR_INVALID_PARAM
;
758 buffer_size
= ndr_size_SERVICE_DESCRIPTION(&desc_buf
, NULL
, 0);
759 r
->out
.buffer
= blob
.data
;
764 case SERVICE_CONFIG_FAILURE_ACTIONS
:
766 struct SERVICE_FAILURE_ACTIONS actions
;
767 enum ndr_err_code ndr_err
;
770 /* nothing to say...just service the request */
772 ZERO_STRUCT( actions
);
774 ndr_err
= ndr_push_struct_blob(&blob
, p
->mem_ctx
, NULL
,
776 (ndr_push_flags_fn_t
)ndr_push_SERVICE_FAILURE_ACTIONS
);
777 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
778 return WERR_INVALID_PARAM
;
781 buffer_size
= ndr_size_SERVICE_FAILURE_ACTIONS(&actions
, NULL
, 0);
782 r
->out
.buffer
= blob
.data
;
789 return WERR_UNKNOWN_LEVEL
;
792 buffer_size
+= buffer_size
% 4;
793 *r
->out
.needed
= (buffer_size
> r
->in
.offered
) ? buffer_size
: r
->in
.offered
;
795 if (buffer_size
> r
->in
.offered
)
796 return WERR_INSUFFICIENT_BUFFER
;
801 /********************************************************************
802 _svcctl_LockServiceDatabase
803 ********************************************************************/
805 WERROR
_svcctl_LockServiceDatabase(pipes_struct
*p
,
806 struct svcctl_LockServiceDatabase
*r
)
808 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
810 /* perform access checks */
812 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
815 if ( !(info
->access_granted
& SC_RIGHT_MGR_LOCK
) )
816 return WERR_ACCESS_DENIED
;
818 /* Just open a handle. Doesn't actually lock anything */
820 return create_open_service_handle( p
, r
->out
.lock
, SVC_HANDLE_IS_DBLOCK
, NULL
, 0 );
823 /********************************************************************
824 _svcctl_UnlockServiceDatabase
825 ********************************************************************/
827 WERROR
_svcctl_UnlockServiceDatabase(pipes_struct
*p
,
828 struct svcctl_UnlockServiceDatabase
*r
)
830 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.lock
);
833 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_DBLOCK
) )
836 return close_policy_hnd( p
, r
->out
.lock
) ? WERR_OK
: WERR_BADFID
;
839 /********************************************************************
840 _svcctl_QueryServiceObjectSecurity
841 ********************************************************************/
843 WERROR
_svcctl_QueryServiceObjectSecurity(pipes_struct
*p
,
844 struct svcctl_QueryServiceObjectSecurity
*r
)
846 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
849 uint8_t *buffer
= NULL
;
853 /* only support the SCM and individual services */
855 if ( !info
|| !(info
->type
& (SVC_HANDLE_IS_SERVICE
|SVC_HANDLE_IS_SCM
)) )
858 /* check access reights (according to MSDN) */
860 if ( !(info
->access_granted
& STD_RIGHT_READ_CONTROL_ACCESS
) )
861 return WERR_ACCESS_DENIED
;
863 /* TODO: handle something besides DACL_SECURITY_INFORMATION */
865 if ( (r
->in
.security_flags
& DACL_SECURITY_INFORMATION
) != DACL_SECURITY_INFORMATION
)
866 return WERR_INVALID_PARAM
;
868 /* lookup the security descriptor and marshall it up for a reply */
870 if ( !(sec_desc
= svcctl_get_secdesc( p
->mem_ctx
, info
->name
, get_root_nt_token() )) )
873 *r
->out
.needed
= ndr_size_security_descriptor( sec_desc
, NULL
, 0 );
875 if ( *r
->out
.needed
> r
->in
.offered
) {
876 ZERO_STRUCTP( &r
->out
.buffer
);
877 return WERR_INSUFFICIENT_BUFFER
;
880 status
= marshall_sec_desc(p
->mem_ctx
, sec_desc
, &buffer
, &len
);
881 if (!NT_STATUS_IS_OK(status
)) {
882 return ntstatus_to_werror(status
);
885 *r
->out
.needed
= len
;
886 r
->out
.buffer
= buffer
;
891 /********************************************************************
892 _svcctl_SetServiceObjectSecurity
893 ********************************************************************/
895 WERROR
_svcctl_SetServiceObjectSecurity(pipes_struct
*p
,
896 struct svcctl_SetServiceObjectSecurity
*r
)
898 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
899 SEC_DESC
*sec_desc
= NULL
;
900 uint32 required_access
;
903 if ( !info
|| !(info
->type
& (SVC_HANDLE_IS_SERVICE
|SVC_HANDLE_IS_SCM
)) )
906 /* can't set the security de4scriptor on the ServiceControlManager */
908 if ( info
->type
== SVC_HANDLE_IS_SCM
)
909 return WERR_ACCESS_DENIED
;
911 /* check the access on the open handle */
913 switch ( r
->in
.security_flags
) {
914 case DACL_SECURITY_INFORMATION
:
915 required_access
= STD_RIGHT_WRITE_DAC_ACCESS
;
918 case OWNER_SECURITY_INFORMATION
:
919 case GROUP_SECURITY_INFORMATION
:
920 required_access
= STD_RIGHT_WRITE_OWNER_ACCESS
;
923 case SACL_SECURITY_INFORMATION
:
924 return WERR_INVALID_PARAM
;
926 return WERR_INVALID_PARAM
;
929 if ( !(info
->access_granted
& required_access
) )
930 return WERR_ACCESS_DENIED
;
932 /* read the security descfriptor */
934 status
= unmarshall_sec_desc(p
->mem_ctx
,
938 if (!NT_STATUS_IS_OK(status
)) {
939 return ntstatus_to_werror(status
);
942 /* store the new SD */
944 if ( !svcctl_set_secdesc( p
->mem_ctx
, info
->name
, sec_desc
,
945 p
->server_info
->ptok
) )
946 return WERR_ACCESS_DENIED
;
952 WERROR
_svcctl_DeleteService(pipes_struct
*p
, struct svcctl_DeleteService
*r
)
954 p
->rng_fault_state
= True
;
955 return WERR_NOT_SUPPORTED
;
958 WERROR
_svcctl_SetServiceStatus(pipes_struct
*p
, struct svcctl_SetServiceStatus
*r
)
960 p
->rng_fault_state
= True
;
961 return WERR_NOT_SUPPORTED
;
964 WERROR
_svcctl_NotifyBootConfigStatus(pipes_struct
*p
, struct svcctl_NotifyBootConfigStatus
*r
)
966 p
->rng_fault_state
= True
;
967 return WERR_NOT_SUPPORTED
;
970 WERROR
_svcctl_SCSetServiceBitsW(pipes_struct
*p
, struct svcctl_SCSetServiceBitsW
*r
)
972 p
->rng_fault_state
= True
;
973 return WERR_NOT_SUPPORTED
;
976 WERROR
_svcctl_ChangeServiceConfigW(pipes_struct
*p
, struct svcctl_ChangeServiceConfigW
*r
)
978 p
->rng_fault_state
= True
;
979 return WERR_NOT_SUPPORTED
;
982 WERROR
_svcctl_CreateServiceW(pipes_struct
*p
, struct svcctl_CreateServiceW
*r
)
984 p
->rng_fault_state
= True
;
985 return WERR_NOT_SUPPORTED
;
988 WERROR
_svcctl_QueryServiceLockStatusW(pipes_struct
*p
, struct svcctl_QueryServiceLockStatusW
*r
)
990 p
->rng_fault_state
= True
;
991 return WERR_NOT_SUPPORTED
;
994 WERROR
_svcctl_GetServiceKeyNameW(pipes_struct
*p
, struct svcctl_GetServiceKeyNameW
*r
)
996 p
->rng_fault_state
= True
;
997 return WERR_NOT_SUPPORTED
;
1000 WERROR
_svcctl_SCSetServiceBitsA(pipes_struct
*p
, struct svcctl_SCSetServiceBitsA
*r
)
1002 p
->rng_fault_state
= True
;
1003 return WERR_NOT_SUPPORTED
;
1006 WERROR
_svcctl_ChangeServiceConfigA(pipes_struct
*p
, struct svcctl_ChangeServiceConfigA
*r
)
1008 p
->rng_fault_state
= True
;
1009 return WERR_NOT_SUPPORTED
;
1012 WERROR
_svcctl_CreateServiceA(pipes_struct
*p
, struct svcctl_CreateServiceA
*r
)
1014 p
->rng_fault_state
= True
;
1015 return WERR_NOT_SUPPORTED
;
1018 WERROR
_svcctl_EnumDependentServicesA(pipes_struct
*p
, struct svcctl_EnumDependentServicesA
*r
)
1020 p
->rng_fault_state
= True
;
1021 return WERR_NOT_SUPPORTED
;
1024 WERROR
_svcctl_EnumServicesStatusA(pipes_struct
*p
, struct svcctl_EnumServicesStatusA
*r
)
1026 p
->rng_fault_state
= True
;
1027 return WERR_NOT_SUPPORTED
;
1030 WERROR
_svcctl_OpenSCManagerA(pipes_struct
*p
, struct svcctl_OpenSCManagerA
*r
)
1032 p
->rng_fault_state
= True
;
1033 return WERR_NOT_SUPPORTED
;
1036 WERROR
_svcctl_OpenServiceA(pipes_struct
*p
, struct svcctl_OpenServiceA
*r
)
1038 p
->rng_fault_state
= True
;
1039 return WERR_NOT_SUPPORTED
;
1042 WERROR
_svcctl_QueryServiceConfigA(pipes_struct
*p
, struct svcctl_QueryServiceConfigA
*r
)
1044 p
->rng_fault_state
= True
;
1045 return WERR_NOT_SUPPORTED
;
1048 WERROR
_svcctl_QueryServiceLockStatusA(pipes_struct
*p
, struct svcctl_QueryServiceLockStatusA
*r
)
1050 p
->rng_fault_state
= True
;
1051 return WERR_NOT_SUPPORTED
;
1054 WERROR
_svcctl_StartServiceA(pipes_struct
*p
, struct svcctl_StartServiceA
*r
)
1056 p
->rng_fault_state
= True
;
1057 return WERR_NOT_SUPPORTED
;
1060 WERROR
_svcctl_GetServiceDisplayNameA(pipes_struct
*p
, struct svcctl_GetServiceDisplayNameA
*r
)
1062 p
->rng_fault_state
= True
;
1063 return WERR_NOT_SUPPORTED
;
1066 WERROR
_svcctl_GetServiceKeyNameA(pipes_struct
*p
, struct svcctl_GetServiceKeyNameA
*r
)
1068 p
->rng_fault_state
= True
;
1069 return WERR_NOT_SUPPORTED
;
1072 WERROR
_svcctl_GetCurrentGroupeStateW(pipes_struct
*p
, struct svcctl_GetCurrentGroupeStateW
*r
)
1074 p
->rng_fault_state
= True
;
1075 return WERR_NOT_SUPPORTED
;
1078 WERROR
_svcctl_EnumServiceGroupW(pipes_struct
*p
, struct svcctl_EnumServiceGroupW
*r
)
1080 p
->rng_fault_state
= True
;
1081 return WERR_NOT_SUPPORTED
;
1084 WERROR
_svcctl_ChangeServiceConfig2A(pipes_struct
*p
, struct svcctl_ChangeServiceConfig2A
*r
)
1086 p
->rng_fault_state
= True
;
1087 return WERR_NOT_SUPPORTED
;
1090 WERROR
_svcctl_ChangeServiceConfig2W(pipes_struct
*p
, struct svcctl_ChangeServiceConfig2W
*r
)
1092 p
->rng_fault_state
= True
;
1093 return WERR_NOT_SUPPORTED
;
1096 WERROR
_svcctl_QueryServiceConfig2A(pipes_struct
*p
, struct svcctl_QueryServiceConfig2A
*r
)
1098 p
->rng_fault_state
= True
;
1099 return WERR_NOT_SUPPORTED
;
1102 WERROR
_EnumServicesStatusExA(pipes_struct
*p
, struct EnumServicesStatusExA
*r
)
1104 p
->rng_fault_state
= True
;
1105 return WERR_NOT_SUPPORTED
;
1108 WERROR
_EnumServicesStatusExW(pipes_struct
*p
, struct EnumServicesStatusExW
*r
)
1110 p
->rng_fault_state
= True
;
1111 return WERR_NOT_SUPPORTED
;
1114 WERROR
_svcctl_SCSendTSMessage(pipes_struct
*p
, struct svcctl_SCSendTSMessage
*r
)
1116 p
->rng_fault_state
= True
;
1117 return WERR_NOT_SUPPORTED
;