ReactOS  0.4.13-dev-52-g0efcfec
services.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <winsvc.h>
#include <winreg.h>
#include <winuser.h>
#include <netevent.h>
#include <ndk/obfuncs.h>
#include <ndk/rtlfuncs.h>
#include <services/services.h>
#include <svcctl_s.h>
#include "resource.h"
Include dependency graph for services.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _SERVICE_GROUP
 
struct  _SERVICE_IMAGE
 
struct  _SERVICE
 
struct  _START_LOCK
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define COM_NO_WINDOWS_H
 
#define NTOS_MODE_USER
 
#define LOCK_TAG   0x4C697041 /* 'ApiL' */
 

Typedefs

typedef struct _SERVICE_GROUP SERVICE_GROUP
 
typedef struct _SERVICE_GROUPPSERVICE_GROUP
 
typedef struct _SERVICE_IMAGE SERVICE_IMAGE
 
typedef struct _SERVICE_IMAGEPSERVICE_IMAGE
 
typedef struct _SERVICE SERVICE
 
typedef struct _SERVICEPSERVICE
 
typedef struct _START_LOCK START_LOCK
 
typedef struct _START_LOCKPSTART_LOCK
 

Functions

DWORD ScmOpenServiceKey (LPWSTR lpServiceName, REGSAM samDesired, PHKEY phKey)
 
DWORD ScmCreateServiceKey (LPCWSTR lpServiceName, REGSAM samDesired, PHKEY phKey)
 
DWORD ScmWriteDependencies (HKEY hServiceKey, LPCWSTR lpDependencies, DWORD dwDependenciesLength)
 
DWORD ScmMarkServiceForDelete (PSERVICE pService)
 
BOOL ScmIsDeleteFlagSet (HKEY hServiceKey)
 
DWORD ScmReadString (HKEY hServiceKey, LPCWSTR lpValueName, LPWSTR *lpValue)
 
DWORD ScmReadDependencies (HKEY hServiceKey, LPWSTR *lpDependencies, DWORD *lpdwDependenciesLength)
 
DWORD ScmSetServicePassword (IN PCWSTR pszServiceName, IN PCWSTR pszPassword)
 
DWORD ScmWriteSecurityDescriptor (_In_ HKEY hServiceKey, _In_ PSECURITY_DESCRIPTOR pSecurityDescriptor)
 
DWORD ScmReadSecurityDescriptor (_In_ HKEY hServiceKey, _Out_ PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
 
DWORD ScmDeleteRegKey (_In_ HKEY hKey, _In_ PCWSTR pszSubKey)
 
DWORD ScmDecryptPassword (_In_ PBYTE pPassword, _In_ DWORD dwPasswordSize, _Out_ PWSTR *pDecryptedPassword)
 
DWORD ScmCreateLastKnownGoodControlSet (VOID)
 
DWORD ScmCreateServiceDatabase (VOID)
 
VOID ScmShutdownServiceDatabase (VOID)
 
VOID ScmGetBootAndSystemDriverState (VOID)
 
VOID ScmAutoStartServices (VOID)
 
VOID ScmAutoShutdownServices (VOID)
 
DWORD ScmStartService (PSERVICE Service, DWORD argc, LPWSTR *argv)
 
VOID ScmRemoveServiceImage (PSERVICE_IMAGE pServiceImage)
 
PSERVICE ScmGetServiceEntryByName (LPCWSTR lpServiceName)
 
PSERVICE ScmGetServiceEntryByDisplayName (LPCWSTR lpDisplayName)
 
PSERVICE ScmGetServiceEntryByResumeCount (DWORD dwResumeCount)
 
DWORD ScmCreateNewServiceRecord (LPCWSTR lpServiceName, PSERVICE *lpServiceRecord, DWORD dwServiceType, DWORD dwStartType)
 
VOID ScmDeleteServiceRecord (PSERVICE lpService)
 
DWORD ScmControlService (HANDLE hControlPipe, PWSTR pServiceName, SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwControl)
 
BOOL ScmLockDatabaseExclusive (VOID)
 
BOOL ScmLockDatabaseShared (VOID)
 
VOID ScmUnlockDatabase (VOID)
 
VOID ScmInitNamedPipeCriticalSection (VOID)
 
VOID ScmDeleteNamedPipeCriticalSection (VOID)
 
DWORD ScmGetServiceNameFromTag (PTAG_INFO_NAME_FROM_TAG_IN_PARAMS InParams, PTAG_INFO_NAME_FROM_TAG_OUT_PARAMS *OutParams)
 
DWORD ScmGenerateServiceTag (PSERVICE lpServiceRecord)
 
DWORD ScmStartDriver (PSERVICE lpService)
 
DWORD ScmControlDriver (PSERVICE lpService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
 
PSERVICE_GROUP ScmGetServiceGroupByName (_In_ LPCWSTR lpGroupName)
 
DWORD ScmCreateGroupList (VOID)
 
DWORD ScmSetServiceGroup (PSERVICE lpService, LPCWSTR lpGroupName)
 
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)
 
VOID ScmStartRpcServer (VOID)
 
DWORD ScmInitializeSecurity (VOID)
 
VOID ScmShutdownSecurity (VOID)
 
DWORD ScmCreateDefaultServiceSD (PSECURITY_DESCRIPTOR *ppSecurityDescriptor)
 
VOID PrintString (LPCSTR fmt,...)
 
VOID ScmLogEvent (DWORD dwEventId, WORD wType, WORD wStrings, LPCWSTR *lpStrings)
 
VOID ScmWaitForLsa (VOID)
 

Variables

LIST_ENTRY ServiceListHead
 
LIST_ENTRY GroupListHead
 
LIST_ENTRY ImageListHead
 
BOOL ScmInitialize
 
BOOL ScmShutdown
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 12 of file services.h.

◆ COM_NO_WINDOWS_H

#define COM_NO_WINDOWS_H

Definition at line 13 of file services.h.

◆ LOCK_TAG

#define LOCK_TAG   0x4C697041 /* 'ApiL' */

Definition at line 86 of file services.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 21 of file services.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 11 of file services.h.

Typedef Documentation

◆ PSERVICE

◆ PSERVICE_GROUP

◆ PSERVICE_IMAGE

◆ PSTART_LOCK

◆ SERVICE

◆ SERVICE_GROUP

◆ SERVICE_IMAGE

◆ START_LOCK

Function Documentation

◆ PrintString()

VOID PrintString ( LPCSTR  fmt,
  ... 
)

Definition at line 36 of file services.c.

37 {
38 #if DBG
39  CHAR buffer[512];
40  va_list ap;
41 
42  va_start(ap, fmt);
43  vsprintf(buffer, fmt, ap);
44  va_end(ap);
45 
47 #endif
48 }
char CHAR
Definition: xmlstorage.h:175
GLuint buffer
Definition: glext.h:5915
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
Definition: dsound.c:943
void WINAPI SHIM_OBJ_NAME() OutputDebugStringA(LPCSTR lpOutputString)
Definition: ignoredbgout.c:18

◆ ScmAcquireServiceStartLock()

DWORD ScmAcquireServiceStartLock ( IN BOOL  IsServiceController,
OUT LPSC_RPC_LOCK  lpLock 
)

Definition at line 31 of file lock.c.

33 {
34  DWORD dwRequiredSize;
35  DWORD dwError = ERROR_SUCCESS;
36 
37  *lpLock = NULL;
38 
39  /* Lock the service database exclusively */
41 
42  if (pServiceStartLock != NULL)
43  {
45  goto done;
46  }
47 
48  /* Allocate a new lock for the database */
49  dwRequiredSize = sizeof(START_LOCK);
50 
51  if (!IsServiceController)
52  {
53  /* FIXME: dwRequiredSize += RtlLengthSid(UserSid <-- to be retrieved); */
54  }
55 
58  dwRequiredSize);
59  if (pServiceStartLock == NULL)
60  {
61  dwError = ERROR_NOT_ENOUGH_MEMORY;
62  goto done;
63  }
64 
67 
68  /* FIXME: Retrieve the owner SID. Use IsServiceController. */
70 
72 
73 done:
74  /* Unlock the service database */
76 
77  return dwError;
78 }
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL ScmLockDatabaseExclusive(VOID)
Definition: database.c:2310
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
SC_RPC_LOCK * LPSC_RPC_LOCK
Definition: svcctl.idl:24
__u16 time
Definition: mkdosfs.c:366
#define DWORD
Definition: nt_native.h:44
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
smooth NULL
Definition: ftsmooth.c:416
struct _START_LOCK START_LOCK
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_SERVICE_DATABASE_LOCKED
Definition: winerror.h:606
struct _SID * PSID
Definition: eventlog.c:35
PSID LockOwnerSid
Definition: services.h:92
DWORD TimeWhenLocked
Definition: services.h:91
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2324
#define LOCK_TAG
Definition: services.h:86
DWORD Tag
Definition: services.h:90

Referenced by RLockServiceDatabase(), ScmStartService(), and wWinMain().

◆ ScmAutoShutdownServices()

VOID ScmAutoShutdownServices ( VOID  )

Definition at line 2272 of file database.c.

