ReactOS 0.4.16-dev-188-g678aa63
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/setypes.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_ PVOID ContextHandle, _In_ PBYTE pPassword, _In_ DWORD dwPasswordSize, _Out_ PWSTR *pDecryptedPassword)
 
DWORD ScmCreateLastKnownGoodControlSet (VOID)
 
DWORD ScmAcceptBoot (VOID)
 
DWORD ScmRunLastKnownGood (VOID)
 
DWORD ScmCreateServiceDatabase (VOID)
 
VOID ScmShutdownServiceDatabase (VOID)
 
VOID ScmGetBootAndSystemDriverState (VOID)
 
VOID ScmAutoStartServices (VOID)
 
VOID ScmAutoShutdownServices (VOID)
 
DWORD ScmStartService (PSERVICE Service, DWORD argc, const PCWSTR *argv)
 
DWORD ScmReferenceService (PSERVICE lpService)
 
DWORD ScmDereferenceService (PSERVICE lpService)
 
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 (_In_ HANDLE hControlPipe, _In_ PCWSTR pServiceName, _In_ DWORD dwControl, _In_ SERVICE_STATUS_HANDLE hServiceStatus)
 
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,...)
 
DWORD SetSecurityServicesEvent (VOID)
 
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
 
BOOL ScmLiveSetup
 
BOOL ScmSetupInProgress
 
PSECURITY_DESCRIPTOR pPipeSD
 

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 90 of file services.h.

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 22 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 39 of file services.c.

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

◆ ScmAcceptBoot()

DWORD ScmAcceptBoot ( VOID  )

Definition at line 336 of file controlset.c.

337{
338 DWORD dwCurrentControlSet, dwDefaultControlSet;
339 DWORD dwFailedControlSet, dwLastKnownGoodControlSet;
340 DWORD dwNewControlSet;
341 DWORD dwError;
342
343 DPRINT("ScmAcceptBoot()\n");
344
345 if (bBootAccepted)
346 {
347 DPRINT1("Boot has already been accepted\n");
349 }
350
351 /* Get the control set values */
352 dwError = ScmGetControlSetValues(&dwCurrentControlSet,
353 &dwDefaultControlSet,
354 &dwFailedControlSet,
355 &dwLastKnownGoodControlSet);
356 if (dwError != ERROR_SUCCESS)
357 return dwError;
358
359 /* Search for a new control set number */
360 for (dwNewControlSet = 1; dwNewControlSet < 1000; dwNewControlSet++)
361 {
362 if ((dwNewControlSet != dwCurrentControlSet) &&
363 (dwNewControlSet != dwDefaultControlSet) &&
364 (dwNewControlSet != dwFailedControlSet) &&
365 (dwNewControlSet != dwLastKnownGoodControlSet))
366 break;
367 }
368
369 /* Fail if we did not find an unused control set!*/
370 if (dwNewControlSet >= 1000)
371 {
372 DPRINT1("Too many control sets\n");
373 return ERROR_NO_MORE_ITEMS;
374 }
375
376 /* Copy the current control set */
377 dwError = ScmCopyControlSet(dwCurrentControlSet,
378 dwNewControlSet);
379 if (dwError != ERROR_SUCCESS)
380 return dwError;
381
382 /* Delete the current last known good contol set, if it is not used anywhere else */
383 if ((dwLastKnownGoodControlSet != dwCurrentControlSet) &&
384 (dwLastKnownGoodControlSet != dwDefaultControlSet) &&
385 (dwLastKnownGoodControlSet != dwFailedControlSet))
386 {
387 ScmDeleteControlSet(dwLastKnownGoodControlSet);
388 }
389
390 /* Set the new 'LastKnownGood' control set */
391 dwError = ScmSetLastKnownGoodControlSet(dwNewControlSet);
392 if (dwError != ERROR_SUCCESS)
393 return dwError;
394
396
397 return ERROR_SUCCESS;
398}
#define DPRINT1
Definition: precomp.h:8
static DWORD ScmSetLastKnownGoodControlSet(DWORD dwControlSet)
Definition: controlset.c:112
static DWORD ScmDeleteControlSet(DWORD dwControlSet)
Definition: controlset.c:241
static DWORD ScmGetControlSetValues(PDWORD pdwCurrentControlSet, PDWORD pdwDefaultControlSet, PDWORD pdwFailedControlSet, PDWORD pdwLastKnownGoodControlSet)
Definition: controlset.c:29
static DWORD ScmCopyControlSet(DWORD dwSourceControlSet, DWORD dwDestinationControlSet)
Definition: controlset.c:178
static BOOL bBootAccepted
Definition: controlset.c:22
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
unsigned long DWORD
Definition: ntddk_ex.h:95
#define DPRINT
Definition: sndvol32.h:73
#define ERROR_BOOT_ALREADY_ACCEPTED
Definition: winerror.h:627

Referenced by RNotifyBootConfigStatus().

◆ 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
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);
60 {
62 goto done;
63 }
64
67
68 /* FIXME: Retrieve the owner SID. Use IsServiceController. */
70
72
73done:
74 /* Unlock the service database */
76
77 return dwError;
78}
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2328
BOOL ScmLockDatabaseExclusive(VOID)
Definition: database.c:2314
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
#define LOCK_TAG
Definition: services.h:90
struct _START_LOCK START_LOCK
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
__u16 time
Definition: mkdosfs.c:8
struct _SID * PSID
Definition: eventlog.c:35
#define DWORD
Definition: nt_native.h:44
DWORD TimeWhenLocked
Definition: services.h:95
DWORD Tag
Definition: services.h:94
PSID LockOwnerSid
Definition: services.h:96
SC_RPC_LOCK * LPSC_RPC_LOCK
Definition: svcctl.idl:24
#define ERROR_SERVICE_DATABASE_LOCKED
Definition: winerror.h:606

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

◆ ScmAutoShutdownServices()

VOID ScmAutoShutdownServices ( VOID  )

Definition at line 2276 of file database.c.

