2008-03-28 17:56:00 +01:00
|
|
|
/*
|
|
|
|
* Services.exe - RPC functions
|
|
|
|
*
|
|
|
|
* Copyright 2007 Google (Mikolaj Zalewski)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <winternl.h>
|
|
|
|
#include <winsvc.h>
|
|
|
|
#include <ntsecapi.h>
|
|
|
|
#include <rpc.h>
|
|
|
|
|
|
|
|
#include "wine/list.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "services.h"
|
|
|
|
#include "svcctl.h"
|
|
|
|
|
|
|
|
extern HANDLE __wine_make_process_system(void);
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(service);
|
|
|
|
|
|
|
|
static const GENERIC_MAPPING g_scm_generic =
|
|
|
|
{
|
|
|
|
(STANDARD_RIGHTS_READ | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_QUERY_LOCK_STATUS),
|
|
|
|
(STANDARD_RIGHTS_WRITE | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_MODIFY_BOOT_CONFIG),
|
|
|
|
(STANDARD_RIGHTS_EXECUTE | SC_MANAGER_CONNECT | SC_MANAGER_LOCK),
|
|
|
|
SC_MANAGER_ALL_ACCESS
|
|
|
|
};
|
|
|
|
|
2008-03-15 16:42:38 +01:00
|
|
|
static const GENERIC_MAPPING g_svc_generic =
|
|
|
|
{
|
|
|
|
(STANDARD_RIGHTS_READ | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_INTERROGATE | SERVICE_ENUMERATE_DEPENDENTS),
|
|
|
|
(STANDARD_RIGHTS_WRITE | SERVICE_CHANGE_CONFIG),
|
|
|
|
(STANDARD_RIGHTS_EXECUTE | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_USER_DEFINED_CONTROL),
|
|
|
|
SERVICE_ALL_ACCESS
|
|
|
|
};
|
|
|
|
|
2008-03-28 17:56:00 +01:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SC_HTYPE_DONT_CARE = 0,
|
|
|
|
SC_HTYPE_MANAGER,
|
|
|
|
SC_HTYPE_SERVICE
|
|
|
|
} SC_HANDLE_TYPE;
|
|
|
|
|
|
|
|
struct sc_handle
|
|
|
|
{
|
|
|
|
SC_HANDLE_TYPE type;
|
|
|
|
DWORD access;
|
|
|
|
};
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle /* service control manager handle */
|
2008-03-28 17:56:00 +01:00
|
|
|
{
|
|
|
|
struct sc_handle hdr;
|
2008-03-28 18:08:12 +01:00
|
|
|
struct scmdatabase *db;
|
2008-03-28 17:56:00 +01:00
|
|
|
};
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle /* service handle */
|
2008-03-15 16:42:38 +01:00
|
|
|
{
|
|
|
|
struct sc_handle hdr;
|
|
|
|
struct service_entry *service_entry;
|
|
|
|
};
|
|
|
|
|
2008-03-28 18:06:43 +01:00
|
|
|
struct sc_lock
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct scmdatabase *db;
|
2008-03-28 18:06:43 +01:00
|
|
|
};
|
|
|
|
|
2008-03-15 16:42:38 +01:00
|
|
|
/* Check if the given handle is of the required type and allows the requested access. */
|
|
|
|
static DWORD validate_context_handle(SC_RPC_HANDLE handle, DWORD type, DWORD needed_access, struct sc_handle **out_hdr)
|
|
|
|
{
|
|
|
|
struct sc_handle *hdr = (struct sc_handle *)handle;
|
|
|
|
|
|
|
|
if (type != SC_HTYPE_DONT_CARE && hdr->type != type)
|
|
|
|
{
|
|
|
|
WINE_ERR("Handle is of an invalid type (%d, %d)\n", hdr->type, type);
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((needed_access & hdr->access) != needed_access)
|
|
|
|
{
|
|
|
|
WINE_ERR("Access denied - handle created with access %x, needed %x\n", hdr->access, needed_access);
|
|
|
|
return ERROR_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out_hdr = hdr;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
static DWORD validate_scm_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_manager_handle **manager)
|
2008-03-15 16:42:38 +01:00
|
|
|
{
|
|
|
|
struct sc_handle *hdr;
|
|
|
|
DWORD err = validate_context_handle(handle, SC_HTYPE_MANAGER, needed_access, &hdr);
|
|
|
|
if (err == ERROR_SUCCESS)
|
2008-03-28 18:08:12 +01:00
|
|
|
*manager = (struct sc_manager_handle *)hdr;
|
2008-03-15 16:42:38 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
static DWORD validate_service_handle(SC_RPC_HANDLE handle, DWORD needed_access, struct sc_service_handle **service)
|
2008-03-15 16:42:38 +01:00
|
|
|
{
|
|
|
|
struct sc_handle *hdr;
|
|
|
|
DWORD err = validate_context_handle(handle, SC_HTYPE_SERVICE, needed_access, &hdr);
|
|
|
|
if (err == ERROR_SUCCESS)
|
2008-03-28 18:08:12 +01:00
|
|
|
*service = (struct sc_service_handle *)hdr;
|
2008-03-15 16:42:38 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-03-28 17:56:00 +01:00
|
|
|
DWORD svcctl_OpenSCManagerW(
|
|
|
|
MACHINE_HANDLEW MachineName, /* Note: this parameter is ignored */
|
|
|
|
LPCWSTR DatabaseName,
|
|
|
|
DWORD dwAccessMask,
|
|
|
|
SC_RPC_HANDLE *handle)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-03-28 17:56:00 +01:00
|
|
|
|
|
|
|
WINE_TRACE("(%s, %s, %x)\n", wine_dbgstr_w(MachineName), wine_dbgstr_w(DatabaseName), dwAccessMask);
|
|
|
|
|
|
|
|
if (DatabaseName != NULL && DatabaseName[0])
|
|
|
|
{
|
|
|
|
if (strcmpW(DatabaseName, SERVICES_FAILED_DATABASEW) == 0)
|
|
|
|
return ERROR_DATABASE_DOES_NOT_EXIST;
|
|
|
|
if (strcmpW(DatabaseName, SERVICES_ACTIVE_DATABASEW) != 0)
|
|
|
|
return ERROR_INVALID_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(manager = HeapAlloc(GetProcessHeap(), 0, sizeof(*manager))))
|
|
|
|
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
|
|
|
|
|
|
|
|
manager->hdr.type = SC_HTYPE_MANAGER;
|
|
|
|
|
|
|
|
if (dwAccessMask & MAXIMUM_ALLOWED)
|
|
|
|
dwAccessMask |= SC_MANAGER_ALL_ACCESS;
|
|
|
|
manager->hdr.access = dwAccessMask;
|
|
|
|
RtlMapGenericMask(&manager->hdr.access, &g_scm_generic);
|
2008-03-28 18:08:12 +01:00
|
|
|
manager->db = active_database;
|
2008-03-28 17:56:00 +01:00
|
|
|
*handle = &manager->hdr;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SC_RPC_HANDLE_destroy(SC_RPC_HANDLE handle)
|
|
|
|
{
|
|
|
|
struct sc_handle *hdr = (struct sc_handle *)handle;
|
|
|
|
switch (hdr->type)
|
|
|
|
{
|
|
|
|
case SC_HTYPE_MANAGER:
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager = (struct sc_manager_handle *)hdr;
|
2008-03-28 17:56:00 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, manager);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-15 16:42:38 +01:00
|
|
|
case SC_HTYPE_SERVICE:
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service = (struct sc_service_handle *)hdr;
|
2008-03-15 16:42:38 +01:00
|
|
|
release_service(service->service_entry);
|
|
|
|
HeapFree(GetProcessHeap(), 0, service);
|
|
|
|
break;
|
|
|
|
}
|
2008-03-28 17:56:00 +01:00
|
|
|
default:
|
|
|
|
WINE_ERR("invalid handle type %d\n", hdr->type);
|
|
|
|
RpcRaiseException(ERROR_INVALID_HANDLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-16 22:12:08 +01:00
|
|
|
DWORD svcctl_GetServiceDisplayNameW(
|
|
|
|
SC_RPC_HANDLE hSCManager,
|
|
|
|
LPCWSTR lpServiceName,
|
|
|
|
WCHAR *lpBuffer,
|
|
|
|
DWORD cchBufSize,
|
|
|
|
DWORD *cchLength)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-03-16 22:12:08 +01:00
|
|
|
struct service_entry *entry;
|
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s, %d)\n", wine_dbgstr_w(lpServiceName), cchBufSize);
|
|
|
|
|
|
|
|
if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_lock_shared(manager->db);
|
2008-03-16 22:12:08 +01:00
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
entry = scmdatabase_find_service(manager->db, lpServiceName);
|
2008-03-16 22:12:08 +01:00
|
|
|
if (entry != NULL)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
LPCWSTR name;
|
|
|
|
service_lock_shared(entry);
|
|
|
|
name = get_display_name(entry);
|
2008-03-16 22:12:08 +01:00
|
|
|
*cchLength = strlenW(name);
|
|
|
|
if (*cchLength < cchBufSize)
|
|
|
|
{
|
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
lstrcpyW(lpBuffer, name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERROR_INSUFFICIENT_BUFFER;
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(entry);
|
2008-03-16 22:12:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*cchLength = 1;
|
|
|
|
err = ERROR_SERVICE_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
|
|
|
|
2008-03-16 22:12:08 +01:00
|
|
|
if (err != ERROR_SUCCESS && cchBufSize > 0)
|
|
|
|
lpBuffer[0] = 0;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_GetServiceKeyNameW(
|
|
|
|
SC_RPC_HANDLE hSCManager,
|
|
|
|
LPCWSTR lpServiceDisplayName,
|
|
|
|
WCHAR *lpBuffer,
|
|
|
|
DWORD cchBufSize,
|
|
|
|
DWORD *cchLength)
|
|
|
|
{
|
|
|
|
struct service_entry *entry;
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-03-16 22:12:08 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s, %d)\n", wine_dbgstr_w(lpServiceDisplayName), cchBufSize);
|
|
|
|
|
|
|
|
if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_lock_shared(manager->db);
|
2008-03-16 22:12:08 +01:00
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
entry = scmdatabase_find_service_by_displayname(manager->db, lpServiceDisplayName);
|
2008-03-16 22:12:08 +01:00
|
|
|
if (entry != NULL)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_shared(entry);
|
2008-03-16 22:12:08 +01:00
|
|
|
*cchLength = strlenW(entry->name);
|
|
|
|
if (*cchLength < cchBufSize)
|
|
|
|
{
|
|
|
|
err = ERROR_SUCCESS;
|
|
|
|
lstrcpyW(lpBuffer, entry->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = ERROR_INSUFFICIENT_BUFFER;
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(entry);
|
2008-03-16 22:12:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*cchLength = 1;
|
|
|
|
err = ERROR_SERVICE_DOES_NOT_EXIST;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
|
|
|
|
2008-03-16 22:12:08 +01:00
|
|
|
if (err != ERROR_SUCCESS && cchBufSize > 0)
|
|
|
|
lpBuffer[0] = 0;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-03-15 16:42:38 +01:00
|
|
|
static DWORD create_handle_for_service(struct service_entry *entry, DWORD dwDesiredAccess, SC_RPC_HANDLE *phService)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-15 16:42:38 +01:00
|
|
|
|
|
|
|
if (!(service = HeapAlloc(GetProcessHeap(), 0, sizeof(*service))))
|
|
|
|
{
|
|
|
|
release_service(entry);
|
|
|
|
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
service->hdr.type = SC_HTYPE_SERVICE;
|
|
|
|
service->hdr.access = dwDesiredAccess;
|
|
|
|
RtlMapGenericMask(&service->hdr.access, &g_svc_generic);
|
|
|
|
service->service_entry = entry;
|
|
|
|
if (dwDesiredAccess & MAXIMUM_ALLOWED)
|
|
|
|
dwDesiredAccess |= SERVICE_ALL_ACCESS;
|
|
|
|
|
|
|
|
*phService = &service->hdr;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_OpenServiceW(
|
|
|
|
SC_RPC_HANDLE hSCManager,
|
|
|
|
LPCWSTR lpServiceName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
SC_RPC_HANDLE *phService)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-03-15 16:42:38 +01:00
|
|
|
struct service_entry *entry;
|
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s, 0x%x)\n", wine_dbgstr_w(lpServiceName), dwDesiredAccess);
|
|
|
|
|
|
|
|
if ((err = validate_scm_handle(hSCManager, 0, &manager)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
if (!validate_service_name(lpServiceName))
|
|
|
|
return ERROR_INVALID_NAME;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_lock_shared(manager->db);
|
|
|
|
entry = scmdatabase_find_service(manager->db, lpServiceName);
|
2008-03-15 16:42:38 +01:00
|
|
|
if (entry != NULL)
|
|
|
|
entry->ref_count++;
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
|
|
|
|
if (entry == NULL)
|
|
|
|
return ERROR_SERVICE_DOES_NOT_EXIST;
|
|
|
|
|
|
|
|
return create_handle_for_service(entry, dwDesiredAccess, phService);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_CreateServiceW(
|
|
|
|
SC_RPC_HANDLE hSCManager,
|
|
|
|
LPCWSTR lpServiceName,
|
|
|
|
LPCWSTR lpDisplayName,
|
|
|
|
DWORD dwDesiredAccess,
|
|
|
|
DWORD dwServiceType,
|
|
|
|
DWORD dwStartType,
|
|
|
|
DWORD dwErrorControl,
|
|
|
|
LPCWSTR lpBinaryPathName,
|
|
|
|
LPCWSTR lpLoadOrderGroup,
|
|
|
|
DWORD *lpdwTagId,
|
|
|
|
const BYTE *lpDependencies,
|
|
|
|
DWORD dwDependenciesSize,
|
|
|
|
LPCWSTR lpServiceStartName,
|
|
|
|
const BYTE *lpPassword,
|
|
|
|
DWORD dwPasswordSize,
|
|
|
|
SC_RPC_HANDLE *phService)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-03-15 16:42:38 +01:00
|
|
|
struct service_entry *entry;
|
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%s, %s, 0x%x, %s)\n", wine_dbgstr_w(lpServiceName), wine_dbgstr_w(lpDisplayName), dwDesiredAccess, wine_dbgstr_w(lpBinaryPathName));
|
|
|
|
|
|
|
|
if ((err = validate_scm_handle(hSCManager, SC_MANAGER_CREATE_SERVICE, &manager)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!validate_service_name(lpServiceName))
|
|
|
|
return ERROR_INVALID_NAME;
|
|
|
|
if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize) || !lpServiceName[0] || !lpBinaryPathName[0])
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (lpPassword)
|
|
|
|
WINE_FIXME("Don't know how to add a password\n"); /* I always get ERROR_GEN_FAILURE */
|
|
|
|
if (lpDependencies)
|
|
|
|
WINE_FIXME("Dependencies not supported yet\n");
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
err = service_create(lpServiceName, &entry);
|
|
|
|
if (err != ERROR_SUCCESS)
|
|
|
|
return err;
|
2008-03-15 16:42:38 +01:00
|
|
|
entry->config.dwServiceType = dwServiceType;
|
|
|
|
entry->config.dwStartType = dwStartType;
|
|
|
|
entry->config.dwErrorControl = dwErrorControl;
|
|
|
|
entry->config.lpBinaryPathName = strdupW(lpBinaryPathName);
|
|
|
|
entry->config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
|
|
|
|
entry->config.lpServiceStartName = strdupW(lpServiceStartName);
|
|
|
|
entry->config.lpDisplayName = strdupW(lpDisplayName);
|
|
|
|
|
2008-04-22 08:18:14 +02:00
|
|
|
if (lpdwTagId) /* TODO: In most situations a non-NULL TagId will generate an ERROR_INVALID_PARAMETER. */
|
2008-03-15 16:42:38 +01:00
|
|
|
entry->config.dwTagId = *lpdwTagId;
|
|
|
|
else
|
|
|
|
entry->config.dwTagId = 0;
|
|
|
|
|
|
|
|
/* other fields NULL*/
|
|
|
|
|
|
|
|
if (!validate_service_config(entry))
|
|
|
|
{
|
|
|
|
WINE_ERR("Invalid data while trying to create service\n");
|
|
|
|
free_service_entry(entry);
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_lock_exclusive(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
if (scmdatabase_find_service(manager->db, lpServiceName))
|
2008-03-15 16:42:38 +01:00
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
free_service_entry(entry);
|
|
|
|
return ERROR_SERVICE_EXISTS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
if (scmdatabase_find_service_by_displayname(manager->db, get_display_name(entry)))
|
2008-03-15 16:42:38 +01:00
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
free_service_entry(entry);
|
|
|
|
return ERROR_DUPLICATE_SERVICE_NAME;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
err = scmdatabase_add_service(manager->db, entry);
|
2008-03-15 16:42:38 +01:00
|
|
|
if (err != ERROR_SUCCESS)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
free_service_entry(entry);
|
|
|
|
return err;
|
|
|
|
}
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_unlock(manager->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
|
|
|
|
return create_handle_for_service(entry, dwDesiredAccess, phService);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_DeleteService(
|
|
|
|
SC_RPC_HANDLE hService)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-15 16:42:38 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, DELETE, &service)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
scmdatabase_lock_exclusive(service->service_entry->db);
|
|
|
|
service_lock_exclusive(service->service_entry);
|
2008-03-15 16:42:38 +01:00
|
|
|
|
|
|
|
if (!is_marked_for_delete(service->service_entry))
|
2008-03-28 18:08:12 +01:00
|
|
|
err = scmdatabase_remove_service(service->service_entry->db, service->service_entry);
|
2008-03-15 16:42:38 +01:00
|
|
|
else
|
|
|
|
err = ERROR_SERVICE_MARKED_FOR_DELETE;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
|
|
|
scmdatabase_unlock(service->service_entry->db);
|
2008-03-15 16:42:38 +01:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-03-15 16:42:40 +01:00
|
|
|
DWORD svcctl_QueryServiceConfigW(
|
|
|
|
SC_RPC_HANDLE hService,
|
|
|
|
QUERY_SERVICE_CONFIGW *config)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-15 16:42:40 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p)\n", config);
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, SERVICE_QUERY_CONFIG, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_shared(service->service_entry);
|
2008-03-15 16:42:40 +01:00
|
|
|
config->dwServiceType = service->service_entry->config.dwServiceType;
|
|
|
|
config->dwStartType = service->service_entry->config.dwStartType;
|
|
|
|
config->dwErrorControl = service->service_entry->config.dwErrorControl;
|
|
|
|
config->lpBinaryPathName = strdupW(service->service_entry->config.lpBinaryPathName);
|
|
|
|
config->lpLoadOrderGroup = strdupW(service->service_entry->config.lpLoadOrderGroup);
|
|
|
|
config->dwTagId = service->service_entry->config.dwTagId;
|
|
|
|
config->lpDependencies = NULL; /* TODO */
|
|
|
|
config->lpServiceStartName = strdupW(service->service_entry->config.lpServiceStartName);
|
|
|
|
config->lpDisplayName = strdupW(service->service_entry->config.lpDisplayName);
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-15 16:42:40 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-15 19:11:12 +01:00
|
|
|
DWORD svcctl_ChangeServiceConfigW(
|
|
|
|
SC_RPC_HANDLE hService,
|
|
|
|
DWORD dwServiceType,
|
|
|
|
DWORD dwStartType,
|
|
|
|
DWORD dwErrorControl,
|
|
|
|
LPCWSTR lpBinaryPathName,
|
|
|
|
LPCWSTR lpLoadOrderGroup,
|
|
|
|
DWORD *lpdwTagId,
|
|
|
|
const BYTE *lpDependencies,
|
|
|
|
DWORD dwDependenciesSize,
|
|
|
|
LPCWSTR lpServiceStartName,
|
|
|
|
const BYTE *lpPassword,
|
|
|
|
DWORD dwPasswordSize,
|
|
|
|
LPCWSTR lpDisplayName)
|
|
|
|
{
|
2008-04-24 13:53:21 +02:00
|
|
|
struct service_entry new_entry, *entry;
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-15 19:11:12 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, SERVICE_CHANGE_CONFIG, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (!check_multisz((LPCWSTR)lpDependencies, dwDependenciesSize))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* first check if the new configuration is correct */
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_exclusive(service->service_entry);
|
2008-03-15 19:11:12 +01:00
|
|
|
|
|
|
|
if (is_marked_for_delete(service->service_entry))
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-15 19:11:12 +01:00
|
|
|
return ERROR_SERVICE_MARKED_FOR_DELETE;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
if (lpDisplayName != NULL &&
|
2008-04-24 13:53:21 +02:00
|
|
|
(entry = scmdatabase_find_service_by_displayname(service->service_entry->db, lpDisplayName)) &&
|
|
|
|
(entry != service->service_entry))
|
2008-03-15 19:11:12 +01:00
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-15 19:11:12 +01:00
|
|
|
return ERROR_DUPLICATE_SERVICE_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_entry = *service->service_entry;
|
|
|
|
|
|
|
|
if (dwServiceType != SERVICE_NO_CHANGE)
|
|
|
|
new_entry.config.dwServiceType = dwServiceType;
|
|
|
|
|
|
|
|
if (dwStartType != SERVICE_NO_CHANGE)
|
|
|
|
new_entry.config.dwStartType = dwStartType;
|
|
|
|
|
|
|
|
if (dwErrorControl != SERVICE_NO_CHANGE)
|
|
|
|
new_entry.config.dwErrorControl = dwErrorControl;
|
|
|
|
|
|
|
|
if (lpBinaryPathName != NULL)
|
|
|
|
new_entry.config.lpBinaryPathName = (LPWSTR)lpBinaryPathName;
|
|
|
|
|
|
|
|
if (lpLoadOrderGroup != NULL)
|
|
|
|
new_entry.config.lpLoadOrderGroup = (LPWSTR)lpLoadOrderGroup;
|
|
|
|
|
|
|
|
if (lpdwTagId != NULL)
|
|
|
|
WINE_FIXME("Changing tag id not supported\n");
|
|
|
|
|
|
|
|
if (lpDependencies != NULL)
|
|
|
|
WINE_FIXME("Chainging dependencies not supported\n");
|
|
|
|
|
|
|
|
if (lpServiceStartName != NULL)
|
|
|
|
new_entry.config.lpServiceStartName = (LPWSTR)lpServiceStartName;
|
|
|
|
|
|
|
|
if (lpPassword != NULL)
|
|
|
|
WINE_FIXME("Setting password not supported\n");
|
|
|
|
|
|
|
|
if (lpDisplayName != NULL)
|
|
|
|
new_entry.config.lpDisplayName = (LPWSTR)lpDisplayName;
|
|
|
|
|
|
|
|
if (!validate_service_config(&new_entry))
|
|
|
|
{
|
2008-04-07 11:03:01 +02:00
|
|
|
WINE_ERR("The configuration after the change wouldn't be valid\n");
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-15 19:11:12 +01:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* configuration OK. The strings needs to be duplicated */
|
|
|
|
if (lpBinaryPathName != NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, service->service_entry->config.lpBinaryPathName);
|
|
|
|
new_entry.config.lpBinaryPathName = strdupW(lpBinaryPathName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpLoadOrderGroup != NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, service->service_entry->config.lpLoadOrderGroup);
|
|
|
|
new_entry.config.lpLoadOrderGroup = strdupW(lpLoadOrderGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpServiceStartName != NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, service->service_entry->config.lpServiceStartName);
|
|
|
|
new_entry.config.lpServiceStartName = strdupW(lpServiceStartName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpDisplayName != NULL)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, service->service_entry->config.lpDisplayName);
|
|
|
|
new_entry.config.lpDisplayName = strdupW(lpDisplayName);
|
|
|
|
}
|
|
|
|
|
|
|
|
*service->service_entry = new_entry;
|
|
|
|
save_service_config(service->service_entry);
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-15 19:11:12 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:06:32 +01:00
|
|
|
DWORD svcctl_SetServiceStatus(
|
|
|
|
SC_RPC_HANDLE hServiceStatus,
|
|
|
|
LPSERVICE_STATUS lpServiceStatus)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-28 18:06:32 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p, %p)\n", hServiceStatus, lpServiceStatus);
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hServiceStatus, SERVICE_SET_STATUS, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_exclusive(service->service_entry);
|
2008-03-28 18:06:32 +01:00
|
|
|
/* FIXME: be a bit more discriminant about what parts of the status we set
|
|
|
|
* and check that fields are valid */
|
|
|
|
service->service_entry->status.dwServiceType = lpServiceStatus->dwServiceType;
|
|
|
|
service->service_entry->status.dwCurrentState = lpServiceStatus->dwCurrentState;
|
|
|
|
service->service_entry->status.dwControlsAccepted = lpServiceStatus->dwControlsAccepted;
|
|
|
|
service->service_entry->status.dwWin32ExitCode = lpServiceStatus->dwWin32ExitCode;
|
|
|
|
service->service_entry->status.dwServiceSpecificExitCode = lpServiceStatus->dwServiceSpecificExitCode;
|
|
|
|
service->service_entry->status.dwCheckPoint = lpServiceStatus->dwCheckPoint;
|
|
|
|
service->service_entry->status.dwWaitHint = lpServiceStatus->dwWaitHint;
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:06:32 +01:00
|
|
|
|
2008-03-28 18:07:39 +01:00
|
|
|
if (service->service_entry->status_changed_event)
|
|
|
|
SetEvent(service->service_entry->status_changed_event);
|
|
|
|
|
2008-03-28 18:06:32 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceStatusEx(
|
|
|
|
SC_RPC_HANDLE hService,
|
|
|
|
SC_STATUS_TYPE InfoLevel,
|
|
|
|
BYTE *lpBuffer,
|
|
|
|
DWORD cbBufSize,
|
|
|
|
LPDWORD pcbBytesNeeded)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-28 18:06:32 +01:00
|
|
|
DWORD err;
|
|
|
|
LPSERVICE_STATUS_PROCESS pSvcStatusData;
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, SERVICE_QUERY_STATUS, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
if (InfoLevel != SC_STATUS_PROCESS_INFO)
|
|
|
|
return ERROR_INVALID_LEVEL;
|
|
|
|
|
|
|
|
pSvcStatusData = (LPSERVICE_STATUS_PROCESS) lpBuffer;
|
|
|
|
if (pSvcStatusData == NULL)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS))
|
|
|
|
{
|
|
|
|
if( pcbBytesNeeded != NULL)
|
|
|
|
*pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
|
|
|
|
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_shared(service->service_entry);
|
2008-03-28 18:06:32 +01:00
|
|
|
|
|
|
|
pSvcStatusData->dwServiceType = service->service_entry->status.dwServiceType;
|
|
|
|
pSvcStatusData->dwCurrentState = service->service_entry->status.dwCurrentState;
|
|
|
|
pSvcStatusData->dwControlsAccepted = service->service_entry->status.dwControlsAccepted;
|
|
|
|
pSvcStatusData->dwWin32ExitCode = service->service_entry->status.dwWin32ExitCode;
|
|
|
|
pSvcStatusData->dwServiceSpecificExitCode = service->service_entry->status.dwServiceSpecificExitCode;
|
|
|
|
pSvcStatusData->dwCheckPoint = service->service_entry->status.dwCheckPoint;
|
|
|
|
pSvcStatusData->dwWaitHint = service->service_entry->status.dwWaitHint;
|
|
|
|
pSvcStatusData->dwProcessId = service->service_entry->status.dwProcessId;
|
|
|
|
pSvcStatusData->dwServiceFlags = service->service_entry->status.dwServiceFlags;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:06:32 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:07:39 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* service_accepts_control
|
|
|
|
*/
|
|
|
|
static BOOL service_accepts_control(const struct service_entry *service, DWORD dwControl)
|
|
|
|
{
|
|
|
|
DWORD a = service->status.dwControlsAccepted;
|
|
|
|
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
return TRUE;
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
if (a&SERVICE_ACCEPT_STOP)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
if (a&SERVICE_ACCEPT_SHUTDOWN)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
|
|
|
if (a&SERVICE_ACCEPT_PAUSE_CONTINUE)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_PARAMCHANGE:
|
|
|
|
if (a&SERVICE_ACCEPT_PARAMCHANGE)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_NETBINDADD:
|
|
|
|
case SERVICE_CONTROL_NETBINDREMOVE:
|
|
|
|
case SERVICE_CONTROL_NETBINDENABLE:
|
|
|
|
case SERVICE_CONTROL_NETBINDDISABLE:
|
|
|
|
if (a&SERVICE_ACCEPT_NETBINDCHANGE)
|
|
|
|
return TRUE;
|
|
|
|
case SERVICE_CONTROL_HARDWAREPROFILECHANGE:
|
|
|
|
if (a&SERVICE_ACCEPT_HARDWAREPROFILECHANGE)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_POWEREVENT:
|
|
|
|
if (a&SERVICE_ACCEPT_POWEREVENT)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_SESSIONCHANGE:
|
|
|
|
if (a&SERVICE_ACCEPT_SESSIONCHANGE)
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* service_send_control
|
|
|
|
*/
|
2008-05-08 18:08:41 +02:00
|
|
|
static BOOL service_send_control(struct service_entry *service, HANDLE pipe, DWORD dwControl, DWORD *result)
|
2008-03-28 18:07:39 +01:00
|
|
|
{
|
2008-05-08 18:08:41 +02:00
|
|
|
service_start_info *ssi;
|
|
|
|
DWORD len, count = 0;
|
2008-03-28 18:07:39 +01:00
|
|
|
BOOL r;
|
|
|
|
|
2008-05-08 18:08:41 +02:00
|
|
|
/* calculate how much space we need to send the startup info */
|
|
|
|
len = strlenW(service->name) + 1;
|
|
|
|
|
|
|
|
ssi = HeapAlloc(GetProcessHeap(),0,FIELD_OFFSET(service_start_info, data[len]));
|
|
|
|
ssi->cmd = WINESERV_SENDCONTROL;
|
|
|
|
ssi->control = dwControl;
|
|
|
|
ssi->total_size = FIELD_OFFSET(service_start_info, data[len]);
|
|
|
|
ssi->name_size = strlenW(service->name) + 1;
|
|
|
|
strcpyW( ssi->data, service->name );
|
|
|
|
|
|
|
|
r = WriteFile(pipe, ssi, ssi->total_size, &count, NULL);
|
|
|
|
if (!r || count != ssi->total_size)
|
2008-03-28 18:07:39 +01:00
|
|
|
{
|
|
|
|
WINE_ERR("service protocol error - failed to write pipe!\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = ReadFile(pipe, result, sizeof *result, &count, NULL);
|
|
|
|
if (!r || count != sizeof *result)
|
|
|
|
WINE_ERR("service protocol error - failed to read pipe "
|
|
|
|
"r = %d count = %d!\n", r, count);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_StartServiceW(
|
|
|
|
SC_RPC_HANDLE hService,
|
|
|
|
DWORD dwNumServiceArgs,
|
|
|
|
LPCWSTR *lpServiceArgVectors)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-28 18:07:39 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p, %d, %p)\n", hService, dwNumServiceArgs, lpServiceArgVectors);
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, SERVICE_START, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
2008-04-11 12:00:11 +02:00
|
|
|
err = service_start(service->service_entry, dwNumServiceArgs, lpServiceArgVectors);
|
2008-03-28 18:07:39 +01:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_ControlService(
|
|
|
|
SC_RPC_HANDLE hService,
|
|
|
|
DWORD dwControl,
|
|
|
|
SERVICE_STATUS *lpServiceStatus)
|
|
|
|
{
|
|
|
|
DWORD access_required;
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_service_handle *service;
|
2008-03-28 18:07:39 +01:00
|
|
|
DWORD err;
|
|
|
|
BOOL ret;
|
|
|
|
HANDLE control_mutex;
|
|
|
|
HANDLE control_pipe;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p, %d, %p)\n", hService, dwControl, lpServiceStatus);
|
|
|
|
|
|
|
|
switch (dwControl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_CONTINUE:
|
|
|
|
case SERVICE_CONTROL_NETBINDADD:
|
|
|
|
case SERVICE_CONTROL_NETBINDDISABLE:
|
|
|
|
case SERVICE_CONTROL_NETBINDENABLE:
|
|
|
|
case SERVICE_CONTROL_NETBINDREMOVE:
|
|
|
|
case SERVICE_CONTROL_PARAMCHANGE:
|
|
|
|
case SERVICE_CONTROL_PAUSE:
|
|
|
|
access_required = SERVICE_PAUSE_CONTINUE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_INTERROGATE:
|
|
|
|
access_required = SERVICE_INTERROGATE;
|
|
|
|
break;
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
access_required = SERVICE_STOP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (dwControl >= 128 && dwControl <= 255)
|
|
|
|
access_required = SERVICE_USER_DEFINED_CONTROL;
|
|
|
|
else
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = validate_service_handle(hService, access_required, &service)) != 0)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_lock_exclusive(service->service_entry);
|
2008-03-28 18:07:39 +01:00
|
|
|
|
|
|
|
if (lpServiceStatus)
|
|
|
|
{
|
|
|
|
lpServiceStatus->dwServiceType = service->service_entry->status.dwServiceType;
|
|
|
|
lpServiceStatus->dwCurrentState = service->service_entry->status.dwCurrentState;
|
|
|
|
lpServiceStatus->dwControlsAccepted = service->service_entry->status.dwControlsAccepted;
|
|
|
|
lpServiceStatus->dwWin32ExitCode = service->service_entry->status.dwWin32ExitCode;
|
|
|
|
lpServiceStatus->dwServiceSpecificExitCode = service->service_entry->status.dwServiceSpecificExitCode;
|
|
|
|
lpServiceStatus->dwCheckPoint = service->service_entry->status.dwCheckPoint;
|
|
|
|
lpServiceStatus->dwWaitHint = service->service_entry->status.dwWaitHint;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!service_accepts_control(service->service_entry, dwControl))
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:07:39 +01:00
|
|
|
return ERROR_INVALID_SERVICE_CONTROL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (service->service_entry->status.dwCurrentState)
|
|
|
|
{
|
|
|
|
case SERVICE_STOPPED:
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:07:39 +01:00
|
|
|
return ERROR_SERVICE_NOT_ACTIVE;
|
|
|
|
case SERVICE_START_PENDING:
|
|
|
|
if (dwControl==SERVICE_CONTROL_STOP)
|
|
|
|
break;
|
|
|
|
/* fall thru */
|
|
|
|
case SERVICE_STOP_PENDING:
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:07:39 +01:00
|
|
|
return ERROR_SERVICE_CANNOT_ACCEPT_CTRL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prevent races by caching these variables and clearing them on
|
|
|
|
* stop here instead of outside the services lock */
|
|
|
|
control_mutex = service->service_entry->control_mutex;
|
|
|
|
control_pipe = service->service_entry->control_pipe;
|
|
|
|
if (dwControl == SERVICE_CONTROL_STOP)
|
|
|
|
{
|
|
|
|
service->service_entry->control_mutex = NULL;
|
2008-05-05 13:00:49 +02:00
|
|
|
service->service_entry->control_pipe = INVALID_HANDLE_VALUE;
|
2008-03-28 18:07:39 +01:00
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
service_unlock(service->service_entry);
|
2008-03-28 18:07:39 +01:00
|
|
|
|
|
|
|
ret = WaitForSingleObject(control_mutex, 30000);
|
2008-05-05 13:01:15 +02:00
|
|
|
if (ret == WAIT_OBJECT_0)
|
2008-03-28 18:07:39 +01:00
|
|
|
{
|
|
|
|
DWORD result = ERROR_SUCCESS;
|
|
|
|
|
2008-05-08 18:08:41 +02:00
|
|
|
ret = service_send_control(service->service_entry, control_pipe, dwControl, &result);
|
2008-03-28 18:07:39 +01:00
|
|
|
|
|
|
|
if (dwControl == SERVICE_CONTROL_STOP)
|
|
|
|
{
|
|
|
|
CloseHandle(control_mutex);
|
|
|
|
CloseHandle(control_pipe);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ReleaseMutex(control_mutex);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dwControl == SERVICE_CONTROL_STOP)
|
|
|
|
{
|
|
|
|
CloseHandle(control_mutex);
|
|
|
|
CloseHandle(control_pipe);
|
|
|
|
}
|
|
|
|
return ERROR_SERVICE_REQUEST_TIMEOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-28 17:56:00 +01:00
|
|
|
DWORD svcctl_CloseServiceHandle(
|
|
|
|
SC_RPC_HANDLE *handle)
|
|
|
|
{
|
|
|
|
WINE_TRACE("(&%p)\n", *handle);
|
|
|
|
|
|
|
|
SC_RPC_HANDLE_destroy(*handle);
|
|
|
|
*handle = NULL;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:06:43 +01:00
|
|
|
static void SC_RPC_LOCK_destroy(SC_RPC_LOCK hLock)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_lock *lock = hLock;
|
|
|
|
scmdatabase_unlock_startup(lock->db);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lock);
|
2008-03-28 18:06:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER SC_RPC_LOCK_rundown(SC_RPC_LOCK hLock)
|
|
|
|
{
|
|
|
|
SC_RPC_LOCK_destroy(hLock);
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_LockServiceDatabase(
|
|
|
|
SC_RPC_HANDLE hSCManager,
|
|
|
|
SC_RPC_LOCK *phLock)
|
|
|
|
{
|
2008-03-28 18:08:12 +01:00
|
|
|
struct sc_manager_handle *manager;
|
2008-07-17 19:24:58 +02:00
|
|
|
struct sc_lock *lock;
|
2008-03-28 18:06:43 +01:00
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
WINE_TRACE("(%p, %p)\n", hSCManager, phLock);
|
|
|
|
|
|
|
|
if ((err = validate_scm_handle(hSCManager, SC_MANAGER_LOCK, &manager)) != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
2008-03-28 18:08:12 +01:00
|
|
|
err = scmdatabase_lock_startup(manager->db);
|
2008-03-28 18:06:43 +01:00
|
|
|
if (err != ERROR_SUCCESS)
|
|
|
|
return err;
|
|
|
|
|
2008-07-17 19:24:58 +02:00
|
|
|
lock = HeapAlloc(GetProcessHeap(), 0, sizeof(struct sc_lock));
|
|
|
|
if (!lock)
|
2008-03-28 18:08:12 +01:00
|
|
|
{
|
|
|
|
scmdatabase_unlock_startup(manager->db);
|
2008-03-28 18:06:43 +01:00
|
|
|
return ERROR_NOT_ENOUGH_SERVER_MEMORY;
|
2008-03-28 18:08:12 +01:00
|
|
|
}
|
2008-03-28 18:06:43 +01:00
|
|
|
|
2008-07-17 19:24:58 +02:00
|
|
|
lock->db = manager->db;
|
|
|
|
*phLock = lock;
|
|
|
|
|
2008-03-28 18:06:43 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_UnlockServiceDatabase(
|
|
|
|
SC_RPC_LOCK *phLock)
|
|
|
|
{
|
|
|
|
WINE_TRACE("(&%p)\n", *phLock);
|
|
|
|
|
|
|
|
SC_RPC_LOCK_destroy(*phLock);
|
|
|
|
*phLock = NULL;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-03-28 18:08:27 +01:00
|
|
|
DWORD svcctl_QueryServiceObjectSecurity(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_SetServiceObjectSecurity(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceStatus(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DWORD svcctl_NotifyBootConfigStatus(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_SCSetServiceBitsW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DWORD svcctl_EnumDependentServicesW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_EnumServicesStatusW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceLockStatusW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_SCSetServiceBitsA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_ChangeServiceConfigA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_CreateServiceA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_EnumDependentServicesA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_EnumServicesStatusA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_OpenSCManagerA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_OpenServiceA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceConfigA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceLockStatusA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_StartServiceA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_GetServiceDisplayNameA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_GetServiceKeyNameA(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_GetCurrentGroupStateW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_EnumServiceGroupW(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_ChangeServiceConfig2A(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_ChangeServiceConfig2W(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceConfig2A(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD svcctl_QueryServiceConfig2W(
|
|
|
|
void)
|
|
|
|
{
|
|
|
|
WINE_FIXME("\n");
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-11 11:59:51 +02:00
|
|
|
DWORD RPC_Init(void)
|
2008-03-28 17:56:00 +01:00
|
|
|
{
|
|
|
|
WCHAR transport[] = SVCCTL_TRANSPORT;
|
|
|
|
WCHAR endpoint[] = SVCCTL_ENDPOINT;
|
|
|
|
DWORD err;
|
|
|
|
|
|
|
|
if ((err = RpcServerUseProtseqEpW(transport, 0, endpoint, NULL)) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WINE_ERR("RpcServerUseProtseq failed with error %u\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = RpcServerRegisterIf(svcctl_v2_0_s_ifspec, 0, 0)) != ERROR_SUCCESS)
|
|
|
|
{
|
2008-04-07 11:03:01 +02:00
|
|
|
WINE_ERR("RpcServerRegisterIf failed with error %u\n", err);
|
2008-03-28 17:56:00 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((err = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE)) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WINE_ERR("RpcServerListen failed with error %u\n", err);
|
|
|
|
return err;
|
|
|
|
}
|
2008-04-11 11:59:51 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD RPC_MainLoop(void)
|
|
|
|
{
|
|
|
|
DWORD err;
|
|
|
|
HANDLE hExitEvent = __wine_make_process_system();
|
2008-03-28 17:56:00 +01:00
|
|
|
|
|
|
|
SetEvent(g_hStartedEvent);
|
2008-04-11 11:59:51 +02:00
|
|
|
|
|
|
|
WINE_TRACE("Entered main loop\n");
|
|
|
|
|
2008-03-28 17:56:00 +01:00
|
|
|
do
|
|
|
|
{
|
2008-04-11 11:59:51 +02:00
|
|
|
err = WaitForSingleObjectEx(hExitEvent, INFINITE, TRUE);
|
2008-03-28 17:56:00 +01:00
|
|
|
WINE_TRACE("Wait returned %d\n", err);
|
|
|
|
} while (err != WAIT_OBJECT_0);
|
|
|
|
|
|
|
|
WINE_TRACE("Object signaled - wine shutdown\n");
|
2008-04-11 11:59:51 +02:00
|
|
|
CloseHandle(hExitEvent);
|
2008-03-28 17:56:00 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER SC_RPC_HANDLE_rundown(SC_RPC_HANDLE handle)
|
|
|
|
{
|
|
|
|
SC_RPC_HANDLE_destroy(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_FAR * __RPC_USER MIDL_user_allocate(size_t len)
|
|
|
|
{
|
|
|
|
return HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
}
|