2273 {
2274  PLIST_ENTRY ServiceEntry;
2275  PSERVICE CurrentService;
2276 
2277  DPRINT("ScmAutoShutdownServices() called\n");
2278 
2279  /* Lock the service database exclusively */
2281 
2282  ServiceEntry = ServiceListHead.Flink;
2283  while (ServiceEntry != &ServiceListHead)
2284  {
2285  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2286 
2287  if ((CurrentService->Status.dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN) &&
2288  (CurrentService->Status.dwCurrentState == SERVICE_RUNNING ||
2289  CurrentService->Status.dwCurrentState == SERVICE_START_PENDING))
2290  {
2291  /* Send the shutdown notification */
2292  DPRINT("Shutdown service: %S\n", CurrentService->lpServiceName);
2293  ScmControlService(CurrentService->lpImage->hControlPipe,
2294  CurrentService->lpServiceName,
2295  (SERVICE_STATUS_HANDLE)CurrentService,
2297  }
2298 
2299  ServiceEntry = ServiceEntry->Flink;
2300  }
2301 
2302  /* Unlock the service database */
2304 
2305  DPRINT("ScmAutoShutdownServices() done\n");
2306 }
SERVICE_STATUS Status
Definition: services.h:69
DWORD dwCurrentState
Definition: winsvc.h:100
BOOL ScmLockDatabaseExclusive(VOID)
Definition: database.c:2310
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
LIST_ENTRY ServiceListHead
Definition: database.c:29
LPWSTR lpServiceName
Definition: services.h:61
Definition: typedefs.h:117
DWORD dwControlsAccepted
Definition: winsvc.h:101
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2324
PSERVICE_IMAGE lpImage
Definition: services.h:64
DWORD ScmControlService(HANDLE hControlPipe, PWSTR pServiceName, SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwControl)
Definition: database.c:1213
HANDLE hControlPipe
Definition: services.h:50
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

Referenced by ShutdownHandlerRoutine().

◆ ScmAutoStartServices()

VOID ScmAutoStartServices ( VOID  )

Definition at line 2061 of file database.c.

2062 {
2063  DWORD dwError;
2064  PLIST_ENTRY GroupEntry;
2065  PLIST_ENTRY ServiceEntry;
2066  PSERVICE_GROUP CurrentGroup;
2067  PSERVICE CurrentService;
2068  WCHAR szSafeBootServicePath[MAX_PATH];
2069  DWORD SafeBootEnabled;
2070  HKEY hKey;
2071  DWORD dwKeySize;
2072  ULONG i;
2073 
2074  /*
2075  * This function MUST be called ONLY at initialization time.
2076  * Therefore, no need to acquire the user service start lock.
2077  */
2079 
2080  /* Retrieve the SafeBoot parameter */
2082  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
2083  0,
2084  KEY_READ,
2085  &hKey);
2086  if (dwError == ERROR_SUCCESS)
2087  {
2088  dwKeySize = sizeof(SafeBootEnabled);
2089  dwError = RegQueryValueExW(hKey,
2090  L"OptionValue",
2091  0,
2092  NULL,
2093  (LPBYTE)&SafeBootEnabled,
2094  &dwKeySize);
2095  RegCloseKey(hKey);
2096  }
2097 
2098  /* Default to Normal boot if the value doesn't exist */
2099  if (dwError != ERROR_SUCCESS)
2100  SafeBootEnabled = 0;
2101 
2102  /* Acquire the service control critical section, to synchronize starts */
2104 
2105  /* Clear 'ServiceVisited' flag (or set if not to start in Safe Mode) */
2106  ServiceEntry = ServiceListHead.Flink;
2107  while (ServiceEntry != &ServiceListHead)
2108  {
2109  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2110 
2111  /* Build the safe boot path */
2112  StringCchCopyW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2113  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot");
2114 
2115  switch (SafeBootEnabled)
2116  {
2117  /* NOTE: Assumes MINIMAL (1) and DSREPAIR (3) load same items */
2118  case 1:
2119  case 3:
2120  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2121  L"\\Minimal\\");
2122  break;
2123 
2124  case 2:
2125  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2126  L"\\Network\\");
2127  break;
2128  }
2129 
2130  if (SafeBootEnabled != 0)
2131  {
2132  /* If key does not exist then do not assume safe mode */
2134  szSafeBootServicePath,
2135  0,
2136  KEY_READ,
2137  &hKey);
2138  if (dwError == ERROR_SUCCESS)
2139  {
2140  RegCloseKey(hKey);
2141 
2142  /* Finish Safe Boot path off */
2143  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2144  CurrentService->lpServiceName);
2145 
2146  /* Check that the key is in the Safe Boot path */
2148  szSafeBootServicePath,
2149  0,
2150  KEY_READ,
2151  &hKey);
2152  if (dwError != ERROR_SUCCESS)
2153  {
2154  /* Mark service as visited so it is not auto-started */
2155  CurrentService->ServiceVisited = TRUE;
2156  }
2157  else
2158  {
2159  /* Must be auto-started in safe mode - mark as unvisited */
2160  RegCloseKey(hKey);
2161  CurrentService->ServiceVisited = FALSE;
2162  }
2163  }
2164  else
2165  {
2166  DPRINT1("WARNING: Could not open the associated Safe Boot key!");
2167  CurrentService->ServiceVisited = FALSE;
2168  }
2169  }
2170 
2171  ServiceEntry = ServiceEntry->Flink;
2172  }
2173 
2174  /* Start all services which are members of an existing group */
2175  GroupEntry = GroupListHead.Flink;
2176  while (GroupEntry != &GroupListHead)
2177  {
2178  CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
2179 
2180  DPRINT("Group '%S'\n", CurrentGroup->lpGroupName);
2181 
2182  /* Start all services witch have a valid tag */
2183  for (i = 0; i < CurrentGroup->TagCount; i++)
2184  {
2185  ServiceEntry = ServiceListHead.Flink;
2186  while (ServiceEntry != &ServiceListHead)
2187  {
2188  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2189 
2190  if ((CurrentService->lpGroup == CurrentGroup) &&
2191  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2192  (CurrentService->ServiceVisited == FALSE) &&
2193  (CurrentService->dwTag == CurrentGroup->TagArray[i]))
2194  {
2195  CurrentService->ServiceVisited = TRUE;
2196  ScmLoadService(CurrentService, 0, NULL);
2197  }
2198 
2199  ServiceEntry = ServiceEntry->Flink;
2200  }
2201  }
2202 
2203  /* Start all services which have an invalid tag or which do not have a tag */
2204  ServiceEntry = ServiceListHead.Flink;
2205  while (ServiceEntry != &ServiceListHead)
2206  {
2207  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2208 
2209  if ((CurrentService->lpGroup == CurrentGroup) &&
2210  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2211  (CurrentService->ServiceVisited == FALSE))
2212  {
2213  CurrentService->ServiceVisited = TRUE;
2214  ScmLoadService(CurrentService, 0, NULL);
2215  }
2216 
2217  ServiceEntry = ServiceEntry->Flink;
2218  }
2219 
2220  GroupEntry = GroupEntry->Flink;
2221  }
2222 
2223  /* Start all services which are members of any non-existing group */
2224  ServiceEntry = ServiceListHead.Flink;
2225  while (ServiceEntry != &ServiceListHead)
2226  {
2227  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2228 
2229  if ((CurrentService->lpGroup != NULL) &&
2230  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2231  (CurrentService->ServiceVisited == FALSE))
2232  {
2233  CurrentService->ServiceVisited = TRUE;
2234  ScmLoadService(CurrentService, 0, NULL);
2235  }
2236 
2237  ServiceEntry = ServiceEntry->Flink;
2238  }
2239 
2240  /* Start all services which are not a member of any group */
2241  ServiceEntry = ServiceListHead.Flink;
2242  while (ServiceEntry != &ServiceListHead)
2243  {
2244  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2245 
2246  if ((CurrentService->lpGroup == NULL) &&
2247  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2248  (CurrentService->ServiceVisited == FALSE))
2249  {
2250  CurrentService->ServiceVisited = TRUE;
2251  ScmLoadService(CurrentService, 0, NULL);
2252  }
2253 
2254  ServiceEntry = ServiceEntry->Flink;
2255  }
2256 
2257  /* Clear 'ServiceVisited' flag again */
2258  ServiceEntry = ServiceListHead.Flink;
2259  while (ServiceEntry != &ServiceListHead)
2260  {
2261  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2262  CurrentService->ServiceVisited = FALSE;
2263  ServiceEntry = ServiceEntry->Flink;
2264  }
2265 
2266  /* Release the critical section */
2268 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
#define KEY_READ
Definition: nt_native.h:1023
BOOL ScmInitialize
Definition: services.c:28
LPWSTR lpGroupName
Definition: services.h:32
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
PSERVICE_GROUP lpGroup
Definition: services.h:63
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
static DWORD ScmLoadService(PSERVICE Service, DWORD argc, LPWSTR *argv)
Definition: database.c:1909
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LIST_ENTRY ServiceListHead
Definition: database.c:29
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOLEAN ServiceVisited
Definition: services.h:80
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpServiceName
Definition: services.h:61
Definition: typedefs.h:117
PULONG TagArray
Definition: services.h:37
DWORD dwStartType
Definition: services.h:70
ULONG TagCount
Definition: services.h:36
#define DPRINT1
Definition: precomp.h:8
DWORD dwTag
Definition: services.h:72
#define SERVICE_AUTO_START
Definition: cmtypes.h:975
unsigned int ULONG
Definition: retypes.h:1
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by wWinMain().

◆ ScmControlDriver()

DWORD ScmControlDriver ( PSERVICE  lpService,
DWORD  dwControl,
LPSERVICE_STATUS  lpServiceStatus 
)

Definition at line 335 of file driver.c.

338 {
339  DWORD dwError;
340 
341  DPRINT("ScmControlDriver() called\n");
342 
343  switch (dwControl)
344  {
346  /* Check the drivers status */
347  dwError = ScmGetDriverStatus(lpService,
348  lpServiceStatus);
349  if (dwError != ERROR_SUCCESS)
350  goto done;
351 
352  /* Fail, if it is not running */
353  if (lpService->Status.dwCurrentState != SERVICE_RUNNING)
354  {
356  goto done;
357  }
358 
359  /* Unload the driver */
360  dwError = ScmUnloadDriver(lpService);
361  if (dwError == ERROR_INVALID_SERVICE_CONTROL)
362  {
363  /* The driver cannot be stopped, mark it non-stoppable */
364  lpService->Status.dwControlsAccepted = 0;
365  goto done;
366  }
367 
368  /* Make the driver 'stop pending' */
370 
371  /* Check the drivers status again */
372  dwError = ScmGetDriverStatus(lpService,
373  lpServiceStatus);
374  break;
375 
377  dwError = ScmGetDriverStatus(lpService,
378  lpServiceStatus);
379  break;
380 
381  default:
383  }
384 
385 done:
386  DPRINT("ScmControlDriver() done (Erorr: %lu)\n", dwError);
387 
388  return dwError;
389 }
SERVICE_STATUS Status
Definition: services.h:69
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
static DWORD ScmUnloadDriver(PSERVICE lpService)
Definition: driver.c:77
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define ERROR_INVALID_SERVICE_CONTROL
Definition: winerror.h:603
void DPRINT(...)
Definition: polytest.cpp:61
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD ScmGetDriverStatus(PSERVICE lpService, LPSERVICE_STATUS lpServiceStatus)
Definition: driver.c:136
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23

Referenced by RControlService().

◆ ScmControlService()

DWORD ScmControlService ( HANDLE  hControlPipe,
PWSTR  pServiceName,
SERVICE_STATUS_HANDLE  hServiceStatus,
DWORD  dwControl 
)

Definition at line 1213 of file database.c.