2277{
2278 PLIST_ENTRY ServiceEntry;
2279 PSERVICE CurrentService;
2280
2281 DPRINT("ScmAutoShutdownServices() called\n");
2282
2283 /* Lock the service database exclusively */
2285
2286 ServiceEntry = ServiceListHead.Flink;
2287 while (ServiceEntry != &ServiceListHead)
2288 {
2289 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2290
2291 if ((CurrentService->Status.dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN) &&
2292 (CurrentService->Status.dwCurrentState == SERVICE_RUNNING ||
2293 CurrentService->Status.dwCurrentState == SERVICE_START_PENDING))
2294 {
2295 /* Send the shutdown notification */
2296 DPRINT("Shutdown service: %S\n", CurrentService->lpServiceName);
2297 ScmControlService(CurrentService->lpImage->hControlPipe,
2298 CurrentService->lpServiceName,
2300 (SERVICE_STATUS_HANDLE)CurrentService);
2301 }
2302
2303 ServiceEntry = ServiceEntry->Flink;
2304 }
2305
2306 /* Unlock the service database */
2308
2309 DPRINT("ScmAutoShutdownServices() done\n");
2310}
static SERVICE_STATUS_HANDLE(WINAPI *pRegisterServiceCtrlHandlerExA)(LPCSTR
DWORD ScmControlService(_In_ HANDLE hControlPipe, _In_ PCWSTR pServiceName, _In_ DWORD dwControl, _In_ SERVICE_STATUS_HANDLE hServiceStatus)
Definition: database.c:1569
LIST_ENTRY ServiceListHead
Definition: database.c:29
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
HANDLE hControlPipe
Definition: services.h:53
DWORD dwControlsAccepted
Definition: winsvc.h:101
DWORD dwCurrentState
Definition: winsvc.h:100
SERVICE_STATUS Status
Definition: services.h:72
PSERVICE_IMAGE lpImage
Definition: services.h:67
LPWSTR lpServiceName
Definition: services.h:64
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30

Referenced by ShutdownHandlerRoutine().

◆ ScmAutoStartServices()

VOID ScmAutoStartServices ( VOID  )

Definition at line 2065 of file database.c.

2066{
2067 DWORD dwError;
2068 PLIST_ENTRY GroupEntry;
2069 PLIST_ENTRY ServiceEntry;
2070 PSERVICE_GROUP CurrentGroup;
2071 PSERVICE CurrentService;
2072 WCHAR szSafeBootServicePath[MAX_PATH];
2073 DWORD SafeBootEnabled;
2074 HKEY hKey;
2075 DWORD dwKeySize;
2076 ULONG i;
2077
2078 /*
2079 * This function MUST be called ONLY at initialization time.
2080 * Therefore, no need to acquire the user service start lock.
2081 */
2083
2084 /* Retrieve the SafeBoot parameter */
2086 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
2087 0,
2088 KEY_READ,
2089 &hKey);
2090 if (dwError == ERROR_SUCCESS)
2091 {
2092 dwKeySize = sizeof(SafeBootEnabled);
2093 dwError = RegQueryValueExW(hKey,
2094 L"OptionValue",
2095 0,
2096 NULL,
2097 (LPBYTE)&SafeBootEnabled,
2098 &dwKeySize);
2100 }
2101
2102 /* Default to Normal boot if the value doesn't exist */
2103 if (dwError != ERROR_SUCCESS)
2104 SafeBootEnabled = 0;
2105
2106 /* Acquire the service control critical section, to synchronize starts */
2108
2109 /* Clear 'ServiceVisited' flag (or set if not to start in Safe Mode) */
2110 ServiceEntry = ServiceListHead.Flink;
2111 while (ServiceEntry != &ServiceListHead)
2112 {
2113 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2114
2115 /* Build the safe boot path */
2116 StringCchCopyW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2117 L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot");
2118
2119 switch (SafeBootEnabled)
2120 {
2121 /* NOTE: Assumes MINIMAL (1) and DSREPAIR (3) load same items */
2122 case 1:
2123 case 3:
2124 StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2125 L"\\Minimal\\");
2126 break;
2127
2128 case 2:
2129 StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2130 L"\\Network\\");
2131 break;
2132 }
2133
2134 if (SafeBootEnabled != 0)
2135 {
2136 /* If key does not exist then do not assume safe mode */
2138 szSafeBootServicePath,
2139 0,
2140 KEY_READ,
2141 &hKey);
2142 if (dwError == ERROR_SUCCESS)
2143 {
2145
2146 /* Finish Safe Boot path off */
2147 StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2148 CurrentService->lpServiceName);
2149
2150 /* Check that the key is in the Safe Boot path */
2152 szSafeBootServicePath,
2153 0,
2154 KEY_READ,
2155 &hKey);
2156 if (dwError != ERROR_SUCCESS)
2157 {
2158 /* Mark service as visited so it is not auto-started */
2159 CurrentService->ServiceVisited = TRUE;
2160 }
2161 else
2162 {
2163 /* Must be auto-started in safe mode - mark as unvisited */
2165 CurrentService->ServiceVisited = FALSE;
2166 }
2167 }
2168 else
2169 {
2170 DPRINT1("WARNING: Could not open the associated Safe Boot key\n");
2171 CurrentService->ServiceVisited = FALSE;
2172 }
2173 }
2174
2175 ServiceEntry = ServiceEntry->Flink;
2176 }
2177
2178 /* Start all services which are members of an existing group */
2179 GroupEntry = GroupListHead.Flink;
2180 while (GroupEntry != &GroupListHead)
2181 {
2182 CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
2183
2184 DPRINT("Group '%S'\n", CurrentGroup->lpGroupName);
2185
2186 /* Start all services witch have a valid tag */
2187 for (i = 0; i < CurrentGroup->TagCount; i++)
2188 {
2189 ServiceEntry = ServiceListHead.Flink;
2190 while (ServiceEntry != &ServiceListHead)
2191 {
2192 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2193
2194 if ((CurrentService->lpGroup == CurrentGroup) &&
2195 (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2196 (CurrentService->ServiceVisited == FALSE) &&
2197 (CurrentService->dwTag == CurrentGroup->TagArray[i]))
2198 {
2199 CurrentService->ServiceVisited = TRUE;
2200 ScmLoadService(CurrentService, 0, NULL);
2201 }
2202
2203 ServiceEntry = ServiceEntry->Flink;
2204 }
2205 }
2206
2207 /* Start all services which have an invalid tag or which do not have a tag */
2208 ServiceEntry = ServiceListHead.Flink;
2209 while (ServiceEntry != &ServiceListHead)
2210 {
2211 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2212
2213 if ((CurrentService->lpGroup == CurrentGroup) &&
2214 (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2215 (CurrentService->ServiceVisited == FALSE))
2216 {
2217 CurrentService->ServiceVisited = TRUE;
2218 ScmLoadService(CurrentService, 0, NULL);
2219 }
2220
2221 ServiceEntry = ServiceEntry->Flink;
2222 }
2223
2224 GroupEntry = GroupEntry->Flink;
2225 }
2226
2227 /* Start all services which are members of any non-existing group */
2228 ServiceEntry = ServiceListHead.Flink;
2229 while (ServiceEntry != &ServiceListHead)
2230 {
2231 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2232
2233 if ((CurrentService->lpGroup != NULL) &&
2234 (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2235 (CurrentService->ServiceVisited == FALSE))
2236 {
2237 CurrentService->ServiceVisited = TRUE;
2238 ScmLoadService(CurrentService, 0, NULL);
2239 }
2240
2241 ServiceEntry = ServiceEntry->Flink;
2242 }
2243
2244 /* Start all services which are not a member of any group */
2245 ServiceEntry = ServiceListHead.Flink;
2246 while (ServiceEntry != &ServiceListHead)
2247 {
2248 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2249
2250 if ((CurrentService->lpGroup == NULL) &&
2251 (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2252 (CurrentService->ServiceVisited == FALSE))
2253 {
2254 CurrentService->ServiceVisited = TRUE;
2255 ScmLoadService(CurrentService, 0, NULL);
2256 }
2257
2258 ServiceEntry = ServiceEntry->Flink;
2259 }
2260
2261 /* Clear 'ServiceVisited' flag again */
2262 ServiceEntry = ServiceListHead.Flink;
2263 while (ServiceEntry != &ServiceListHead)
2264 {
2265 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2266 CurrentService->ServiceVisited = FALSE;
2267 ServiceEntry = ServiceEntry->Flink;
2268 }
2269
2270 /* Release the critical section */
2272}
static DWORD ScmLoadService(PSERVICE Service, DWORD argc, const PCWSTR *argv)
Definition: database.c:1911
static CRITICAL_SECTION ControlServiceCriticalSection
Definition: database.c:37
BOOL ScmInitialize
Definition: services.c:28
#define RegCloseKey(hKey)
Definition: registry.h:49
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
#define MAX_PATH
Definition: compat.h:34
FxAutoRegKey hKey
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
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
#define ASSERT(a)
Definition: mode.c:44
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
PULONG TagArray
Definition: services.h:40
ULONG TagCount
Definition: services.h:39
LPWSTR lpGroupName
Definition: services.h:35
PSERVICE_GROUP lpGroup
Definition: services.h:66
BOOLEAN ServiceVisited
Definition: services.h:84
DWORD dwStartType
Definition: services.h:73
DWORD dwTag
Definition: services.h:75
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define SERVICE_AUTO_START
Definition: cmtypes.h:977
__wchar_t WCHAR
Definition: xmlstorage.h:180

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
385done:
386 DPRINT("ScmControlDriver() done (Erorr: %lu)\n", dwError);
387
388 return dwError;
389}
static DWORD ScmGetDriverStatus(PSERVICE lpService, LPSERVICE_STATUS lpServiceStatus)
Definition: driver.c:136
static DWORD ScmUnloadDriver(PSERVICE lpService)
Definition: driver.c:77
#define ERROR_INVALID_SERVICE_CONTROL
Definition: winerror.h:603
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39

Referenced by RControlService().

◆ ScmControlService()

DWORD ScmControlService ( _In_ HANDLE  hControlPipe,
_In_ PCWSTR  pServiceName,
_In_ DWORD  dwControl,
_In_ SERVICE_STATUS_HANDLE  hServiceStatus 
)

Definition at line 1569 of file database.c.

1574{
1575 return ScmControlServiceEx(hControlPipe,
1576 pServiceName,
1577 dwControl,
1579 0, 0, NULL);
1580}
DWORD ScmControlServiceEx(_In_ HANDLE hControlPipe, _In_ PCWSTR pServiceName, _In_ DWORD dwControl, _In_ SERVICE_STATUS_HANDLE hServiceStatus, _In_opt_ DWORD dwServiceTag, _In_opt_ DWORD argc, _In_reads_opt_(argc) const PCWSTR *argv)
Definition: database.c:1417
SERVICE_STATUS_HANDLE hServiceStatus
Definition: main.c:10

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

◆ ScmCreateDefaultServiceSD()

DWORD ScmCreateDefaultServiceSD ( PSECURITY_DESCRIPTOR ppSecurityDescriptor)

Definition at line 320 of file security.c.

322{
323 PSECURITY_DESCRIPTOR pRelativeSD = NULL;
324 DWORD dwBufferLength = 0;
326 DWORD dwError = ERROR_SUCCESS;
327
328 /* Convert the absolute SD to a self-relative SD */
330 NULL,
331 &dwBufferLength);
333 {
334 dwError = RtlNtStatusToDosError(Status);
335 goto done;
336 }
337
338 DPRINT("BufferLength %lu\n", dwBufferLength);
339
340 pRelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
342 dwBufferLength);
343 if (pRelativeSD == NULL)
344 {
345 dwError = ERROR_OUTOFMEMORY;
346 goto done;
347 }
348 DPRINT("pRelativeSD %p\n", pRelativeSD);
349
351 pRelativeSD,
352 &dwBufferLength);
353 if (!NT_SUCCESS(Status))
354 {
355 dwError = RtlNtStatusToDosError(Status);
356 goto done;
357 }
358
359 *ppSecurityDescriptor = pRelativeSD;
360
361done:
362 if (dwError != ERROR_SUCCESS)
363 {
364 if (pRelativeSD != NULL)
365 RtlFreeHeap(RtlGetProcessHeap(), 0, pRelativeSD);
366 }
367
368 return dwError;
369}
LONG NTSTATUS
Definition: precomp.h:26
static PSECURITY_DESCRIPTOR pDefaultSD
Definition: security.c:26
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
NTSYSAPI NTSTATUS NTAPI RtlAbsoluteToSelfRelativeSD(IN PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor, IN OUT PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor, IN PULONG BufferLength)
Definition: sd.c:626
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69

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",
253 NULL,
254 NULL);
255
257}
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
static NTSTATUS WINAPI CreateGroupListRoutine(PWSTR ValueName, ULONG ValueType, PVOID ValueData, ULONG ValueLength, PVOID Context, PVOID EntryContext)
Definition: groupdb.c:188
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4220
#define RTL_REGISTRY_CONTROL
Definition: nt_native.h:163
PRTL_QUERY_REGISTRY_ROUTINE QueryRoutine
Definition: nt_native.h:109
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by ScmCreateServiceDatabase().

