2005-10-09 20:24:00 +00:00
|
|
|
/*
|
|
|
|
* services.h
|
|
|
|
*/
|
|
|
|
|
2014-02-05 16:35:49 +00:00
|
|
|
#ifndef _SERVICES_H
|
|
|
|
#define _SERVICES_H
|
|
|
|
|
2005-07-26 14:00:45 +00:00
|
|
|
#include <stdio.h>
|
2014-10-02 16:28:18 +00:00
|
|
|
#include <stdlib.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
|
2005-10-19 17:03:38 +00:00
|
|
|
#define WIN32_NO_STATUS
|
2014-01-13 13:10:28 +00:00
|
|
|
#define _INC_WINDOWS
|
|
|
|
#define COM_NO_WINDOWS_H
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winsvc.h>
|
2014-01-13 13:10:28 +00:00
|
|
|
#include <winreg.h>
|
2015-02-16 11:47:40 +00:00
|
|
|
#include <winuser.h>
|
2011-05-26 10:50:26 +00:00
|
|
|
#include <netevent.h>
|
2005-06-20 21:04:03 +00:00
|
|
|
#define NTOS_MODE_USER
|
2019-08-05 18:18:17 +00:00
|
|
|
#include <ndk/setypes.h>
|
2011-08-14 12:59:05 +00:00
|
|
|
#include <ndk/obfuncs.h>
|
|
|
|
#include <ndk/rtlfuncs.h>
|
2005-10-19 17:03:38 +00:00
|
|
|
#include <services/services.h>
|
2013-01-24 23:00:42 +00:00
|
|
|
#include <svcctl_s.h>
|
2005-12-31 18:56:34 +00:00
|
|
|
|
2015-02-16 11:47:40 +00:00
|
|
|
#include "resource.h"
|
|
|
|
|
2005-12-31 18:56:34 +00:00
|
|
|
typedef struct _SERVICE_GROUP
|
|
|
|
{
|
|
|
|
LIST_ENTRY GroupListEntry;
|
|
|
|
LPWSTR lpGroupName;
|
|
|
|
|
|
|
|
DWORD dwRefCount;
|
|
|
|
BOOLEAN ServicesRunning;
|
|
|
|
ULONG TagCount;
|
|
|
|
PULONG TagArray;
|
|
|
|
|
|
|
|
WCHAR szGroupName[1];
|
|
|
|
} SERVICE_GROUP, *PSERVICE_GROUP;
|
|
|
|
|
|
|
|
|
2006-12-26 01:29:22 +00:00
|
|
|
typedef struct _SERVICE_IMAGE
|
|
|
|
{
|
2011-07-17 15:45:03 +00:00
|
|
|
LIST_ENTRY ImageListEntry;
|
2016-05-28 21:56:56 +00:00
|
|
|
LPWSTR pszImagePath;
|
|
|
|
LPWSTR pszAccountName;
|
2011-07-17 15:45:03 +00:00
|
|
|
DWORD dwImageRunCount;
|
|
|
|
|
|
|
|
HANDLE hControlPipe;
|
|
|
|
HANDLE hProcess;
|
|
|
|
DWORD dwProcessId;
|
2016-05-28 21:56:56 +00:00
|
|
|
HANDLE hToken;
|
2017-01-02 20:45:36 +00:00
|
|
|
HANDLE hProfile;
|
2006-12-26 01:29:22 +00:00
|
|
|
} SERVICE_IMAGE, *PSERVICE_IMAGE;
|
|
|
|
|
|
|
|
|
2005-04-23 00:01:37 +00:00
|
|
|
typedef struct _SERVICE
|
|
|
|
{
|
2005-10-22 18:59:39 +00:00
|
|
|
LIST_ENTRY ServiceListEntry;
|
|
|
|
LPWSTR lpServiceName;
|
2005-10-30 13:13:53 +00:00
|
|
|
LPWSTR lpDisplayName;
|
2005-12-31 22:42:41 +00:00
|
|
|
PSERVICE_GROUP lpGroup;
|
2006-12-26 01:29:22 +00:00
|
|
|
PSERVICE_IMAGE lpImage;
|
2005-10-30 21:52:23 +00:00
|
|
|
BOOL bDeleted;
|
2005-12-18 19:50:53 +00:00
|
|
|
DWORD dwResumeCount;
|
2008-08-29 20:43:12 +00:00
|
|
|
DWORD dwRefCount;
|
2005-10-22 18:59:39 +00:00
|
|
|
|
|
|
|
SERVICE_STATUS Status;
|
|
|
|
DWORD dwStartType;
|
|
|
|
DWORD dwErrorControl;
|
|
|
|
DWORD dwTag;
|
|
|
|
|
2018-05-01 19:33:37 +00:00
|
|
|
DWORD dwServiceBits;
|
2024-01-21 21:42:26 +00:00
|
|
|
DWORD dwServiceTag;
|
2018-05-01 19:33:37 +00:00
|
|
|
|
2005-10-22 18:59:39 +00:00
|
|
|
ULONG Flags;
|
|
|
|
|
2016-06-09 21:30:48 +00:00
|
|
|
PSECURITY_DESCRIPTOR pSecurityDescriptor;
|
2005-12-23 15:56:51 +00:00
|
|
|
|
2005-10-22 18:59:39 +00:00
|
|
|
BOOLEAN ServiceVisited;
|
|
|
|
|
|
|
|
WCHAR szServiceName[1];
|
2005-04-23 00:01:37 +00:00
|
|
|
} SERVICE, *PSERVICE;
|
2002-06-07 20:11:03 +00:00
|
|
|
|
2005-04-15 22:02:37 +00:00
|
|
|
|
2012-07-07 15:35:40 +00:00
|
|
|
#define LOCK_TAG 0x4C697041 /* 'ApiL' */
|
|
|
|
|
|
|
|
typedef struct _START_LOCK
|
|
|
|
{
|
|
|
|
DWORD Tag; /* Must be LOCK_TAG */
|
|
|
|
DWORD TimeWhenLocked; /* Number of seconds since 1970 */
|
2016-11-05 14:55:55 +00:00
|
|
|
PSID LockOwnerSid; /* It is NULL if the SCM acquired the lock */
|
2012-07-07 15:35:40 +00:00
|
|
|
} START_LOCK, *PSTART_LOCK;
|
|
|
|
|
|
|
|
|
2005-10-30 13:13:53 +00:00
|
|
|
/* VARIABLES ***************************************************************/
|
|
|
|
|
2005-12-25 14:45:30 +00:00
|
|
|
extern LIST_ENTRY ServiceListHead;
|
2005-12-31 18:56:34 +00:00
|
|
|
extern LIST_ENTRY GroupListHead;
|
2011-07-17 15:45:03 +00:00
|
|
|
extern LIST_ENTRY ImageListHead;
|
2013-03-17 12:39:44 +00:00
|
|
|
extern BOOL ScmInitialize;
|
2005-10-30 13:13:53 +00:00
|
|
|
extern BOOL ScmShutdown;
|
2020-01-07 23:14:50 +00:00
|
|
|
extern BOOL ScmLiveSetup;
|
2022-02-21 10:12:48 +00:00
|
|
|
extern BOOL ScmSetupInProgress;
|
2019-08-04 20:30:40 +00:00
|
|
|
extern PSECURITY_DESCRIPTOR pPipeSD;
|
2005-10-30 13:13:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* FUNCTIONS ***************************************************************/
|
|
|
|
|
2005-10-23 19:50:05 +00:00
|
|
|
/* config.c */
|
2002-06-07 20:11:03 +00:00
|
|
|
|
2005-11-01 13:52:22 +00:00
|
|
|
DWORD ScmOpenServiceKey(LPWSTR lpServiceName,
|
|
|
|
REGSAM samDesired,
|
|
|
|
PHKEY phKey);
|
|
|
|
|
2009-01-06 07:53:04 +00:00
|
|
|
DWORD ScmCreateServiceKey(LPCWSTR lpServiceName,
|
2005-11-06 11:56:56 +00:00
|
|
|
REGSAM samDesired,
|
|
|
|
PHKEY phKey);
|
|
|
|
|
2005-10-23 19:50:05 +00:00
|
|
|
DWORD ScmWriteDependencies(HKEY hServiceKey,
|
2011-11-06 13:33:29 +00:00
|
|
|
LPCWSTR lpDependencies,
|
2005-10-23 19:50:05 +00:00
|
|
|
DWORD dwDependenciesLength);
|
2002-06-07 20:11:03 +00:00
|
|
|
|
2005-11-06 11:56:56 +00:00
|
|
|
DWORD ScmMarkServiceForDelete(PSERVICE pService);
|
|
|
|
BOOL ScmIsDeleteFlagSet(HKEY hServiceKey);
|
|
|
|
|
|
|
|
DWORD ScmReadString(HKEY hServiceKey,
|
2012-09-18 21:54:43 +00:00
|
|
|
LPCWSTR lpValueName,
|
2005-11-06 11:56:56 +00:00
|
|
|
LPWSTR *lpValue);
|
|
|
|
|
2009-12-25 15:08:03 +00:00
|
|
|
DWORD
|
|
|
|
ScmReadDependencies(HKEY hServiceKey,
|
|
|
|
LPWSTR *lpDependencies,
|
|
|
|
DWORD *lpdwDependenciesLength);
|
|
|
|
|
2016-05-23 15:02:37 +00:00
|
|
|
DWORD
|
|
|
|
ScmSetServicePassword(
|
|
|
|
IN PCWSTR pszServiceName,
|
|
|
|
IN PCWSTR pszPassword);
|
2002-06-07 20:11:03 +00:00
|
|
|
|
2016-06-09 21:30:48 +00:00
|
|
|
DWORD
|
|
|
|
ScmWriteSecurityDescriptor(
|
|
|
|
_In_ HKEY hServiceKey,
|
|
|
|
_In_ PSECURITY_DESCRIPTOR pSecurityDescriptor);
|
|
|
|
|
2016-06-11 09:41:05 +00:00
|
|
|
DWORD
|
|
|
|
ScmReadSecurityDescriptor(
|
|
|
|
_In_ HKEY hServiceKey,
|
|
|
|
_Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
|
|
|
|
|
2016-11-27 20:12:39 +00:00
|
|
|
DWORD
|
2016-11-27 20:39:10 +00:00
|
|
|
ScmDeleteRegKey(
|
|
|
|
_In_ HKEY hKey,
|
|
|
|
_In_ PCWSTR pszSubKey);
|
2016-06-09 21:30:48 +00:00
|
|
|
|
2018-09-17 14:34:48 +00:00
|
|
|
DWORD
|
|
|
|
ScmDecryptPassword(
|
2021-07-17 14:26:16 +00:00
|
|
|
_In_ PVOID ContextHandle,
|
2018-09-17 14:34:48 +00:00
|
|
|
_In_ PBYTE pPassword,
|
|
|
|
_In_ DWORD dwPasswordSize,
|
|
|
|
_Out_ PWSTR *pDecryptedPassword);
|
|
|
|
|
|
|
|
|
2012-07-07 18:17:59 +00:00
|
|
|
/* controlset.c */
|
|
|
|
|
2018-09-28 23:31:02 +00:00
|
|
|
DWORD
|
|
|
|
ScmCreateLastKnownGoodControlSet(VOID);
|
2012-07-07 18:17:59 +00:00
|
|
|
|
2019-08-10 12:24:11 +00:00
|
|
|
DWORD
|
|
|
|
ScmAcceptBoot(VOID);
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
ScmRunLastKnownGood(VOID);
|
|
|
|
|
2012-07-07 18:17:59 +00:00
|
|
|
|
2002-06-07 20:11:03 +00:00
|
|
|
/* database.c */
|
|
|
|
|
2005-11-06 11:56:56 +00:00
|
|
|
DWORD ScmCreateServiceDatabase(VOID);
|
2007-09-06 14:51:38 +00:00
|
|
|
VOID ScmShutdownServiceDatabase(VOID);
|
2002-06-07 20:11:03 +00:00
|
|
|
VOID ScmGetBootAndSystemDriverState(VOID);
|
|
|
|
VOID ScmAutoStartServices(VOID);
|
2007-09-06 14:51:38 +00:00
|
|
|
VOID ScmAutoShutdownServices(VOID);
|
2010-10-31 10:00:21 +00:00
|
|
|
DWORD ScmStartService(PSERVICE Service,
|
|
|
|
DWORD argc,
|
|
|
|
LPWSTR *argv);
|
2002-06-07 20:11:03 +00:00
|
|
|
|
2018-02-24 10:14:05 +00:00
|
|
|
VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage);
|
2009-01-06 07:53:04 +00:00
|
|
|
PSERVICE ScmGetServiceEntryByName(LPCWSTR lpServiceName);
|
|
|
|
PSERVICE ScmGetServiceEntryByDisplayName(LPCWSTR lpDisplayName);
|
2005-12-18 19:50:53 +00:00
|
|
|
PSERVICE ScmGetServiceEntryByResumeCount(DWORD dwResumeCount);
|
2009-01-06 07:53:04 +00:00
|
|
|
DWORD ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
|
2018-02-12 13:58:02 +00:00
|
|
|
PSERVICE *lpServiceRecord,
|
|
|
|
DWORD dwServiceType,
|
|
|
|
DWORD dwStartType);
|
2008-08-29 20:43:12 +00:00
|
|
|
VOID ScmDeleteServiceRecord(PSERVICE lpService);
|
2005-10-09 20:24:00 +00:00
|
|
|
DWORD ScmMarkServiceForDelete(PSERVICE pService);
|
2005-04-23 00:01:37 +00:00
|
|
|
|
2018-02-24 10:14:05 +00:00
|
|
|
DWORD ScmControlService(HANDLE hControlPipe,
|
|
|
|
PWSTR pServiceName,
|
|
|
|
SERVICE_STATUS_HANDLE hServiceStatus,
|
2010-10-31 10:00:21 +00:00
|
|
|
DWORD dwControl);
|
|
|
|
|
2010-02-27 21:47:59 +00:00
|
|
|
BOOL ScmLockDatabaseExclusive(VOID);
|
|
|
|
BOOL ScmLockDatabaseShared(VOID);
|
|
|
|
VOID ScmUnlockDatabase(VOID);
|
|
|
|
|
2011-02-27 19:25:14 +00:00
|
|
|
VOID ScmInitNamedPipeCriticalSection(VOID);
|
|
|
|
VOID ScmDeleteNamedPipeCriticalSection(VOID);
|
|
|
|
|
2018-12-30 11:25:18 +00:00
|
|
|
DWORD ScmGetServiceNameFromTag(PTAG_INFO_NAME_FROM_TAG_IN_PARAMS InParams,
|
|
|
|
PTAG_INFO_NAME_FROM_TAG_OUT_PARAMS *OutParams);
|
2010-02-27 21:47:59 +00:00
|
|
|
|
2018-12-30 13:09:54 +00:00
|
|
|
DWORD ScmGenerateServiceTag(PSERVICE lpServiceRecord);
|
|
|
|
|
2005-11-20 20:18:00 +00:00
|
|
|
/* driver.c */
|
|
|
|
|
2018-02-12 13:58:02 +00:00
|
|
|
DWORD ScmStartDriver(PSERVICE lpService);
|
2005-11-20 20:18:00 +00:00
|
|
|
DWORD ScmControlDriver(PSERVICE lpService,
|
|
|
|
DWORD dwControl,
|
|
|
|
LPSERVICE_STATUS lpServiceStatus);
|
|
|
|
|
|
|
|
|
2005-12-31 18:56:34 +00:00
|
|
|
/* groupdb.c */
|
|
|
|
|
2016-12-03 12:48:44 +00:00
|
|
|
PSERVICE_GROUP
|
|
|
|
ScmGetServiceGroupByName(
|
|
|
|
_In_ LPCWSTR lpGroupName);
|
|
|
|
|
2005-12-31 18:56:34 +00:00
|
|
|
DWORD ScmCreateGroupList(VOID);
|
2005-12-31 22:42:41 +00:00
|
|
|
DWORD ScmSetServiceGroup(PSERVICE lpService,
|
2009-01-06 07:53:04 +00:00
|
|
|
LPCWSTR lpGroupName);
|
2005-12-31 18:56:34 +00:00
|
|
|
|
|
|
|
|
2012-07-07 15:35:40 +00:00
|
|
|
/* lock.c */
|
2014-09-28 14:10:16 +00:00
|
|
|
|
2012-07-07 15:35:40 +00:00
|
|
|
DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController,
|
|
|
|
OUT LPSC_RPC_LOCK lpLock);
|
|
|
|
DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock);
|
|
|
|
VOID ScmQueryServiceLockStatusW(OUT LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus);
|
|
|
|
VOID ScmQueryServiceLockStatusA(OUT LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus);
|
|
|
|
|
|
|
|
|
2005-04-15 22:02:37 +00:00
|
|
|
/* rpcserver.c */
|
|
|
|
|
|
|
|
VOID ScmStartRpcServer(VOID);
|
|
|
|
|
|
|
|
|
2016-06-09 21:30:48 +00:00
|
|
|
/* security.c */
|
|
|
|
|
|
|
|
DWORD ScmInitializeSecurity(VOID);
|
|
|
|
VOID ScmShutdownSecurity(VOID);
|
|
|
|
|
2016-06-26 20:09:37 +00:00
|
|
|
DWORD
|
|
|
|
ScmCreateDefaultServiceSD(
|
|
|
|
PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
|
|
|
|
|
2016-06-09 21:30:48 +00:00
|
|
|
|
2005-10-23 19:50:05 +00:00
|
|
|
/* services.c */
|
|
|
|
|
|
|
|
VOID PrintString(LPCSTR fmt, ...);
|
2019-08-31 15:24:47 +00:00
|
|
|
DWORD SetSecurityServicesEvent(VOID);
|
2014-09-28 14:10:16 +00:00
|
|
|
VOID ScmLogEvent(DWORD dwEventId,
|
|
|
|
WORD wType,
|
2011-05-26 10:50:26 +00:00
|
|
|
WORD wStrings,
|
|
|
|
LPCWSTR *lpStrings);
|
2012-06-11 19:02:00 +00:00
|
|
|
VOID ScmWaitForLsa(VOID);
|
2005-10-23 19:50:05 +00:00
|
|
|
|
2014-02-05 16:35:49 +00:00
|
|
|
#endif /* _SERVICES_H */
|