1217 {
1218  PSCM_CONTROL_PACKET ControlPacket;
1219  SCM_REPLY_PACKET ReplyPacket;
1220 
1221  DWORD dwWriteCount = 0;
1222  DWORD dwReadCount = 0;
1223  DWORD PacketSize;
1224  PWSTR Ptr;
1225  DWORD dwError = ERROR_SUCCESS;
1226  BOOL bResult;
1227  OVERLAPPED Overlapped = {0};
1228 
1229  DPRINT("ScmControlService() called\n");
1230 
1231  /* Acquire the service control critical section, to synchronize requests */
1233 
1234  /* Calculate the total length of the start command line */
1235  PacketSize = sizeof(SCM_CONTROL_PACKET);
1236  PacketSize += (DWORD)((wcslen(pServiceName) + 1) * sizeof(WCHAR));
1237 
1238  ControlPacket = HeapAlloc(GetProcessHeap(),
1240  PacketSize);
1241  if (ControlPacket == NULL)
1242  {
1244  return ERROR_NOT_ENOUGH_MEMORY;
1245  }
1246 
1247  ControlPacket->dwSize = PacketSize;
1248  ControlPacket->dwControl = dwControl;
1249  ControlPacket->hServiceStatus = hServiceStatus;
1250 
1251  ControlPacket->dwServiceNameOffset = sizeof(SCM_CONTROL_PACKET);
1252 
1253  Ptr = (PWSTR)((PBYTE)ControlPacket + ControlPacket->dwServiceNameOffset);
1254  wcscpy(Ptr, pServiceName);
1255 
1256  ControlPacket->dwArgumentsCount = 0;
1257  ControlPacket->dwArgumentsOffset = 0;
1258 
1259  bResult = WriteFile(hControlPipe,
1260  ControlPacket,
1261  PacketSize,
1262  &dwWriteCount,
1263  &Overlapped);
1264  if (bResult == FALSE)
1265  {
1266  DPRINT("WriteFile() returned FALSE\n");
1267 
1268  dwError = GetLastError();
1269  if (dwError == ERROR_IO_PENDING)
1270  {
1271  DPRINT("dwError: ERROR_IO_PENDING\n");
1272 
1273  dwError = WaitForSingleObject(hControlPipe,
1274  PipeTimeout);
1275  DPRINT("WaitForSingleObject() returned %lu\n", dwError);
1276 
1277  if (dwError == WAIT_TIMEOUT)
1278  {
1279  bResult = CancelIo(hControlPipe);
1280  if (bResult == FALSE)
1281  {
1282  DPRINT1("CancelIo() failed (Error: %lu)\n", GetLastError());
1283  }
1284 
1286  goto Done;
1287  }
1288  else if (dwError == WAIT_OBJECT_0)
1289  {
1290  bResult = GetOverlappedResult(hControlPipe,
1291  &Overlapped,
1292  &dwWriteCount,
1293  TRUE);
1294  if (bResult == FALSE)
1295  {
1296  dwError = GetLastError();
1297  DPRINT1("GetOverlappedResult() failed (Error %lu)\n", dwError);
1298 
1299  goto Done;
1300  }
1301  }
1302  }
1303  else
1304  {
1305  DPRINT1("WriteFile() failed (Error %lu)\n", dwError);
1306  goto Done;
1307  }
1308  }
1309 
1310  /* Read the reply */
1311  Overlapped.hEvent = (HANDLE) NULL;
1312 
1313  bResult = ReadFile(hControlPipe,
1314  &ReplyPacket,
1315  sizeof(SCM_REPLY_PACKET),
1316  &dwReadCount,
1317  &Overlapped);
1318  if (bResult == FALSE)
1319  {
1320  DPRINT("ReadFile() returned FALSE\n");
1321 
1322  dwError = GetLastError();
1323  if (dwError == ERROR_IO_PENDING)
1324  {
1325  DPRINT("dwError: ERROR_IO_PENDING\n");
1326 
1327  dwError = WaitForSingleObject(hControlPipe,
1328  PipeTimeout);
1329  DPRINT("WaitForSingleObject() returned %lu\n", dwError);
1330 
1331  if (dwError == WAIT_TIMEOUT)
1332  {
1333  bResult = CancelIo(hControlPipe);
1334  if (bResult == FALSE)
1335  {
1336  DPRINT1("CancelIo() failed (Error: %lu)\n", GetLastError());
1337  }
1338 
1340  goto Done;
1341  }
1342  else if (dwError == WAIT_OBJECT_0)
1343  {
1344  bResult = GetOverlappedResult(hControlPipe,
1345  &Overlapped,
1346  &dwReadCount,
1347  TRUE);
1348  if (bResult == FALSE)
1349  {
1350  dwError = GetLastError();
1351  DPRINT1("GetOverlappedResult() failed (Error %lu)\n", dwError);
1352 
1353  goto Done;
1354  }
1355  }
1356  }
1357  else
1358  {
1359  DPRINT1("ReadFile() failed (Error %lu)\n", dwError);
1360  goto Done;
1361  }
1362  }
1363 
1364 Done:
1365  /* Release the control packet */
1367  0,
1368  ControlPacket);
1369 
1370  if (dwReadCount == sizeof(SCM_REPLY_PACKET))
1371  {
1372  dwError = ReplyPacket.dwError;
1373  }
1374 
1376 
1377  DPRINT("ScmControlService() done\n");
1378 
1379  return dwError;
1380 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD dwServiceNameOffset
Definition: services.h:35
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
SERVICE_STATUS_HANDLE hServiceStatus
Definition: services.h:34
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:204
uint16_t * PWSTR
Definition: typedefs.h:54
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
#define ERROR_SERVICE_REQUEST_TIMEOUT
Definition: winerror.h:604
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define DWORD
Definition: nt_native.h:44
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
unsigned int BOOL
Definition: ntddk_ex.h:94
HANDLE hEvent
Definition: winbase.h:792
BOOL WINAPI CancelIo(IN HANDLE hFile)
Definition: deviceio.c:290
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
DWORD dwArgumentsCount
Definition: services.h:32
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define WAIT_TIMEOUT
Definition: dderror.h:14
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
SERVICE_STATUS_HANDLE hServiceStatus
Definition: main.c:10
static DWORD PipeTimeout
Definition: database.c:38
DWORD dwArgumentsOffset
Definition: services.h:36
_In_ USHORT PacketSize
Definition: iofuncs.h:1056
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
struct _SCM_CONTROL_PACKET SCM_CONTROL_PACKET
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
BYTE * PBYTE
Definition: pedump.c:66
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RControlService(), RSetServiceStatus(), and ScmAutoShutdownServices().

◆ ScmCreateDefaultServiceSD()

DWORD ScmCreateDefaultServiceSD ( PSECURITY_DESCRIPTOR ppSecurityDescriptor)

Definition at line 235 of file security.c.

237 {
238  PSECURITY_DESCRIPTOR pRelativeSD = NULL;
239  DWORD dwBufferLength = 0;
241  DWORD dwError = ERROR_SUCCESS;
242 
243  /* Convert the absolute SD to a self-relative SD */
245  NULL,
246  &dwBufferLength);
248  {
249  dwError = RtlNtStatusToDosError(Status);
250  goto done;
251  }
252 
253  DPRINT("BufferLength %lu\n", dwBufferLength);
254 
255  pRelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
257  dwBufferLength);
258  if (pRelativeSD == NULL)
259  {
260  dwError = ERROR_OUTOFMEMORY;
261  goto done;
262  }
263  DPRINT("pRelativeSD %p\n", pRelativeSD);
264 
266  pRelativeSD,
267  &dwBufferLength);
268  if (!NT_SUCCESS(Status))
269  {
270  dwError = RtlNtStatusToDosError(Status);
271  goto done;
272  }
273 
274  *ppSecurityDescriptor = pRelativeSD;
275 
276 done:
277  if (dwError != ERROR_SUCCESS)
278  {
279  if (pRelativeSD != NULL)
280  RtlFreeHeap(RtlGetProcessHeap(), 0, pRelativeSD);
281  }
282 
283  return dwError;
284 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
NTSYSAPI NTSTATUS NTAPI RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, IN PULONG BufferLength)
Definition: sd.c:626
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:24
static PSECURITY_DESCRIPTOR pDefaultSD
Definition: security.c:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmCreateGroupList()

DWORD ScmCreateGroupList ( VOID  )

Definition at line 235 of file groupdb.c.

236 {
239 
242 
243  /* Build group order list */
245  sizeof(QueryTable));
246 
247  QueryTable[0].Name = L"List";
249 
251  L"ServiceGroupOrder",
252  QueryTable,
253  NULL,
254  NULL);
255 
257 }
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:3988
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
LONG NTSTATUS
Definition: precomp.h:26
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
smooth NULL
Definition: ftsmooth.c:416
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
static NTSTATUS WINAPI CreateGroupListRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: groupdb.c:188
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by ScmCreateServiceDatabase().

◆ ScmCreateLastKnownGoodControlSet()

DWORD ScmCreateLastKnownGoodControlSet ( VOID  )

Definition at line 465 of file controlset.c.

466 {
467  DWORD dwCurrentControlSet, dwDefaultControlSet;
468  DWORD dwFailedControlSet, dwLastKnownGoodControlSet;
469  DWORD dwNewControlSet;
470  DWORD dwError;
471 
472  /* Get the control set values */
473  dwError = ScmGetControlSetValues(&dwCurrentControlSet,
474  &dwDefaultControlSet,
475  &dwFailedControlSet,
476  &dwLastKnownGoodControlSet);
477  if (dwError != ERROR_SUCCESS)
478  return dwError;
479 
480  /* First boot after setup? */
481  if ((ScmGetSetupInProgress() == 0) &&
482  (dwCurrentControlSet == dwLastKnownGoodControlSet))
483  {
484  DPRINT("First boot after setup!\n");
485 
486  /* Search for a new control set number */
487  for (dwNewControlSet = 1; dwNewControlSet < 1000; dwNewControlSet++)
488  {
489  if ((dwNewControlSet != dwCurrentControlSet) &&
490  (dwNewControlSet != dwDefaultControlSet) &&
491  (dwNewControlSet != dwFailedControlSet) &&
492  (dwNewControlSet != dwLastKnownGoodControlSet))
493  break;
494  }
495 
496  /* Fail if we did not find an unused control set!*/
497  if (dwNewControlSet >= 1000)
498  {
499  DPRINT1("Too many control sets!\n");
500  return ERROR_NO_MORE_ITEMS;
501  }
502 
503  /* Copy the current control set */
504  dwError = ScmCopyControlSet(dwCurrentControlSet,
505  dwNewControlSet);
506  if (dwError != ERROR_SUCCESS)
507  return dwError;
508 
509  /* Set the new 'LastKnownGood' control set */
510  dwError = ScmSetLastKnownGoodControlSet(dwNewControlSet);
511  }
512 
513  return dwError;
514 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static DWORD ScmGetSetupInProgress(VOID)
Definition: controlset.c:362
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
static DWORD ScmCopyControlSet(DWORD dwSourceControlSet, DWORD dwDestinationControlSet)
Definition: controlset.c:398
static DWORD ScmSetLastKnownGoodControlSet(DWORD dwControlSet)
Definition: controlset.c:332
void DPRINT(...)
Definition: polytest.cpp:61
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DPRINT1
Definition: precomp.h:8
static DWORD ScmGetControlSetValues(PDWORD pdwCurrentControlSet, PDWORD pdwDefaultControlSet, PDWORD pdwFailedControlSet, PDWORD pdwLastKnownGoodControlSet)
Definition: controlset.c:249

Referenced by wWinMain().

◆ ScmCreateNewServiceRecord()

DWORD ScmCreateNewServiceRecord ( LPCWSTR  lpServiceName,
PSERVICE lpServiceRecord,
DWORD  dwServiceType,
DWORD  dwStartType 
)

Definition at line 666 of file database.c.

670 {
671  PSERVICE lpService = NULL;
672 
673  DPRINT("Service: '%S'\n", lpServiceName);
674 
675  /* Allocate service entry */
676  lpService = HeapAlloc(GetProcessHeap(),
678  FIELD_OFFSET(SERVICE, szServiceName[wcslen(lpServiceName) + 1]));
679  if (lpService == NULL)
681 
682  *lpServiceRecord = lpService;
683 
684  /* Copy service name */
685  wcscpy(lpService->szServiceName, lpServiceName);
686  lpService->lpServiceName = lpService->szServiceName;
687  lpService->lpDisplayName = lpService->lpServiceName;
688 
689  /* Set the start type */
690  lpService->dwStartType = dwStartType;
691 
692  /* Set the resume count */
693  lpService->dwResumeCount = ResumeCount++;
694 
695  /* Append service record */
697  &lpService->ServiceListEntry);
698 
699  /* Initialize the service status */
700  lpService->Status.dwServiceType = dwServiceType;
702  lpService->Status.dwControlsAccepted = 0;
703  lpService->Status.dwWin32ExitCode =
705  lpService->Status.dwServiceSpecificExitCode = 0;
706  lpService->Status.dwCheckPoint = 0;
707  lpService->Status.dwWaitHint =
708  (dwServiceType & SERVICE_DRIVER) ? 0 : 2000; /* 2 seconds */
709 
710  return ERROR_SUCCESS;
711 }
SERVICE_STATUS Status
Definition: services.h:69
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwCurrentState
Definition: winsvc.h:100
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:609
static DWORD ResumeCount
Definition: database.c:32
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
LPWSTR lpDisplayName
Definition: services.h:62
#define InsertTailList(ListHead, Entry)
#define ERROR_SERVICE_NEVER_STARTED
Definition: winerror.h:628
#define SERVICE_DISABLED
Definition: cmtypes.h:977
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_STOPPED
Definition: winsvc.h:21
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY ServiceListEntry
Definition: services.h:60
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwServiceType
Definition: winsvc.h:99
LIST_ENTRY ServiceListHead
Definition: database.c:29
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
DWORD dwResumeCount
Definition: services.h:66
LPWSTR lpServiceName
Definition: services.h:61
DWORD dwStartType
Definition: services.h:70
DWORD dwControlsAccepted
Definition: winsvc.h:101
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define SERVICE_DRIVER
Definition: cmtypes.h:956
WCHAR szServiceName[1]
Definition: services.h:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmCreateServiceDatabase()

DWORD ScmCreateServiceDatabase ( VOID  )

Definition at line 987 of file database.c.