◆ ScmCreateLastKnownGoodControlSet()

DWORD ScmCreateLastKnownGoodControlSet ( VOID  )

Definition at line 275 of file controlset.c.

276{
277 DWORD dwCurrentControlSet, dwDefaultControlSet;
278 DWORD dwFailedControlSet, dwLastKnownGoodControlSet;
279 DWORD dwNewControlSet;
280 DWORD dwError;
281
282 /* Get the control set values */
283 dwError = ScmGetControlSetValues(&dwCurrentControlSet,
284 &dwDefaultControlSet,
285 &dwFailedControlSet,
286 &dwLastKnownGoodControlSet);
287 if (dwError != ERROR_SUCCESS)
288 return dwError;
289
290 /* First boot after setup? */
291 if ((ScmGetSetupInProgress() == 0) &&
292 (dwCurrentControlSet == dwLastKnownGoodControlSet))
293 {
294 DPRINT("First boot after setup\n");
295
296 /* Search for a new control set number */
297 for (dwNewControlSet = 1; dwNewControlSet < 1000; dwNewControlSet++)
298 {
299 if ((dwNewControlSet != dwCurrentControlSet) &&
300 (dwNewControlSet != dwDefaultControlSet) &&
301 (dwNewControlSet != dwFailedControlSet) &&
302 (dwNewControlSet != dwLastKnownGoodControlSet))
303 break;
304 }
305
306 /* Fail if we did not find an unused control set!*/
307 if (dwNewControlSet >= 1000)
308 {
309 DPRINT1("Too many control sets\n");
310 return ERROR_NO_MORE_ITEMS;
311 }
312
313 /* Copy the current control set */
314 dwError = ScmCopyControlSet(dwCurrentControlSet,
315 dwNewControlSet);
316 if (dwError != ERROR_SUCCESS)
317 return dwError;
318
319 /* Set the new 'LastKnownGood' control set */
320 dwError = ScmSetLastKnownGoodControlSet(dwNewControlSet);
321 if (dwError == ERROR_SUCCESS)
322 {
323 /*
324 * Accept the boot here in order to prevent the creation of
325 * another control set when a user is going to get logged on
326 */
328 }
329 }
330
331 return dwError;
332}
static DWORD ScmGetSetupInProgress(VOID)
Definition: controlset.c:142

Referenced by wWinMain().

◆ ScmCreateNewServiceRecord()

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

Definition at line 767 of file database.c.

