s3/packaging: Add keyutils-devel to build requires.
[Samba/bb.git] / source / rpc_server / srv_svcctl_nt.c
blob226a390f256ffd88cf51a95bff7d88cf2e4185f1
1 /*
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.
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/>.
25 #include "includes.h"
27 #undef DBGC_CLASS
28 #define DBGC_CLASS DBGC_RPC_SRV
30 struct service_control_op {
31 const char *name;
32 SERVICE_CONTROL_OPS *ops;
35 #define SVCCTL_NUM_INTERNAL_SERVICES 4
37 /* handle external services */
38 extern SERVICE_CONTROL_OPS rcinit_svc_ops;
40 /* builtin services (see service_db.c and services/svc_*.c */
41 extern SERVICE_CONTROL_OPS spoolss_svc_ops;
42 extern SERVICE_CONTROL_OPS netlogon_svc_ops;
43 extern SERVICE_CONTROL_OPS winreg_svc_ops;
44 extern SERVICE_CONTROL_OPS wins_svc_ops;
46 /* make sure this number patches the number of builtin
47 SERVICE_CONTROL_OPS structure listed above */
49 #define SVCCTL_NUM_INTERNAL_SERVICES 4
51 struct service_control_op *svcctl_ops;
53 static const struct generic_mapping scm_generic_map =
54 { SC_MANAGER_READ_ACCESS, SC_MANAGER_WRITE_ACCESS, SC_MANAGER_EXECUTE_ACCESS, SC_MANAGER_ALL_ACCESS };
55 static const struct generic_mapping svc_generic_map =
56 { SERVICE_READ_ACCESS, SERVICE_WRITE_ACCESS, SERVICE_EXECUTE_ACCESS, SERVICE_ALL_ACCESS };
59 /********************************************************************
60 ********************************************************************/
62 bool init_service_op_table( void )
64 const char **service_list = lp_svcctl_list();
65 int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_count( service_list );
66 int i;
68 if ( !(svcctl_ops = TALLOC_ARRAY( NULL, struct service_control_op, num_services+1)) ) {
69 DEBUG(0,("init_service_op_table: talloc() failed!\n"));
70 return False;
73 /* services listed in smb.conf get the rc.init interface */
75 for ( i=0; service_list && service_list[i]; i++ ) {
76 svcctl_ops[i].name = talloc_strdup( svcctl_ops, service_list[i] );
77 svcctl_ops[i].ops = &rcinit_svc_ops;
80 /* add builtin services */
82 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "Spooler" );
83 svcctl_ops[i].ops = &spoolss_svc_ops;
84 i++;
86 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "NETLOGON" );
87 svcctl_ops[i].ops = &netlogon_svc_ops;
88 i++;
90 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "RemoteRegistry" );
91 svcctl_ops[i].ops = &winreg_svc_ops;
92 i++;
94 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "WINS" );
95 svcctl_ops[i].ops = &wins_svc_ops;
96 i++;
98 /* NULL terminate the array */
100 svcctl_ops[i].name = NULL;
101 svcctl_ops[i].ops = NULL;
103 return True;
106 /********************************************************************
107 ********************************************************************/
109 static struct service_control_op* find_service_by_name( const char *name )
111 int i;
113 for ( i=0; svcctl_ops[i].name; i++ ) {
114 if ( strequal( name, svcctl_ops[i].name ) )
115 return &svcctl_ops[i];
118 return NULL;
120 /********************************************************************
121 ********************************************************************/
123 static NTSTATUS svcctl_access_check( SEC_DESC *sec_desc, NT_USER_TOKEN *token,
124 uint32 access_desired, uint32 *access_granted )
126 if ( geteuid() == sec_initial_uid() ) {
127 DEBUG(5,("svcctl_access_check: using root's token\n"));
128 token = get_root_nt_token();
131 return se_access_check( sec_desc, token, access_desired, access_granted);
134 /********************************************************************
135 ********************************************************************/
137 static SEC_DESC* construct_scm_sd( TALLOC_CTX *ctx )
139 SEC_ACE ace[2];
140 size_t i = 0;
141 SEC_DESC *sd;
142 SEC_ACL *theacl;
143 size_t sd_size;
145 /* basic access for Everyone */
147 init_sec_ace(&ace[i++], &global_sid_World,
148 SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_READ_ACCESS, 0);
150 /* Full Access 'BUILTIN\Administrators' */
152 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
153 SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_ALL_ACCESS, 0);
156 /* create the security descriptor */
158 if ( !(theacl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
159 return NULL;
161 if ( !(sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
162 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
163 theacl, &sd_size)) )
164 return NULL;
166 return sd;
169 /******************************************************************
170 free() function for REGISTRY_KEY
171 *****************************************************************/
173 static void free_service_handle_info(void *ptr)
175 TALLOC_FREE( ptr );
178 /******************************************************************
179 Find a registry key handle and return a SERVICE_INFO
180 *****************************************************************/
182 static SERVICE_INFO *find_service_info_by_hnd(pipes_struct *p, POLICY_HND *hnd)
184 SERVICE_INFO *service_info = NULL;
186 if( !find_policy_by_hnd( p, hnd, (void **)(void *)&service_info) ) {
187 DEBUG(2,("find_service_info_by_hnd: handle not found\n"));
188 return NULL;
191 return service_info;
194 /******************************************************************
195 *****************************************************************/
197 static WERROR create_open_service_handle( pipes_struct *p, POLICY_HND *handle, uint32 type,
198 const char *service, uint32 access_granted )
200 SERVICE_INFO *info = NULL;
201 WERROR result = WERR_OK;
202 struct service_control_op *s_op;
204 if ( !(info = TALLOC_ZERO_P( NULL, SERVICE_INFO )) )
205 return WERR_NOMEM;
207 /* the Service Manager has a NULL name */
209 info->type = SVC_HANDLE_IS_SCM;
211 switch ( type ) {
212 case SVC_HANDLE_IS_SCM:
213 info->type = SVC_HANDLE_IS_SCM;
214 break;
216 case SVC_HANDLE_IS_DBLOCK:
217 info->type = SVC_HANDLE_IS_DBLOCK;
218 break;
220 case SVC_HANDLE_IS_SERVICE:
221 info->type = SVC_HANDLE_IS_SERVICE;
223 /* lookup the SERVICE_CONTROL_OPS */
225 if ( !(s_op = find_service_by_name( service )) ) {
226 result = WERR_NO_SUCH_SERVICE;
227 goto done;
230 info->ops = s_op->ops;
232 if ( !(info->name = talloc_strdup( info, s_op->name )) ) {
233 result = WERR_NOMEM;
234 goto done;
236 break;
238 default:
239 result = WERR_NO_SUCH_SERVICE;
240 goto done;
243 info->access_granted = access_granted;
245 /* store the SERVICE_INFO and create an open handle */
247 if ( !create_policy_hnd( p, handle, free_service_handle_info, info ) ) {
248 result = WERR_ACCESS_DENIED;
249 goto done;
252 done:
253 if ( !W_ERROR_IS_OK(result) )
254 free_service_handle_info( info );
256 return result;
259 /********************************************************************
260 ********************************************************************/
262 WERROR _svcctl_OpenSCManagerW(pipes_struct *p,
263 struct svcctl_OpenSCManagerW *r)
265 SEC_DESC *sec_desc;
266 uint32 access_granted = 0;
267 NTSTATUS status;
269 /* perform access checks */
271 if ( !(sec_desc = construct_scm_sd( p->mem_ctx )) )
272 return WERR_NOMEM;
274 se_map_generic( &r->in.access_mask, &scm_generic_map );
275 status = svcctl_access_check( sec_desc, p->pipe_user.nt_user_token, r->in.access_mask, &access_granted );
276 if ( !NT_STATUS_IS_OK(status) )
277 return ntstatus_to_werror( status );
279 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SCM, NULL, access_granted );
282 /********************************************************************
283 _svcctl_OpenServiceW
284 ********************************************************************/
286 WERROR _svcctl_OpenServiceW(pipes_struct *p,
287 struct svcctl_OpenServiceW *r)
289 SEC_DESC *sec_desc;
290 uint32 access_granted = 0;
291 NTSTATUS status;
292 const char *service = NULL;
294 service = r->in.ServiceName;
295 if (!service) {
296 return WERR_NOMEM;
298 DEBUG(5, ("_svcctl_OpenServiceW: Attempting to open Service [%s], \n", service));
300 /* based on my tests you can open a service if you have a valid scm handle */
302 if ( !find_service_info_by_hnd( p, r->in.scmanager_handle) )
303 return WERR_BADFID;
305 /* perform access checks. Use the root token in order to ensure that we
306 retrieve the security descriptor */
308 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, service, get_root_nt_token() )) )
309 return WERR_NOMEM;
311 se_map_generic( &r->in.access_mask, &svc_generic_map );
312 status = svcctl_access_check( sec_desc, p->pipe_user.nt_user_token, r->in.access_mask, &access_granted );
313 if ( !NT_STATUS_IS_OK(status) )
314 return ntstatus_to_werror( status );
316 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SERVICE, service, access_granted );
319 /********************************************************************
320 ********************************************************************/
322 WERROR _svcctl_CloseServiceHandle(pipes_struct *p, struct svcctl_CloseServiceHandle *r)
324 if ( !close_policy_hnd( p, r->in.handle ) )
325 return WERR_BADFID;
327 ZERO_STRUCTP(r->out.handle);
329 return WERR_OK;
332 /********************************************************************
333 _svcctl_GetServiceDisplayNameW
334 ********************************************************************/
336 WERROR _svcctl_GetServiceDisplayNameW(pipes_struct *p,
337 struct svcctl_GetServiceDisplayNameW *r)
339 const char *service;
340 const char *display_name;
341 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
343 /* can only use an SCM handle here */
345 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
346 return WERR_BADFID;
348 service = r->in.service_name;
350 display_name = svcctl_lookup_dispname(p->mem_ctx, service, p->pipe_user.nt_user_token );
351 if (!display_name) {
352 display_name = "";
355 *r->out.display_name = display_name;
356 *r->out.display_name_length = strlen(display_name);
358 return WERR_OK;
361 /********************************************************************
362 _svcctl_QueryServiceStatus
363 ********************************************************************/
365 WERROR _svcctl_QueryServiceStatus(pipes_struct *p,
366 struct svcctl_QueryServiceStatus *r)
368 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
370 /* perform access checks */
372 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
373 return WERR_BADFID;
375 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
376 return WERR_ACCESS_DENIED;
378 /* try the service specific status call */
380 return info->ops->service_status( info->name, r->out.service_status );
383 /********************************************************************
384 ********************************************************************/
386 static int enumerate_status( TALLOC_CTX *ctx, ENUM_SERVICES_STATUS **status, NT_USER_TOKEN *token )
388 int num_services = 0;
389 int i;
390 ENUM_SERVICES_STATUS *st;
391 const char *display_name;
393 /* just count */
394 while ( svcctl_ops[num_services].name )
395 num_services++;
397 if ( !(st = TALLOC_ARRAY( ctx, ENUM_SERVICES_STATUS, num_services )) ) {
398 DEBUG(0,("enumerate_status: talloc() failed!\n"));
399 return -1;
402 for ( i=0; i<num_services; i++ ) {
403 init_unistr( &st[i].servicename, svcctl_ops[i].name );
405 display_name = svcctl_lookup_dispname(ctx, svcctl_ops[i].name, token );
406 init_unistr( &st[i].displayname, display_name ? display_name : "");
408 svcctl_ops[i].ops->service_status( svcctl_ops[i].name, &st[i].status );
411 *status = st;
413 return num_services;
416 /********************************************************************
417 ********************************************************************/
419 WERROR _svcctl_enum_services_status(pipes_struct *p, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, SVCCTL_R_ENUM_SERVICES_STATUS *r_u)
421 ENUM_SERVICES_STATUS *services = NULL;
422 int num_services;
423 int i = 0;
424 size_t buffer_size = 0;
425 WERROR result = WERR_OK;
426 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
427 NT_USER_TOKEN *token = p->pipe_user.nt_user_token;
429 /* perform access checks */
431 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
432 return WERR_BADFID;
434 if ( !(info->access_granted & SC_RIGHT_MGR_ENUMERATE_SERVICE) ) {
435 return WERR_ACCESS_DENIED;
438 num_services = enumerate_status( p->mem_ctx, &services, token );
439 if (num_services == -1 ) {
440 return WERR_NOMEM;
443 for ( i=0; i<num_services; i++ ) {
444 buffer_size += svcctl_sizeof_enum_services_status(&services[i]);
447 buffer_size += buffer_size % 4;
449 if (buffer_size > q_u->buffer_size ) {
450 num_services = 0;
451 result = WERR_MORE_DATA;
454 rpcbuf_init(&r_u->buffer, q_u->buffer_size, p->mem_ctx);
456 if ( W_ERROR_IS_OK(result) ) {
457 for ( i=0; i<num_services; i++ )
458 svcctl_io_enum_services_status( "", &services[i], &r_u->buffer, 0 );
461 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
462 r_u->returned = (uint32)num_services;
464 if ( !(r_u->resume = TALLOC_P( p->mem_ctx, uint32 )) )
465 return WERR_NOMEM;
467 *r_u->resume = 0x0;
469 return result;
472 /********************************************************************
473 _svcctl_StartServiceW
474 ********************************************************************/
476 WERROR _svcctl_StartServiceW(pipes_struct *p,
477 struct svcctl_StartServiceW *r)
479 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
481 /* perform access checks */
483 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
484 return WERR_BADFID;
486 if ( !(info->access_granted & SC_RIGHT_SVC_START) )
487 return WERR_ACCESS_DENIED;
489 return info->ops->start_service( info->name );
492 /********************************************************************
493 _svcctl_ControlService
494 ********************************************************************/
496 WERROR _svcctl_ControlService(pipes_struct *p,
497 struct svcctl_ControlService *r)
499 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
501 /* perform access checks */
503 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
504 return WERR_BADFID;
506 switch ( r->in.control ) {
507 case SVCCTL_CONTROL_STOP:
508 if ( !(info->access_granted & SC_RIGHT_SVC_STOP) )
509 return WERR_ACCESS_DENIED;
511 return info->ops->stop_service( info->name,
512 r->out.service_status );
514 case SVCCTL_CONTROL_INTERROGATE:
515 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
516 return WERR_ACCESS_DENIED;
518 return info->ops->service_status( info->name,
519 r->out.service_status );
522 /* default control action */
524 return WERR_ACCESS_DENIED;
527 /********************************************************************
528 _svcctl_EnumDependentServicesW
529 ********************************************************************/
531 WERROR _svcctl_EnumDependentServicesW(pipes_struct *p,
532 struct svcctl_EnumDependentServicesW *r)
534 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.service );
536 /* perform access checks */
538 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
539 return WERR_BADFID;
541 if ( !(info->access_granted & SC_RIGHT_SVC_ENUMERATE_DEPENDENTS) )
542 return WERR_ACCESS_DENIED;
544 /* we have to set the outgoing buffer size to the same as the
545 incoming buffer size (even in the case of failure */
546 /* this is done in the autogenerated server already - gd */
548 *r->out.bytes_needed = r->in.buf_size;
550 /* no dependent services...basically a stub function */
551 *r->out.services_returned = 0;
553 return WERR_OK;
556 /********************************************************************
557 ********************************************************************/
559 WERROR _svcctl_query_service_status_ex( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u )
561 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
562 uint32 buffer_size;
564 /* perform access checks */
566 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
567 return WERR_BADFID;
569 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
570 return WERR_ACCESS_DENIED;
572 /* we have to set the outgoing buffer size to the same as the
573 incoming buffer size (even in the case of failure) */
575 rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
576 r_u->needed = q_u->buffer_size;
578 switch ( q_u->level ) {
579 case SVC_STATUS_PROCESS_INFO:
581 SERVICE_STATUS_PROCESS svc_stat_proc;
583 /* Get the status of the service.. */
584 info->ops->service_status( info->name, &svc_stat_proc.status );
585 svc_stat_proc.process_id = sys_getpid();
586 svc_stat_proc.service_flags = 0x0;
588 svcctl_io_service_status_process( "", &svc_stat_proc, &r_u->buffer, 0 );
589 buffer_size = sizeof(SERVICE_STATUS_PROCESS);
590 break;
593 default:
594 return WERR_UNKNOWN_LEVEL;
598 buffer_size += buffer_size % 4;
599 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
601 if (buffer_size > q_u->buffer_size )
602 return WERR_MORE_DATA;
604 return WERR_OK;
607 /********************************************************************
608 ********************************************************************/
610 static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name,
611 struct QUERY_SERVICE_CONFIG *config,
612 NT_USER_TOKEN *token )
614 REGVAL_CTR *values;
615 REGISTRY_VALUE *val;
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 if ( (val = regval_ctr_getvalue( values, "DisplayName" )) != NULL )
625 config->displayname = regval_sz(val);
626 else
627 config->displayname = name;
629 if ( (val = regval_ctr_getvalue( values, "ObjectName" )) != NULL ) {
630 config->startname = regval_sz(val);
633 if ( (val = regval_ctr_getvalue( values, "ImagePath" )) != NULL ) {
634 config->executablepath = regval_sz(val);
637 /* a few hard coded values */
638 /* loadordergroup and dependencies are empty */
640 config->tag_id = 0x00000000; /* unassigned loadorder group */
641 config->service_type = SVCCTL_WIN32_OWN_PROC;
642 config->error_control = SVCCTL_SVC_ERROR_NORMAL;
644 /* set the start type. NetLogon and WINS are disabled to prevent
645 the client from showing the "Start" button (if of course the services
646 are not running */
648 if ( strequal( name, "NETLOGON" ) && ( lp_servicenumber(name) == -1 ) )
649 config->start_type = SVCCTL_DISABLED;
650 else if ( strequal( name, "WINS" ) && ( !lp_wins_support() ))
651 config->start_type = SVCCTL_DISABLED;
652 else
653 config->start_type = SVCCTL_DEMAND_START;
656 TALLOC_FREE( values );
658 return WERR_OK;
661 /********************************************************************
662 _svcctl_QueryServiceConfigW
663 ********************************************************************/
665 WERROR _svcctl_QueryServiceConfigW(pipes_struct *p,
666 struct svcctl_QueryServiceConfigW *r)
668 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
669 uint32 buffer_size;
670 WERROR wresult;
672 /* perform access checks */
674 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
675 return WERR_BADFID;
677 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_CONFIG) )
678 return WERR_ACCESS_DENIED;
680 /* we have to set the outgoing buffer size to the same as the
681 incoming buffer size (even in the case of failure */
682 *r->out.bytes_needed = r->in.buf_size;
684 wresult = fill_svc_config( p->mem_ctx, info->name, r->out.query, p->pipe_user.nt_user_token );
685 if ( !W_ERROR_IS_OK(wresult) )
686 return wresult;
688 buffer_size = ndr_size_QUERY_SERVICE_CONFIG(r->out.query, 0);
689 *r->out.bytes_needed = (buffer_size > r->in.buf_size) ? buffer_size : r->in.buf_size;
691 if (buffer_size > r->in.buf_size ) {
692 ZERO_STRUCTP(r->out.query);
693 return WERR_INSUFFICIENT_BUFFER;
696 return WERR_OK;
699 /********************************************************************
700 ********************************************************************/
702 WERROR _svcctl_query_service_config2( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u )
704 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
705 uint32 buffer_size;
707 /* perform access checks */
709 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
710 return WERR_BADFID;
712 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_CONFIG) )
713 return WERR_ACCESS_DENIED;
715 /* we have to set the outgoing buffer size to the same as the
716 incoming buffer size (even in the case of failure */
718 rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
719 r_u->needed = q_u->buffer_size;
721 switch ( q_u->level ) {
722 case SERVICE_CONFIG_DESCRIPTION:
724 SERVICE_DESCRIPTION desc_buf;
725 const char *description;
727 description = svcctl_lookup_description(p->mem_ctx, info->name, p->pipe_user.nt_user_token );
729 ZERO_STRUCTP( &desc_buf );
731 init_service_description_buffer( &desc_buf, description ? description : "");
732 svcctl_io_service_description( "", &desc_buf, &r_u->buffer, 0 );
733 buffer_size = svcctl_sizeof_service_description( &desc_buf );
735 break;
737 break;
738 case SERVICE_CONFIG_FAILURE_ACTIONS:
740 SERVICE_FAILURE_ACTIONS actions;
742 /* nothing to say...just service the request */
744 ZERO_STRUCTP( &actions );
745 svcctl_io_service_fa( "", &actions, &r_u->buffer, 0 );
746 buffer_size = svcctl_sizeof_service_fa( &actions );
748 break;
750 break;
752 default:
753 return WERR_UNKNOWN_LEVEL;
756 buffer_size += buffer_size % 4;
757 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
759 if (buffer_size > q_u->buffer_size )
760 return WERR_INSUFFICIENT_BUFFER;
762 return WERR_OK;
765 /********************************************************************
766 _svcctl_LockServiceDatabase
767 ********************************************************************/
769 WERROR _svcctl_LockServiceDatabase(pipes_struct *p,
770 struct svcctl_LockServiceDatabase *r)
772 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
774 /* perform access checks */
776 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
777 return WERR_BADFID;
779 if ( !(info->access_granted & SC_RIGHT_MGR_LOCK) )
780 return WERR_ACCESS_DENIED;
782 /* Just open a handle. Doesn't actually lock anything */
784 return create_open_service_handle( p, r->out.lock, SVC_HANDLE_IS_DBLOCK, NULL, 0 );
787 /********************************************************************
788 _svcctl_UnlockServiceDatabase
789 ********************************************************************/
791 WERROR _svcctl_UnlockServiceDatabase(pipes_struct *p,
792 struct svcctl_UnlockServiceDatabase *r)
794 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.lock );
797 if ( !info || (info->type != SVC_HANDLE_IS_DBLOCK) )
798 return WERR_BADFID;
800 return close_policy_hnd( p, r->out.lock) ? WERR_OK : WERR_BADFID;
803 /********************************************************************
804 _svcctl_QueryServiceObjectSecurity
805 ********************************************************************/
807 WERROR _svcctl_QueryServiceObjectSecurity(pipes_struct *p,
808 struct svcctl_QueryServiceObjectSecurity *r)
810 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
811 SEC_DESC *sec_desc;
812 NTSTATUS status;
813 uint8_t *buffer = NULL;
814 size_t len = 0;
817 /* only support the SCM and individual services */
819 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
820 return WERR_BADFID;
822 /* check access reights (according to MSDN) */
824 if ( !(info->access_granted & STD_RIGHT_READ_CONTROL_ACCESS) )
825 return WERR_ACCESS_DENIED;
827 /* TODO: handle something besides DACL_SECURITY_INFORMATION */
829 if ( (r->in.security_flags & DACL_SECURITY_INFORMATION) != DACL_SECURITY_INFORMATION )
830 return WERR_INVALID_PARAM;
832 /* lookup the security descriptor and marshall it up for a reply */
834 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, info->name, get_root_nt_token() )) )
835 return WERR_NOMEM;
837 *r->out.needed = ndr_size_security_descriptor( sec_desc, 0 );
839 if ( *r->out.needed > r->in.buffer_size ) {
840 ZERO_STRUCTP( &r->out.buffer );
841 return WERR_INSUFFICIENT_BUFFER;
844 status = marshall_sec_desc(p->mem_ctx, sec_desc, &buffer, &len);
845 if (!NT_STATUS_IS_OK(status)) {
846 return ntstatus_to_werror(status);
849 *r->out.needed = len;
850 r->out.buffer = buffer;
852 return WERR_OK;
855 /********************************************************************
856 _svcctl_SetServiceObjectSecurity
857 ********************************************************************/
859 WERROR _svcctl_SetServiceObjectSecurity(pipes_struct *p,
860 struct svcctl_SetServiceObjectSecurity *r)
862 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
863 SEC_DESC *sec_desc = NULL;
864 uint32 required_access;
865 NTSTATUS status;
867 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
868 return WERR_BADFID;
870 /* can't set the security de4scriptor on the ServiceControlManager */
872 if ( info->type == SVC_HANDLE_IS_SCM )
873 return WERR_ACCESS_DENIED;
875 /* check the access on the open handle */
877 switch ( r->in.security_flags ) {
878 case DACL_SECURITY_INFORMATION:
879 required_access = STD_RIGHT_WRITE_DAC_ACCESS;
880 break;
882 case OWNER_SECURITY_INFORMATION:
883 case GROUP_SECURITY_INFORMATION:
884 required_access = STD_RIGHT_WRITE_OWNER_ACCESS;
885 break;
887 case SACL_SECURITY_INFORMATION:
888 return WERR_INVALID_PARAM;
889 default:
890 return WERR_INVALID_PARAM;
893 if ( !(info->access_granted & required_access) )
894 return WERR_ACCESS_DENIED;
896 /* read the security descfriptor */
898 status = unmarshall_sec_desc(p->mem_ctx,
899 r->in.buffer, r->in.buffer_size,
900 &sec_desc);
901 if (!NT_STATUS_IS_OK(status)) {
902 return ntstatus_to_werror(status);
905 /* store the new SD */
907 if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc, p->pipe_user.nt_user_token ) )
908 return WERR_ACCESS_DENIED;
910 return WERR_OK;
914 WERROR _svcctl_DeleteService(pipes_struct *p, struct svcctl_DeleteService *r)
916 p->rng_fault_state = True;
917 return WERR_NOT_SUPPORTED;
920 WERROR _svcctl_SetServiceStatus(pipes_struct *p, struct svcctl_SetServiceStatus *r)
922 p->rng_fault_state = True;
923 return WERR_NOT_SUPPORTED;
926 WERROR _svcctl_NotifyBootConfigStatus(pipes_struct *p, struct svcctl_NotifyBootConfigStatus *r)
928 p->rng_fault_state = True;
929 return WERR_NOT_SUPPORTED;
932 WERROR _svcctl_SCSetServiceBitsW(pipes_struct *p, struct svcctl_SCSetServiceBitsW *r)
934 p->rng_fault_state = True;
935 return WERR_NOT_SUPPORTED;
938 WERROR _svcctl_ChangeServiceConfigW(pipes_struct *p, struct svcctl_ChangeServiceConfigW *r)
940 p->rng_fault_state = True;
941 return WERR_NOT_SUPPORTED;
944 WERROR _svcctl_CreateServiceW(pipes_struct *p, struct svcctl_CreateServiceW *r)
946 p->rng_fault_state = True;
947 return WERR_NOT_SUPPORTED;
950 WERROR _svcctl_EnumServicesStatusW(pipes_struct *p, struct svcctl_EnumServicesStatusW *r)
952 p->rng_fault_state = True;
953 return WERR_NOT_SUPPORTED;
956 WERROR _svcctl_QueryServiceLockStatusW(pipes_struct *p, struct svcctl_QueryServiceLockStatusW *r)
958 p->rng_fault_state = True;
959 return WERR_NOT_SUPPORTED;
962 WERROR _svcctl_GetServiceKeyNameW(pipes_struct *p, struct svcctl_GetServiceKeyNameW *r)
964 p->rng_fault_state = True;
965 return WERR_NOT_SUPPORTED;
968 WERROR _svcctl_SCSetServiceBitsA(pipes_struct *p, struct svcctl_SCSetServiceBitsA *r)
970 p->rng_fault_state = True;
971 return WERR_NOT_SUPPORTED;
974 WERROR _svcctl_ChangeServiceConfigA(pipes_struct *p, struct svcctl_ChangeServiceConfigA *r)
976 p->rng_fault_state = True;
977 return WERR_NOT_SUPPORTED;
980 WERROR _svcctl_CreateServiceA(pipes_struct *p, struct svcctl_CreateServiceA *r)
982 p->rng_fault_state = True;
983 return WERR_NOT_SUPPORTED;
986 WERROR _svcctl_EnumDependentServicesA(pipes_struct *p, struct svcctl_EnumDependentServicesA *r)
988 p->rng_fault_state = True;
989 return WERR_NOT_SUPPORTED;
992 WERROR _svcctl_EnumServicesStatusA(pipes_struct *p, struct svcctl_EnumServicesStatusA *r)
994 p->rng_fault_state = True;
995 return WERR_NOT_SUPPORTED;
998 WERROR _svcctl_OpenSCManagerA(pipes_struct *p, struct svcctl_OpenSCManagerA *r)
1000 p->rng_fault_state = True;
1001 return WERR_NOT_SUPPORTED;
1004 WERROR _svcctl_OpenServiceA(pipes_struct *p, struct svcctl_OpenServiceA *r)
1006 p->rng_fault_state = True;
1007 return WERR_NOT_SUPPORTED;
1010 WERROR _svcctl_QueryServiceConfigA(pipes_struct *p, struct svcctl_QueryServiceConfigA *r)
1012 p->rng_fault_state = True;
1013 return WERR_NOT_SUPPORTED;
1016 WERROR _svcctl_QueryServiceLockStatusA(pipes_struct *p, struct svcctl_QueryServiceLockStatusA *r)
1018 p->rng_fault_state = True;
1019 return WERR_NOT_SUPPORTED;
1022 WERROR _svcctl_StartServiceA(pipes_struct *p, struct svcctl_StartServiceA *r)
1024 p->rng_fault_state = True;
1025 return WERR_NOT_SUPPORTED;
1028 WERROR _svcctl_GetServiceDisplayNameA(pipes_struct *p, struct svcctl_GetServiceDisplayNameA *r)
1030 p->rng_fault_state = True;
1031 return WERR_NOT_SUPPORTED;
1034 WERROR _svcctl_GetServiceKeyNameA(pipes_struct *p, struct svcctl_GetServiceKeyNameA *r)
1036 p->rng_fault_state = True;
1037 return WERR_NOT_SUPPORTED;
1040 WERROR _svcctl_GetCurrentGroupeStateW(pipes_struct *p, struct svcctl_GetCurrentGroupeStateW *r)
1042 p->rng_fault_state = True;
1043 return WERR_NOT_SUPPORTED;
1046 WERROR _svcctl_EnumServiceGroupW(pipes_struct *p, struct svcctl_EnumServiceGroupW *r)
1048 p->rng_fault_state = True;
1049 return WERR_NOT_SUPPORTED;
1052 WERROR _svcctl_ChangeServiceConfig2A(pipes_struct *p, struct svcctl_ChangeServiceConfig2A *r)
1054 p->rng_fault_state = True;
1055 return WERR_NOT_SUPPORTED;
1058 WERROR _svcctl_ChangeServiceConfig2W(pipes_struct *p, struct svcctl_ChangeServiceConfig2W *r)
1060 p->rng_fault_state = True;
1061 return WERR_NOT_SUPPORTED;
1064 WERROR _svcctl_QueryServiceConfig2A(pipes_struct *p, struct svcctl_QueryServiceConfig2A *r)
1066 p->rng_fault_state = True;
1067 return WERR_NOT_SUPPORTED;
1070 WERROR _svcctl_QueryServiceConfig2W(pipes_struct *p, struct svcctl_QueryServiceConfig2W *r)
1072 p->rng_fault_state = True;
1073 return WERR_NOT_SUPPORTED;
1076 WERROR _svcctl_QueryServiceStatusEx(pipes_struct *p, struct svcctl_QueryServiceStatusEx *r)
1078 p->rng_fault_state = True;
1079 return WERR_NOT_SUPPORTED;
1082 WERROR _EnumServicesStatusExA(pipes_struct *p, struct EnumServicesStatusExA *r)
1084 p->rng_fault_state = True;
1085 return WERR_NOT_SUPPORTED;
1088 WERROR _EnumServicesStatusExW(pipes_struct *p, struct EnumServicesStatusExW *r)
1090 p->rng_fault_state = True;
1091 return WERR_NOT_SUPPORTED;
1094 WERROR _svcctl_SCSendTSMessage(pipes_struct *p, struct svcctl_SCSendTSMessage *r)
1096 p->rng_fault_state = True;
1097 return WERR_NOT_SUPPORTED;