988 {
989  WCHAR szSubKey[MAX_PATH];
991  HKEY hServiceKey;
992  DWORD dwSubKey;
993  DWORD dwSubKeyLength;
994  FILETIME ftLastChanged;
995  DWORD dwError;
996 
997  DPRINT("ScmCreateServiceDatabase() called\n");
998 
999  /* Retrieve the NoInteractiveServies value */
1001 
1002  /* Create the service group list */
1003  dwError = ScmCreateGroupList();
1004  if (dwError != ERROR_SUCCESS)
1005  return dwError;
1006 
1007  /* Initialize image and service lists */
1010 
1011  /* Initialize the database lock */
1013 
1015  L"System\\CurrentControlSet\\Services",
1016  0,
1017  KEY_READ,
1018  &hServicesKey);
1019  if (dwError != ERROR_SUCCESS)
1020  return dwError;
1021 
1022  dwSubKey = 0;
1023  for (;;)
1024  {
1025  dwSubKeyLength = MAX_PATH;
1026  dwError = RegEnumKeyExW(hServicesKey,
1027  dwSubKey,
1028  szSubKey,
1029  &dwSubKeyLength,
1030  NULL,
1031  NULL,
1032  NULL,
1033  &ftLastChanged);
1034  if (dwError == ERROR_SUCCESS &&
1035  szSubKey[0] != L'{')
1036  {
1037  DPRINT("SubKeyName: '%S'\n", szSubKey);
1038 
1039  dwError = RegOpenKeyExW(hServicesKey,
1040  szSubKey,
1041  0,
1042  KEY_READ,
1043  &hServiceKey);
1044  if (dwError == ERROR_SUCCESS)
1045  {
1046  dwError = CreateServiceListEntry(szSubKey,
1047  hServiceKey);
1048 
1049  RegCloseKey(hServiceKey);
1050  }
1051  }
1052 
1053  if (dwError != ERROR_SUCCESS)
1054  break;
1055 
1056  dwSubKey++;
1057  }
1058 
1060 
1061  /* Wait for the LSA server */
1062  ScmWaitForLsa();
1063 
1064  /* Delete services that are marked for delete */
1066 
1067  DPRINT("ScmCreateServiceDatabase() done\n");
1068 
1069  return ERROR_SUCCESS;
1070 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY ImageListHead
Definition: database.c:28
#define KEY_READ
Definition: nt_native.h:1023
static RTL_RESOURCE DatabaseLock
Definition: database.c:31
VOID ScmWaitForLsa(VOID)
Definition: services.c:85
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static DWORD CreateServiceListEntry(LPCWSTR lpServiceName, HKEY hServiceKey)
Definition: database.c:756
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static HANDLE hServicesKey
Definition: devinst.c:21
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LIST_ENTRY ServiceListHead
Definition: database.c:29
static const WCHAR L[]
Definition: oid.c:1250
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
static VOID ScmGetNoInteractiveServicesValue(VOID)
Definition: database.c:961
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2541
DWORD ScmCreateGroupList(VOID)
Definition: groupdb.c:235
VOID ScmDeleteMarkedServices(VOID)
Definition: database.c:920
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by wWinMain().

◆ ScmCreateServiceKey()

DWORD ScmCreateServiceKey ( LPCWSTR  lpServiceName,
REGSAM  samDesired,
PHKEY  phKey 
)

Definition at line 72 of file config.c.

75 {
77  DWORD dwDisposition;
78  DWORD dwError;
79 
80  *phKey = NULL;
81 
83  L"System\\CurrentControlSet\\Services",
84  0,
86  &hServicesKey);
87  if (dwError != ERROR_SUCCESS)
88  return dwError;
89 
90  dwError = RegCreateKeyExW(hServicesKey,
91  lpServiceName,
92  0,
93  NULL,
95  samDesired,
96  NULL,
97  phKey,
98  &dwDisposition);
99 #if 0
100  if ((dwError == ERROR_SUCCESS) &&
101  (dwDisposition == REG_OPENED_EXISTING_KEY))
102  {
103  RegCloseKey(*phKey);
104  *phKey = NULL;
105  dwError = ERROR_SERVICE_EXISTS;
106  }
107 #endif
108 
110 
111  return dwError;
112 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
static HANDLE hServicesKey
Definition: devinst.c:21
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
static const WCHAR L[]
Definition: oid.c:1250
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by RCreateServiceW().

◆ ScmDecryptPassword()

DWORD ScmDecryptPassword ( _In_ PBYTE  pPassword,
_In_ DWORD  dwPasswordSize,
_Out_ PWSTR pDecryptedPassword 
)

Definition at line 701 of file config.c.

705 {
706  struct ustring inData, keyData, outData;
707  BYTE SessionKey[16];
708  PWSTR pBuffer;
710 
711  /* Get the session key */
713  SessionKey);
714  if (!NT_SUCCESS(Status))
715  {
716  DPRINT1("SystemFunction028 failed (Status 0x%08lx)\n", Status);
718  }
719 
720  inData.Length = dwPasswordSize;
721  inData.MaximumLength = inData.Length;
722  inData.Buffer = pPassword;
723 
724  keyData.Length = sizeof(SessionKey);
725  keyData.MaximumLength = keyData.Length;
726  keyData.Buffer = SessionKey;
727 
728  outData.Length = 0;
729  outData.MaximumLength = 0;
730  outData.Buffer = NULL;
731 
732  /* Get the required buffer size */
733  Status = SystemFunction005(&inData,
734  &keyData,
735  &outData);
737  {
738  DPRINT1("SystemFunction005 failed (Status 0x%08lx)\n", Status);
740  }
741 
742  /* Allocate a buffer for the clear text password */
743  pBuffer = HeapAlloc(GetProcessHeap(), 0, outData.Length);
744  if (pBuffer == NULL)
745  return ERROR_OUTOFMEMORY;
746 
747  outData.MaximumLength = outData.Length;
748  outData.Buffer = (unsigned char *)pBuffer;
749 
750  /* Decrypt the password */
751  Status = SystemFunction005(&inData,
752  &keyData,
753  &outData);
754  if (!NT_SUCCESS(Status))
755  {
756  DPRINT1("SystemFunction005 failed (Status 0x%08lx)\n", Status);
759  }
760 
761  *pClearTextPassword = pBuffer;
762 
763  return ERROR_SUCCESS;
764 }
NTSTATUS WINAPI SystemFunction005(const struct ustring *in, const struct ustring *key, struct ustring *out)
Definition: sysfunc.c:182
#define ERROR_SUCCESS
Definition: deptool.c:10
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned char BYTE
Definition: mem.h:68
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSTATUS WINAPI SystemFunction028(IN PVOID ContextHandle, OUT LPBYTE SessionKey)
Definition: config.c:18
#define DPRINT1
Definition: precomp.h:8
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmDeleteNamedPipeCriticalSection()

VOID ScmDeleteNamedPipeCriticalSection ( VOID  )

Definition at line 2359 of file database.c.

2360 {
2362 }
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by wWinMain().

◆ ScmDeleteRegKey()

DWORD ScmDeleteRegKey ( _In_ HKEY  hKey,
_In_ PCWSTR  pszSubKey 
)

Definition at line 639 of file config.c.