771{
772 PSERVICE lpService = NULL;
773
774 DPRINT("Service: '%S'\n", lpServiceName);
775
776 /* Allocate service entry */
777 lpService = HeapAlloc(GetProcessHeap(),
779 FIELD_OFFSET(SERVICE, szServiceName[wcslen(lpServiceName) + 1]));
780 if (lpService == NULL)
782
783 *lpServiceRecord = lpService;
784
785 /* Copy service name */
786 wcscpy(lpService->szServiceName, lpServiceName);
787 lpService->lpServiceName = lpService->szServiceName;
788 lpService->lpDisplayName = lpService->lpServiceName;
789
790 /* Set the start type */
791 lpService->dwStartType = dwStartType;
792
793 /* Set the resume count */
794 lpService->dwResumeCount = ResumeCount++;
795
796 /* Append service record */
798 &lpService->ServiceListEntry);
799
800 /* Initialize the service status */
801 lpService->Status.dwServiceType = dwServiceType;
803 lpService->Status.dwControlsAccepted = 0;
804 lpService->Status.dwWin32ExitCode =
806 lpService->Status.dwServiceSpecificExitCode = 0;
807 lpService->Status.dwCheckPoint = 0;
808 lpService->Status.dwWaitHint =
809 (dwServiceType & SERVICE_DRIVER) ? 0 : 2000; /* 2 seconds */
810
811 return ERROR_SUCCESS;
812}
static DWORD ResumeCount
Definition: database.c:32
#define InsertTailList(ListHead, Entry)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwCheckPoint
Definition: winsvc.h:104
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
LPWSTR lpDisplayName
Definition: services.h:65
LIST_ENTRY ServiceListEntry
Definition: services.h:63
DWORD dwResumeCount
Definition: services.h:69
WCHAR szServiceName[1]
Definition: services.h:86
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define ERROR_SERVICE_NEVER_STARTED
Definition: winerror.h:628
#define ERROR_SERVICE_DISABLED
Definition: winerror.h:609
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_DISABLED
Definition: cmtypes.h:979
#define SERVICE_DRIVER
Definition: cmtypes.h:958

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmCreateServiceDatabase()

DWORD ScmCreateServiceDatabase ( VOID  )

Definition at line 1187 of file database.c.

1188{
1189 WCHAR szSubKey[MAX_PATH];
1191 HKEY hServiceKey;
1192 DWORD dwSubKey;
1193 DWORD dwSubKeyLength;
1194 FILETIME ftLastChanged;
1195 DWORD dwError;
1196
1197 DPRINT("ScmCreateServiceDatabase() called\n");
1198
1199 /* Retrieve the NoInteractiveServies value */
1201
1202 /* Create the service group list */
1203 dwError = ScmCreateGroupList();
1204 if (dwError != ERROR_SUCCESS)
1205 return dwError;
1206
1207 /* Initialize image and service lists */
1210
1211 /* Initialize the database lock */
1213
1215 L"System\\CurrentControlSet\\Services",
1216 0,
1217 KEY_READ,
1218 &hServicesKey);
1219 if (dwError != ERROR_SUCCESS)
1220 return dwError;
1221
1222 dwSubKey = 0;
1223 for (;;)
1224 {
1225 dwSubKeyLength = MAX_PATH;
1226 dwError = RegEnumKeyExW(hServicesKey,
1227 dwSubKey,
1228 szSubKey,
1229 &dwSubKeyLength,
1230 NULL,
1231 NULL,
1232 NULL,
1233 &ftLastChanged);
1234 if (dwError == ERROR_SUCCESS &&
1235 szSubKey[0] != L'{')
1236 {
1237 DPRINT("SubKeyName: '%S'\n", szSubKey);
1238
1239 dwError = RegOpenKeyExW(hServicesKey,
1240 szSubKey,
1241 0,
1242 KEY_READ,
1243 &hServiceKey);
1244 if (dwError == ERROR_SUCCESS)
1245 {
1246 dwError = CreateServiceListEntry(szSubKey,
1247 hServiceKey);
1248
1249 RegCloseKey(hServiceKey);
1250 }
1251 }
1252
1253 if (dwError != ERROR_SUCCESS)
1254 break;
1255
1256 dwSubKey++;
1257 }
1258
1260
1261 /* Wait for the LSA server */
1262 ScmWaitForLsa();
1263
1264 /* Delete services that are marked for delete */
1266
1267 DPRINT("ScmCreateServiceDatabase() done\n");
1268
1269 return ERROR_SUCCESS;
1270}
static HANDLE hServicesKey
Definition: devinst.c:21
static DWORD CreateServiceListEntry(LPCWSTR lpServiceName, HKEY hServiceKey)
Definition: database.c:956
LIST_ENTRY ImageListHead
Definition: database.c:28
static RTL_RESOURCE DatabaseLock
Definition: database.c:31
static VOID ScmGetNoInteractiveServicesValue(VOID)
Definition: database.c:1161
VOID ScmDeleteMarkedServices(VOID)
Definition: database.c:1120
VOID ScmWaitForLsa(VOID)
Definition: services.c:207
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:2504
DWORD ScmCreateGroupList(VOID)
Definition: groupdb.c:235
NTSYSAPI VOID NTAPI RtlInitializeResource(_In_ PRTL_RESOURCE Resource)

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,
87 if (dwError != ERROR_SUCCESS)
88 return dwError;
89
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}
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:1096
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_OPENED_EXISTING_KEY
Definition: nt_native.h:1085
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624

Referenced by RCreateServiceW().

◆ ScmDecryptPassword()

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

Definition at line 708 of file config.c.

713{
714 struct ustring inData, keyData, outData;
715 BYTE SessionKey[16];
718
719 /* Get the session key */
720 Status = SystemFunction028(ContextHandle,
721 SessionKey);
722 if (!NT_SUCCESS(Status))
723 {
724 DPRINT1("SystemFunction028 failed (Status 0x%08lx)\n", Status);
726 }
727
728 inData.Length = dwPasswordSize;
729 inData.MaximumLength = inData.Length;
730 inData.Buffer = pPassword;
731
732 keyData.Length = sizeof(SessionKey);
733 keyData.MaximumLength = keyData.Length;
734 keyData.Buffer = SessionKey;
735
736 outData.Length = 0;
737 outData.MaximumLength = 0;
738 outData.Buffer = NULL;
739
740 /* Get the required buffer size */
741 Status = SystemFunction005(&inData,
742 &keyData,
743 &outData);
745 {
746 DPRINT1("SystemFunction005 failed (Status 0x%08lx)\n", Status);
748 }
749
750 /* Allocate a buffer for the clear text password */
751 pBuffer = HeapAlloc(GetProcessHeap(), 0, outData.Length);
752 if (pBuffer == NULL)
753 return ERROR_OUTOFMEMORY;
754
755 outData.MaximumLength = outData.Length;
756 outData.Buffer = (unsigned char *)pBuffer;
757
758 /* Decrypt the password */
759 Status = SystemFunction005(&inData,
760 &keyData,
761 &outData);
762 if (!NT_SUCCESS(Status))
763 {
764 DPRINT1("SystemFunction005 failed (Status 0x%08lx)\n", Status);
767 }
768
769 *pClearTextPassword = pBuffer;
770
771 return ERROR_SUCCESS;
772}
NTSTATUS WINAPI SystemFunction028(IN PVOID ContextHandle, OUT LPBYTE SessionKey)
NTSTATUS WINAPI SystemFunction005(const struct ustring *in, const struct ustring *key, struct ustring *out)
Definition: sysfunc.c:182
#define HeapFree(x, y, z)
Definition: compat.h:735
PVOID pBuffer
Definition: config.c:19
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char BYTE
Definition: xxhash.c:193

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmDeleteNamedPipeCriticalSection()

VOID ScmDeleteNamedPipeCriticalSection ( VOID  )

Definition at line 2363 of file database.c.

2364{
2366}
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)

Referenced by wWinMain().

◆ ScmDeleteRegKey()

DWORD ScmDeleteRegKey ( _In_ HKEY  hKey,
_In_ PCWSTR  pszSubKey 
)

Definition at line 646 of file config.c.

