*
* Largely Rewritten (Again) by:
* Copyright (C) Gerald (Jerry) Carter 2005.
+ * Copyright (C) Guenther Deschner 2008.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
bool init_service_op_table( void )
{
const char **service_list = lp_svcctl_list();
- int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_count( service_list );
+ int num_services = SVCCTL_NUM_INTERNAL_SERVICES + str_list_length( service_list );
int i;
if ( !(svcctl_ops = TALLOC_ARRAY( NULL, struct service_control_op, num_services+1)) ) {
static NTSTATUS svcctl_access_check( SEC_DESC *sec_desc, NT_USER_TOKEN *token,
uint32 access_desired, uint32 *access_granted )
{
- NTSTATUS result;
-
if ( geteuid() == sec_initial_uid() ) {
DEBUG(5,("svcctl_access_check: using root's token\n"));
token = get_root_nt_token();
}
- se_access_check( sec_desc, token, access_desired, access_granted, &result );
-
- return result;
+ return se_access_check( sec_desc, token, access_desired, access_granted);
}
/********************************************************************
static SEC_DESC* construct_scm_sd( TALLOC_CTX *ctx )
{
SEC_ACE ace[2];
- SEC_ACCESS mask;
size_t i = 0;
SEC_DESC *sd;
SEC_ACL *acl;
/* basic access for Everyone */
- init_sec_access(&mask, SC_MANAGER_READ_ACCESS );
- init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+ init_sec_ace(&ace[i++], &global_sid_World,
+ SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_READ_ACCESS, 0);
/* Full Access 'BUILTIN\Administrators' */
- init_sec_access(&mask,SC_MANAGER_ALL_ACCESS );
- init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
+ init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators,
+ SEC_ACE_TYPE_ACCESS_ALLOWED, SC_MANAGER_ALL_ACCESS, 0);
/* create the security descriptor */
SERVICE_INFO *service_info = NULL;
if( !find_policy_by_hnd( p, hnd, (void **)(void *)&service_info) ) {
- DEBUG(2,("find_service_info_by_hnd: handle not found"));
+ DEBUG(2,("find_service_info_by_hnd: handle not found\n"));
return NULL;
}
return WERR_NOMEM;
se_map_generic( &r->in.access_mask, &scm_generic_map );
- status = svcctl_access_check( sec_desc, p->pipe_user.nt_user_token, r->in.access_mask, &access_granted );
+ status = svcctl_access_check( sec_desc, p->server_info->ptok,
+ r->in.access_mask, &access_granted );
if ( !NT_STATUS_IS_OK(status) )
return ntstatus_to_werror( status );
return WERR_NOMEM;
se_map_generic( &r->in.access_mask, &svc_generic_map );
- status = svcctl_access_check( sec_desc, p->pipe_user.nt_user_token, r->in.access_mask, &access_granted );
+ status = svcctl_access_check( sec_desc, p->server_info->ptok,
+ r->in.access_mask, &access_granted );
if ( !NT_STATUS_IS_OK(status) )
return ntstatus_to_werror( status );
if ( !close_policy_hnd( p, r->in.handle ) )
return WERR_BADFID;
+ ZERO_STRUCTP(r->out.handle);
+
return WERR_OK;
}
service = r->in.service_name;
- display_name = svcctl_lookup_dispname(p->mem_ctx, service, p->pipe_user.nt_user_token );
+ display_name = svcctl_lookup_dispname(p->mem_ctx, service,
+ p->server_info->ptok);
if (!display_name) {
display_name = "";
}
size_t buffer_size = 0;
WERROR result = WERR_OK;
SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
- NT_USER_TOKEN *token = p->pipe_user.nt_user_token;
+ NT_USER_TOKEN *token = p->server_info->ptok;
/* perform access checks */
return info->ops->service_status( info->name,
r->out.service_status );
+ default:
+ return WERR_ACCESS_DENIED;
}
-
- /* default control action */
-
- return WERR_ACCESS_DENIED;
}
/********************************************************************
+ _svcctl_EnumDependentServicesW
********************************************************************/
-WERROR _svcctl_enum_dependent_services( pipes_struct *p, SVCCTL_Q_ENUM_DEPENDENT_SERVICES *q_u, SVCCTL_R_ENUM_DEPENDENT_SERVICES *r_u )
+WERROR _svcctl_EnumDependentServicesW(pipes_struct *p,
+ struct svcctl_EnumDependentServicesW *r)
{
- SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
+ SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.service );
/* perform access checks */
/* we have to set the outgoing buffer size to the same as the
incoming buffer size (even in the case of failure */
+ /* this is done in the autogenerated server already - gd */
- rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
-
- r_u->needed = q_u->buffer_size;
+ *r->out.bytes_needed = r->in.buf_size;
/* no dependent services...basically a stub function */
- r_u->returned = 0;
+ *r->out.services_returned = 0;
return WERR_OK;
}
/********************************************************************
+ _svcctl_QueryServiceStatusEx
********************************************************************/
-WERROR _svcctl_query_service_status_ex( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_STATUSEX *q_u, SVCCTL_R_QUERY_SERVICE_STATUSEX *r_u )
+WERROR _svcctl_QueryServiceStatusEx(pipes_struct *p,
+ struct svcctl_QueryServiceStatusEx *r)
{
- SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
+ SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
uint32 buffer_size;
/* perform access checks */
/* we have to set the outgoing buffer size to the same as the
incoming buffer size (even in the case of failure) */
- rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
- r_u->needed = q_u->buffer_size;
+ *r->out.bytes_needed = r->in.buf_size;
- switch ( q_u->level ) {
+ switch ( r->in.info_level ) {
case SVC_STATUS_PROCESS_INFO:
{
- SERVICE_STATUS_PROCESS svc_stat_proc;
+ struct SERVICE_STATUS_PROCESS svc_stat_proc;
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
/* Get the status of the service.. */
info->ops->service_status( info->name, &svc_stat_proc.status );
svc_stat_proc.process_id = sys_getpid();
svc_stat_proc.service_flags = 0x0;
- svcctl_io_service_status_process( "", &svc_stat_proc, &r_u->buffer, 0 );
- buffer_size = sizeof(SERVICE_STATUS_PROCESS);
+ ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
+ &svc_stat_proc,
+ (ndr_push_flags_fn_t)ndr_push_SERVICE_STATUS_PROCESS);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return WERR_INVALID_PARAM;
+ }
+
+ r->out.buffer = blob.data;
+ buffer_size = sizeof(struct SERVICE_STATUS_PROCESS);
break;
}
buffer_size += buffer_size % 4;
- r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
+ *r->out.bytes_needed = (buffer_size > r->in.buf_size) ? buffer_size : r->in.buf_size;
- if (buffer_size > q_u->buffer_size )
- return WERR_MORE_DATA;
+ if (buffer_size > r->in.buf_size ) {
+ return WERR_INSUFFICIENT_BUFFER;
+ }
return WERR_OK;
}
/********************************************************************
********************************************************************/
-static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name, SERVICE_CONFIG *config, NT_USER_TOKEN *token )
+static WERROR fill_svc_config( TALLOC_CTX *ctx, const char *name,
+ struct QUERY_SERVICE_CONFIG *config,
+ NT_USER_TOKEN *token )
{
REGVAL_CTR *values;
REGISTRY_VALUE *val;
/* now fill in the individual values */
- config->displayname = TALLOC_ZERO_P( ctx, UNISTR2 );
if ( (val = regval_ctr_getvalue( values, "DisplayName" )) != NULL )
- init_unistr2( config->displayname, regval_sz( val ), UNI_STR_TERMINATE );
+ config->displayname = regval_sz(val);
else
- init_unistr2( config->displayname, name, UNI_STR_TERMINATE );
+ config->displayname = name;
if ( (val = regval_ctr_getvalue( values, "ObjectName" )) != NULL ) {
- config->startname = TALLOC_ZERO_P( ctx, UNISTR2 );
- init_unistr2( config->startname, regval_sz( val ), UNI_STR_TERMINATE );
+ config->startname = regval_sz(val);
}
if ( (val = regval_ctr_getvalue( values, "ImagePath" )) != NULL ) {
- config->executablepath = TALLOC_ZERO_P( ctx, UNISTR2 );
- init_unistr2( config->executablepath, regval_sz( val ), UNI_STR_TERMINATE );
+ config->executablepath = regval_sz(val);
}
/* a few hard coded values */
/* loadordergroup and dependencies are empty */
config->tag_id = 0x00000000; /* unassigned loadorder group */
- config->service_type = SVCCTL_WIN32_OWN_PROC;
+ config->service_type = SERVICE_TYPE_WIN32_OWN_PROCESS;
config->error_control = SVCCTL_SVC_ERROR_NORMAL;
/* set the start type. NetLogon and WINS are disabled to prevent
}
/********************************************************************
+ _svcctl_QueryServiceConfigW
********************************************************************/
-WERROR _svcctl_query_service_config( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_CONFIG *q_u, SVCCTL_R_QUERY_SERVICE_CONFIG *r_u )
+WERROR _svcctl_QueryServiceConfigW(pipes_struct *p,
+ struct svcctl_QueryServiceConfigW *r)
{
- SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
+ SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
uint32 buffer_size;
WERROR wresult;
/* we have to set the outgoing buffer size to the same as the
incoming buffer size (even in the case of failure */
- r_u->needed = q_u->buffer_size;
+ *r->out.bytes_needed = r->in.buf_size;
- wresult = fill_svc_config( p->mem_ctx, info->name, &r_u->config, p->pipe_user.nt_user_token );
+ wresult = fill_svc_config( p->mem_ctx, info->name, r->out.query,
+ p->server_info->ptok);
if ( !W_ERROR_IS_OK(wresult) )
return wresult;
- buffer_size = svcctl_sizeof_service_config( &r_u->config );
- r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
+ buffer_size = ndr_size_QUERY_SERVICE_CONFIG(r->out.query, NULL, 0);
+ *r->out.bytes_needed = (buffer_size > r->in.buf_size) ? buffer_size : r->in.buf_size;
- if (buffer_size > q_u->buffer_size ) {
- ZERO_STRUCTP( &r_u->config );
+ if (buffer_size > r->in.buf_size ) {
+ ZERO_STRUCTP(r->out.query);
return WERR_INSUFFICIENT_BUFFER;
}
}
/********************************************************************
+ _svcctl_QueryServiceConfig2W
********************************************************************/
-WERROR _svcctl_query_service_config2( pipes_struct *p, SVCCTL_Q_QUERY_SERVICE_CONFIG2 *q_u, SVCCTL_R_QUERY_SERVICE_CONFIG2 *r_u )
+WERROR _svcctl_QueryServiceConfig2W(pipes_struct *p,
+ struct svcctl_QueryServiceConfig2W *r)
{
- SERVICE_INFO *info = find_service_info_by_hnd( p, &q_u->handle );
+ SERVICE_INFO *info = find_service_info_by_hnd( p, r->in.handle );
uint32 buffer_size;
/* perform access checks */
/* we have to set the outgoing buffer size to the same as the
incoming buffer size (even in the case of failure */
- rpcbuf_init( &r_u->buffer, q_u->buffer_size, p->mem_ctx );
- r_u->needed = q_u->buffer_size;
+ *r->out.bytes_needed = r->in.buf_size;
- switch ( q_u->level ) {
+ switch ( r->in.info_level ) {
case SERVICE_CONFIG_DESCRIPTION:
{
- SERVICE_DESCRIPTION desc_buf;
+ struct SERVICE_DESCRIPTION desc_buf;
const char *description;
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
- description = svcctl_lookup_description(p->mem_ctx, info->name, p->pipe_user.nt_user_token );
+ description = svcctl_lookup_description(
+ p->mem_ctx, info->name, p->server_info->ptok);
- ZERO_STRUCTP( &desc_buf );
+ desc_buf.description = description;
- init_service_description_buffer( &desc_buf, description ? description : "");
- svcctl_io_service_description( "", &desc_buf, &r_u->buffer, 0 );
- buffer_size = svcctl_sizeof_service_description( &desc_buf );
+ ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
+ &desc_buf,
+ (ndr_push_flags_fn_t)ndr_push_SERVICE_DESCRIPTION);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return WERR_INVALID_PARAM;
+ }
+
+ buffer_size = ndr_size_SERVICE_DESCRIPTION(&desc_buf, NULL, 0);
+ r->out.buffer = blob.data;
break;
}
break;
case SERVICE_CONFIG_FAILURE_ACTIONS:
{
- SERVICE_FAILURE_ACTIONS actions;
+ struct SERVICE_FAILURE_ACTIONS actions;
+ enum ndr_err_code ndr_err;
+ DATA_BLOB blob;
/* nothing to say...just service the request */
- ZERO_STRUCTP( &actions );
- svcctl_io_service_fa( "", &actions, &r_u->buffer, 0 );
- buffer_size = svcctl_sizeof_service_fa( &actions );
+ ZERO_STRUCT( actions );
+
+ ndr_err = ndr_push_struct_blob(&blob, p->mem_ctx, NULL,
+ &actions,
+ (ndr_push_flags_fn_t)ndr_push_SERVICE_FAILURE_ACTIONS);
+ if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ return WERR_INVALID_PARAM;
+ }
+
+ buffer_size = ndr_size_SERVICE_FAILURE_ACTIONS(&actions, NULL, 0);
+ r->out.buffer = blob.data;
break;
}
}
buffer_size += buffer_size % 4;
- r_u->needed = (buffer_size > q_u->buffer_size) ? buffer_size : q_u->buffer_size;
+ *r->out.bytes_needed = (buffer_size > r->in.buf_size) ? buffer_size : r->in.buf_size;
- if (buffer_size > q_u->buffer_size )
+ if (buffer_size > r->in.buf_size )
return WERR_INSUFFICIENT_BUFFER;
return WERR_OK;
if ( !(sec_desc = svcctl_get_secdesc( p->mem_ctx, info->name, get_root_nt_token() )) )
return WERR_NOMEM;
- *r->out.needed = ndr_size_security_descriptor( sec_desc, 0 );
+ *r->out.needed = ndr_size_security_descriptor( sec_desc, NULL, 0 );
if ( *r->out.needed > r->in.buffer_size ) {
ZERO_STRUCTP( &r->out.buffer );
/* store the new SD */
- if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc, p->pipe_user.nt_user_token ) )
+ if ( !svcctl_set_secdesc( p->mem_ctx, info->name, sec_desc,
+ p->server_info->ptok) )
return WERR_ACCESS_DENIED;
return WERR_OK;
return WERR_NOT_SUPPORTED;
}
-WERROR _svcctl_EnumDependentServicesW(pipes_struct *p, struct svcctl_EnumDependentServicesW *r)
-{
- p->rng_fault_state = True;
- return WERR_NOT_SUPPORTED;
-}
-
WERROR _svcctl_EnumServicesStatusW(pipes_struct *p, struct svcctl_EnumServicesStatusW *r)
{
p->rng_fault_state = True;
return WERR_NOT_SUPPORTED;
}
-WERROR _svcctl_QueryServiceConfigW(pipes_struct *p, struct svcctl_QueryServiceConfigW *r)
-{
- p->rng_fault_state = True;
- return WERR_NOT_SUPPORTED;
-}
-
WERROR _svcctl_QueryServiceLockStatusW(pipes_struct *p, struct svcctl_QueryServiceLockStatusW *r)
{
p->rng_fault_state = True;
return WERR_NOT_SUPPORTED;
}
-WERROR _svcctl_QueryServiceConfig2W(pipes_struct *p, struct svcctl_QueryServiceConfig2W *r)
-{
- p->rng_fault_state = True;
- return WERR_NOT_SUPPORTED;
-}
-
-WERROR _svcctl_QueryServiceStatusEx(pipes_struct *p, struct svcctl_QueryServiceStatusEx *r)
-{
- p->rng_fault_state = True;
- return WERR_NOT_SUPPORTED;
-}
-
WERROR _EnumServicesStatusExA(pipes_struct *p, struct EnumServicesStatusExA *r)
{
p->rng_fault_state = True;