642 {
643  DWORD dwMaxSubkeyLen, dwMaxValueLen;
644  DWORD dwMaxLen, dwSize;
645  PWSTR pszName = NULL;
646  HKEY hSubKey;
647  DWORD dwError;
648 
649  dwError = RegOpenKeyExW(hKey, pszSubKey, 0, KEY_READ, &hSubKey);
650  if (dwError != ERROR_SUCCESS)
651  return dwError;
652 
653  /* Get maximum length of key and value names */
654  dwError = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
655  &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
656  if (dwError != ERROR_SUCCESS)
657  goto done;
658 
659  dwMaxSubkeyLen++;
660  dwMaxValueLen++;
661  dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
662 
663  /* Allocate the name buffer */
664  pszName = HeapAlloc(GetProcessHeap(), 0, dwMaxLen * sizeof(WCHAR));
665  if (pszName == NULL)
666  {
667  dwError = ERROR_NOT_ENOUGH_MEMORY;
668  goto done;
669  }
670 
671  /* Recursively delete all the subkeys */
672  while (TRUE)
673  {
674  dwSize = dwMaxLen;
675  if (RegEnumKeyExW(hSubKey, 0, pszName, &dwSize,
677  {
678  break;
679  }
680 
681  dwError = ScmDeleteRegKey(hSubKey, pszName);
682  if (dwError != ERROR_SUCCESS)
683  goto done;
684  }
685 
686 done:
687  if (pszName != NULL)
688  HeapFree(GetProcessHeap(), 0, pszName);
689 
690  RegCloseKey(hSubKey);
691 
692  /* Finally delete the key */
693  if (dwError == ERROR_SUCCESS)
694  dwError = RegDeleteKeyW(hKey, pszSubKey);
695 
696  return dwError;
697 }
#define max(a, b)
Definition: svc.c:63
#define TRUE
Definition: types.h:120
DWORD ScmDeleteRegKey(_In_ HKEY hKey, _In_ PCWSTR pszSubKey)
Definition: config.c:639
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
uint16_t * PWSTR
Definition: typedefs.h:54
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1240
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3704
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2541
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by RCloseServiceHandle(), ScmDeleteMarkedServices(), and ScmDeleteRegKey().

◆ ScmDeleteServiceRecord()

VOID ScmDeleteServiceRecord ( PSERVICE  lpService)

Definition at line 715 of file database.c.

716 {
717  DPRINT("Deleting Service %S\n", lpService->lpServiceName);
718 
719  /* Delete the display name */
720  if (lpService->lpDisplayName != NULL &&
721  lpService->lpDisplayName != lpService->lpServiceName)
722  HeapFree(GetProcessHeap(), 0, lpService->lpDisplayName);
723 
724  /* Dereference the service image */
725  if (lpService->lpImage)
726  {
727  lpService->lpImage->dwImageRunCount--;
728 
729  if (lpService->lpImage->dwImageRunCount == 0)
730  {
731  ScmRemoveServiceImage(lpService->lpImage);
732  lpService->lpImage = NULL;
733  }
734  }
735 
736  /* Decrement the group reference counter */
737  ScmSetServiceGroup(lpService, NULL);
738 
739  /* Release the SecurityDescriptor */
740  if (lpService->pSecurityDescriptor != NULL)
741  HeapFree(GetProcessHeap(), 0, lpService->pSecurityDescriptor);
742 
743  /* Remove the Service from the List */
744  RemoveEntryList(&lpService->ServiceListEntry);
745 
746  DPRINT("Deleted Service %S\n", lpService->lpServiceName);
747 
748  /* Delete the service record */
749  HeapFree(GetProcessHeap(), 0, lpService);
750 
751  DPRINT("Done\n");
752 }
LPWSTR lpDisplayName
Definition: services.h:62
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
DWORD dwImageRunCount
Definition: services.h:48
smooth NULL
Definition: ftsmooth.c:416
DWORD ScmSetServiceGroup(PSERVICE lpService, LPCWSTR lpGroupName)
Definition: groupdb.c:61
void DPRINT(...)
Definition: polytest.cpp:61
LIST_ENTRY ServiceListEntry
Definition: services.h:60
#define GetProcessHeap()
Definition: compat.h:395
LPWSTR lpServiceName
Definition: services.h:61
PSECURITY_DESCRIPTOR pSecurityDescriptor
Definition: services.h:78
PSERVICE_IMAGE lpImage
Definition: services.h:64
#define HeapFree(x, y, z)
Definition: compat.h:394
VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage)
Definition: database.c:525

Referenced by RCloseServiceHandle().

◆ ScmGenerateServiceTag()

DWORD ScmGenerateServiceTag ( PSERVICE  lpServiceRecord)

Definition at line 643 of file database.c.

644 {
645  /* Check for an overflow */
646  if (ServiceTag == -1)
647  {
648  return ERROR_INVALID_DATA;
649  }
650 
651  /* This is only valid for Win32 services */
652  if (!(lpServiceRecord->Status.dwServiceType & SERVICE_WIN32))
653  {
655  }
656 
657  /* Increment the tag counter and set it */
658  ServiceTag = ServiceTag % 0xFFFFFFFF + 1;
659  lpServiceRecord->dwTag = ServiceTag;
660 
661  return ERROR_SUCCESS;
662 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
SERVICE_STATUS Status
Definition: services.h:69
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD dwServiceType
Definition: winsvc.h:99
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define SERVICE_WIN32
Definition: cmtypes.h:962
DWORD dwTag
Definition: services.h:72
static DWORD ServiceTag
Definition: database.c:34

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmGetBootAndSystemDriverState()

VOID ScmGetBootAndSystemDriverState ( VOID  )

Definition at line 1184 of file database.c.

1185 {
1186  PLIST_ENTRY ServiceEntry;
1187  PSERVICE CurrentService;
1188 
1189  DPRINT("ScmGetBootAndSystemDriverState() called\n");
1190 
1191  ServiceEntry = ServiceListHead.Flink;
1192  while (ServiceEntry != &ServiceListHead)
1193  {
1194  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
1195 
1196  if (CurrentService->dwStartType == SERVICE_BOOT_START ||
1197  CurrentService->dwStartType == SERVICE_SYSTEM_START)
1198  {
1199  /* Check driver */
1200  DPRINT(" Checking service: %S\n", CurrentService->lpServiceName);
1201 
1202  ScmCheckDriver(CurrentService);
1203  }
1204 
1205  ServiceEntry = ServiceEntry->Flink;
1206  }
1207 
1208  DPRINT("ScmGetBootAndSystemDriverState() done\n");
1209 }
#define SERVICE_SYSTEM_START
Definition: cmtypes.h:974
static NTSTATUS ScmCheckDriver(PSERVICE Service)
Definition: database.c:1086
void DPRINT(...)
Definition: polytest.cpp:61
#define SERVICE_BOOT_START
Definition: cmtypes.h:973
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ServiceListHead
Definition: database.c:29
LPWSTR lpServiceName
Definition: services.h:61
Definition: typedefs.h:117
DWORD dwStartType
Definition: services.h:70

Referenced by wWinMain().

◆ ScmGetServiceEntryByDisplayName()

PSERVICE ScmGetServiceEntryByDisplayName ( LPCWSTR  lpDisplayName)

Definition at line 585 of file database.c.

586 {
587  PLIST_ENTRY ServiceEntry;
588  PSERVICE CurrentService;
589 
590  DPRINT("ScmGetServiceEntryByDisplayName() called\n");
591 
592  ServiceEntry = ServiceListHead.Flink;
593  while (ServiceEntry != &ServiceListHead)
594  {
595  CurrentService = CONTAINING_RECORD(ServiceEntry,
596  SERVICE,
597  ServiceListEntry);
598  if (_wcsicmp(CurrentService->lpDisplayName, lpDisplayName) == 0)
599  {
600  DPRINT("Found service: '%S'\n", CurrentService->lpDisplayName);
601  return CurrentService;
602  }
603 
604  ServiceEntry = ServiceEntry->Flink;
605  }
606 
607  DPRINT("Couldn't find a matching service\n");
608 
609  return NULL;
610 }
LPWSTR lpDisplayName
Definition: services.h:62
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ServiceListHead
Definition: database.c:29
Definition: typedefs.h:117
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2730
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by RCreateServiceW(), RGetServiceKeyNameA(), and RGetServiceKeyNameW().

◆ ScmGetServiceEntryByName()

PSERVICE ScmGetServiceEntryByName ( LPCWSTR  lpServiceName)

Definition at line 556 of file database.c.

557 {
558  PLIST_ENTRY ServiceEntry;
559  PSERVICE CurrentService;
560 
561  DPRINT("ScmGetServiceEntryByName() called\n");
562 
563  ServiceEntry = ServiceListHead.Flink;
564  while (ServiceEntry != &ServiceListHead)
565  {
566  CurrentService = CONTAINING_RECORD(ServiceEntry,
567  SERVICE,
568  ServiceListEntry);
569  if (_wcsicmp(CurrentService->lpServiceName, lpServiceName) == 0)
570  {
571  DPRINT("Found service: '%S'\n", CurrentService->lpServiceName);
572  return CurrentService;
573  }
574 
575  ServiceEntry = ServiceEntry->Flink;
576  }
577 
578  DPRINT("Couldn't find a matching service\n");
579 
580  return NULL;
581 }
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ServiceListHead
Definition: database.c:29
LPWSTR lpServiceName
Definition: services.h:61
Definition: typedefs.h:117
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by Int_EnumDependentServicesW(), RCreateServiceW(), RGetServiceDisplayNameA(), RGetServiceDisplayNameW(), and ROpenServiceW().

◆ ScmGetServiceEntryByResumeCount()

PSERVICE ScmGetServiceEntryByResumeCount ( DWORD  dwResumeCount)

Definition at line 614 of file database.c.

615 {
616  PLIST_ENTRY ServiceEntry;
617  PSERVICE CurrentService;
618 
619  DPRINT("ScmGetServiceEntryByResumeCount() called\n");
620 
621  ServiceEntry = ServiceListHead.Flink;
622  while (ServiceEntry != &ServiceListHead)
623  {
624  CurrentService = CONTAINING_RECORD(ServiceEntry,
625  SERVICE,
626  ServiceListEntry);
627  if (CurrentService->dwResumeCount > dwResumeCount)
628  {
629  DPRINT("Found service: '%S'\n", CurrentService->lpDisplayName);
630  return CurrentService;
631  }
632 
633  ServiceEntry = ServiceEntry->Flink;
634  }
635 
636  DPRINT("Couldn't find a matching service\n");
637 
638  return NULL;
639 }
LPWSTR lpDisplayName
Definition: services.h:62
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
LIST_ENTRY ServiceListHead
Definition: database.c:29
DWORD dwResumeCount
Definition: services.h:66
Definition: typedefs.h:117

Referenced by REnumServiceGroupW(), and REnumServicesStatusExW().

◆ ScmGetServiceGroupByName()

PSERVICE_GROUP ScmGetServiceGroupByName ( _In_ LPCWSTR  lpGroupName)

Definition at line 26 of file groupdb.c.

28 {
29  PLIST_ENTRY GroupEntry;
30  PSERVICE_GROUP lpGroup;
31 
32  DPRINT("ScmGetServiceGroupByName(%S)\n", lpGroupName);
33 
34  GroupEntry = GroupListHead.Flink;
35  while (GroupEntry != &GroupListHead)
36  {
37  lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
38 
39  if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
40  return lpGroup;
41 
42  GroupEntry = GroupEntry->Flink;
43  }
44 
45  GroupEntry = UnknownGroupListHead.Flink;
46  while (GroupEntry != &UnknownGroupListHead)
47  {
48  lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
49 
50  if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
51  return lpGroup;
52 
53  GroupEntry = GroupEntry->Flink;
54  }
55 
56  return NULL;
57 }
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
LPWSTR lpGroupName
Definition: services.h:32
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by RI_ScGetCurrentGroupStateW().

◆ ScmGetServiceNameFromTag()

DWORD ScmGetServiceNameFromTag ( PTAG_INFO_NAME_FROM_TAG_IN_PARAMS  InParams,
PTAG_INFO_NAME_FROM_TAG_OUT_PARAMS OutParams 
)

◆ ScmInitializeSecurity()

DWORD ScmInitializeSecurity ( VOID  )

Definition at line 288 of file security.c.

289 {
290  DWORD dwError;
291 
292  dwError = ScmCreateSids();
293  if (dwError != ERROR_SUCCESS)
294  return dwError;
295 
296  dwError = ScmCreateAcls();
297  if (dwError != ERROR_SUCCESS)
298  return dwError;
299 
300  dwError = ScmCreateDefaultSD();
301  if (dwError != ERROR_SUCCESS)
302  return dwError;
303 
304  return ERROR_SUCCESS;
305 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static DWORD ScmCreateSids(VOID)
Definition: security.c:50
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD ScmCreateDefaultSD(VOID)
Definition: security.c:179
static DWORD ScmCreateAcls(VOID)
Definition: security.c:110

Referenced by wWinMain().

◆ ScmInitNamedPipeCriticalSection()

VOID ScmInitNamedPipeCriticalSection ( VOID  )

Definition at line 2331 of file database.c.

2332 {
2333  HKEY hKey;
2334  DWORD dwKeySize;
2335  DWORD dwError;
2336 
2338 
2340  L"SYSTEM\\CurrentControlSet\\Control",
2341  0,
2342  KEY_READ,
2343  &hKey);
2344  if (dwError == ERROR_SUCCESS)
2345  {
2346  dwKeySize = sizeof(PipeTimeout);
2347  RegQueryValueExW(hKey,
2348  L"ServicesPipeTimeout",
2349  0,
2350  NULL,
2351  (LPBYTE)&PipeTimeout,
2352  &dwKeySize);
2353  RegCloseKey(hKey);
2354  }
2355 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
static DWORD PipeTimeout
Definition: database.c:38
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by wWinMain().

◆ ScmIsDeleteFlagSet()

BOOL ScmIsDeleteFlagSet ( HKEY  hServiceKey)

Definition at line 251 of file config.c.

252 {
253  DWORD dwError;
254  DWORD dwType;
255  DWORD dwFlag;
256  DWORD dwSize = sizeof(DWORD);
257 
258  dwError = RegQueryValueExW(hServiceKey,
259  L"DeleteFlag",
260  0,
261  &dwType,
262  (LPBYTE)&dwFlag,
263  &dwSize);
264 
265  return (dwError == ERROR_SUCCESS);
266 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DWORD
Definition: nt_native.h:44
unsigned char * LPBYTE
Definition: typedefs.h:52
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by CreateServiceListEntry().

◆ ScmLockDatabaseExclusive()

BOOL ScmLockDatabaseExclusive ( VOID  )

Definition at line 2310 of file database.c.

2311 {
2313 }
#define TRUE
Definition: types.h:120
static RTL_RESOURCE DatabaseLock
Definition: database.c:31
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceExclusive(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

Referenced by RChangeServiceConfig2W(), RChangeServiceConfigW(), RCloseServiceHandle(), RCreateServiceW(), RDeleteService(), ROpenServiceW(), RSetServiceObjectSecurity(), RSetServiceStatus(), ScmAcquireServiceStartLock(), ScmAutoShutdownServices(), ScmGetServiceNameFromTag(), and ScmReleaseServiceStartLock().

◆ ScmLockDatabaseShared()

BOOL ScmLockDatabaseShared ( VOID  )

Definition at line 2317 of file database.c.

2318 {
2320 }
#define TRUE
Definition: types.h:120
static RTL_RESOURCE DatabaseLock
Definition: database.c:31
NTSYSAPI BOOLEAN NTAPI RtlAcquireResourceShared(_In_ PRTL_RESOURCE Resource, _In_ BOOLEAN Wait)

Referenced by REnumServiceGroupW(), REnumServicesStatusExW(), RI_ScGetCurrentGroupStateW(), RQueryServiceConfig2A(), RQueryServiceConfig2W(), RQueryServiceConfigA(), RQueryServiceConfigW(), RQueryServiceObjectSecurity(), RQueryServiceStatus(), RQueryServiceStatusEx(), ScmQueryServiceLockStatusA(), and ScmQueryServiceLockStatusW().

◆ ScmLogEvent()

VOID ScmLogEvent ( DWORD  dwEventId,
WORD  wType,
WORD  wStrings,
LPCWSTR lpStrings 
)

Definition at line 52 of file services.c.

56 {
57  HANDLE hLog;
58 
60  L"Service Control Manager");
61  if (hLog == NULL)
62  {
63  DPRINT1("ScmLogEvent: RegisterEventSourceW failed %lu\n", GetLastError());
64  return;
65  }
66 
67  if (!ReportEventW(hLog,
68  wType,
69  0,
70  dwEventId,
71  NULL,
72  wStrings,
73  0,
74  lpStrings,
75  NULL))
76  {
77  DPRINT1("ScmLogEvent: ReportEventW failed %lu\n", GetLastError());
78  }
79 
81 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
static HANDLE hLog
Definition: misc.cpp:15
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI ReportEventW(IN HANDLE hEventLog, IN WORD wType, IN WORD wCategory, IN DWORD dwEventID, IN PSID lpUserSid, IN WORD wNumStrings, IN DWORD dwDataSize, IN LPCWSTR *lpStrings, IN LPVOID lpRawData)
Definition: eventlog.c:1516
BOOL WINAPI DeregisterEventSource(IN HANDLE hEventLog)
Definition: eventlog.c:473
#define DPRINT1
Definition: precomp.h:8
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295

Referenced by RControlService(), RSetServiceStatus(), ScmLoadService(), and ScmWaitForServiceConnect().

◆ ScmMarkServiceForDelete()

DWORD ScmMarkServiceForDelete ( PSERVICE  pService)

Definition at line 223 of file config.c.

224 {
225  HKEY hServiceKey = NULL;
226  DWORD dwValue = 1;
227  DWORD dwError;
228 
229  DPRINT("ScmMarkServiceForDelete() called\n");
230 
231  dwError = ScmOpenServiceKey(pService->lpServiceName,
232  KEY_WRITE,
233  &hServiceKey);
234  if (dwError != ERROR_SUCCESS)
235  return dwError;
236 
237  dwError = RegSetValueExW(hServiceKey,
238  L"DeleteFlag",
239  0,
240  REG_DWORD,
241  (LPBYTE)&dwValue,
242  sizeof(DWORD));
243 
244  RegCloseKey(hServiceKey);
245 
246  return dwError;
247 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define KEY_WRITE
Definition: nt_native.h:1031
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpServiceName
Definition: services.h:61
DWORD ScmOpenServiceKey(LPWSTR lpServiceName, REGSAM samDesired, PHKEY phKey)
Definition: config.c:42
#define REG_DWORD
Definition: sdbapi.c:596

Referenced by RDeleteService().

◆ ScmOpenServiceKey()

DWORD ScmOpenServiceKey ( LPWSTR  lpServiceName,
REGSAM  samDesired,
PHKEY  phKey 
)

Definition at line 42 of file config.c.

45 {
47  DWORD dwError;
48 
49  *phKey = NULL;
50 
52  L"System\\CurrentControlSet\\Services",
53  0,
54  KEY_READ,
55  &hServicesKey);
56  if (dwError != ERROR_SUCCESS)
57  return dwError;
58 
59  dwError = RegOpenKeyExW(hServicesKey,
60  lpServiceName,
61  0,
62  samDesired,
63  phKey);
64 
66 
67  return dwError;
68 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
static HANDLE hServicesKey
Definition: devinst.c:21
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by RChangeServiceConfig2W(), RChangeServiceConfigW(), RQueryServiceConfig2A(), RQueryServiceConfig2W(), RQueryServiceConfigA(), RQueryServiceConfigW(), RSetServiceObjectSecurity(), and ScmMarkServiceForDelete().

◆ ScmQueryServiceLockStatusA()

VOID ScmQueryServiceLockStatusA ( OUT LPQUERY_SERVICE_LOCK_STATUSA  lpLockStatus)

Definition at line 159 of file lock.c.

160 {
161  /* Lock the service database shared */
163 
164  if (pServiceStartLock != NULL)
165  {
166  lpLockStatus->fIsLocked = TRUE;
167 
168  /* FIXME: Retrieve the owner name. */
169  lpLockStatus->lpLockOwner = NULL;
170 
171  lpLockStatus->dwLockDuration = (DWORD)time(NULL) - pServiceStartLock->TimeWhenLocked;
172  }
173  else
174  {
175  lpLockStatus->fIsLocked = FALSE;
176 
177  strcpy((LPSTR)(lpLockStatus + 1), "");
178  lpLockStatus->lpLockOwner = (LPSTR)(ULONG_PTR)sizeof(QUERY_SERVICE_LOCK_STATUSA);
179 
180  lpLockStatus->dwLockDuration = 0;
181  }
182 
183  /* Unlock the service database */
185 
186  return;
187 }
#define TRUE
Definition: types.h:120
BOOL ScmLockDatabaseShared(VOID)
Definition: database.c:2317
__u16 time
Definition: mkdosfs.c:366
char * LPSTR
Definition: xmlstorage.h:182
#define DWORD
Definition: nt_native.h:44
uint32_t ULONG_PTR
Definition: typedefs.h:63
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
smooth NULL
Definition: ftsmooth.c:416
DWORD TimeWhenLocked
Definition: services.h:91
struct _QUERY_SERVICE_LOCK_STATUSA QUERY_SERVICE_LOCK_STATUSA
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2324
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388

Referenced by RQueryServiceLockStatusA().

◆ ScmQueryServiceLockStatusW()

VOID ScmQueryServiceLockStatusW ( OUT LPQUERY_SERVICE_LOCK_STATUSW  lpLockStatus)

Definition at line 127 of file lock.c.

128 {
129  /* Lock the service database shared */
131 
132  if (pServiceStartLock != NULL)
133  {
134  lpLockStatus->fIsLocked = TRUE;
135 
136  /* FIXME: Retrieve the owner name. */
137  lpLockStatus->lpLockOwner = NULL;
138 
139  lpLockStatus->dwLockDuration = (DWORD)time(NULL) - pServiceStartLock->TimeWhenLocked;
140  }
141  else
142  {
143  lpLockStatus->fIsLocked = FALSE;
144 
145  wcscpy((LPWSTR)(lpLockStatus + 1), L"");
146  lpLockStatus->lpLockOwner = (LPWSTR)(ULONG_PTR)sizeof(QUERY_SERVICE_LOCK_STATUSW);
147 
148  lpLockStatus->dwLockDuration = 0;
149  }
150 
151  /* Unlock the service database */
153 
154  return;
155 }
#define TRUE
Definition: types.h:120
BOOL ScmLockDatabaseShared(VOID)
Definition: database.c:2317
__u16 time
Definition: mkdosfs.c:366
#define DWORD
Definition: nt_native.h:44
uint32_t ULONG_PTR
Definition: typedefs.h:63
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
smooth NULL
Definition: ftsmooth.c:416
struct _QUERY_SERVICE_LOCK_STATUSW QUERY_SERVICE_LOCK_STATUSW
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
DWORD TimeWhenLocked
Definition: services.h:91
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2324
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by RQueryServiceLockStatusW().

◆ ScmReadDependencies()

DWORD ScmReadDependencies ( HKEY  hServiceKey,
LPWSTR lpDependencies,
DWORD lpdwDependenciesLength 
)

Definition at line 349 of file config.c.

352 {
353  LPWSTR lpGroups = NULL;
354  LPWSTR lpServices = NULL;
355  SIZE_T cchGroupsLength = 0;
356  SIZE_T cchServicesLength = 0;
357  LPWSTR lpSrc;
358  LPWSTR lpDest;
359  SIZE_T cchLength;
360  SIZE_T cchTotalLength;
361 
362  *lpDependencies = NULL;
363  *lpdwDependenciesLength = 0;
364 
365  /* Read the dependency values */
366  ScmReadString(hServiceKey,
367  L"DependOnGroup",
368  &lpGroups);
369 
370  ScmReadString(hServiceKey,
371  L"DependOnService",
372  &lpServices);
373 
374  /* Leave, if there are no dependencies */
375  if (lpGroups == NULL && lpServices == NULL)
376  return ERROR_SUCCESS;
377 
378  /* Determine the total buffer size for the dependencies */
379  if (lpGroups)
380  {
381  DPRINT("Groups:\n");
382  lpSrc = lpGroups;
383  while (*lpSrc != 0)
384  {
385  DPRINT(" %S\n", lpSrc);
386 
387  cchLength = wcslen(lpSrc) + 1;
388  cchGroupsLength += cchLength + 1;
389 
390  lpSrc = lpSrc + cchLength;
391  }
392  }
393 
394  if (lpServices)
395  {
396  DPRINT("Services:\n");
397  lpSrc = lpServices;
398  while (*lpSrc != 0)
399  {
400  DPRINT(" %S\n", lpSrc);
401 
402  cchLength = wcslen(lpSrc) + 1;
403  cchServicesLength += cchLength;
404 
405  lpSrc = lpSrc + cchLength;
406  }
407  }
408 
409  cchTotalLength = cchGroupsLength + cchServicesLength + 1;
410  DPRINT("cchTotalLength: %lu\n", cchTotalLength);
411 
412  /* Allocate the common buffer for the dependencies */
413  *lpDependencies = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cchTotalLength * sizeof(WCHAR));
414  if (*lpDependencies == NULL)
415  {
416  if (lpGroups)
417  HeapFree(GetProcessHeap(), 0, lpGroups);
418 
419  if (lpServices)
420  HeapFree(GetProcessHeap(), 0, lpServices);
421 
423  }
424 
425  /* Return the allocated buffer length in characters */
426  *lpdwDependenciesLength = (DWORD)cchTotalLength;
427 
428  /* Copy the service dependencies into the common buffer */
429  lpDest = *lpDependencies;
430  if (lpServices)
431  {
432  memcpy(lpDest,
433  lpServices,
434  cchServicesLength * sizeof(WCHAR));
435 
436  lpDest = lpDest + cchServicesLength;
437  }
438 
439  /* Copy the group dependencies into the common buffer */
440  if (lpGroups)
441  {
442  lpSrc = lpGroups;
443  while (*lpSrc != 0)
444  {
445  cchLength = wcslen(lpSrc) + 1;
446 
447  *lpDest = SC_GROUP_IDENTIFIERW;
448  lpDest++;
449 
450  wcscpy(lpDest, lpSrc);
451 
452  lpDest = lpDest + cchLength;
453  lpSrc = lpSrc + cchLength;
454  }
455  }
456 
457  /* Free the temporary buffers */
458  if (lpGroups)
459  HeapFree(GetProcessHeap(), 0, lpGroups);
460 
461  if (lpServices)
462  HeapFree(GetProcessHeap(), 0, lpServices);
463 
464  return ERROR_SUCCESS;
465 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SC_GROUP_IDENTIFIERW
Definition: winsvc.h:12
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define DWORD
Definition: nt_native.h:44
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DWORD ScmReadString(HKEY hServiceKey, LPCWSTR lpValueName, LPWSTR *lpValue)
Definition: config.c:270
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RQueryServiceConfigA(), and RQueryServiceConfigW().

◆ ScmReadSecurityDescriptor()

DWORD ScmReadSecurityDescriptor ( _In_ HKEY  hServiceKey,
_Out_ PSECURITY_DESCRIPTOR ppSecurityDescriptor 
)

Definition at line 559 of file config.c.

562 {
563  PSECURITY_DESCRIPTOR pRelativeSD = NULL;
564  HKEY hSecurityKey = NULL;
565  DWORD dwBufferLength = 0;
566  DWORD dwType;
567  DWORD dwError;
568 
569  DPRINT("ScmReadSecurityDescriptor(%p %p)\n", hServiceKey, ppSecurityDescriptor);
570 
571  *ppSecurityDescriptor = NULL;
572 
573  dwError = RegOpenKeyExW(hServiceKey,
574  L"Security",
575  0,
577  &hSecurityKey);
578  if (dwError != ERROR_SUCCESS)
579  {
580  DPRINT("RegOpenKeyExW() failed (Error %lu)\n", dwError);
581 
582  /* Do not fail if the Security key does not exist */
583  if (dwError == ERROR_FILE_NOT_FOUND)
584  dwError = ERROR_SUCCESS;
585  goto done;
586  }
587 
588  dwError = RegQueryValueExW(hSecurityKey,
589  L"Security",
590  0,
591  &dwType,
592  NULL,
593  &dwBufferLength);
594  if (dwError != ERROR_SUCCESS)
595  {
596  DPRINT("RegQueryValueExW() failed (Error %lu)\n", dwError);
597 
598  /* Do not fail if the Security value does not exist */
599  if (dwError == ERROR_FILE_NOT_FOUND)
600  dwError = ERROR_SUCCESS;
601  goto done;
602  }
603 
604  DPRINT("dwBufferLength: %lu\n", dwBufferLength);
605  pRelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
607  dwBufferLength);
608  if (pRelativeSD == NULL)
609  {
610  return ERROR_OUTOFMEMORY;
611  }
612 
613  DPRINT("pRelativeSD: %lu\n", pRelativeSD);
614  dwError = RegQueryValueExW(hSecurityKey,
615  L"Security",
616  0,
617  &dwType,
618  (LPBYTE)pRelativeSD,
619  &dwBufferLength);
620  if (dwError != ERROR_SUCCESS)
621  {
622  goto done;
623  }
624 
625  *ppSecurityDescriptor = pRelativeSD;
626 
627 done:
628  if (dwError != ERROR_SUCCESS && pRelativeSD != NULL)
629  RtlFreeHeap(RtlGetProcessHeap(), 0, pRelativeSD);
630 
631  if (hSecurityKey != NULL)
632  RegCloseKey(hSecurityKey);
633 
634  return dwError;
635 }
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:585
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by CreateServiceListEntry().

◆ ScmReadString()

DWORD ScmReadString ( HKEY  hServiceKey,
LPCWSTR  lpValueName,
LPWSTR lpValue 
)

Definition at line 270 of file config.c.

273 {
274  DWORD dwError = 0;
275  DWORD dwSize = 0;
276  DWORD dwType = 0;
277  LPWSTR ptr = NULL;
278  LPWSTR expanded = NULL;
279 
280  *lpValue = NULL;
281 
282  dwError = RegQueryValueExW(hServiceKey,
283  lpValueName,
284  0,
285  &dwType,
286  NULL,
287  &dwSize);
288  if (dwError != ERROR_SUCCESS)
289  return dwError;
290 
292  if (ptr == NULL)
294 
295  dwError = RegQueryValueExW(hServiceKey,
296  lpValueName,
297  0,
298  &dwType,
299  (LPBYTE)ptr,
300  &dwSize);
301  if (dwError != ERROR_SUCCESS)
302  {
303  HeapFree(GetProcessHeap(), 0, ptr);
304  return dwError;
305  }
306 
307  if (dwType == REG_EXPAND_SZ)
308  {
309  /* Expand the value... */
311  if (dwSize > 0)
312  {
313  expanded = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize * sizeof(WCHAR));
314  if (expanded)
315  {
316  if (dwSize == ExpandEnvironmentStringsW(ptr, expanded, dwSize))
317  {
318  *lpValue = expanded;
319  dwError = ERROR_SUCCESS;
320  }
321  else
322  {
323  dwError = GetLastError();
324  HeapFree(GetProcessHeap(), 0, expanded);
325  }
326  }
327  else
328  {
329  dwError = ERROR_NOT_ENOUGH_MEMORY;
330  }
331  }
332  else
333  {
334  dwError = GetLastError();
335  }
336 
337  HeapFree(GetProcessHeap(), 0, ptr);
338  }
339  else
340  {
341  *lpValue = ptr;
342  }
343 
344  return dwError;
345 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
unsigned char * LPBYTE
Definition: typedefs.h:52
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by CreateServiceListEntry(), RQueryServiceConfig2A(), RQueryServiceConfig2W(), RQueryServiceConfigA(), RQueryServiceConfigW(), and ScmReadDependencies().

◆ ScmReleaseServiceStartLock()

DWORD ScmReleaseServiceStartLock ( IN OUT LPSC_RPC_LOCK  lpLock)

Definition at line 82 of file lock.c.

83 {
84  PSTART_LOCK pStartLock;
85  DWORD dwError = ERROR_SUCCESS;
86 
87  if (lpLock == NULL)
89 
90  pStartLock = (PSTART_LOCK)*lpLock;
91 
92  if (pStartLock->Tag != LOCK_TAG)
94 
95  /* Lock the service database exclusively */
97 
98  /* Release the lock handle */
99  if ((pStartLock == pServiceStartLock) &&
100  (pServiceStartLock != NULL))
101  {
104  *lpLock = NULL;
105 
106  dwError = ERROR_SUCCESS;
107  }
108  else
109  {
110  dwError = ERROR_INVALID_SERVICE_LOCK;
111  }
112 
113  /* Unlock the service database */
115 
116  return dwError;
117 }
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL ScmLockDatabaseExclusive(VOID)
Definition: database.c:2310
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
smooth NULL
Definition: ftsmooth.c:416
struct _START_LOCK * PSTART_LOCK
#define GetProcessHeap()
Definition: compat.h:395
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_INVALID_SERVICE_LOCK
Definition: winerror.h:622
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2324
#define LOCK_TAG
Definition: services.h:86
DWORD Tag
Definition: services.h:90
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RUnlockServiceDatabase(), ScmStartService(), and wWinMain().

◆ ScmRemoveServiceImage()

VOID ScmRemoveServiceImage ( PSERVICE_IMAGE  pServiceImage)

Definition at line 525 of file database.c.

526 {
527  DPRINT1("ScmRemoveServiceImage() called\n");
528 
529  /* FIXME: Terminate the process */
530 
531  /* Remove the service image from the list */
532  RemoveEntryList(&pServiceImage->ImageListEntry);
533 
534  /* Close the process handle */
535  if (pServiceImage->hProcess != INVALID_HANDLE_VALUE)
536  CloseHandle(pServiceImage->hProcess);
537 
538  /* Close the control pipe */
539  if (pServiceImage->hControlPipe != INVALID_HANDLE_VALUE)
540  CloseHandle(pServiceImage->hControlPipe);
541 
542  /* Unload the user profile */
543  if (pServiceImage->hProfile != NULL)
544  UnloadUserProfile(pServiceImage->hToken, pServiceImage->hProfile);
545 
546  /* Close the logon token */
547  if (pServiceImage->hToken != NULL)
548  CloseHandle(pServiceImage->hToken);
549 
550  /* Release the service image */
551  HeapFree(GetProcessHeap(), 0, pServiceImage);
552 }
#define CloseHandle
Definition: compat.h:398
HANDLE hToken
Definition: services.h:53
LIST_ENTRY ImageListEntry
Definition: services.h:45
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
BOOL WINAPI UnloadUserProfile(_In_ HANDLE hToken, _In_ HANDLE hProfile)
Definition: profile.c:2101
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
HANDLE hProfile
Definition: services.h:54
#define DPRINT1
Definition: precomp.h:8
HANDLE hProcess
Definition: services.h:51
HANDLE hControlPipe
Definition: services.h:50
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RSetServiceStatus(), ScmDeleteServiceRecord(), and ScmLoadService().

◆ ScmSetServiceGroup()

DWORD ScmSetServiceGroup ( PSERVICE  lpService,
LPCWSTR  lpGroupName 
)

Definition at line 61 of file groupdb.c.

63 {
64  PLIST_ENTRY GroupEntry;
65  PSERVICE_GROUP lpGroup;
66 
67  DPRINT("ScmSetServiceGroup(%S)\n", lpGroupName);
68 
69  if (lpService->lpGroup != NULL)
70  {
71  ASSERT(lpService->lpGroup->dwRefCount != 0);
72  ASSERT(lpService->lpGroup->dwRefCount == (DWORD)-1 ||
73  lpService->lpGroup->dwRefCount < 10000);
74  if (lpService->lpGroup->dwRefCount != (DWORD)-1)
75  {
76  lpService->lpGroup->dwRefCount--;
77  if (lpService->lpGroup->dwRefCount == 0)
78  {
79  ASSERT(lpService->lpGroup->TagCount == 0);
80  ASSERT(lpService->lpGroup->TagArray == NULL);
82  HeapFree(GetProcessHeap(), 0, lpService->lpGroup);
83  lpService->lpGroup = NULL;
84  }
85  }
86  }
87 
88  if (lpGroupName == NULL)
89  return ERROR_SUCCESS;
90 
91  GroupEntry = GroupListHead.Flink;
92  while (GroupEntry != &GroupListHead)
93  {
94  lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
95 
96  if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
97  {
98  lpService->lpGroup = lpGroup;
99  return ERROR_SUCCESS;
100  }
101 
102  GroupEntry = GroupEntry->Flink;
103  }
104 
105  GroupEntry = UnknownGroupListHead.Flink;
106  while (GroupEntry != &UnknownGroupListHead)
107  {
108  lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
109 
110  if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
111  {
112  lpGroup->dwRefCount++;
113  lpService->lpGroup = lpGroup;
114  return ERROR_SUCCESS;
115  }
116 
117  GroupEntry = GroupEntry->Flink;
118  }
119 
122  sizeof(SERVICE_GROUP) + ((wcslen(lpGroupName) + 1)* sizeof(WCHAR)));
123  if (lpGroup == NULL)
125 
126  wcscpy(lpGroup->szGroupName, lpGroupName);
127  lpGroup->lpGroupName = lpGroup->szGroupName;
128  lpGroup->dwRefCount = 1;
129  lpService->lpGroup = lpGroup;
130 
132  &lpGroup->GroupListEntry);
133 
134  return ERROR_SUCCESS;
135 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
LPWSTR lpGroupName
Definition: services.h:32
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
PSERVICE_GROUP lpGroup
Definition: services.h:63
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
WCHAR szGroupName[1]
Definition: services.h:39
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
struct _SERVICE_GROUP * PSERVICE_GROUP
Definition: typedefs.h:117
DWORD dwRefCount
Definition: services.h:34
LIST_ENTRY GroupListEntry
Definition: services.h:31
PULONG TagArray
Definition: services.h:37
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
ULONG TagCount
Definition: services.h:36
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
struct _SERVICE_GROUP SERVICE_GROUP
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)

Referenced by CreateServiceListEntry(), RChangeServiceConfigW(), RCreateServiceW(), and ScmDeleteServiceRecord().

◆ ScmSetServicePassword()

DWORD ScmSetServicePassword ( IN PCWSTR  pszServiceName,
IN PCWSTR  pszPassword 
)

Definition at line 469 of file config.c.

472 {
474  LSA_HANDLE PolicyHandle = NULL;
475  UNICODE_STRING ServiceName = {0, 0, NULL};
478  DWORD dwError = ERROR_SUCCESS;
479 
481 
485  &PolicyHandle);
486  if (!NT_SUCCESS(Status))
488 
489  ServiceName.Length = (wcslen(pszServiceName) + 4) * sizeof(WCHAR);
490  ServiceName.MaximumLength = ServiceName.Length + sizeof(WCHAR);
493  ServiceName.MaximumLength);
494  if (ServiceName.Buffer == NULL)
496 
497  wcscpy(ServiceName.Buffer, L"_SC_");
498  wcscat(ServiceName.Buffer, pszServiceName);
499 
500  RtlInitUnicodeString(&Password, pszPassword);
501 
502  Status = LsaStorePrivateData(PolicyHandle,
503  &ServiceName,
504  pszPassword ? &Password : NULL);
505  if (!NT_SUCCESS(Status))
506  {
507  dwError = RtlNtStatusToDosError(Status);
508  goto done;
509  }
510 
511 done:
512  if (ServiceName.Buffer != NULL)
513  HeapFree(GetProcessHeap(), 0, ServiceName.Buffer);
514 
515  if (PolicyHandle != NULL)
516  LsaClose(PolicyHandle);
517 
518  return dwError;
519 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define ERROR_SUCCESS
Definition: deptool.c:10
NTSTATUS WINAPI LsaStorePrivateData(IN LSA_HANDLE PolicyHandle, IN PLSA_UNICODE_STRING KeyName, IN PLSA_UNICODE_STRING PrivateData OPTIONAL)
Definition: lsa.c:2207
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:192
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
NTSTATUS WINAPI LsaOpenPolicy(IN PLSA_UNICODE_STRING SystemName OPTIONAL, IN PLSA_OBJECT_ATTRIBUTES ObjectAttributes, IN ACCESS_MASK DesiredAccess, OUT PLSA_HANDLE PolicyHandle)
Definition: lsa.c:1181
smooth NULL
Definition: ftsmooth.c:416
LPTSTR ServiceName
Definition: ServiceMain.c:15
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define POLICY_CREATE_SECRET
Definition: ntsecapi.h:66
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmShutdownSecurity()

VOID ScmShutdownSecurity ( VOID  )

Definition at line 309 of file security.c.

310 {
312  ScmFreeAcls();
313  ScmFreeSids();
314 }
static VOID ScmFreeAcls(VOID)
Definition: security.c:167
static VOID ScmFreeDefaultSD(VOID)
Definition: security.c:227
static VOID ScmFreeSids(VOID)
Definition: security.c:31

Referenced by wWinMain().

◆ ScmShutdownServiceDatabase()

VOID ScmShutdownServiceDatabase ( VOID  )

Definition at line 1074 of file database.c.

1075 {
1076  DPRINT("ScmShutdownServiceDatabase() called\n");
1077 
1080 
1081  DPRINT("ScmShutdownServiceDatabase() done\n");
1082 }
NTSYSAPI VOID NTAPI RtlDeleteResource(_In_ PRTL_RESOURCE Resource)
static RTL_RESOURCE DatabaseLock
Definition: database.c:31
void DPRINT(...)
Definition: polytest.cpp:61
VOID ScmDeleteMarkedServices(VOID)
Definition: database.c:920

Referenced by ShutdownHandlerRoutine().

◆ ScmStartDriver()

DWORD ScmStartDriver ( PSERVICE  lpService)

Definition at line 314 of file driver.c.

315 {
316  DWORD dwError;
317 
318  DPRINT("ScmStartDriver(%p)\n", pService);
319 
320  dwError = ScmLoadDriver(pService);
321  if (dwError == ERROR_SUCCESS)
322  {
323  pService->Status.dwCurrentState = SERVICE_RUNNING;
324  pService->Status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
325  pService->Status.dwWin32ExitCode = ERROR_SUCCESS;
326  }
327 
328  DPRINT("ScmStartDriver returns %lu\n", dwError);
329 
330  return dwError;
331 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_RUNNING
Definition: winsvc.h:24
void DPRINT(...)
Definition: polytest.cpp:61
static DWORD ScmLoadDriver(PSERVICE lpService)
Definition: driver.c:24
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by ScmLoadService().

◆ ScmStartRpcServer()

VOID ScmStartRpcServer ( VOID  )

Definition at line 105 of file rpcserver.c.

106 {
108 
109  DPRINT("ScmStartRpcServer() called\n");
110 
111  Status = RpcServerUseProtseqEpW(L"ncacn_np",
112  10,
113  L"\\pipe\\ntsvcs",
114  NULL);
115  if (Status != RPC_S_OK)
116  {
117  DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
118  return;
119  }
120 
121  Status = RpcServerRegisterIf(svcctl_v2_0_s_ifspec,
122  NULL,
123  NULL);
124  if (Status != RPC_S_OK)
125  {
126  DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status);
127  return;
128  }
129 
130  Status = RpcServerListen(1, 20, TRUE);
131  if (Status != RPC_S_OK)
132  {
133  DPRINT1("RpcServerListen() failed (Status %lx)\n", Status);
134  return;
135  }
136 
137  DPRINT("ScmStartRpcServer() done\n");
138 }
#define TRUE
Definition: types.h:120
long RPC_STATUS
Definition: rpc.h:52
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1527
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
RPC_STATUS WINAPI RpcServerRegisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, RPC_MGR_EPV *MgrEpv)
Definition: rpc_server.c:1123
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
RPC_STATUS WINAPI RpcServerUseProtseqEpW(RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor)
Definition: rpc_server.c:934
#define DPRINT1
Definition: precomp.h:8
#define RPC_S_OK
Definition: rpcnterr.h:22

Referenced by wWinMain().

◆ ScmStartService()

DWORD ScmStartService ( PSERVICE  Service,
DWORD  argc,
LPWSTR argv 
)

Definition at line 2021 of file database.c.

2024 {
2025  DWORD dwError = ERROR_SUCCESS;
2026  SC_RPC_LOCK Lock = NULL;
2027 
2028  DPRINT("ScmStartService() called\n");
2029  DPRINT("Start Service %p (%S)\n", Service, Service->lpServiceName);
2030 
2031  /* Acquire the service control critical section, to synchronize starts */
2033 
2034  /*
2035  * Acquire the user service start lock while the service is starting, if
2036  * needed (i.e. if we are not starting it during the initialization phase).
2037  * If we don't success, bail out.
2038  */
2039  if (!ScmInitialize)
2040  {
2041  dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
2042  if (dwError != ERROR_SUCCESS) goto done;
2043  }
2044 
2045  /* Really start the service */
2046  dwError = ScmLoadService(Service, argc, argv);
2047 
2048  /* Release the service start lock, if needed, and the critical section */
2050 
2051 done:
2053 
2054  DPRINT("ScmStartService() done (Error %lu)\n", dwError);
2055 
2056  return dwError;
2057 }
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL ScmInitialize
Definition: services.c:28
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define argv
Definition: mplay32.c:18
DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController, OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:31
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static DWORD ScmLoadService(PSERVICE Service, DWORD argc, LPWSTR *argv)
Definition: database.c:1909
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:82
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)