649{
650 DWORD dwMaxSubkeyLen, dwMaxValueLen;
651 DWORD dwMaxLen, dwSize;
652 PWSTR pszName = NULL;
653 HKEY hSubKey;
654 DWORD dwError;
655
656 dwError = RegOpenKeyExW(hKey, pszSubKey, 0, KEY_READ, &hSubKey);
657 if (dwError != ERROR_SUCCESS)
658 return dwError;
659
660 /* Get maximum length of key and value names */
661 dwError = RegQueryInfoKeyW(hSubKey, NULL, NULL, NULL, NULL,
662 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
663 if (dwError != ERROR_SUCCESS)
664 goto done;
665
666 dwMaxSubkeyLen++;
667 dwMaxValueLen++;
668 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
669
670 /* Allocate the name buffer */
671 pszName = HeapAlloc(GetProcessHeap(), 0, dwMaxLen * sizeof(WCHAR));
672 if (pszName == NULL)
673 {
674 dwError = ERROR_NOT_ENOUGH_MEMORY;
675 goto done;
676 }
677
678 /* Recursively delete all the subkeys */
679 while (TRUE)
680 {
681 dwSize = dwMaxLen;
682 if (RegEnumKeyExW(hSubKey, 0, pszName, &dwSize,
684 {
685 break;
686 }
687
688 dwError = ScmDeleteRegKey(hSubKey, pszName);
689 if (dwError != ERROR_SUCCESS)
690 goto done;
691 }
692
693done:
694 if (pszName != NULL)
695 HeapFree(GetProcessHeap(), 0, pszName);
696
697 RegCloseKey(hSubKey);
698
699 /* Finally delete the key */
700 if (dwError == ERROR_SUCCESS)
701 dwError = RegDeleteKeyW(hKey, pszSubKey);
702
703 return dwError;
704}
DWORD ScmDeleteRegKey(_In_ HKEY hKey, _In_ PCWSTR pszSubKey)
Definition: config.c:646
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1239
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:3662
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define max(a, b)
Definition: svc.c:63

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

◆ ScmDeleteServiceRecord()

VOID ScmDeleteServiceRecord ( PSERVICE  lpService)

Definition at line 816 of file database.c.

817{
818 DPRINT("Deleting Service %S\n", lpService->lpServiceName);
819
820 /* Delete the display name */
821 if (lpService->lpDisplayName != NULL &&
822 lpService->lpDisplayName != lpService->lpServiceName)
823 HeapFree(GetProcessHeap(), 0, lpService->lpDisplayName);
824
825 /* Dereference the service image */
826 if (lpService->lpImage)
827 {
828 lpService->lpImage->dwImageRunCount--;
829
830 if (lpService->lpImage->dwImageRunCount == 0)
831 {
832 ScmRemoveServiceImage(lpService->lpImage);
833 lpService->lpImage = NULL;
834 }
835 }
836
837 /* Decrement the group reference counter */
838 ScmSetServiceGroup(lpService, NULL);
839
840 /* Release the SecurityDescriptor */
841 if (lpService->pSecurityDescriptor != NULL)
843
844 /* Remove the Service from the List */
846
847 DPRINT("Deleted Service %S\n", lpService->lpServiceName);
848
849 /* Delete the service record */
850 HeapFree(GetProcessHeap(), 0, lpService);
851
852 DPRINT("Done\n");
853}
VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage)
Definition: database.c:622
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
DWORD ScmSetServiceGroup(PSERVICE lpService, LPCWSTR lpGroupName)
Definition: groupdb.c:61
DWORD dwImageRunCount
Definition: services.h:51
PSECURITY_DESCRIPTOR pSecurityDescriptor
Definition: services.h:82

Referenced by ScmDeleteService().

◆ ScmDereferenceService()

DWORD ScmDereferenceService ( PSERVICE  lpService)

Definition at line 939 of file database.c.

940{
941 DWORD ref;
942
943 ASSERT(lpService->RefCount > 0);
944
945 ref = InterlockedDecrement(&lpService->RefCount);
946
947 if (ref == 0 && lpService->bDeleted &&
949 {
950 ScmDeleteService(lpService);
951 }
952 return ref;
953}
#define InterlockedDecrement
Definition: armddk.h:52
DWORD ScmDeleteService(PSERVICE lpService)
Definition: database.c:863
BOOL bDeleted
Definition: services.h:68
LONG RefCount
Definition: services.h:70
Definition: send.c:48

Referenced by RCloseServiceHandle(), RSetServiceStatus(), and ScmStopThread().

◆ ScmGenerateServiceTag()

DWORD ScmGenerateServiceTag ( PSERVICE  lpServiceRecord)

Definition at line 744 of file database.c.

745{
746 /* Check for an overflow */
747 if (ServiceTag == -1)
748 {
749 return ERROR_INVALID_DATA;
750 }
751
752 /* This is only valid for Win32 services */
753 if (!(lpServiceRecord->Status.dwServiceType & SERVICE_WIN32))
754 {
756 }
757
758 /* Increment the tag counter and set it */
759 ServiceTag = ServiceTag % 0xFFFFFFFF + 1;
760 lpServiceRecord->dwServiceTag = ServiceTag;
761
762 return ERROR_SUCCESS;
763}
static DWORD ServiceTag
Definition: database.c:34
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
DWORD dwServiceTag
Definition: services.h:78
#define ERROR_INVALID_DATA
Definition: winerror.h:116
#define SERVICE_WIN32
Definition: cmtypes.h:964

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmGetBootAndSystemDriverState()

VOID ScmGetBootAndSystemDriverState ( VOID  )

Definition at line 1384 of file database.c.

1385{
1386 PLIST_ENTRY ServiceEntry;
1387 PSERVICE CurrentService;
1388
1389 DPRINT("ScmGetBootAndSystemDriverState() called\n");
1390
1391 ServiceEntry = ServiceListHead.Flink;
1392 while (ServiceEntry != &ServiceListHead)
1393 {
1394 CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
1395
1396 if (CurrentService->dwStartType == SERVICE_BOOT_START ||
1397 CurrentService->dwStartType == SERVICE_SYSTEM_START)
1398 {
1399 /* Check driver */
1400 DPRINT(" Checking service: %S\n", CurrentService->lpServiceName);
1401
1402 ScmCheckDriver(CurrentService);
1403 }
1404
1405 ServiceEntry = ServiceEntry->Flink;
1406 }
1407
1408 DPRINT("ScmGetBootAndSystemDriverState() done\n");
1409}
static NTSTATUS ScmCheckDriver(PSERVICE Service)
Definition: database.c:1286
#define SERVICE_BOOT_START
Definition: cmtypes.h:975
#define SERVICE_SYSTEM_START
Definition: cmtypes.h:976

Referenced by wWinMain().

◆ ScmGetServiceEntryByDisplayName()

PSERVICE ScmGetServiceEntryByDisplayName ( LPCWSTR  lpDisplayName)

Definition at line 686 of file database.c.

687{
688 PLIST_ENTRY ServiceEntry;
689 PSERVICE CurrentService;
690
691 DPRINT("ScmGetServiceEntryByDisplayName() called\n");
692
693 ServiceEntry = ServiceListHead.Flink;
694 while (ServiceEntry != &ServiceListHead)
695 {
696 CurrentService = CONTAINING_RECORD(ServiceEntry,
697 SERVICE,
698 ServiceListEntry);
699 if (_wcsicmp(CurrentService->lpDisplayName, lpDisplayName) == 0)
700 {
701 DPRINT("Found service: '%S'\n", CurrentService->lpDisplayName);
702 return CurrentService;
703 }
704
705 ServiceEntry = ServiceEntry->Flink;
706 }
707
708 DPRINT("Couldn't find a matching service\n");
709
710 return NULL;
711}
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_In_ LPCSTR _Out_writes_to_opt_ cchDisplayName LPSTR lpDisplayName
Definition: winbase.h:2790

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

◆ ScmGetServiceEntryByName()

PSERVICE ScmGetServiceEntryByName ( LPCWSTR  lpServiceName)

Definition at line 657 of file database.c.

658{
659 PLIST_ENTRY ServiceEntry;
660 PSERVICE CurrentService;
661
662 DPRINT("ScmGetServiceEntryByName() called\n");
663
664 ServiceEntry = ServiceListHead.Flink;
665 while (ServiceEntry != &ServiceListHead)
666 {
667 CurrentService = CONTAINING_RECORD(ServiceEntry,
668 SERVICE,
669 ServiceListEntry);
670 if (_wcsicmp(CurrentService->lpServiceName, lpServiceName) == 0)
671 {
672 DPRINT("Found service: '%S'\n", CurrentService->lpServiceName);
673 return CurrentService;
674 }
675
676 ServiceEntry = ServiceEntry->Flink;
677 }
678
679 DPRINT("Couldn't find a matching service\n");
680
681 return NULL;
682}

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

◆ ScmGetServiceEntryByResumeCount()

PSERVICE ScmGetServiceEntryByResumeCount ( DWORD  dwResumeCount)

Definition at line 715 of file database.c.

716{
717 PLIST_ENTRY ServiceEntry;
718 PSERVICE CurrentService;
719
720 DPRINT("ScmGetServiceEntryByResumeCount() called\n");
721
722 ServiceEntry = ServiceListHead.Flink;
723 while (ServiceEntry != &ServiceListHead)
724 {
725 CurrentService = CONTAINING_RECORD(ServiceEntry,
726 SERVICE,
727 ServiceListEntry);
728 if (CurrentService->dwResumeCount > dwResumeCount)
729 {
730 DPRINT("Found service: '%S'\n", CurrentService->lpDisplayName);
731 return CurrentService;
732 }
733
734 ServiceEntry = ServiceEntry->Flink;
735 }
736
737 DPRINT("Couldn't find a matching service\n");
738
739 return NULL;
740}

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}

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 373 of file security.c.

374{
375 DWORD dwError;
376
377 dwError = ScmCreateSids();
378 if (dwError != ERROR_SUCCESS)
379 return dwError;
380
381 dwError = ScmCreateAcls();
382 if (dwError != ERROR_SUCCESS)
383 return dwError;
384
385 dwError = ScmCreateDefaultSD();
386 if (dwError != ERROR_SUCCESS)
387 return dwError;
388
389 dwError = ScmCreatePipeSD();
390 if (dwError != ERROR_SUCCESS)
391 return dwError;
392
393 return ERROR_SUCCESS;
394}
static DWORD ScmCreatePipeSD(VOID)
Definition: security.c:271
static DWORD ScmCreateSids(VOID)
Definition: security.c:55
static DWORD ScmCreateAcls(VOID)
Definition: security.c:127
static DWORD ScmCreateDefaultSD(VOID)
Definition: security.c:214

Referenced by wWinMain().

◆ ScmInitNamedPipeCriticalSection()

VOID ScmInitNamedPipeCriticalSection ( VOID  )

Definition at line 2335 of file database.c.

2336{
2337 HKEY hKey;
2338 DWORD dwKeySize;
2339 DWORD dwError;
2340
2342
2344 L"SYSTEM\\CurrentControlSet\\Control",
2345 0,
2346 KEY_READ,
2347 &hKey);
2348 if (dwError == ERROR_SUCCESS)
2349 {
2350 dwKeySize = sizeof(PipeTimeout);
2352 L"ServicesPipeTimeout",
2353 0,
2354 NULL,
2356 &dwKeySize);
2358 }
2359}
static DWORD PipeTimeout
Definition: database.c:38
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751

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}

