2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
5 * Copyright (C) Marcin Krzysztof Porwit 2005.
7 * Largely Rewritten (Again) by:
8 * Copyright (C) Gerald (Jerry) Carter 2005.
9 * Copyright (C) Guenther Deschner 2008,2009.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <http://www.gnu.org/licenses/>.
26 #include "../librpc/gen_ndr/srv_svcctl.h"
31 #define DBGC_CLASS DBGC_RPC_SRV
33 struct service_control_op {
35 SERVICE_CONTROL_OPS *ops;
38 /* handle external services */
39 extern SERVICE_CONTROL_OPS rcinit_svc_ops;
41 /* builtin services (see service_db.c and services/svc_*.c */
42 extern SERVICE_CONTROL_OPS spoolss_svc_ops;
43 extern SERVICE_CONTROL_OPS netlogon_svc_ops;
44 extern SERVICE_CONTROL_OPS winreg_svc_ops;
45 extern SERVICE_CONTROL_OPS wins_svc_ops;
47 /* make sure this number patches the number of builtin
48 SERVICE_CONTROL_OPS structure listed above */
50 #define SVCCTL_NUM_INTERNAL_SERVICES 4
52 struct service_control_op *svcctl_ops;
54 static const struct generic_mapping scm_generic_map =
55 { SC_MANAGER_READ_ACCESS, SC_MANAGER_WRITE_ACCESS, SC_MANAGER_EXECUTE_ACCESS, SC_MANAGER_ALL_ACCESS };
56 static const struct generic_mapping svc_generic_map =
57 { SERVICE_READ_ACCESS, SERVICE_WRITE_ACCESS, SERVICE_EXECUTE_ACCESS, SERVICE_ALL_ACCESS };
60 /********************************************************************
61 ********************************************************************/
63 bool init_service_op_table( void )
65 const char **service_list = lp_svcctl_list();
66 int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_length( service_list );
69 if ( !(svcctl_ops = TALLOC_ARRAY( NULL, struct service_control_op, num_services+1)) ) {
70 DEBUG(0,("init_service_op_table: talloc() failed!\n"));
74 /* services listed in smb.conf get the rc.init interface */
76 for ( i=0; service_list && service_list[i]; i++ ) {
77 svcctl_ops[i].name = talloc_strdup( svcctl_ops, service_list[i] );
78 svcctl_ops[i].ops = &rcinit_svc_ops;
81 /* add builtin services */
83 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "Spooler" );
84 svcctl_ops[i].ops = &spoolss_svc_ops;
87 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "NETLOGON" );
88 svcctl_ops[i].ops = &netlogon_svc_ops;
91 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "RemoteRegistry" );
92 svcctl_ops[i].ops = &winreg_svc_ops;
95 svcctl_ops[i].name = talloc_strdup( svcctl_ops, "WINS" );
96 svcctl_ops[i].ops = &wins_svc_ops;
99 /* NULL terminate the array */
101 svcctl_ops[i].name = NULL;
102 svcctl_ops[i].ops = NULL;
107 /********************************************************************
108 ********************************************************************/
110 static struct service_control_op* find_service_by_name( const char *name )
114 for ( i=0; svcctl_ops[i].name; i++ ) {
115 if ( strequal( name, svcctl_ops[i].name ) )
116 return &svcctl_ops[i];
121 /********************************************************************
122 ********************************************************************/
124 static NTSTATUS svcctl_access_check( SEC_DESC *sec_desc, NT_USER_TOKEN *token,
125 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 return se_access_check( sec_desc, token, access_desired, access_granted);
135 /********************************************************************
136 ********************************************************************/
138 static SEC_DESC* construct_scm_sd( TALLOC_CTX *ctx )
146 /* basic access for Everyone */
148 init_sec_ace(&ace[i++], &global_sid_World,
149 SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_READ_ACCESS, 0);
151 /* Full Access 'BUILTIN\Administrators' */
153 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
154 SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_ALL_ACCESS, 0);
157 /* create the security descriptor */
159 if ( !(theacl = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) )
162 if ( !(sd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
163 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
170 /******************************************************************
171 Find a registry key handle and return a SERVICE_INFO
172 *****************************************************************/
174 static SERVICE_INFO *find_service_info_by_hnd(pipes_struct *p, struct policy_handle *hnd)
176 SERVICE_INFO *service_info = NULL;
178 if( !find_policy_by_hnd( p, hnd, (void **)(void *)&service_info) ) {
179 DEBUG(2,("find_service_info_by_hnd: handle not found\n"));
186 /******************************************************************
187 *****************************************************************/
189 static WERROR create_open_service_handle( pipes_struct *p, struct policy_handle *handle, uint32 type,
190 const char *service, uint32 access_granted )
192 SERVICE_INFO *info = NULL;
193 WERROR result = WERR_OK;
194 struct service_control_op *s_op;
196 if ( !(info = TALLOC_ZERO_P( NULL, SERVICE_INFO )) )
199 /* the Service Manager has a NULL name */
201 info->type = SVC_HANDLE_IS_SCM;
204 case SVC_HANDLE_IS_SCM:
205 info->type = SVC_HANDLE_IS_SCM;
208 case SVC_HANDLE_IS_DBLOCK:
209 info->type = SVC_HANDLE_IS_DBLOCK;
212 case SVC_HANDLE_IS_SERVICE:
213 info->type = SVC_HANDLE_IS_SERVICE;
215 /* lookup the SERVICE_CONTROL_OPS */
217 if ( !(s_op = find_service_by_name( service )) ) {
218 result = WERR_NO_SUCH_SERVICE;
222 info->ops = s_op->ops;
224 if ( !(info->name = talloc_strdup( info, s_op->name )) ) {
231 result = WERR_NO_SUCH_SERVICE;
235 info->access_granted = access_granted;
237 /* store the SERVICE_INFO and create an open handle */
239 if ( !create_policy_hnd( p, handle, info ) ) {
240 result = WERR_ACCESS_DENIED;
245 if ( !W_ERROR_IS_OK(result) )
251 /********************************************************************
252 _svcctl_OpenSCManagerW
253 ********************************************************************/
255 WERROR _svcctl_OpenSCManagerW(pipes_struct *p,
256 struct svcctl_OpenSCManagerW *r)
259 uint32 access_granted = 0;
262 /* perform access checks */
264 if ( !(sec_desc = construct_scm_sd( p->mem_ctx )) )
267 se_map_generic( &r->in.access_mask, &scm_generic_map );
268 status = svcctl_access_check( sec_desc, p->server_info->ptok,
269 r->in.access_mask, &access_granted );
270 if ( !NT_STATUS_IS_OK(status) )
271 return ntstatus_to_werror( status );
273 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SCM, NULL, access_granted );
276 /********************************************************************
278 ********************************************************************/
280 WERROR _svcctl_OpenServiceW(pipes_struct *p,
281 struct svcctl_OpenServiceW *r)
284 uint32 access_granted = 0;
286 const char *service = NULL;
288 service = r->in.ServiceName;
292 DEBUG(5, ("_svcctl_OpenServiceW: Attempting to open Service [%s], \n", service));
294 /* based on my tests you can open a service if you have a valid scm handle */
296 if ( !find_service_info_by_hnd( p, r->in.scmanager_handle) )
299 /* perform access checks. Use the root token in order to ensure that we
300 retrieve the security descriptor */
302 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, service, get_root_nt_token() )) )
305 se_map_generic( &r->in.access_mask, &svc_generic_map );
306 status = svcctl_access_check( sec_desc, p->server_info->ptok,
307 r->in.access_mask, &access_granted );
308 if ( !NT_STATUS_IS_OK(status) )
309 return ntstatus_to_werror( status );
311 return create_open_service_handle( p, r->out.handle, SVC_HANDLE_IS_SERVICE, service, access_granted );
314 /********************************************************************
315 _svcctl_CloseServiceHandle
316 ********************************************************************/
318 WERROR _svcctl_CloseServiceHandle(pipes_struct *p,
319 struct svcctl_CloseServiceHandle *r)
321 if ( !close_policy_hnd( p, r->in.handle ) )
324 ZERO_STRUCTP(r->out.handle);
329 /********************************************************************
330 _svcctl_GetServiceDisplayNameW
331 ********************************************************************/
333 WERROR _svcctl_GetServiceDisplayNameW(pipes_struct *p,
334 struct svcctl_GetServiceDisplayNameW *r)
337 const char *display_name;
338 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
340 /* can only use an SCM handle here */
342 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
345 service = r->in.service_name;
347 display_name = svcctl_lookup_dispname(p->mem_ctx, service,
348 p->server_info->ptok);
353 *r->out.display_name = display_name;
354 *r->out.display_name_length = strlen(display_name);
359 /********************************************************************
360 _svcctl_QueryServiceStatus
361 ********************************************************************/
363 WERROR _svcctl_QueryServiceStatus(pipes_struct *p,
364 struct svcctl_QueryServiceStatus *r)
366 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
368 /* perform access checks */
370 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
373 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
374 return WERR_ACCESS_DENIED;
376 /* try the service specific status call */
378 return info->ops->service_status( info->name, r->out.service_status );
381 /********************************************************************
382 ********************************************************************/
384 static int enumerate_status( TALLOC_CTX *ctx, struct ENUM_SERVICE_STATUSW **status, NT_USER_TOKEN *token )
386 int num_services = 0;
388 struct ENUM_SERVICE_STATUSW *st;
389 const char *display_name;
392 while ( svcctl_ops[num_services].name )
395 if ( !(st = TALLOC_ARRAY( ctx, struct ENUM_SERVICE_STATUSW, num_services )) ) {
396 DEBUG(0,("enumerate_status: talloc() failed!\n"));
400 for ( i=0; i<num_services; i++ ) {
401 st[i].service_name = talloc_strdup(st, svcctl_ops[i].name );
403 display_name = svcctl_lookup_dispname(ctx, svcctl_ops[i].name, token );
404 st[i].display_name = talloc_strdup(st, display_name ? display_name : "");
406 svcctl_ops[i].ops->service_status( svcctl_ops[i].name, &st[i].status );
414 /********************************************************************
415 _svcctl_EnumServicesStatusW
416 ********************************************************************/
418 WERROR _svcctl_EnumServicesStatusW(pipes_struct *p,
419 struct svcctl_EnumServicesStatusW *r)
421 struct ENUM_SERVICE_STATUSW *services = NULL;
424 size_t buffer_size = 0;
425 WERROR result = WERR_OK;
426 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
427 NT_USER_TOKEN *token = p->server_info->ptok;
428 DATA_BLOB blob = data_blob_null;
430 /* perform access checks */
432 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
435 if ( !(info->access_granted & SC_RIGHT_MGR_ENUMERATE_SERVICE) ) {
436 return WERR_ACCESS_DENIED;
439 num_services = enumerate_status( p->mem_ctx, &services, token );
440 if (num_services == -1 ) {
444 for ( i=0; i<num_services; i++ ) {
445 buffer_size += ndr_size_ENUM_SERVICE_STATUSW(&services[i], NULL, 0);
448 buffer_size += buffer_size % 4;
450 if (buffer_size > r->in.offered) {
452 result = WERR_MORE_DATA;
455 if ( W_ERROR_IS_OK(result) ) {
457 enum ndr_err_code ndr_err;
458 struct ndr_push *ndr;
460 ndr = ndr_push_init_ctx(p->mem_ctx, NULL);
462 return WERR_INVALID_PARAM;
465 ndr_err = ndr_push_ENUM_SERVICE_STATUSW_array(
466 ndr, num_services, services);
467 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
468 return ntstatus_to_werror(ndr_map_error2ntstatus(ndr_err));
470 blob = ndr_push_blob(ndr);
471 memcpy(r->out.service, blob.data, MIN(blob.length, r->in.offered));
474 *r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
475 *r->out.services_returned = (uint32)num_services;
476 if (r->out.resume_handle) {
477 *r->out.resume_handle = 0;
483 /********************************************************************
484 _svcctl_StartServiceW
485 ********************************************************************/
487 WERROR _svcctl_StartServiceW(pipes_struct *p,
488 struct svcctl_StartServiceW *r)
490 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
492 /* perform access checks */
494 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
497 if ( !(info->access_granted & SC_RIGHT_SVC_START) )
498 return WERR_ACCESS_DENIED;
500 return info->ops->start_service( info->name );
503 /********************************************************************
504 _svcctl_ControlService
505 ********************************************************************/
507 WERROR _svcctl_ControlService(pipes_struct *p,
508 struct svcctl_ControlService *r)
510 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
512 /* perform access checks */
514 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
517 switch ( r->in.control ) {
518 case SVCCTL_CONTROL_STOP:
519 if ( !(info->access_granted & SC_RIGHT_SVC_STOP) )
520 return WERR_ACCESS_DENIED;
522 return info->ops->stop_service( info->name,
523 r->out.service_status );
525 case SVCCTL_CONTROL_INTERROGATE:
526 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
527 return WERR_ACCESS_DENIED;
529 return info->ops->service_status( info->name,
530 r->out.service_status );
532 return WERR_INVALID_PARAM;
536 /********************************************************************
537 _svcctl_EnumDependentServicesW
538 ********************************************************************/
540 WERROR _svcctl_EnumDependentServicesW(pipes_struct *p,
541 struct svcctl_EnumDependentServicesW *r)
543 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.service );
545 /* perform access checks */
547 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
550 if ( !(info->access_granted & SC_RIGHT_SVC_ENUMERATE_DEPENDENTS) )
551 return WERR_ACCESS_DENIED;
553 switch (r->in.state) {
554 case SERVICE_STATE_ACTIVE:
555 case SERVICE_STATE_INACTIVE:
556 case SERVICE_STATE_ALL:
559 return WERR_INVALID_PARAM;
562 /* we have to set the outgoing buffer size to the same as the
563 incoming buffer size (even in the case of failure */
564 /* this is done in the autogenerated server already - gd */
566 *r->out.needed = r->in.offered;
568 /* no dependent services...basically a stub function */
569 *r->out.services_returned = 0;
574 /********************************************************************
575 _svcctl_QueryServiceStatusEx
576 ********************************************************************/
578 WERROR _svcctl_QueryServiceStatusEx(pipes_struct *p,
579 struct svcctl_QueryServiceStatusEx *r)
581 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
584 /* perform access checks */
586 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
589 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_STATUS) )
590 return WERR_ACCESS_DENIED;
592 /* we have to set the outgoing buffer size to the same as the
593 incoming buffer size (even in the case of failure) */
594 *r->out.needed = r->in.offered;
596 switch ( r->in.info_level ) {
597 case SVC_STATUS_PROCESS_INFO:
599 struct SERVICE_STATUS_PROCESS svc_stat_proc;
600 enum ndr_err_code ndr_err;
603 /* Get the status of the service.. */
604 info->ops->service_status( info->name, &svc_stat_proc.status );
605 svc_stat_proc.process_id = sys_getpid();
606 svc_stat_proc.service_flags = 0x0;
608 ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
610 (ndr_push_flags_fn_t)ndr_push_SERVICE_STATUS_PROCESS);
611 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
612 return WERR_INVALID_PARAM;
615 r->out.buffer = blob.data;
616 buffer_size = sizeof(struct SERVICE_STATUS_PROCESS);
621 return WERR_UNKNOWN_LEVEL;
625 buffer_size += buffer_size % 4;
626 *r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
628 if (buffer_size > r->in.offered ) {
629 return WERR_INSUFFICIENT_BUFFER;
635 /********************************************************************
636 ********************************************************************/
638 static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name,
639 struct QUERY_SERVICE_CONFIG *config,
640 NT_USER_TOKEN *token )
642 struct regval_ctr *values;
643 struct regval_blob *val;
645 /* retrieve the registry values for this service */
647 if ( !(values = svcctl_fetch_regvalues( name, token )) )
648 return WERR_REG_CORRUPT;
650 /* now fill in the individual values */
652 if ( (val = regval_ctr_getvalue( values, "DisplayName" )) != NULL )
653 config->displayname = regval_sz(val);
655 config->displayname = name;
657 if ( (val = regval_ctr_getvalue( values, "ObjectName" )) != NULL ) {
658 config->startname = regval_sz(val);
661 if ( (val = regval_ctr_getvalue( values, "ImagePath" )) != NULL ) {
662 config->executablepath = regval_sz(val);
665 /* a few hard coded values */
666 /* loadordergroup and dependencies are empty */
668 config->tag_id = 0x00000000; /* unassigned loadorder group */
669 config->service_type = SERVICE_TYPE_WIN32_OWN_PROCESS;
670 config->error_control = SVCCTL_SVC_ERROR_NORMAL;
672 /* set the start type. NetLogon and WINS are disabled to prevent
673 the client from showing the "Start" button (if of course the services
676 if ( strequal( name, "NETLOGON" ) && ( lp_servicenumber(name) == -1 ) )
677 config->start_type = SVCCTL_DISABLED;
678 else if ( strequal( name, "WINS" ) && ( !lp_wins_support() ))
679 config->start_type = SVCCTL_DISABLED;
681 config->start_type = SVCCTL_DEMAND_START;
684 TALLOC_FREE( values );
689 /********************************************************************
690 _svcctl_QueryServiceConfigW
691 ********************************************************************/
693 WERROR _svcctl_QueryServiceConfigW(pipes_struct *p,
694 struct svcctl_QueryServiceConfigW *r)
696 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
700 /* perform access checks */
702 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
705 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_CONFIG) )
706 return WERR_ACCESS_DENIED;
708 /* we have to set the outgoing buffer size to the same as the
709 incoming buffer size (even in the case of failure */
711 *r->out.needed = r->in.offered;
713 wresult = fill_svc_config( p->mem_ctx, info->name, r->out.query,
714 p->server_info->ptok);
715 if ( !W_ERROR_IS_OK(wresult) )
718 buffer_size = ndr_size_QUERY_SERVICE_CONFIG(r->out.query, NULL, 0);
719 *r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
721 if (buffer_size > r->in.offered ) {
722 ZERO_STRUCTP(r->out.query);
723 return WERR_INSUFFICIENT_BUFFER;
729 /********************************************************************
730 _svcctl_QueryServiceConfig2W
731 ********************************************************************/
733 WERROR _svcctl_QueryServiceConfig2W(pipes_struct *p,
734 struct svcctl_QueryServiceConfig2W *r)
736 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
739 /* perform access checks */
741 if ( !info || (info->type != SVC_HANDLE_IS_SERVICE) )
744 if ( !(info->access_granted & SC_RIGHT_SVC_QUERY_CONFIG) )
745 return WERR_ACCESS_DENIED;
747 /* we have to set the outgoing buffer size to the same as the
748 incoming buffer size (even in the case of failure */
749 *r->out.needed = r->in.offered;
751 switch ( r->in.info_level ) {
752 case SERVICE_CONFIG_DESCRIPTION:
754 struct SERVICE_DESCRIPTION desc_buf;
755 const char *description;
756 enum ndr_err_code ndr_err;
759 description = svcctl_lookup_description(
760 p->mem_ctx, info->name, p->server_info->ptok);
762 desc_buf.description = description;
764 ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
766 (ndr_push_flags_fn_t)ndr_push_SERVICE_DESCRIPTION);
767 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
768 return WERR_INVALID_PARAM;
771 buffer_size = ndr_size_SERVICE_DESCRIPTION(&desc_buf, NULL, 0);
772 r->out.buffer = blob.data;
777 case SERVICE_CONFIG_FAILURE_ACTIONS:
779 struct SERVICE_FAILURE_ACTIONS actions;
780 enum ndr_err_code ndr_err;
783 /* nothing to say...just service the request */
785 ZERO_STRUCT( actions );
787 ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
789 (ndr_push_flags_fn_t)ndr_push_SERVICE_FAILURE_ACTIONS);
790 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
791 return WERR_INVALID_PARAM;
794 buffer_size = ndr_size_SERVICE_FAILURE_ACTIONS(&actions, NULL, 0);
795 r->out.buffer = blob.data;
802 return WERR_UNKNOWN_LEVEL;
805 buffer_size += buffer_size % 4;
806 *r->out.needed = (buffer_size > r->in.offered) ? buffer_size : r->in.offered;
808 if (buffer_size > r->in.offered)
809 return WERR_INSUFFICIENT_BUFFER;
814 /********************************************************************
815 _svcctl_LockServiceDatabase
816 ********************************************************************/
818 WERROR _svcctl_LockServiceDatabase(pipes_struct *p,
819 struct svcctl_LockServiceDatabase *r)
821 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
823 /* perform access checks */
825 if ( !info || (info->type != SVC_HANDLE_IS_SCM) )
828 if ( !(info->access_granted & SC_RIGHT_MGR_LOCK) )
829 return WERR_ACCESS_DENIED;
831 /* Just open a handle. Doesn't actually lock anything */
833 return create_open_service_handle( p, r->out.lock, SVC_HANDLE_IS_DBLOCK, NULL, 0 );
836 /********************************************************************
837 _svcctl_UnlockServiceDatabase
838 ********************************************************************/
840 WERROR _svcctl_UnlockServiceDatabase(pipes_struct *p,
841 struct svcctl_UnlockServiceDatabase *r)
843 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.lock );
846 if ( !info || (info->type != SVC_HANDLE_IS_DBLOCK) )
849 return close_policy_hnd( p, r->out.lock) ? WERR_OK : WERR_BADFID;
852 /********************************************************************
853 _svcctl_QueryServiceObjectSecurity
854 ********************************************************************/
856 WERROR _svcctl_QueryServiceObjectSecurity(pipes_struct *p,
857 struct svcctl_QueryServiceObjectSecurity *r)
859 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
862 uint8_t *buffer = NULL;
866 /* only support the SCM and individual services */
868 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
871 /* check access reights (according to MSDN) */
873 if ( !(info->access_granted & STD_RIGHT_READ_CONTROL_ACCESS) )
874 return WERR_ACCESS_DENIED;
876 /* TODO: handle something besides DACL_SECURITY_INFORMATION */
878 if ( (r->in.security_flags & DACL_SECURITY_INFORMATION) != DACL_SECURITY_INFORMATION )
879 return WERR_INVALID_PARAM;
881 /* lookup the security descriptor and marshall it up for a reply */
883 if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, info->name, get_root_nt_token() )) )
886 *r->out.needed = ndr_size_security_descriptor( sec_desc, NULL, 0 );
888 if ( *r->out.needed > r->in.offered) {
889 return WERR_INSUFFICIENT_BUFFER;
892 status = marshall_sec_desc(p->mem_ctx, sec_desc, &buffer, &len);
893 if (!NT_STATUS_IS_OK(status)) {
894 return ntstatus_to_werror(status);
897 *r->out.needed = len;
898 r->out.buffer = buffer;
903 /********************************************************************
904 _svcctl_SetServiceObjectSecurity
905 ********************************************************************/
907 WERROR _svcctl_SetServiceObjectSecurity(pipes_struct *p,
908 struct svcctl_SetServiceObjectSecurity *r)
910 SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
911 SEC_DESC *sec_desc = NULL;
912 uint32 required_access;
915 if ( !info || !(info->type & (SVC_HANDLE_IS_SERVICE|SVC_HANDLE_IS_SCM)) )
918 /* can't set the security de4scriptor on the ServiceControlManager */
920 if ( info->type == SVC_HANDLE_IS_SCM )
921 return WERR_ACCESS_DENIED;
923 /* check the access on the open handle */
925 switch ( r->in.security_flags ) {
926 case DACL_SECURITY_INFORMATION:
927 required_access = STD_RIGHT_WRITE_DAC_ACCESS;
930 case OWNER_SECURITY_INFORMATION:
931 case GROUP_SECURITY_INFORMATION:
932 required_access = STD_RIGHT_WRITE_OWNER_ACCESS;
935 case SACL_SECURITY_INFORMATION:
936 return WERR_INVALID_PARAM;
938 return WERR_INVALID_PARAM;
941 if ( !(info->access_granted & required_access) )
942 return WERR_ACCESS_DENIED;
944 /* read the security descfriptor */
946 status = unmarshall_sec_desc(p->mem_ctx,
950 if (!NT_STATUS_IS_OK(status)) {
951 return ntstatus_to_werror(status);
954 /* store the new SD */
956 if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc,
957 p->server_info->ptok) )
958 return WERR_ACCESS_DENIED;
964 WERROR _svcctl_DeleteService(pipes_struct *p, struct svcctl_DeleteService *r)
966 p->rng_fault_state = True;
967 return WERR_NOT_SUPPORTED;
970 WERROR _svcctl_SetServiceStatus(pipes_struct *p, struct svcctl_SetServiceStatus *r)
972 p->rng_fault_state = True;
973 return WERR_NOT_SUPPORTED;
976 WERROR _svcctl_NotifyBootConfigStatus(pipes_struct *p, struct svcctl_NotifyBootConfigStatus *r)
978 p->rng_fault_state = True;
979 return WERR_NOT_SUPPORTED;
982 WERROR _svcctl_SCSetServiceBitsW(pipes_struct *p, struct svcctl_SCSetServiceBitsW *r)
984 p->rng_fault_state = True;
985 return WERR_NOT_SUPPORTED;
988 WERROR _svcctl_ChangeServiceConfigW(pipes_struct *p, struct svcctl_ChangeServiceConfigW *r)
990 p->rng_fault_state = True;
991 return WERR_NOT_SUPPORTED;
994 WERROR _svcctl_CreateServiceW(pipes_struct *p, struct svcctl_CreateServiceW *r)
996 p->rng_fault_state = True;
997 return WERR_NOT_SUPPORTED;
1000 WERROR _svcctl_QueryServiceLockStatusW(pipes_struct *p, struct svcctl_QueryServiceLockStatusW *r)
1002 p->rng_fault_state = True;
1003 return WERR_NOT_SUPPORTED;
1006 WERROR _svcctl_GetServiceKeyNameW(pipes_struct *p, struct svcctl_GetServiceKeyNameW *r)
1008 p->rng_fault_state = True;
1009 return WERR_NOT_SUPPORTED;
1012 WERROR _svcctl_SCSetServiceBitsA(pipes_struct *p, struct svcctl_SCSetServiceBitsA *r)
1014 p->rng_fault_state = True;
1015 return WERR_NOT_SUPPORTED;
1018 WERROR _svcctl_ChangeServiceConfigA(pipes_struct *p, struct svcctl_ChangeServiceConfigA *r)
1020 p->rng_fault_state = True;
1021 return WERR_NOT_SUPPORTED;
1024 WERROR _svcctl_CreateServiceA(pipes_struct *p, struct svcctl_CreateServiceA *r)
1026 p->rng_fault_state = True;
1027 return WERR_NOT_SUPPORTED;
1030 WERROR _svcctl_EnumDependentServicesA(pipes_struct *p, struct svcctl_EnumDependentServicesA *r)
1032 p->rng_fault_state = True;
1033 return WERR_NOT_SUPPORTED;
1036 WERROR _svcctl_EnumServicesStatusA(pipes_struct *p, struct svcctl_EnumServicesStatusA *r)
1038 p->rng_fault_state = True;
1039 return WERR_NOT_SUPPORTED;
1042 WERROR _svcctl_OpenSCManagerA(pipes_struct *p, struct svcctl_OpenSCManagerA *r)
1044 p->rng_fault_state = True;
1045 return WERR_NOT_SUPPORTED;
1048 WERROR _svcctl_OpenServiceA(pipes_struct *p, struct svcctl_OpenServiceA *r)
1050 p->rng_fault_state = True;
1051 return WERR_NOT_SUPPORTED;
1054 WERROR _svcctl_QueryServiceConfigA(pipes_struct *p, struct svcctl_QueryServiceConfigA *r)
1056 p->rng_fault_state = True;
1057 return WERR_NOT_SUPPORTED;
1060 WERROR _svcctl_QueryServiceLockStatusA(pipes_struct *p, struct svcctl_QueryServiceLockStatusA *r)
1062 p->rng_fault_state = True;
1063 return WERR_NOT_SUPPORTED;
1066 WERROR _svcctl_StartServiceA(pipes_struct *p, struct svcctl_StartServiceA *r)
1068 p->rng_fault_state = True;
1069 return WERR_NOT_SUPPORTED;
1072 WERROR _svcctl_GetServiceDisplayNameA(pipes_struct *p, struct svcctl_GetServiceDisplayNameA *r)
1074 p->rng_fault_state = True;
1075 return WERR_NOT_SUPPORTED;
1078 WERROR _svcctl_GetServiceKeyNameA(pipes_struct *p, struct svcctl_GetServiceKeyNameA *r)
1080 p->rng_fault_state = True;
1081 return WERR_NOT_SUPPORTED;
1084 WERROR _svcctl_GetCurrentGroupeStateW(pipes_struct *p, struct svcctl_GetCurrentGroupeStateW *r)
1086 p->rng_fault_state = True;
1087 return WERR_NOT_SUPPORTED;
1090 WERROR _svcctl_EnumServiceGroupW(pipes_struct *p, struct svcctl_EnumServiceGroupW *r)
1092 p->rng_fault_state = True;
1093 return WERR_NOT_SUPPORTED;
1096 WERROR _svcctl_ChangeServiceConfig2A(pipes_struct *p, struct svcctl_ChangeServiceConfig2A *r)
1098 p->rng_fault_state = True;
1099 return WERR_NOT_SUPPORTED;
1102 WERROR _svcctl_ChangeServiceConfig2W(pipes_struct *p, struct svcctl_ChangeServiceConfig2W *r)
1104 p->rng_fault_state = True;
1105 return WERR_NOT_SUPPORTED;
1108 WERROR _svcctl_QueryServiceConfig2A(pipes_struct *p, struct svcctl_QueryServiceConfig2A *r)
1110 p->rng_fault_state = True;
1111 return WERR_NOT_SUPPORTED;
1114 WERROR _EnumServicesStatusExA(pipes_struct *p, struct EnumServicesStatusExA *r)
1116 p->rng_fault_state = True;
1117 return WERR_NOT_SUPPORTED;
1120 WERROR _EnumServicesStatusExW(pipes_struct *p, struct EnumServicesStatusExW *r)
1122 p->rng_fault_state = True;
1123 return WERR_NOT_SUPPORTED;
1126 WERROR _svcctl_SCSendTSMessage(pipes_struct *p, struct svcctl_SCSendTSMessage *r)
1128 p->rng_fault_state = True;
1129 return WERR_NOT_SUPPORTED;