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.
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 3 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, see <http://www.gnu.org/licenses/>.
27 #define DBGC_CLASS DBGC_RPC_SRV
29 struct service_control_op
{
31 SERVICE_CONTROL_OPS
*ops
;
34 #define SVCCTL_NUM_INTERNAL_SERVICES 4
36 /* handle external services */
37 extern SERVICE_CONTROL_OPS rcinit_svc_ops
;
39 /* builtin services (see service_db.c and services/svc_*.c */
40 extern SERVICE_CONTROL_OPS spoolss_svc_ops
;
41 extern SERVICE_CONTROL_OPS netlogon_svc_ops
;
42 extern SERVICE_CONTROL_OPS winreg_svc_ops
;
43 extern SERVICE_CONTROL_OPS wins_svc_ops
;
45 /* make sure this number patches the number of builtin
46 SERVICE_CONTROL_OPS structure listed above */
48 #define SVCCTL_NUM_INTERNAL_SERVICES 4
50 struct service_control_op
*svcctl_ops
;
52 static const struct generic_mapping scm_generic_map
=
53 { SC_MANAGER_READ_ACCESS
, SC_MANAGER_WRITE_ACCESS
, SC_MANAGER_EXECUTE_ACCESS
, SC_MANAGER_ALL_ACCESS
};
54 static const struct generic_mapping svc_generic_map
=
55 { SERVICE_READ_ACCESS
, SERVICE_WRITE_ACCESS
, SERVICE_EXECUTE_ACCESS
, SERVICE_ALL_ACCESS
};
58 /********************************************************************
59 ********************************************************************/
61 bool init_service_op_table( void )
63 const char **service_list
= lp_svcctl_list();
64 int num_services
= SVCCTL_NUM_INTERNAL_SERVICES
+ str_list_count( service_list
);
67 if ( !(svcctl_ops
= TALLOC_ARRAY( NULL
, struct service_control_op
, num_services
+1)) ) {
68 DEBUG(0,("init_service_op_table: talloc() failed!\n"));
72 /* services listed in smb.conf get the rc.init interface */
74 for ( i
=0; service_list
&& service_list
[i
]; i
++ ) {
75 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, service_list
[i
] );
76 svcctl_ops
[i
].ops
= &rcinit_svc_ops
;
79 /* add builtin services */
81 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "Spooler" );
82 svcctl_ops
[i
].ops
= &spoolss_svc_ops
;
85 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "NETLOGON" );
86 svcctl_ops
[i
].ops
= &netlogon_svc_ops
;
89 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "RemoteRegistry" );
90 svcctl_ops
[i
].ops
= &winreg_svc_ops
;
93 svcctl_ops
[i
].name
= talloc_strdup( svcctl_ops
, "WINS" );
94 svcctl_ops
[i
].ops
= &wins_svc_ops
;
97 /* NULL terminate the array */
99 svcctl_ops
[i
].name
= NULL
;
100 svcctl_ops
[i
].ops
= NULL
;
105 /********************************************************************
106 ********************************************************************/
108 static struct service_control_op
* find_service_by_name( const char *name
)
112 for ( i
=0; svcctl_ops
[i
].name
; i
++ ) {
113 if ( strequal( name
, svcctl_ops
[i
].name
) )
114 return &svcctl_ops
[i
];
119 /********************************************************************
120 ********************************************************************/
122 static NTSTATUS
svcctl_access_check( SEC_DESC
*sec_desc
, NT_USER_TOKEN
*token
,
123 uint32 access_desired
, uint32
*access_granted
)
127 if ( geteuid() == sec_initial_uid() ) {
128 DEBUG(5,("svcctl_access_check: using root's token\n"));
129 token
= get_root_nt_token();
132 se_access_check( sec_desc
, token
, access_desired
, access_granted
, &result
);
137 /********************************************************************
138 ********************************************************************/
140 static SEC_DESC
* construct_scm_sd( TALLOC_CTX
*ctx
)
149 /* basic access for Everyone */
151 init_sec_access(&mask
, SC_MANAGER_READ_ACCESS
);
152 init_sec_ace(&ace
[i
++], &global_sid_World
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
154 /* Full Access 'BUILTIN\Administrators' */
156 init_sec_access(&mask
,SC_MANAGER_ALL_ACCESS
);
157 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
160 /* create the security descriptor */
162 if ( !(acl
= make_sec_acl(ctx
, NT4_ACL_REVISION
, i
, ace
)) )
165 if ( !(sd
= make_sec_desc(ctx
, SECURITY_DESCRIPTOR_REVISION_1
,
166 SEC_DESC_SELF_RELATIVE
, NULL
, NULL
, NULL
,
173 /******************************************************************
174 free() function for REGISTRY_KEY
175 *****************************************************************/
177 static void free_service_handle_info(void *ptr
)
182 /******************************************************************
183 Find a registry key handle and return a SERVICE_INFO
184 *****************************************************************/
186 static SERVICE_INFO
*find_service_info_by_hnd(pipes_struct
*p
, POLICY_HND
*hnd
)
188 SERVICE_INFO
*service_info
= NULL
;
190 if( !find_policy_by_hnd( p
, hnd
, (void **)(void *)&service_info
) ) {
191 DEBUG(2,("find_service_info_by_hnd: handle not found\n"));
198 /******************************************************************
199 *****************************************************************/
201 static WERROR
create_open_service_handle( pipes_struct
*p
, POLICY_HND
*handle
, uint32 type
,
202 const char *service
, uint32 access_granted
)
204 SERVICE_INFO
*info
= NULL
;
205 WERROR result
= WERR_OK
;
206 struct service_control_op
*s_op
;
208 if ( !(info
= TALLOC_ZERO_P( NULL
, SERVICE_INFO
)) )
211 /* the Service Manager has a NULL name */
213 info
->type
= SVC_HANDLE_IS_SCM
;
216 case SVC_HANDLE_IS_SCM
:
217 info
->type
= SVC_HANDLE_IS_SCM
;
220 case SVC_HANDLE_IS_DBLOCK
:
221 info
->type
= SVC_HANDLE_IS_DBLOCK
;
224 case SVC_HANDLE_IS_SERVICE
:
225 info
->type
= SVC_HANDLE_IS_SERVICE
;
227 /* lookup the SERVICE_CONTROL_OPS */
229 if ( !(s_op
= find_service_by_name( service
)) ) {
230 result
= WERR_NO_SUCH_SERVICE
;
234 info
->ops
= s_op
->ops
;
236 if ( !(info
->name
= talloc_strdup( info
, s_op
->name
)) ) {
243 result
= WERR_NO_SUCH_SERVICE
;
247 info
->access_granted
= access_granted
;
249 /* store the SERVICE_INFO and create an open handle */
251 if ( !create_policy_hnd( p
, handle
, free_service_handle_info
, info
) ) {
252 result
= WERR_ACCESS_DENIED
;
257 if ( !W_ERROR_IS_OK(result
) )
258 free_service_handle_info( info
);
263 /********************************************************************
264 ********************************************************************/
266 WERROR
_svcctl_OpenSCManagerW(pipes_struct
*p
,
267 struct svcctl_OpenSCManagerW
*r
)
270 uint32 access_granted
= 0;
273 /* perform access checks */
275 if ( !(sec_desc
= construct_scm_sd( p
->mem_ctx
)) )
278 se_map_generic( &r
->in
.access_mask
, &scm_generic_map
);
279 status
= svcctl_access_check( sec_desc
, p
->pipe_user
.nt_user_token
, r
->in
.access_mask
, &access_granted
);
280 if ( !NT_STATUS_IS_OK(status
) )
281 return ntstatus_to_werror( status
);
283 return create_open_service_handle( p
, r
->out
.handle
, SVC_HANDLE_IS_SCM
, NULL
, access_granted
);
286 /********************************************************************
288 ********************************************************************/
290 WERROR
_svcctl_OpenServiceW(pipes_struct
*p
,
291 struct svcctl_OpenServiceW
*r
)
294 uint32 access_granted
= 0;
296 const char *service
= NULL
;
298 service
= r
->in
.ServiceName
;
302 DEBUG(5, ("_svcctl_OpenServiceW: Attempting to open Service [%s], \n", service
));
304 /* based on my tests you can open a service if you have a valid scm handle */
306 if ( !find_service_info_by_hnd( p
, r
->in
.scmanager_handle
) )
309 /* perform access checks. Use the root token in order to ensure that we
310 retrieve the security descriptor */
312 if ( !(sec_desc
= svcctl_get_secdesc( p
->mem_ctx
, service
, get_root_nt_token() )) )
315 se_map_generic( &r
->in
.access_mask
, &svc_generic_map
);
316 status
= svcctl_access_check( sec_desc
, p
->pipe_user
.nt_user_token
, r
->in
.access_mask
, &access_granted
);
317 if ( !NT_STATUS_IS_OK(status
) )
318 return ntstatus_to_werror( status
);
320 return create_open_service_handle( p
, r
->out
.handle
, SVC_HANDLE_IS_SERVICE
, service
, access_granted
);
323 /********************************************************************
324 ********************************************************************/
326 WERROR
_svcctl_CloseServiceHandle(pipes_struct
*p
, struct svcctl_CloseServiceHandle
*r
)
328 if ( !close_policy_hnd( p
, r
->in
.handle
) )
334 /********************************************************************
335 _svcctl_GetServiceDisplayNameW
336 ********************************************************************/
338 WERROR
_svcctl_GetServiceDisplayNameW(pipes_struct
*p
,
339 struct svcctl_GetServiceDisplayNameW
*r
)
342 const char *display_name
;
343 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
345 /* can only use an SCM handle here */
347 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
350 service
= r
->in
.service_name
;
352 display_name
= svcctl_lookup_dispname(p
->mem_ctx
, service
, p
->pipe_user
.nt_user_token
);
357 *r
->out
.display_name
= display_name
;
358 *r
->out
.display_name_length
= strlen(display_name
);
363 /********************************************************************
364 _svcctl_QueryServiceStatus
365 ********************************************************************/
367 WERROR
_svcctl_QueryServiceStatus(pipes_struct
*p
,
368 struct svcctl_QueryServiceStatus
*r
)
370 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
372 /* perform access checks */
374 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
377 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
378 return WERR_ACCESS_DENIED
;
380 /* try the service specific status call */
382 return info
->ops
->service_status( info
->name
, r
->out
.service_status
);
385 /********************************************************************
386 ********************************************************************/
388 static int enumerate_status( TALLOC_CTX
*ctx
, ENUM_SERVICES_STATUS
**status
, NT_USER_TOKEN
*token
)
390 int num_services
= 0;
392 ENUM_SERVICES_STATUS
*st
;
393 const char *display_name
;
396 while ( svcctl_ops
[num_services
].name
)
399 if ( !(st
= TALLOC_ARRAY( ctx
, ENUM_SERVICES_STATUS
, num_services
)) ) {
400 DEBUG(0,("enumerate_status: talloc() failed!\n"));
404 for ( i
=0; i
<num_services
; i
++ ) {
405 init_unistr( &st
[i
].servicename
, svcctl_ops
[i
].name
);
407 display_name
= svcctl_lookup_dispname(ctx
, svcctl_ops
[i
].name
, token
);
408 init_unistr( &st
[i
].displayname
, display_name
? display_name
: "");
410 svcctl_ops
[i
].ops
->service_status( svcctl_ops
[i
].name
, &st
[i
].status
);
418 /********************************************************************
419 ********************************************************************/
421 WERROR
_svcctl_enum_services_status(pipes_struct
*p
, SVCCTL_Q_ENUM_SERVICES_STATUS
*q_u
, SVCCTL_R_ENUM_SERVICES_STATUS
*r_u
)
423 ENUM_SERVICES_STATUS
*services
= NULL
;
426 size_t buffer_size
= 0;
427 WERROR result
= WERR_OK
;
428 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, &q_u
->handle
);
429 NT_USER_TOKEN
*token
= p
->pipe_user
.nt_user_token
;
431 /* perform access checks */
433 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
436 if ( !(info
->access_granted
& SC_RIGHT_MGR_ENUMERATE_SERVICE
) ) {
437 return WERR_ACCESS_DENIED
;
440 num_services
= enumerate_status( p
->mem_ctx
, &services
, token
);
441 if (num_services
== -1 ) {
445 for ( i
=0; i
<num_services
; i
++ ) {
446 buffer_size
+= svcctl_sizeof_enum_services_status(&services
[i
]);
449 buffer_size
+= buffer_size
% 4;
451 if (buffer_size
> q_u
->buffer_size
) {
453 result
= WERR_MORE_DATA
;
456 rpcbuf_init(&r_u
->buffer
, q_u
->buffer_size
, p
->mem_ctx
);
458 if ( W_ERROR_IS_OK(result
) ) {
459 for ( i
=0; i
<num_services
; i
++ )
460 svcctl_io_enum_services_status( "", &services
[i
], &r_u
->buffer
, 0 );
463 r_u
->needed
= (buffer_size
> q_u
->buffer_size
) ? buffer_size
: q_u
->buffer_size
;
464 r_u
->returned
= (uint32
)num_services
;
466 if ( !(r_u
->resume
= TALLOC_P( p
->mem_ctx
, uint32
)) )
474 /********************************************************************
475 _svcctl_StartServiceW
476 ********************************************************************/
478 WERROR
_svcctl_StartServiceW(pipes_struct
*p
,
479 struct svcctl_StartServiceW
*r
)
481 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
483 /* perform access checks */
485 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
488 if ( !(info
->access_granted
& SC_RIGHT_SVC_START
) )
489 return WERR_ACCESS_DENIED
;
491 return info
->ops
->start_service( info
->name
);
494 /********************************************************************
495 _svcctl_ControlService
496 ********************************************************************/
498 WERROR
_svcctl_ControlService(pipes_struct
*p
,
499 struct svcctl_ControlService
*r
)
501 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
503 /* perform access checks */
505 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
508 switch ( r
->in
.control
) {
509 case SVCCTL_CONTROL_STOP
:
510 if ( !(info
->access_granted
& SC_RIGHT_SVC_STOP
) )
511 return WERR_ACCESS_DENIED
;
513 return info
->ops
->stop_service( info
->name
,
514 r
->out
.service_status
);
516 case SVCCTL_CONTROL_INTERROGATE
:
517 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
518 return WERR_ACCESS_DENIED
;
520 return info
->ops
->service_status( info
->name
,
521 r
->out
.service_status
);
524 /* default control action */
526 return WERR_ACCESS_DENIED
;
529 /********************************************************************
530 _svcctl_EnumDependentServicesW
531 ********************************************************************/
533 WERROR
_svcctl_EnumDependentServicesW(pipes_struct
*p
,
534 struct svcctl_EnumDependentServicesW
*r
)
536 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.service
);
538 /* perform access checks */
540 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
543 if ( !(info
->access_granted
& SC_RIGHT_SVC_ENUMERATE_DEPENDENTS
) )
544 return WERR_ACCESS_DENIED
;
546 /* we have to set the outgoing buffer size to the same as the
547 incoming buffer size (even in the case of failure */
548 /* this is done in the autogenerated server already - gd */
550 *r
->out
.bytes_needed
= r
->in
.buf_size
;
552 /* no dependent services...basically a stub function */
553 *r
->out
.services_returned
= 0;
558 /********************************************************************
559 ********************************************************************/
561 WERROR
_svcctl_query_service_status_ex( pipes_struct
*p
, SVCCTL_Q_QUERY_SERVICE_STATUSEX
*q_u
, SVCCTL_R_QUERY_SERVICE_STATUSEX
*r_u
)
563 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, &q_u
->handle
);
566 /* perform access checks */
568 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
571 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_STATUS
) )
572 return WERR_ACCESS_DENIED
;
574 /* we have to set the outgoing buffer size to the same as the
575 incoming buffer size (even in the case of failure) */
577 rpcbuf_init( &r_u
->buffer
, q_u
->buffer_size
, p
->mem_ctx
);
578 r_u
->needed
= q_u
->buffer_size
;
580 switch ( q_u
->level
) {
581 case SVC_STATUS_PROCESS_INFO
:
583 SERVICE_STATUS_PROCESS svc_stat_proc
;
585 /* Get the status of the service.. */
586 info
->ops
->service_status( info
->name
, &svc_stat_proc
.status
);
587 svc_stat_proc
.process_id
= sys_getpid();
588 svc_stat_proc
.service_flags
= 0x0;
590 svcctl_io_service_status_process( "", &svc_stat_proc
, &r_u
->buffer
, 0 );
591 buffer_size
= sizeof(SERVICE_STATUS_PROCESS
);
596 return WERR_UNKNOWN_LEVEL
;
600 buffer_size
+= buffer_size
% 4;
601 r_u
->needed
= (buffer_size
> q_u
->buffer_size
) ? buffer_size
: q_u
->buffer_size
;
603 if (buffer_size
> q_u
->buffer_size
)
604 return WERR_MORE_DATA
;
609 /********************************************************************
610 ********************************************************************/
612 static WERROR
fill_svc_config( TALLOC_CTX
*ctx
, const char *name
, SERVICE_CONFIG
*config
, NT_USER_TOKEN
*token
)
617 /* retrieve the registry values for this service */
619 if ( !(values
= svcctl_fetch_regvalues( name
, token
)) )
620 return WERR_REG_CORRUPT
;
622 /* now fill in the individual values */
624 config
->displayname
= TALLOC_ZERO_P( ctx
, UNISTR2
);
625 if ( (val
= regval_ctr_getvalue( values
, "DisplayName" )) != NULL
)
626 init_unistr2( config
->displayname
, regval_sz( val
), UNI_STR_TERMINATE
);
628 init_unistr2( config
->displayname
, name
, UNI_STR_TERMINATE
);
630 if ( (val
= regval_ctr_getvalue( values
, "ObjectName" )) != NULL
) {
631 config
->startname
= TALLOC_ZERO_P( ctx
, UNISTR2
);
632 init_unistr2( config
->startname
, regval_sz( val
), UNI_STR_TERMINATE
);
635 if ( (val
= regval_ctr_getvalue( values
, "ImagePath" )) != NULL
) {
636 config
->executablepath
= TALLOC_ZERO_P( ctx
, UNISTR2
);
637 init_unistr2( config
->executablepath
, regval_sz( val
), UNI_STR_TERMINATE
);
640 /* a few hard coded values */
641 /* loadordergroup and dependencies are empty */
643 config
->tag_id
= 0x00000000; /* unassigned loadorder group */
644 config
->service_type
= SVCCTL_WIN32_OWN_PROC
;
645 config
->error_control
= SVCCTL_SVC_ERROR_NORMAL
;
647 /* set the start type. NetLogon and WINS are disabled to prevent
648 the client from showing the "Start" button (if of course the services
651 if ( strequal( name
, "NETLOGON" ) && ( lp_servicenumber(name
) == -1 ) )
652 config
->start_type
= SVCCTL_DISABLED
;
653 else if ( strequal( name
, "WINS" ) && ( !lp_wins_support() ))
654 config
->start_type
= SVCCTL_DISABLED
;
656 config
->start_type
= SVCCTL_DEMAND_START
;
659 TALLOC_FREE( values
);
664 /********************************************************************
665 ********************************************************************/
667 WERROR
_svcctl_query_service_config( pipes_struct
*p
, SVCCTL_Q_QUERY_SERVICE_CONFIG
*q_u
, SVCCTL_R_QUERY_SERVICE_CONFIG
*r_u
)
669 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, &q_u
->handle
);
673 /* perform access checks */
675 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
678 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_CONFIG
) )
679 return WERR_ACCESS_DENIED
;
681 /* we have to set the outgoing buffer size to the same as the
682 incoming buffer size (even in the case of failure */
684 r_u
->needed
= q_u
->buffer_size
;
686 wresult
= fill_svc_config( p
->mem_ctx
, info
->name
, &r_u
->config
, p
->pipe_user
.nt_user_token
);
687 if ( !W_ERROR_IS_OK(wresult
) )
690 buffer_size
= svcctl_sizeof_service_config( &r_u
->config
);
691 r_u
->needed
= (buffer_size
> q_u
->buffer_size
) ? buffer_size
: q_u
->buffer_size
;
693 if (buffer_size
> q_u
->buffer_size
) {
694 ZERO_STRUCTP( &r_u
->config
);
695 return WERR_INSUFFICIENT_BUFFER
;
701 /********************************************************************
702 ********************************************************************/
704 WERROR
_svcctl_query_service_config2( pipes_struct
*p
, SVCCTL_Q_QUERY_SERVICE_CONFIG2
*q_u
, SVCCTL_R_QUERY_SERVICE_CONFIG2
*r_u
)
706 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, &q_u
->handle
);
709 /* perform access checks */
711 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SERVICE
) )
714 if ( !(info
->access_granted
& SC_RIGHT_SVC_QUERY_CONFIG
) )
715 return WERR_ACCESS_DENIED
;
717 /* we have to set the outgoing buffer size to the same as the
718 incoming buffer size (even in the case of failure */
720 rpcbuf_init( &r_u
->buffer
, q_u
->buffer_size
, p
->mem_ctx
);
721 r_u
->needed
= q_u
->buffer_size
;
723 switch ( q_u
->level
) {
724 case SERVICE_CONFIG_DESCRIPTION
:
726 SERVICE_DESCRIPTION desc_buf
;
727 const char *description
;
729 description
= svcctl_lookup_description(p
->mem_ctx
, info
->name
, p
->pipe_user
.nt_user_token
);
731 ZERO_STRUCTP( &desc_buf
);
733 init_service_description_buffer( &desc_buf
, description
? description
: "");
734 svcctl_io_service_description( "", &desc_buf
, &r_u
->buffer
, 0 );
735 buffer_size
= svcctl_sizeof_service_description( &desc_buf
);
740 case SERVICE_CONFIG_FAILURE_ACTIONS
:
742 SERVICE_FAILURE_ACTIONS actions
;
744 /* nothing to say...just service the request */
746 ZERO_STRUCTP( &actions
);
747 svcctl_io_service_fa( "", &actions
, &r_u
->buffer
, 0 );
748 buffer_size
= svcctl_sizeof_service_fa( &actions
);
755 return WERR_UNKNOWN_LEVEL
;
758 buffer_size
+= buffer_size
% 4;
759 r_u
->needed
= (buffer_size
> q_u
->buffer_size
) ? buffer_size
: q_u
->buffer_size
;
761 if (buffer_size
> q_u
->buffer_size
)
762 return WERR_INSUFFICIENT_BUFFER
;
767 /********************************************************************
768 _svcctl_LockServiceDatabase
769 ********************************************************************/
771 WERROR
_svcctl_LockServiceDatabase(pipes_struct
*p
,
772 struct svcctl_LockServiceDatabase
*r
)
774 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
776 /* perform access checks */
778 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_SCM
) )
781 if ( !(info
->access_granted
& SC_RIGHT_MGR_LOCK
) )
782 return WERR_ACCESS_DENIED
;
784 /* Just open a handle. Doesn't actually lock anything */
786 return create_open_service_handle( p
, r
->out
.lock
, SVC_HANDLE_IS_DBLOCK
, NULL
, 0 );
789 /********************************************************************
790 _svcctl_UnlockServiceDatabase
791 ********************************************************************/
793 WERROR
_svcctl_UnlockServiceDatabase(pipes_struct
*p
,
794 struct svcctl_UnlockServiceDatabase
*r
)
796 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.lock
);
799 if ( !info
|| (info
->type
!= SVC_HANDLE_IS_DBLOCK
) )
802 return close_policy_hnd( p
, r
->out
.lock
) ? WERR_OK
: WERR_BADFID
;
805 /********************************************************************
806 _svcctl_QueryServiceObjectSecurity
807 ********************************************************************/
809 WERROR
_svcctl_QueryServiceObjectSecurity(pipes_struct
*p
,
810 struct svcctl_QueryServiceObjectSecurity
*r
)
812 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
815 uint8_t *buffer
= NULL
;
819 /* only support the SCM and individual services */
821 if ( !info
|| !(info
->type
& (SVC_HANDLE_IS_SERVICE
|SVC_HANDLE_IS_SCM
)) )
824 /* check access reights (according to MSDN) */
826 if ( !(info
->access_granted
& STD_RIGHT_READ_CONTROL_ACCESS
) )
827 return WERR_ACCESS_DENIED
;
829 /* TODO: handle something besides DACL_SECURITY_INFORMATION */
831 if ( (r
->in
.security_flags
& DACL_SECURITY_INFORMATION
) != DACL_SECURITY_INFORMATION
)
832 return WERR_INVALID_PARAM
;
834 /* lookup the security descriptor and marshall it up for a reply */
836 if ( !(sec_desc
= svcctl_get_secdesc( p
->mem_ctx
, info
->name
, get_root_nt_token() )) )
839 *r
->out
.needed
= ndr_size_security_descriptor( sec_desc
, 0 );
841 if ( *r
->out
.needed
> r
->in
.buffer_size
) {
842 ZERO_STRUCTP( &r
->out
.buffer
);
843 return WERR_INSUFFICIENT_BUFFER
;
846 status
= marshall_sec_desc(p
->mem_ctx
, sec_desc
, &buffer
, &len
);
847 if (!NT_STATUS_IS_OK(status
)) {
848 return ntstatus_to_werror(status
);
851 *r
->out
.needed
= len
;
852 r
->out
.buffer
= buffer
;
857 /********************************************************************
858 _svcctl_SetServiceObjectSecurity
859 ********************************************************************/
861 WERROR
_svcctl_SetServiceObjectSecurity(pipes_struct
*p
,
862 struct svcctl_SetServiceObjectSecurity
*r
)
864 SERVICE_INFO
*info
= find_service_info_by_hnd( p
, r
->in
.handle
);
865 SEC_DESC
*sec_desc
= NULL
;
866 uint32 required_access
;
869 if ( !info
|| !(info
->type
& (SVC_HANDLE_IS_SERVICE
|SVC_HANDLE_IS_SCM
)) )
872 /* can't set the security de4scriptor on the ServiceControlManager */
874 if ( info
->type
== SVC_HANDLE_IS_SCM
)
875 return WERR_ACCESS_DENIED
;
877 /* check the access on the open handle */
879 switch ( r
->in
.security_flags
) {
880 case DACL_SECURITY_INFORMATION
:
881 required_access
= STD_RIGHT_WRITE_DAC_ACCESS
;
884 case OWNER_SECURITY_INFORMATION
:
885 case GROUP_SECURITY_INFORMATION
:
886 required_access
= STD_RIGHT_WRITE_OWNER_ACCESS
;
889 case SACL_SECURITY_INFORMATION
:
890 return WERR_INVALID_PARAM
;
892 return WERR_INVALID_PARAM
;
895 if ( !(info
->access_granted
& required_access
) )
896 return WERR_ACCESS_DENIED
;
898 /* read the security descfriptor */
900 status
= unmarshall_sec_desc(p
->mem_ctx
,
901 r
->in
.buffer
, r
->in
.buffer_size
,
903 if (!NT_STATUS_IS_OK(status
)) {
904 return ntstatus_to_werror(status
);
907 /* store the new SD */
909 if ( !svcctl_set_secdesc( p
->mem_ctx
, info
->name
, sec_desc
, p
->pipe_user
.nt_user_token
) )
910 return WERR_ACCESS_DENIED
;
916 WERROR
_svcctl_DeleteService(pipes_struct
*p
, struct svcctl_DeleteService
*r
)
918 p
->rng_fault_state
= True
;
919 return WERR_NOT_SUPPORTED
;
922 WERROR
_svcctl_SetServiceStatus(pipes_struct
*p
, struct svcctl_SetServiceStatus
*r
)
924 p
->rng_fault_state
= True
;
925 return WERR_NOT_SUPPORTED
;
928 WERROR
_svcctl_NotifyBootConfigStatus(pipes_struct
*p
, struct svcctl_NotifyBootConfigStatus
*r
)
930 p
->rng_fault_state
= True
;
931 return WERR_NOT_SUPPORTED
;
934 WERROR
_svcctl_SCSetServiceBitsW(pipes_struct
*p
, struct svcctl_SCSetServiceBitsW
*r
)
936 p
->rng_fault_state
= True
;
937 return WERR_NOT_SUPPORTED
;
940 WERROR
_svcctl_ChangeServiceConfigW(pipes_struct
*p
, struct svcctl_ChangeServiceConfigW
*r
)
942 p
->rng_fault_state
= True
;
943 return WERR_NOT_SUPPORTED
;
946 WERROR
_svcctl_CreateServiceW(pipes_struct
*p
, struct svcctl_CreateServiceW
*r
)
948 p
->rng_fault_state
= True
;
949 return WERR_NOT_SUPPORTED
;
952 WERROR
_svcctl_EnumServicesStatusW(pipes_struct
*p
, struct svcctl_EnumServicesStatusW
*r
)
954 p
->rng_fault_state
= True
;
955 return WERR_NOT_SUPPORTED
;
958 WERROR
_svcctl_QueryServiceConfigW(pipes_struct
*p
, struct svcctl_QueryServiceConfigW
*r
)
960 p
->rng_fault_state
= True
;
961 return WERR_NOT_SUPPORTED
;
964 WERROR
_svcctl_QueryServiceLockStatusW(pipes_struct
*p
, struct svcctl_QueryServiceLockStatusW
*r
)
966 p
->rng_fault_state
= True
;
967 return WERR_NOT_SUPPORTED
;
970 WERROR
_svcctl_GetServiceKeyNameW(pipes_struct
*p
, struct svcctl_GetServiceKeyNameW
*r
)
972 p
->rng_fault_state
= True
;
973 return WERR_NOT_SUPPORTED
;
976 WERROR
_svcctl_SCSetServiceBitsA(pipes_struct
*p
, struct svcctl_SCSetServiceBitsA
*r
)
978 p
->rng_fault_state
= True
;
979 return WERR_NOT_SUPPORTED
;
982 WERROR
_svcctl_ChangeServiceConfigA(pipes_struct
*p
, struct svcctl_ChangeServiceConfigA
*r
)
984 p
->rng_fault_state
= True
;
985 return WERR_NOT_SUPPORTED
;
988 WERROR
_svcctl_CreateServiceA(pipes_struct
*p
, struct svcctl_CreateServiceA
*r
)
990 p
->rng_fault_state
= True
;
991 return WERR_NOT_SUPPORTED
;
994 WERROR
_svcctl_EnumDependentServicesA(pipes_struct
*p
, struct svcctl_EnumDependentServicesA
*r
)
996 p
->rng_fault_state
= True
;
997 return WERR_NOT_SUPPORTED
;
1000 WERROR
_svcctl_EnumServicesStatusA(pipes_struct
*p
, struct svcctl_EnumServicesStatusA
*r
)
1002 p
->rng_fault_state
= True
;
1003 return WERR_NOT_SUPPORTED
;
1006 WERROR
_svcctl_OpenSCManagerA(pipes_struct
*p
, struct svcctl_OpenSCManagerA
*r
)
1008 p
->rng_fault_state
= True
;
1009 return WERR_NOT_SUPPORTED
;
1012 WERROR
_svcctl_OpenServiceA(pipes_struct
*p
, struct svcctl_OpenServiceA
*r
)
1014 p
->rng_fault_state
= True
;
1015 return WERR_NOT_SUPPORTED
;
1018 WERROR
_svcctl_QueryServiceConfigA(pipes_struct
*p
, struct svcctl_QueryServiceConfigA
*r
)
1020 p
->rng_fault_state
= True
;
1021 return WERR_NOT_SUPPORTED
;
1024 WERROR
_svcctl_QueryServiceLockStatusA(pipes_struct
*p
, struct svcctl_QueryServiceLockStatusA
*r
)
1026 p
->rng_fault_state
= True
;
1027 return WERR_NOT_SUPPORTED
;
1030 WERROR
_svcctl_StartServiceA(pipes_struct
*p
, struct svcctl_StartServiceA
*r
)
1032 p
->rng_fault_state
= True
;
1033 return WERR_NOT_SUPPORTED
;
1036 WERROR
_svcctl_GetServiceDisplayNameA(pipes_struct
*p
, struct svcctl_GetServiceDisplayNameA
*r
)
1038 p
->rng_fault_state
= True
;
1039 return WERR_NOT_SUPPORTED
;
1042 WERROR
_svcctl_GetServiceKeyNameA(pipes_struct
*p
, struct svcctl_GetServiceKeyNameA
*r
)
1044 p
->rng_fault_state
= True
;
1045 return WERR_NOT_SUPPORTED
;
1048 WERROR
_svcctl_GetCurrentGroupeStateW(pipes_struct
*p
, struct svcctl_GetCurrentGroupeStateW
*r
)
1050 p
->rng_fault_state
= True
;
1051 return WERR_NOT_SUPPORTED
;
1054 WERROR
_svcctl_EnumServiceGroupW(pipes_struct
*p
, struct svcctl_EnumServiceGroupW
*r
)
1056 p
->rng_fault_state
= True
;
1057 return WERR_NOT_SUPPORTED
;
1060 WERROR
_svcctl_ChangeServiceConfig2A(pipes_struct
*p
, struct svcctl_ChangeServiceConfig2A
*r
)
1062 p
->rng_fault_state
= True
;
1063 return WERR_NOT_SUPPORTED
;
1066 WERROR
_svcctl_ChangeServiceConfig2W(pipes_struct
*p
, struct svcctl_ChangeServiceConfig2W
*r
)
1068 p
->rng_fault_state
= True
;
1069 return WERR_NOT_SUPPORTED
;
1072 WERROR
_svcctl_QueryServiceConfig2A(pipes_struct
*p
, struct svcctl_QueryServiceConfig2A
*r
)
1074 p
->rng_fault_state
= True
;
1075 return WERR_NOT_SUPPORTED
;
1078 WERROR
_svcctl_QueryServiceConfig2W(pipes_struct
*p
, struct svcctl_QueryServiceConfig2W
*r
)
1080 p
->rng_fault_state
= True
;
1081 return WERR_NOT_SUPPORTED
;
1084 WERROR
_svcctl_QueryServiceStatusEx(pipes_struct
*p
, struct svcctl_QueryServiceStatusEx
*r
)
1086 p
->rng_fault_state
= True
;
1087 return WERR_NOT_SUPPORTED
;
1090 WERROR
_EnumServicesStatusExA(pipes_struct
*p
, struct EnumServicesStatusExA
*r
)
1092 p
->rng_fault_state
= True
;
1093 return WERR_NOT_SUPPORTED
;
1096 WERROR
_EnumServicesStatusExW(pipes_struct
*p
, struct EnumServicesStatusExW
*r
)
1098 p
->rng_fault_state
= True
;
1099 return WERR_NOT_SUPPORTED
;
1102 WERROR
_svcctl_SCSendTSMessage(pipes_struct
*p
, struct svcctl_SCSendTSMessage
*r
)
1104 p
->rng_fault_state
= True
;
1105 return WERR_NOT_SUPPORTED
;