Referenced by CreateServiceListEntry().

◆ ScmLockDatabaseExclusive()

◆ ScmLockDatabaseShared()

◆ ScmLogEvent()

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

Definition at line 174 of file services.c.

178{
179 HANDLE hLog;
180
182 L"Service Control Manager");
183 if (hLog == NULL)
184 {
185 DPRINT1("ScmLogEvent: RegisterEventSourceW failed %lu\n", GetLastError());
186 return;
187 }
188
189 if (!ReportEventW(hLog,
190 wType,
191 0,
192 dwEventId,
193 NULL,
194 wStrings,
195 0,
196 lpStrings,
197 NULL))
198 {
199 DPRINT1("ScmLogEvent: ReportEventW failed %lu\n", GetLastError());
200 }
201
203}
static HANDLE hLog
Definition: misc.cpp:13
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
HANDLE WINAPI RegisterEventSourceW(IN LPCWSTR lpUNCServerName, IN LPCWSTR lpSourceName)
Definition: eventlog.c:1295
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by RControlService(), RSetServiceStatus(), ScmLoadService(), ScmStopThread(), 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}
DWORD ScmOpenServiceKey(LPWSTR lpServiceName, REGSAM samDesired, PHKEY phKey)
Definition: config.c:42
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:4882
#define KEY_WRITE
Definition: nt_native.h:1031
#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,
56 if (dwError != ERROR_SUCCESS)
57 return dwError;
58
60 lpServiceName,
61 0,
62 samDesired,
63 phKey);
64
66
67 return dwError;
68}

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}
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
BOOL ScmLockDatabaseShared(VOID)
Definition: database.c:2321
uint32_t ULONG_PTR
Definition: typedefs.h:65
struct _QUERY_SERVICE_LOCK_STATUSA QUERY_SERVICE_LOCK_STATUSA
char * LPSTR
Definition: xmlstorage.h:182

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}
struct _QUERY_SERVICE_LOCK_STATUSW QUERY_SERVICE_LOCK_STATUSW
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}
DWORD ScmReadString(HKEY hServiceKey, LPCWSTR lpValueName, LPWSTR *lpValue)
Definition: config.c:270
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define SC_GROUP_IDENTIFIERW
Definition: winsvc.h:12

Referenced by RQueryServiceConfigA(), and RQueryServiceConfigW().

◆ ScmReadSecurityDescriptor()

DWORD ScmReadSecurityDescriptor ( _In_ HKEY  hServiceKey,
_Out_ PSECURITY_DESCRIPTOR ppSecurityDescriptor 
)

Definition at line 566 of file config.c.