Referenced by RStartServiceA(), and RStartServiceW().

◆ ScmUnlockDatabase()

◆ ScmWaitForLsa()

VOID ScmWaitForLsa ( VOID  )

Definition at line 85 of file services.c.

86 {
87  HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, L"LSA_RPC_SERVER_ACTIVE");
88  if (hEvent == NULL)
89  {
90  DPRINT1("Failed to create or open the notification event (Error %lu)\n", GetLastError());
91  }
92  else
93  {
94  DPRINT("Wait for the LSA server!\n");
96  DPRINT("LSA server running!\n");
98  }
99 
100  DPRINT("ScmWaitForLsa() done\n");
101 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
static const WCHAR L[]
Definition: oid.c:1250
#define DPRINT1
Definition: precomp.h:8
#define INFINITE
Definition: serial.h:102

Referenced by ScmCreateServiceDatabase().

◆ ScmWriteDependencies()

DWORD ScmWriteDependencies ( HKEY  hServiceKey,
LPCWSTR  lpDependencies,
DWORD  dwDependenciesLength 
)

Definition at line 117 of file config.c.

120 {
121  DWORD dwError = ERROR_SUCCESS;
122  SIZE_T cchGroupLength = 0;
123  SIZE_T cchServiceLength = 0;
124  SIZE_T cchLength;
125  LPWSTR lpGroupDeps;
126  LPWSTR lpServiceDeps;
127  LPCWSTR lpSrc;
128  LPWSTR lpDst;
129 
130  if (*lpDependencies == 0)
131  {
132  RegDeleteValueW(hServiceKey,
133  L"DependOnService");
134  RegDeleteValueW(hServiceKey,
135  L"DependOnGroup");
136  }
137  else
138  {
139  lpGroupDeps = HeapAlloc(GetProcessHeap(),
141  (dwDependenciesLength + 2) * sizeof(WCHAR));
142  if (lpGroupDeps == NULL)
144 
145  lpSrc = lpDependencies;
146  lpDst = lpGroupDeps;
147  while (*lpSrc != 0)
148  {
149  cchLength = wcslen(lpSrc) + 1;
150  if (*lpSrc == SC_GROUP_IDENTIFIERW)
151  {
152  lpSrc++;
153  cchLength--;
154  cchGroupLength += cchLength;
155  wcscpy(lpDst, lpSrc);
156  lpDst = lpDst + cchLength;
157  }
158 
159  lpSrc = lpSrc + cchLength;
160  }
161  *lpDst = 0;
162  lpDst++;
163  cchGroupLength++;
164 
165  lpSrc = lpDependencies;
166  lpServiceDeps = lpDst;
167  while (*lpSrc != 0)
168  {
169  cchLength = wcslen(lpSrc) + 1;
170  if (*lpSrc != SC_GROUP_IDENTIFIERW)
171  {
172  cchServiceLength += cchLength;
173  wcscpy(lpDst, lpSrc);
174  lpDst = lpDst + cchLength;
175  }
176 
177  lpSrc = lpSrc + cchLength;
178  }
179  *lpDst = 0;
180  cchServiceLength++;
181 
182  if (cchGroupLength > 1)
183  {
184  dwError = RegSetValueExW(hServiceKey,
185  L"DependOnGroup",
186  0,
187  REG_MULTI_SZ,
188  (LPBYTE)lpGroupDeps,
189  (DWORD)(cchGroupLength * sizeof(WCHAR)));
190  }
191  else
192  {
193  RegDeleteValueW(hServiceKey,
194  L"DependOnGroup");
195  }
196 
197  if (dwError == ERROR_SUCCESS)
198  {
199  if (cchServiceLength > 1)
200  {
201  dwError = RegSetValueExW(hServiceKey,
202  L"DependOnService",
203  0,
204  REG_MULTI_SZ,
205  (LPBYTE)lpServiceDeps,
206  (DWORD)(cchServiceLength * sizeof(WCHAR)));
207  }
208  else
209  {
210  RegDeleteValueW(hServiceKey,
211  L"DependOnService");
212  }
213  }
214 
215  HeapFree(GetProcessHeap(), 0, lpGroupDeps);
216  }
217 
218  return dwError;
219 }
#define ERROR_SUCCESS
Definition: deptool.c:10
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define SC_GROUP_IDENTIFIERW
Definition: winsvc.h:12
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
unsigned char * LPBYTE
Definition: typedefs.h:52
#define REG_MULTI_SZ
Definition: nt_native.h:1501
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
ULONG_PTR SIZE_T
Definition: typedefs.h:78
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2368
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
WCHAR * LPWSTR
Definition: xmlstorage.h:184
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmWriteSecurityDescriptor()

DWORD ScmWriteSecurityDescriptor ( _In_ HKEY  hServiceKey,
_In_ PSECURITY_DESCRIPTOR  pSecurityDescriptor 
)

Definition at line 523 of file config.c.

526 {
527  HKEY hSecurityKey = NULL;
528  DWORD dwDisposition;
529  DWORD dwError;
530 
531  DPRINT("ScmWriteSecurityDescriptor(%p %p)\n", hServiceKey, pSecurityDescriptor);
532 
533  dwError = RegCreateKeyExW(hServiceKey,
534  L"Security",
535  0,
536  NULL,
539  NULL,
540  &hSecurityKey,
541  &dwDisposition);
542  if (dwError != ERROR_SUCCESS)
543  return dwError;
544 
545  dwError = RegSetValueExW(hSecurityKey,
546  L"Security",
547  0,
548  REG_BINARY,
549  (LPBYTE)pSecurityDescriptor,
550  RtlLengthSecurityDescriptor(pSecurityDescriptor));
551 
552  RegCloseKey(hSecurityKey);
553 
554  return dwError;
555 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define REG_BINARY
Definition: nt_native.h:1496
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1094
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
NTSYSAPI ULONG WINAPI RtlLengthSecurityDescriptor(PSECURITY_DESCRIPTOR)

Referenced by CreateServiceListEntry(), RCreateServiceW(), and RSetServiceObjectSecurity().

Variable Documentation

◆ GroupListHead

◆ ImageListHead

◆ ScmInitialize

BOOL ScmInitialize

Definition at line 28 of file services.c.

Referenced by ScmAutoStartServices(), ScmStartService(), and wWinMain().

◆ ScmShutdown

◆ ServiceListHead