Move the "rid_name" typedef to the only place where it might be used
[Samba.git] / source3 / rpc_server / srv_svcctl_nt.c
blob187fb368e2032b98c91a7c45116108aa5193db5a
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_length( 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 *acl;
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 ( !(acl = 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 acl, &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->server_info->ptok,
276 r->in.access_mask, &access_granted );
277 if ( !NT_STATUS_IS_OK(status) )
278 return ntstatus_to_werror( status );
280 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SCM, NULL, access_granted );
283 /********************************************************************
284 _svcctl_OpenServiceW
285 ********************************************************************/
287 WERROR _svcctl_OpenServiceW(pipes_struct *p,
288 struct svcctl_OpenServiceW *r)
290 SEC_DESC *sec_desc;
291 uint32 access_granted = 0;
292 NTSTATUS status;
293 const char *service = NULL;
295 service = r->in.ServiceName;
296 if (!service) {
297 return WERR_NOMEM;
299 DEBUG(5, ("_svcctl_OpenServiceW: Attempting to open Service [%s], \n", service));
301 /* based on my tests you can open a service if you have a valid scm handle */
303 if ( !find_service_info_by_hnd( p, r->in.scmanager_handle) )
304 return WERR_BADFID;
306 /* perform access checks. Use the root token in order to ensure that we
307 retrieve the security descriptor */
309 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, service, get_root_nt_token() )) )
310 return WERR_NOMEM;
312 se_map_generic( &r->in.access_mask, &svc_generic_map );
313 status = svcctl_access_check( sec_desc, p->server_info->ptok,
314 r->in.access_mask, &access_granted );
315 if ( !NT_STATUS_IS_OK(status) )
316 return ntstatus_to_werror( status );
318 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SERVICE, service, access_granted );
321 /********************************************************************
322 ********************************************************************/
324 WERROR _svcctl_CloseServiceHandle(pipes_struct *p, struct svcctl_CloseServiceHandle *r)
326 if ( !close_policy_hnd( p, r->in.handle ) )
327 return WERR_BADFID;
329 ZERO_STRUCTP(r->out.handle);
331 return WERR_OK;
334 /********************************************************************
335 _svcctl_GetServiceDisplayNameW
336 ********************************************************************/
338 WERROR _svcctl_GetServiceDisplayNameW(pipes_struct *p,
339 struct svcctl_GetServiceDisplayNameW *r)
341 const char *service;
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) )
348 return WERR_BADFID;
350 service = r->in.service_name;
352 display_name = svcctl_lookup_dispname(p->mem_ctx, service,
353 p->server_info->ptok);
354 if (!display_name) {
355 display_name = "";
358 *r->out.display_name = display_name;
359 *r->out.display_name_length = strlen(display_name);
361 return WERR_OK;
364 /********************************************************************
365 _svcctl_QueryServiceStatus
366 ********************************************************************/
368 WERROR _svcctl_QueryServiceStatus(pipes_struct *p,
369 struct svcctl_QueryServiceStatus *r)
371 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
373 /* perform access checks */
375 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
376 return WERR_BADFID;
378 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
379 return WERR_ACCESS_DENIED;
381 /* try the service specific status call */
383 return info->ops->service_status( info->name, r->out.service_status );
386 /********************************************************************
387 ********************************************************************/
389 static int enumerate_status( TALLOC_CTX *ctx, ENUM_SERVICES_STATUS **status, NT_USER_TOKEN *token )
391 int num_services = 0;
392 int i;
393 ENUM_SERVICES_STATUS *st;
394 const char *display_name;
396 /* just count */
397 while ( svcctl_ops[num_services].name )
398 num_services++;
400 if ( !(st = TALLOC_ARRAY( ctx, ENUM_SERVICES_STATUS, num_services )) ) {
401 DEBUG(0,("enumerate_status: talloc() failed!\n"));
402 return -1;
405 for ( i=0; i<num_services; i++ ) {
406 init_unistr( &st[i].servicename, svcctl_ops[i].name );
408 display_name = svcctl_lookup_dispname(ctx, svcctl_ops[i].name, token );
409 init_unistr( &st[i].displayname, display_name ? display_name : "");
411 svcctl_ops[i].ops->service_status( svcctl_ops[i].name, &st[i].status );
414 *status = st;
416 return num_services;
419 /********************************************************************
420 ********************************************************************/
422 WERROR _svcctl_enum_services_status(pipes_struct *p, SVCCTL_Q_ENUM_SERVICES_STATUS *q_u, SVCCTL_R_ENUM_SERVICES_STATUS *r_u)
424 ENUM_SERVICES_STATUS *services = NULL;
425 int num_services;
426 int i = 0;
427 size_t buffer_size = 0;
428 WERROR result = WERR_OK;
429 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
430 NT_USER_TOKEN *token = p->server_info->ptok;
432 /* perform access checks */
434 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
435 return WERR_BADFID;
437 if ( !(info->access_granted & SC_RIGHT_MGR_ENUMERATE_SERVICE) ) {
438 return WERR_ACCESS_DENIED;
441 num_services = enumerate_status( p->mem_ctx, &services, token );
442 if (num_services == -1 ) {
443 return WERR_NOMEM;
446 for ( i=0; i<num_services; i++ ) {
447 buffer_size += svcctl_sizeof_enum_services_status(&services[i]);
450 buffer_size += buffer_size % 4;
452 if (buffer_size > q_u->buffer_size ) {
453 num_services = 0;
454 result = WERR_MORE_DATA;
457 rpcbuf_init(&r_u->buffer, q_u->buffer_size, p->mem_ctx);
459 if ( W_ERROR_IS_OK(result) ) {
460 for ( i=0; i<num_services; i++ )
461 svcctl_io_enum_services_status( "", &services[i], &r_u->buffer, 0 );
464 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
465 r_u->returned = (uint32)num_services;
467 if ( !(r_u->resume = TALLOC_P( p->mem_ctx, uint32 )) )
468 return WERR_NOMEM;
470 *r_u->resume = 0x0;
472 return result;
475 /********************************************************************
476 _svcctl_StartServiceW
477 ********************************************************************/
479 WERROR _svcctl_StartServiceW(pipes_struct *p,
480 struct svcctl_StartServiceW *r)
482 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
484 /* perform access checks */
486 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
487 return WERR_BADFID;
489 if ( !(info->access_granted & SC_RIGHT_SVC_START) )
490 return WERR_ACCESS_DENIED;
492 return info->ops->start_service( info->name );
495 /********************************************************************
496 _svcctl_ControlService
497 ********************************************************************/
499 WERROR _svcctl_ControlService(pipes_struct *p,
500 struct svcctl_ControlService *r)
502 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
504 /* perform access checks */
506 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
507 return WERR_BADFID;
509 switch ( r->in.control ) {
510 case SVCCTL_CONTROL_STOP:
511 if ( !(info->access_granted & SC_RIGHT_SVC_STOP) )
512 return WERR_ACCESS_DENIED;
514 return info->ops->stop_service( info->name,
515 r->out.service_status );
517 case SVCCTL_CONTROL_INTERROGATE:
518 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
519 return WERR_ACCESS_DENIED;
521 return info->ops->service_status( info->name,
522 r->out.service_status );
523 default:
524 return WERR_ACCESS_DENIED;
528 /********************************************************************
529 _svcctl_EnumDependentServicesW
530 ********************************************************************/
532 WERROR _svcctl_EnumDependentServicesW(pipes_struct *p,
533 struct svcctl_EnumDependentServicesW *r)
535 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.service );
537 /* perform access checks */
539 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
540 return WERR_BADFID;
542 if ( !(info->access_granted & SC_RIGHT_SVC_ENUMERATE_DEPENDENTS) )
543 return WERR_ACCESS_DENIED;
545 /* we have to set the outgoing buffer size to the same as the
546 incoming buffer size (even in the case of failure */
547 /* this is done in the autogenerated server already - gd */
549 *r->out.bytes_needed = r->in.buf_size;
551 /* no dependent services...basically a stub function */
552 *r->out.services_returned = 0;
554 return WERR_OK;
557 /********************************************************************
558 ********************************************************************/
560 WERROR _svcctl_query_service_status_ex( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u )
562 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
563 uint32 buffer_size;
565 /* perform access checks */
567 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
568 return WERR_BADFID;
570 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
571 return WERR_ACCESS_DENIED;
573 /* we have to set the outgoing buffer size to the same as the
574 incoming buffer size (even in the case of failure) */
576 rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
577 r_u->needed = q_u->buffer_size;
579 switch ( q_u->level ) {
580 case SVC_STATUS_PROCESS_INFO:
582 SERVICE_STATUS_PROCESS svc_stat_proc;
584 /* Get the status of the service.. */
585 info->ops->service_status( info->name, &svc_stat_proc.status );
586 svc_stat_proc.process_id = sys_getpid();
587 svc_stat_proc.service_flags = 0x0;
589 svcctl_io_service_status_process( "", &svc_stat_proc, &r_u->buffer, 0 );
590 buffer_size = sizeof(SERVICE_STATUS_PROCESS);
591 break;
594 default:
595 return WERR_UNKNOWN_LEVEL;
599 buffer_size += buffer_size % 4;
600 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
602 if (buffer_size > q_u->buffer_size )
603 return WERR_MORE_DATA;
605 return WERR_OK;
608 /********************************************************************
609 ********************************************************************/
611 static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name,
612 struct QUERY_SERVICE_CONFIG *config,
613 NT_USER_TOKEN *token )
615 REGVAL_CTR *values;
616 REGISTRY_VALUE *val;
618 /* retrieve the registry values for this service */
620 if ( !(values = svcctl_fetch_regvalues( name, token )) )
621 return WERR_REG_CORRUPT;
623 /* now fill in the individual values */
625 if ( (val = regval_ctr_getvalue( values, "DisplayName" )) != NULL )
626 config->displayname = regval_sz(val);
627 else
628 config->displayname = name;
630 if ( (val = regval_ctr_getvalue( values, "ObjectName" )) != NULL ) {
631 config->startname = regval_sz(val);
634 if ( (val = regval_ctr_getvalue( values, "ImagePath" )) != NULL ) {
635 config->executablepath = regval_sz(val);
638 /* a few hard coded values */
639 /* loadordergroup and dependencies are empty */
641 config->tag_id = 0x00000000; /* unassigned loadorder group */
642 config->service_type = SVCCTL_WIN32_OWN_PROC;
643 config->error_control = SVCCTL_SVC_ERROR_NORMAL;
645 /* set the start type. NetLogon and WINS are disabled to prevent
646 the client from showing the "Start" button (if of course the services
647 are not running */
649 if ( strequal( name, "NETLOGON" ) && ( lp_servicenumber(name) == -1 ) )
650 config->start_type = SVCCTL_DISABLED;
651 else if ( strequal( name, "WINS" ) && ( !lp_wins_support() ))
652 config->start_type = SVCCTL_DISABLED;
653 else
654 config->start_type = SVCCTL_DEMAND_START;
657 TALLOC_FREE( values );
659 return WERR_OK;
662 /********************************************************************
663 _svcctl_QueryServiceConfigW
664 ********************************************************************/
666 WERROR _svcctl_QueryServiceConfigW(pipes_struct *p,
667 struct svcctl_QueryServiceConfigW *r)
669 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
670 uint32 buffer_size;
671 WERROR wresult;
673 /* perform access checks */
675 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
676 return WERR_BADFID;
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->out.bytes_needed = r->in.buf_size;
686 wresult = fill_svc_config( p->mem_ctx, info->name, r->out.query,
687 p->server_info->ptok);
688 if ( !W_ERROR_IS_OK(wresult) )
689 return wresult;
691 buffer_size = ndr_size_QUERY_SERVICE_CONFIG(r->out.query, NULL, 0);
692 *r->out.bytes_needed = (buffer_size > r->in.buf_size) ? buffer_size : r->in.buf_size;
694 if (buffer_size > r->in.buf_size ) {
695 ZERO_STRUCTP(r->out.query);
696 return WERR_INSUFFICIENT_BUFFER;
699 return WERR_OK;
702 /********************************************************************
703 ********************************************************************/
705 WERROR _svcctl_query_service_config2( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u )
707 SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
708 uint32 buffer_size;
710 /* perform access checks */
712 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
713 return WERR_BADFID;
715 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_CONFIG) )
716 return WERR_ACCESS_DENIED;
718 /* we have to set the outgoing buffer size to the same as the
719 incoming buffer size (even in the case of failure */
721 rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
722 r_u->needed = q_u->buffer_size;
724 switch ( q_u->level ) {
725 case SERVICE_CONFIG_DESCRIPTION:
727 SERVICE_DESCRIPTION desc_buf;
728 const char *description;
730 description = svcctl_lookup_description(
731 p->mem_ctx, info->name, p->server_info->ptok);
733 ZERO_STRUCTP( &desc_buf );
735 init_service_description_buffer( &desc_buf, description ? description : "");
736 svcctl_io_service_description( "", &desc_buf, &r_u->buffer, 0 );
737 buffer_size = svcctl_sizeof_service_description( &desc_buf );
739 break;
741 break;
742 case SERVICE_CONFIG_FAILURE_ACTIONS:
744 SERVICE_FAILURE_ACTIONS actions;
746 /* nothing to say...just service the request */
748 ZERO_STRUCTP( &actions );
749 svcctl_io_service_fa( "", &actions, &r_u->buffer, 0 );
750 buffer_size = svcctl_sizeof_service_fa( &actions );
752 break;
754 break;
756 default:
757 return WERR_UNKNOWN_LEVEL;
760 buffer_size += buffer_size % 4;
761 r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
763 if (buffer_size > q_u->buffer_size )
764 return WERR_INSUFFICIENT_BUFFER;
766 return WERR_OK;
769 /********************************************************************
770 _svcctl_LockServiceDatabase
771 ********************************************************************/
773 WERROR _svcctl_LockServiceDatabase(pipes_struct *p,
774 struct svcctl_LockServiceDatabase *r)
776 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
778 /* perform access checks */
780 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
781 return WERR_BADFID;
783 if ( !(info->access_granted & SC_RIGHT_MGR_LOCK) )
784 return WERR_ACCESS_DENIED;
786 /* Just open a handle. Doesn't actually lock anything */
788 return create_open_service_handle( p, r->out.lock, SVC_HANDLE_IS_DBLOCK, NULL, 0 );
791 /********************************************************************
792 _svcctl_UnlockServiceDatabase
793 ********************************************************************/
795 WERROR _svcctl_UnlockServiceDatabase(pipes_struct *p,
796 struct svcctl_UnlockServiceDatabase *r)
798 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.lock );
801 if ( !info || (info->type != SVC_HANDLE_IS_DBLOCK) )
802 return WERR_BADFID;
804 return close_policy_hnd( p, r->out.lock) ? WERR_OK : WERR_BADFID;
807 /********************************************************************
808 _svcctl_QueryServiceObjectSecurity
809 ********************************************************************/
811 WERROR _svcctl_QueryServiceObjectSecurity(pipes_struct *p,
812 struct svcctl_QueryServiceObjectSecurity *r)
814 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
815 SEC_DESC *sec_desc;
816 NTSTATUS status;
817 uint8_t *buffer = NULL;
818 size_t len = 0;
821 /* only support the SCM and individual services */
823 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
824 return WERR_BADFID;
826 /* check access reights (according to MSDN) */
828 if ( !(info->access_granted & STD_RIGHT_READ_CONTROL_ACCESS) )
829 return WERR_ACCESS_DENIED;
831 /* TODO: handle something besides DACL_SECURITY_INFORMATION */
833 if ( (r->in.security_flags & DACL_SECURITY_INFORMATION) != DACL_SECURITY_INFORMATION )
834 return WERR_INVALID_PARAM;
836 /* lookup the security descriptor and marshall it up for a reply */
838 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, info->name, get_root_nt_token() )) )
839 return WERR_NOMEM;
841 *r->out.needed = ndr_size_security_descriptor( sec_desc, NULL, 0 );
843 if ( *r->out.needed > r->in.buffer_size ) {
844 ZERO_STRUCTP( &r->out.buffer );
845 return WERR_INSUFFICIENT_BUFFER;
848 status = marshall_sec_desc(p->mem_ctx, sec_desc, &buffer, &len);
849 if (!NT_STATUS_IS_OK(status)) {
850 return ntstatus_to_werror(status);
853 *r->out.needed = len;
854 r->out.buffer = buffer;
856 return WERR_OK;
859 /********************************************************************
860 _svcctl_SetServiceObjectSecurity
861 ********************************************************************/
863 WERROR _svcctl_SetServiceObjectSecurity(pipes_struct *p,
864 struct svcctl_SetServiceObjectSecurity *r)
866 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
867 SEC_DESC *sec_desc = NULL;
868 uint32 required_access;
869 NTSTATUS status;
871 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
872 return WERR_BADFID;
874 /* can't set the security de4scriptor on the ServiceControlManager */
876 if ( info->type == SVC_HANDLE_IS_SCM )
877 return WERR_ACCESS_DENIED;
879 /* check the access on the open handle */
881 switch ( r->in.security_flags ) {
882 case DACL_SECURITY_INFORMATION:
883 required_access = STD_RIGHT_WRITE_DAC_ACCESS;
884 break;
886 case OWNER_SECURITY_INFORMATION:
887 case GROUP_SECURITY_INFORMATION:
888 required_access = STD_RIGHT_WRITE_OWNER_ACCESS;
889 break;
891 case SACL_SECURITY_INFORMATION:
892 return WERR_INVALID_PARAM;
893 default:
894 return WERR_INVALID_PARAM;
897 if ( !(info->access_granted & required_access) )
898 return WERR_ACCESS_DENIED;
900 /* read the security descfriptor */
902 status = unmarshall_sec_desc(p->mem_ctx,
903 r->in.buffer, r->in.buffer_size,
904 &sec_desc);
905 if (!NT_STATUS_IS_OK(status)) {
906 return ntstatus_to_werror(status);
909 /* store the new SD */
911 if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc,
912 p->server_info->ptok) )
913 return WERR_ACCESS_DENIED;
915 return WERR_OK;
919 WERROR _svcctl_DeleteService(pipes_struct *p, struct svcctl_DeleteService *r)
921 p->rng_fault_state = True;
922 return WERR_NOT_SUPPORTED;
925 WERROR _svcctl_SetServiceStatus(pipes_struct *p, struct svcctl_SetServiceStatus *r)
927 p->rng_fault_state = True;
928 return WERR_NOT_SUPPORTED;
931 WERROR _svcctl_NotifyBootConfigStatus(pipes_struct *p, struct svcctl_NotifyBootConfigStatus *r)
933 p->rng_fault_state = True;
934 return WERR_NOT_SUPPORTED;
937 WERROR _svcctl_SCSetServiceBitsW(pipes_struct *p, struct svcctl_SCSetServiceBitsW *r)
939 p->rng_fault_state = True;
940 return WERR_NOT_SUPPORTED;
943 WERROR _svcctl_ChangeServiceConfigW(pipes_struct *p, struct svcctl_ChangeServiceConfigW *r)
945 p->rng_fault_state = True;
946 return WERR_NOT_SUPPORTED;
949 WERROR _svcctl_CreateServiceW(pipes_struct *p, struct svcctl_CreateServiceW *r)
951 p->rng_fault_state = True;
952 return WERR_NOT_SUPPORTED;
955 WERROR _svcctl_EnumServicesStatusW(pipes_struct *p, struct svcctl_EnumServicesStatusW *r)
957 p->rng_fault_state = True;
958 return WERR_NOT_SUPPORTED;
961 WERROR _svcctl_QueryServiceLockStatusW(pipes_struct *p, struct svcctl_QueryServiceLockStatusW *r)
963 p->rng_fault_state = True;
964 return WERR_NOT_SUPPORTED;
967 WERROR _svcctl_GetServiceKeyNameW(pipes_struct *p, struct svcctl_GetServiceKeyNameW *r)
969 p->rng_fault_state = True;
970 return WERR_NOT_SUPPORTED;
973 WERROR _svcctl_SCSetServiceBitsA(pipes_struct *p, struct svcctl_SCSetServiceBitsA *r)
975 p->rng_fault_state = True;
976 return WERR_NOT_SUPPORTED;
979 WERROR _svcctl_ChangeServiceConfigA(pipes_struct *p, struct svcctl_ChangeServiceConfigA *r)
981 p->rng_fault_state = True;
982 return WERR_NOT_SUPPORTED;
985 WERROR _svcctl_CreateServiceA(pipes_struct *p, struct svcctl_CreateServiceA *r)
987 p->rng_fault_state = True;
988 return WERR_NOT_SUPPORTED;
991 WERROR _svcctl_EnumDependentServicesA(pipes_struct *p, struct svcctl_EnumDependentServicesA *r)
993 p->rng_fault_state = True;
994 return WERR_NOT_SUPPORTED;
997 WERROR _svcctl_EnumServicesStatusA(pipes_struct *p, struct svcctl_EnumServicesStatusA *r)
999 p->rng_fault_state = True;
1000 return WERR_NOT_SUPPORTED;
1003 WERROR _svcctl_OpenSCManagerA(pipes_struct *p, struct svcctl_OpenSCManagerA *r)
1005 p->rng_fault_state = True;
1006 return WERR_NOT_SUPPORTED;
1009 WERROR _svcctl_OpenServiceA(pipes_struct *p, struct svcctl_OpenServiceA *r)
1011 p->rng_fault_state = True;
1012 return WERR_NOT_SUPPORTED;
1015 WERROR _svcctl_QueryServiceConfigA(pipes_struct *p, struct svcctl_QueryServiceConfigA *r)
1017 p->rng_fault_state = True;
1018 return WERR_NOT_SUPPORTED;
1021 WERROR _svcctl_QueryServiceLockStatusA(pipes_struct *p, struct svcctl_QueryServiceLockStatusA *r)
1023 p->rng_fault_state = True;
1024 return WERR_NOT_SUPPORTED;
1027 WERROR _svcctl_StartServiceA(pipes_struct *p, struct svcctl_StartServiceA *r)
1029 p->rng_fault_state = True;
1030 return WERR_NOT_SUPPORTED;
1033 WERROR _svcctl_GetServiceDisplayNameA(pipes_struct *p, struct svcctl_GetServiceDisplayNameA *r)
1035 p->rng_fault_state = True;
1036 return WERR_NOT_SUPPORTED;
1039 WERROR _svcctl_GetServiceKeyNameA(pipes_struct *p, struct svcctl_GetServiceKeyNameA *r)
1041 p->rng_fault_state = True;
1042 return WERR_NOT_SUPPORTED;
1045 WERROR _svcctl_GetCurrentGroupeStateW(pipes_struct *p, struct svcctl_GetCurrentGroupeStateW *r)
1047 p->rng_fault_state = True;
1048 return WERR_NOT_SUPPORTED;
1051 WERROR _svcctl_EnumServiceGroupW(pipes_struct *p, struct svcctl_EnumServiceGroupW *r)
1053 p->rng_fault_state = True;
1054 return WERR_NOT_SUPPORTED;
1057 WERROR _svcctl_ChangeServiceConfig2A(pipes_struct *p, struct svcctl_ChangeServiceConfig2A *r)
1059 p->rng_fault_state = True;
1060 return WERR_NOT_SUPPORTED;
1063 WERROR _svcctl_ChangeServiceConfig2W(pipes_struct *p, struct svcctl_ChangeServiceConfig2W *r)
1065 p->rng_fault_state = True;
1066 return WERR_NOT_SUPPORTED;
1069 WERROR _svcctl_QueryServiceConfig2A(pipes_struct *p, struct svcctl_QueryServiceConfig2A *r)
1071 p->rng_fault_state = True;
1072 return WERR_NOT_SUPPORTED;
1075 WERROR _svcctl_QueryServiceConfig2W(pipes_struct *p, struct svcctl_QueryServiceConfig2W *r)
1077 p->rng_fault_state = True;
1078 return WERR_NOT_SUPPORTED;
1081 WERROR _svcctl_QueryServiceStatusEx(pipes_struct *p, struct svcctl_QueryServiceStatusEx *r)
1083 p->rng_fault_state = True;
1084 return WERR_NOT_SUPPORTED;
1087 WERROR _EnumServicesStatusExA(pipes_struct *p, struct EnumServicesStatusExA *r)
1089 p->rng_fault_state = True;
1090 return WERR_NOT_SUPPORTED;
1093 WERROR _EnumServicesStatusExW(pipes_struct *p, struct EnumServicesStatusExW *r)
1095 p->rng_fault_state = True;
1096 return WERR_NOT_SUPPORTED;
1099 WERROR _svcctl_SCSendTSMessage(pipes_struct *p, struct svcctl_SCSendTSMessage *r)
1101 p->rng_fault_state = True;
1102 return WERR_NOT_SUPPORTED;