569{
570 PSECURITY_DESCRIPTOR pRelativeSD = NULL;
571 HKEY hSecurityKey = NULL;
572 DWORD dwBufferLength = 0;
573 DWORD dwType;
574 DWORD dwError;
575
576 DPRINT("ScmReadSecurityDescriptor(%p %p)\n", hServiceKey, ppSecurityDescriptor);
577
578 *ppSecurityDescriptor = NULL;
579
580 dwError = RegOpenKeyExW(hServiceKey,
581 L"Security",
582 0,
584 &hSecurityKey);
585 if (dwError != ERROR_SUCCESS)
586 {
587 DPRINT("RegOpenKeyExW() failed (Error %lu)\n", dwError);
588
589 /* Do not fail if the Security key does not exist */
590 if (dwError == ERROR_FILE_NOT_FOUND)
591 dwError = ERROR_SUCCESS;
592 goto done;
593 }
594
595 dwError = RegQueryValueExW(hSecurityKey,
596 L"Security",
597 0,
598 &dwType,
599 NULL,
600 &dwBufferLength);
601 if (dwError != ERROR_SUCCESS)
602 {
603 DPRINT("RegQueryValueExW() failed (Error %lu)\n", dwError);
604
605 /* Do not fail if the Security value does not exist */
606 if (dwError == ERROR_FILE_NOT_FOUND)
607 dwError = ERROR_SUCCESS;
608 goto done;
609 }
610
611 DPRINT("dwBufferLength: %lu\n", dwBufferLength);
612 pRelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
614 dwBufferLength);
615 if (pRelativeSD == NULL)
616 {
617 return ERROR_OUTOFMEMORY;
618 }
619
620 DPRINT("pRelativeSD: %lu\n", pRelativeSD);
621 dwError = RegQueryValueExW(hSecurityKey,
622 L"Security",
623 0,
624 &dwType,
625 (LPBYTE)pRelativeSD,
626 &dwBufferLength);
627 if (dwError != ERROR_SUCCESS)
628 {
629 goto done;
630 }
631
632 *ppSecurityDescriptor = pRelativeSD;
633
634done:
635 if (dwError != ERROR_SUCCESS && pRelativeSD != NULL)
636 RtlFreeHeap(RtlGetProcessHeap(), 0, pRelativeSD);
637
638 if (hSecurityKey != NULL)
639 RegCloseKey(hSecurityKey);
640
641 return dwError;
642}
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016

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 {
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
338 }
339 else
340 {
341 *lpValue = ptr;
342 }
343
344 return dwError;
345}
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static PVOID ptr
Definition: dispmode.c:27
#define REG_EXPAND_SZ
Definition: nt_native.h:1494

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

◆ ScmReferenceService()

DWORD ScmReferenceService ( PSERVICE  lpService)

Definition at line 931 of file database.c.

932{
933 return InterlockedIncrement(&lpService->RefCount);
934}
#define InterlockedIncrement
Definition: armddk.h:53

Referenced by RCreateServiceW(), ROpenServiceW(), RSetServiceStatus(), and ScmLoadService().

◆ 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) &&
101 {
104 *lpLock = NULL;
105
106 dwError = ERROR_SUCCESS;
107 }
108 else
109 {
111 }
112
113 /* Unlock the service database */
115
116 return dwError;
117}
struct _START_LOCK * PSTART_LOCK
#define ERROR_INVALID_SERVICE_LOCK
Definition: winerror.h:622

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

◆ ScmRemoveServiceImage()

VOID ScmRemoveServiceImage ( PSERVICE_IMAGE  pServiceImage)

Definition at line 622 of file database.c.

623{
624 DPRINT1("ScmRemoveServiceImage() called\n");
625
626 /* FIXME: Terminate the process */
627
628 /* Remove the service image from the list */
629 RemoveEntryList(&pServiceImage->ImageListEntry);
630
631 /* Close the process handle */
632 if (pServiceImage->hProcess != INVALID_HANDLE_VALUE)
633 CloseHandle(pServiceImage->hProcess);
634
635 /* Close the control pipe */
636 if (pServiceImage->hControlPipe != INVALID_HANDLE_VALUE)
637 CloseHandle(pServiceImage->hControlPipe);
638
639 /* Unload the user profile */
640 if (pServiceImage->hProfile != NULL)
641 {
643 UnloadUserProfile(pServiceImage->hToken, pServiceImage->hProfile);
645 }
646
647 /* Close the logon token */
648 if (pServiceImage->hToken != NULL)
649 CloseHandle(pServiceImage->hToken);
650
651 /* Release the service image */
652 HeapFree(GetProcessHeap(), 0, pServiceImage);
653}
static BOOL ScmEnableBackupRestorePrivileges(_In_ HANDLE hToken, _In_ BOOL bEnable)
Definition: database.c:312
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI UnloadUserProfile(_In_ HANDLE hToken, _In_ HANDLE hProfile)
Definition: profile.c:2184
LIST_ENTRY ImageListEntry
Definition: services.h:48
HANDLE hProfile
Definition: services.h:57
HANDLE hToken
Definition: services.h:56
HANDLE hProcess
Definition: services.h:54

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

◆ ScmRunLastKnownGood()

DWORD ScmRunLastKnownGood ( VOID  )

Definition at line 402 of file controlset.c.

403{
404 DPRINT("ScmRunLastKnownGood()\n");
405
406 if (bBootAccepted)
407 {
408 DPRINT1("Boot has already been accepted\n");
410 }
411
412 /* FIXME */
413
414 return ERROR_SUCCESS;
415}

Referenced by RNotifyBootConfigStatus().

◆ 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}
struct _SERVICE_GROUP * PSERVICE_GROUP
struct _SERVICE_GROUP SERVICE_GROUP
DWORD dwRefCount
Definition: services.h:37
WCHAR szGroupName[1]
Definition: services.h:42
LIST_ENTRY GroupListEntry
Definition: services.h:34

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;
478 DWORD dwError = ERROR_SUCCESS;
479 SIZE_T ServiceNameLength;
480
482
483 ServiceNameLength = wcslen(pszServiceName);
484 if (ServiceNameLength > (UNICODE_STRING_MAX_CHARS - 4))
485 {
487 }
488
492 &PolicyHandle);
493 if (!NT_SUCCESS(Status))
495
496 ServiceName.Length = ((USHORT)ServiceNameLength + 4) * sizeof(WCHAR);
497 ServiceName.MaximumLength = ServiceName.Length + sizeof(WCHAR);
500 ServiceName.MaximumLength);
501 if (ServiceName.Buffer == NULL)
503
504 wcscpy(ServiceName.Buffer, L"_SC_");
505 wcscat(ServiceName.Buffer, pszServiceName);
506
507 RtlInitUnicodeString(&Password, pszPassword);
508
509 Status = LsaStorePrivateData(PolicyHandle,
511 pszPassword ? &Password : NULL);
512 if (!NT_SUCCESS(Status))
513 {
514 dwError = RtlNtStatusToDosError(Status);
515 goto done;
516 }
517
518done:
519 if (ServiceName.Buffer != NULL)
520 HeapFree(GetProcessHeap(), 0, ServiceName.Buffer);
521
522 if (PolicyHandle != NULL)
523 LsaClose(PolicyHandle);
524
525 return dwError;
526}
static WCHAR ServiceName[]
Definition: browser.c:19
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
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:1183
NTSTATUS WINAPI LsaStorePrivateData(IN LSA_HANDLE PolicyHandle, IN PLSA_UNICODE_STRING KeyName, IN PLSA_UNICODE_STRING PrivateData OPTIONAL)
Definition: lsa.c:2209
NTSTATUS WINAPI LsaClose(IN LSA_HANDLE ObjectHandle)
Definition: lsa.c:194
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define UNICODE_STRING_MAX_CHARS
#define POLICY_CREATE_SECRET
Definition: ntsecapi.h:66
unsigned short USHORT
Definition: pedump.c:61
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
@ Password
Definition: telnetd.h:65

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmShutdownSecurity()

VOID ScmShutdownSecurity ( VOID  )

Definition at line 398 of file security.c.

399{
402 ScmFreeAcls();
403 ScmFreeSids();
404}
static VOID ScmFreePipeSD(VOID)
Definition: security.c:312
static VOID ScmFreeAcls(VOID)
Definition: security.c:199
static VOID ScmFreeDefaultSD(VOID)
Definition: security.c:262
static VOID ScmFreeSids(VOID)
Definition: security.c:34

Referenced by wWinMain().

◆ ScmShutdownServiceDatabase()

VOID ScmShutdownServiceDatabase ( VOID  )

Definition at line 1274 of file database.c.

1275{
1276 DPRINT("ScmShutdownServiceDatabase() called\n");
1277
1280
1281 DPRINT("ScmShutdownServiceDatabase() done\n");
1282}
NTSYSAPI VOID NTAPI RtlDeleteResource(_In_ PRTL_RESOURCE Resource)

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}
static DWORD ScmLoadDriver(PSERVICE lpService)
Definition: driver.c:24
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28

Referenced by ScmLoadService().

◆ ScmStartRpcServer()

VOID ScmStartRpcServer ( VOID  )

Definition at line 107 of file rpcserver.c.

108{
110
111 DPRINT("ScmStartRpcServer() called\n");
112
113 Status = RpcServerUseProtseqEpW(L"ncacn_np",
114 10,
115 L"\\pipe\\ntsvcs",
116 NULL);
117 if (Status != RPC_S_OK)
118 {
119 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status);
120 return;
121 }
122
123 Status = RpcServerRegisterIf(svcctl_v2_0_s_ifspec,
124 NULL,
125 NULL);
126 if (Status != RPC_S_OK)
127 {
128 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status);
129 return;
130 }
131
132 Status = RpcServerListen(1, 20, TRUE);
133 if (Status != RPC_S_OK)
134 {
135 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status);
136 return;
137 }
138
139 DPRINT("ScmStartRpcServer() done\n");
140}
RPC_STATUS WINAPI RpcServerListen(UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait)
Definition: rpc_server.c:1520
RPC_STATUS WINAPI RpcServerRegisterIf(RPC_IF_HANDLE IfSpec, UUID *MgrTypeUuid, RPC_MGR_EPV *MgrEpv)
Definition: rpc_server.c:1116
RPC_STATUS WINAPI RpcServerUseProtseqEpW(RPC_WSTR Protseq, UINT MaxCalls, RPC_WSTR Endpoint, LPVOID SecurityDescriptor)
Definition: rpc_server.c:927
#define RPC_S_OK
Definition: rpcnterr.h:22
long RPC_STATUS
Definition: rpc.h:52

Referenced by wWinMain().

◆ ScmStartService()

DWORD ScmStartService ( PSERVICE  Service,
DWORD  argc,
const PCWSTR argv 
)

Definition at line 2024 of file database.c.

2027{
2028 DWORD dwError = ERROR_SUCCESS;
2030
2031 DPRINT("ScmStartService() called\n");
2032 DPRINT("Start Service %p (%S)\n", Service, Service->lpServiceName);
2033
2034 /* Acquire the service control critical section, to synchronize starts */
2036
2037 /*
2038 * Acquire the user service start lock while the service is starting, if
2039 * needed (i.e. if we are not starting it during the initialization phase).
2040 * If we don't success, bail out.
2041 */
2042 if (!ScmInitialize)
2043 {
2045 if (dwError != ERROR_SUCCESS)
2046 goto done;
2047 }
2048
2049 /* Really start the service */
2050 dwError = ScmLoadService(Service, argc, argv);
2051
2052 /* Release the service start lock, if needed, and the critical section */
2054
2055done:
2057
2058 DPRINT("ScmStartService() done (Error %lu)\n", dwError);
2059
2060 return dwError;
2061}
static int argc
Definition: ServiceArgs.c:12
DWORD ScmAcquireServiceStartLock(IN BOOL IsServiceController, OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:31
DWORD ScmReleaseServiceStartLock(IN OUT LPSC_RPC_LOCK lpLock)
Definition: lock.c:82
#define argv
Definition: mplay32.c:18
@ Service
Definition: ntsecapi.h:292
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWAITLOCK * Lock
Definition: wdfsync.h:127

Referenced by RStartServiceA(), and RStartServiceW().

◆ ScmUnlockDatabase()

◆ ScmWaitForLsa()

VOID ScmWaitForLsa ( VOID  )

Definition at line 207 of file services.c.

208{
209 HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, L"LSA_RPC_SERVER_ACTIVE");
210 if (hEvent == NULL)
211 {
212 DPRINT1("Failed to create or open the notification event (Error %lu)\n", GetLastError());
213 }
214 else
215 {
216 DPRINT("Wait for the LSA server\n");
218 DPRINT("LSA server running\n");
220 }
221
222 DPRINT("ScmWaitForLsa() done\n");
223}
#define INFINITE
Definition: serial.h:102
static HANDLE hEvent
Definition: comm.c:54
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651

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,
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,
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}
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
#define REG_MULTI_SZ
Definition: nt_native.h:1501
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmWriteSecurityDescriptor()

DWORD ScmWriteSecurityDescriptor ( _In_ HKEY  hServiceKey,
_In_ PSECURITY_DESCRIPTOR  pSecurityDescriptor 
)

Definition at line 530 of file config.c.

533{
534 HKEY hSecurityKey = NULL;
535 DWORD dwDisposition;
536 DWORD dwError;
537
538 DPRINT("ScmWriteSecurityDescriptor(%p %p)\n", hServiceKey, pSecurityDescriptor);
539
540 dwError = RegCreateKeyExW(hServiceKey,
541 L"Security",
542 0,
543 NULL,
546 NULL,
547 &hSecurityKey,
548 &dwDisposition);
549 if (dwError != ERROR_SUCCESS)
550 return dwError;
551
552 dwError = RegSetValueExW(hSecurityKey,
553 L"Security",
554 0,
556 (LPBYTE)pSecurityDescriptor,
557 RtlLengthSecurityDescriptor(pSecurityDescriptor));
558
559 RegCloseKey(hSecurityKey);
560
561 return dwError;
562}
NTSYSAPI ULONG WINAPI RtlLengthSecurityDescriptor(PSECURITY_DESCRIPTOR)
#define REG_BINARY
Definition: nt_native.h:1496
#define KEY_SET_VALUE
Definition: nt_native.h:1017

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

◆ SetSecurityServicesEvent()

DWORD SetSecurityServicesEvent ( VOID  )

Definition at line 142 of file services.c.

143{
144 DWORD dwError;
145
147 return ERROR_SUCCESS;
148
149 /* Create or open the SECURITY_SERVICES_STARTED event */
151 TRUE,
152 FALSE,
153 L"SECURITY_SERVICES_STARTED");
155 {
156 dwError = GetLastError();
157 if (dwError != ERROR_ALREADY_EXISTS)
158 return dwError;
159
161 FALSE,
162 L"SECURITY_SERVICES_STARTED");
164 return GetLastError();
165 }
166
168
169 return ERROR_SUCCESS;
170}
static HANDLE hScmSecurityServicesEvent
Definition: services.c:33
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:682
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define EVENT_MODIFY_STATE
Definition: winbase.h:163

Referenced by ScmCreateOrReferenceServiceImage().

Variable Documentation

◆ GroupListHead

◆ ImageListHead

LIST_ENTRY ImageListHead
extern

◆ pPipeSD

PSECURITY_DESCRIPTOR pPipeSD
extern

Definition at line 27 of file security.c.

Referenced by ScmCreateNewControlPipe(), ScmCreatePipeSD(), and ScmFreePipeSD().

◆ ScmInitialize

BOOL ScmInitialize
extern

Definition at line 28 of file services.c.

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

◆ ScmLiveSetup

BOOL ScmLiveSetup
extern

Definition at line 30 of file services.c.

Referenced by CheckForLiveCD(), and ScmLogonService().

◆ ScmSetupInProgress

BOOL ScmSetupInProgress
extern

Definition at line 31 of file services.c.

Referenced by CheckForLiveCD(), and ScmLogonService().

◆ ScmShutdown

◆ ServiceListHead