ReactOS  0.4.14-dev-608-gd495a4f
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_ 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, 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,...)
 
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
 
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 87 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 37 of file services.c.

38 {
39 #if DBG
40  CHAR buffer[512];
41  va_list ap;
42 
43  va_start(ap, fmt);
44  vsprintf(buffer, fmt, ap);
45  va_end(ap);
46 
48 #endif
49 }
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

◆ ScmAcceptBoot()

DWORD ScmAcceptBoot ( VOID  )

Definition at line 674 of file controlset.c.

675 {
676  DWORD dwCurrentControlSet, dwDefaultControlSet;
677  DWORD dwFailedControlSet, dwLastKnownGoodControlSet;
678  DWORD dwNewControlSet;
679  DWORD dwError;
680 
681  DPRINT("ScmAcceptBoot()\n");
682 
683  if (bBootAccepted)
684  {
685  DPRINT1("Boot has alread been accepted!\n");
687  }
688 
689  /* Get the control set values */
690  dwError = ScmGetControlSetValues(&dwCurrentControlSet,
691  &dwDefaultControlSet,
692  &dwFailedControlSet,
693  &dwLastKnownGoodControlSet);
694  if (dwError != ERROR_SUCCESS)
695  return dwError;
696 
697  /* Search for a new control set number */
698  for (dwNewControlSet = 1; dwNewControlSet < 1000; dwNewControlSet++)
699  {
700  if ((dwNewControlSet != dwCurrentControlSet) &&
701  (dwNewControlSet != dwDefaultControlSet) &&
702  (dwNewControlSet != dwFailedControlSet) &&
703  (dwNewControlSet != dwLastKnownGoodControlSet))
704  break;
705  }
706 
707  /* Fail if we did not find an unused control set!*/
708  if (dwNewControlSet >= 1000)
709  {
710  DPRINT1("Too many control sets!\n");
711  return ERROR_NO_MORE_ITEMS;
712  }
713 
714  /* Copy the current control set */
715  dwError = ScmCopyControlSet(dwCurrentControlSet,
716  dwNewControlSet);
717  if (dwError != ERROR_SUCCESS)
718  return dwError;
719 
720  /* Delete the current last known good contol set, if it is not used anywhere else */
721  if ((dwLastKnownGoodControlSet != dwCurrentControlSet) &&
722  (dwLastKnownGoodControlSet != dwDefaultControlSet) &&
723  (dwLastKnownGoodControlSet != dwFailedControlSet))
724  {
725  ScmDeleteControlSet(dwLastKnownGoodControlSet);
726  }
727 
728  /* Set the new 'LastKnownGood' control set */
729  dwError = ScmSetLastKnownGoodControlSet(dwNewControlSet);
730  if (dwError != ERROR_SUCCESS)
731  return dwError;
732 
734 
735  return ERROR_SUCCESS;
736 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
static BOOL bBootAccepted
Definition: controlset.c:20
static DWORD ScmCopyControlSet(DWORD dwSourceControlSet, DWORD dwDestinationControlSet)
Definition: controlset.c:506
static DWORD ScmSetLastKnownGoodControlSet(DWORD dwControlSet)
Definition: controlset.c:440
void DPRINT(...)
Definition: polytest.cpp:61
#define ERROR_BOOT_ALREADY_ACCEPTED
Definition: winerror.h:627
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD ScmDeleteControlSet(DWORD dwControlSet)
Definition: controlset.c:574
#define DPRINT1
Definition: precomp.h:8
static DWORD ScmGetControlSetValues(PDWORD pdwCurrentControlSet, PDWORD pdwDefaultControlSet, PDWORD pdwFailedControlSet, PDWORD pdwLastKnownGoodControlSet)
Definition: controlset.c:357

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 
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:2420
#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:403
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:93
DWORD TimeWhenLocked
Definition: services.h:92
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2434
#define LOCK_TAG
Definition: services.h:87
DWORD Tag
Definition: services.h:91

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

◆ ScmAutoShutdownServices()

VOID ScmAutoShutdownServices ( VOID  )

Definition at line 2382 of file database.c.

2383 {
2384  PLIST_ENTRY ServiceEntry;
2385  PSERVICE CurrentService;
2386 
2387  DPRINT("ScmAutoShutdownServices() called\n");
2388 
2389  /* Lock the service database exclusively */
2391 
2392  ServiceEntry = ServiceListHead.Flink;
2393  while (ServiceEntry != &ServiceListHead)
2394  {
2395  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2396 
2397  if ((CurrentService->Status.dwControlsAccepted & SERVICE_ACCEPT_SHUTDOWN) &&
2398  (CurrentService->Status.dwCurrentState == SERVICE_RUNNING ||
2399  CurrentService->Status.dwCurrentState == SERVICE_START_PENDING))
2400  {
2401  /* Send the shutdown notification */
2402  DPRINT("Shutdown service: %S\n", CurrentService->lpServiceName);
2403  ScmControlService(CurrentService->lpImage->hControlPipe,
2404  CurrentService->lpServiceName,
2405  (SERVICE_STATUS_HANDLE)CurrentService,
2407  }
2408 
2409  ServiceEntry = ServiceEntry->Flink;
2410  }
2411 
2412  /* Unlock the service database */
2414 
2415  DPRINT("ScmAutoShutdownServices() done\n");
2416 }
SERVICE_STATUS Status
Definition: services.h:70
DWORD dwCurrentState
Definition: winsvc.h:100
BOOL ScmLockDatabaseExclusive(VOID)
Definition: database.c:2420
#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:62
Definition: typedefs.h:117
DWORD dwControlsAccepted
Definition: winsvc.h:101
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2434
PSERVICE_IMAGE lpImage
Definition: services.h:65
DWORD ScmControlService(HANDLE hControlPipe, PWSTR pServiceName, SERVICE_STATUS_HANDLE hServiceStatus, DWORD dwControl)
Definition: database.c:1314
HANDLE hControlPipe
Definition: services.h:51
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

Referenced by ShutdownHandlerRoutine().

◆ ScmAutoStartServices()

VOID ScmAutoStartServices ( VOID  )

Definition at line 2171 of file database.c.

2172 {
2173  DWORD dwError;
2174  PLIST_ENTRY GroupEntry;
2175  PLIST_ENTRY ServiceEntry;
2176  PSERVICE_GROUP CurrentGroup;
2177  PSERVICE CurrentService;
2178  WCHAR szSafeBootServicePath[MAX_PATH];
2179  DWORD SafeBootEnabled;
2180  HKEY hKey;
2181  DWORD dwKeySize;
2182  ULONG i;
2183 
2184  /*
2185  * This function MUST be called ONLY at initialization time.
2186  * Therefore, no need to acquire the user service start lock.
2187  */
2189 
2190  /* Retrieve the SafeBoot parameter */
2192  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option",
2193  0,
2194  KEY_READ,
2195  &hKey);
2196  if (dwError == ERROR_SUCCESS)
2197  {
2198  dwKeySize = sizeof(SafeBootEnabled);
2199  dwError = RegQueryValueExW(hKey,
2200  L"OptionValue",
2201  0,
2202  NULL,
2203  (LPBYTE)&SafeBootEnabled,
2204  &dwKeySize);
2205  RegCloseKey(hKey);
2206  }
2207 
2208  /* Default to Normal boot if the value doesn't exist */
2209  if (dwError != ERROR_SUCCESS)
2210  SafeBootEnabled = 0;
2211 
2212  /* Acquire the service control critical section, to synchronize starts */
2214 
2215  /* Clear 'ServiceVisited' flag (or set if not to start in Safe Mode) */
2216  ServiceEntry = ServiceListHead.Flink;
2217  while (ServiceEntry != &ServiceListHead)
2218  {
2219  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2220 
2221  /* Build the safe boot path */
2222  StringCchCopyW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2223  L"SYSTEM\\CurrentControlSet\\Control\\SafeBoot");
2224 
2225  switch (SafeBootEnabled)
2226  {
2227  /* NOTE: Assumes MINIMAL (1) and DSREPAIR (3) load same items */
2228  case 1:
2229  case 3:
2230  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2231  L"\\Minimal\\");
2232  break;
2233 
2234  case 2:
2235  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2236  L"\\Network\\");
2237  break;
2238  }
2239 
2240  if (SafeBootEnabled != 0)
2241  {
2242  /* If key does not exist then do not assume safe mode */
2244  szSafeBootServicePath,
2245  0,
2246  KEY_READ,
2247  &hKey);
2248  if (dwError == ERROR_SUCCESS)
2249  {
2250  RegCloseKey(hKey);
2251 
2252  /* Finish Safe Boot path off */
2253  StringCchCatW(szSafeBootServicePath, ARRAYSIZE(szSafeBootServicePath),
2254  CurrentService->lpServiceName);
2255 
2256  /* Check that the key is in the Safe Boot path */
2258  szSafeBootServicePath,
2259  0,
2260  KEY_READ,
2261  &hKey);
2262  if (dwError != ERROR_SUCCESS)
2263  {
2264  /* Mark service as visited so it is not auto-started */
2265  CurrentService->ServiceVisited = TRUE;
2266  }
2267  else
2268  {
2269  /* Must be auto-started in safe mode - mark as unvisited */
2270  RegCloseKey(hKey);
2271  CurrentService->ServiceVisited = FALSE;
2272  }
2273  }
2274  else
2275  {
2276  DPRINT1("WARNING: Could not open the associated Safe Boot key!");
2277  CurrentService->ServiceVisited = FALSE;
2278  }
2279  }
2280 
2281  ServiceEntry = ServiceEntry->Flink;
2282  }
2283 
2284  /* Start all services which are members of an existing group */
2285  GroupEntry = GroupListHead.Flink;
2286  while (GroupEntry != &GroupListHead)
2287  {
2288  CurrentGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
2289 
2290  DPRINT("Group '%S'\n", CurrentGroup->lpGroupName);
2291 
2292  /* Start all services witch have a valid tag */
2293  for (i = 0; i < CurrentGroup->TagCount; i++)
2294  {
2295  ServiceEntry = ServiceListHead.Flink;
2296  while (ServiceEntry != &ServiceListHead)
2297  {
2298  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2299 
2300  if ((CurrentService->lpGroup == CurrentGroup) &&
2301  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2302  (CurrentService->ServiceVisited == FALSE) &&
2303  (CurrentService->dwTag == CurrentGroup->TagArray[i]))
2304  {
2305  CurrentService->ServiceVisited = TRUE;
2306  ScmLoadService(CurrentService, 0, NULL);
2307  }
2308 
2309  ServiceEntry = ServiceEntry->Flink;
2310  }
2311  }
2312 
2313  /* Start all services which have an invalid tag or which do not have a tag */
2314  ServiceEntry = ServiceListHead.Flink;
2315  while (ServiceEntry != &ServiceListHead)
2316  {
2317  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2318 
2319  if ((CurrentService->lpGroup == CurrentGroup) &&
2320  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2321  (CurrentService->ServiceVisited == FALSE))
2322  {
2323  CurrentService->ServiceVisited = TRUE;
2324  ScmLoadService(CurrentService, 0, NULL);
2325  }
2326 
2327  ServiceEntry = ServiceEntry->Flink;
2328  }
2329 
2330  GroupEntry = GroupEntry->Flink;
2331  }
2332 
2333  /* Start all services which are members of any non-existing group */
2334  ServiceEntry = ServiceListHead.Flink;
2335  while (ServiceEntry != &ServiceListHead)
2336  {
2337  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2338 
2339  if ((CurrentService->lpGroup != NULL) &&
2340  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2341  (CurrentService->ServiceVisited == FALSE))
2342  {
2343  CurrentService->ServiceVisited = TRUE;
2344  ScmLoadService(CurrentService, 0, NULL);
2345  }
2346 
2347  ServiceEntry = ServiceEntry->Flink;
2348  }
2349 
2350  /* Start all services which are not a member of any group */
2351  ServiceEntry = ServiceListHead.Flink;
2352  while (ServiceEntry != &ServiceListHead)
2353  {
2354  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2355 
2356  if ((CurrentService->lpGroup == NULL) &&
2357  (CurrentService->dwStartType == SERVICE_AUTO_START) &&
2358  (CurrentService->ServiceVisited == FALSE))
2359  {
2360  CurrentService->ServiceVisited = TRUE;
2361  ScmLoadService(CurrentService, 0, NULL);
2362  }
2363 
2364  ServiceEntry = ServiceEntry->Flink;
2365  }
2366 
2367  /* Clear 'ServiceVisited' flag again */
2368  ServiceEntry = ServiceListHead.Flink;
2369  while (ServiceEntry != &ServiceListHead)
2370  {
2371  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
2372  CurrentService->ServiceVisited = FALSE;
2373  ServiceEntry = ServiceEntry->Flink;
2374  }
2375 
2376  /* Release the critical section */
2378 }
#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:33
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
PSERVICE_GROUP lpGroup
Definition: services.h:64
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:2019
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__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:81
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpServiceName
Definition: services.h:62
Definition: typedefs.h:117
PULONG TagArray
Definition: services.h:38
DWORD dwStartType
Definition: services.h:71
ULONG TagCount
Definition: services.h:37
#define DPRINT1
Definition: precomp.h:8
DWORD dwTag
Definition: services.h:73
#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:3366
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:70
#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 1314 of file database.c.

1318 {
1319  PSCM_CONTROL_PACKET ControlPacket;
1320  SCM_REPLY_PACKET ReplyPacket;
1321 
1322  DWORD dwWriteCount = 0;
1323  DWORD dwReadCount = 0;
1324  DWORD PacketSize;
1325  PWSTR Ptr;
1326  DWORD dwError = ERROR_SUCCESS;
1327  BOOL bResult;
1328  OVERLAPPED Overlapped = {0};
1329 
1330  DPRINT("ScmControlService() called\n");
1331 
1332  /* Acquire the service control critical section, to synchronize requests */
1334 
1335  /* Calculate the total length of the start command line */
1336  PacketSize = sizeof(SCM_CONTROL_PACKET);
1337  PacketSize += (DWORD)((wcslen(pServiceName) + 1) * sizeof(WCHAR));
1338 
1339  ControlPacket = HeapAlloc(GetProcessHeap(),
1341  PacketSize);
1342  if (ControlPacket == NULL)
1343  {
1345  return ERROR_NOT_ENOUGH_MEMORY;
1346  }
1347 
1348  ControlPacket->dwSize = PacketSize;
1349  ControlPacket->dwControl = dwControl;
1350  ControlPacket->hServiceStatus = hServiceStatus;
1351 
1352  ControlPacket->dwServiceNameOffset = sizeof(SCM_CONTROL_PACKET);
1353 
1354  Ptr = (PWSTR)((PBYTE)ControlPacket + ControlPacket->dwServiceNameOffset);
1355  wcscpy(Ptr, pServiceName);
1356 
1357  ControlPacket->dwArgumentsCount = 0;
1358  ControlPacket->dwArgumentsOffset = 0;
1359 
1360  bResult = WriteFile(hControlPipe,
1361  ControlPacket,
1362  PacketSize,
1363  &dwWriteCount,
1364  &Overlapped);
1365  if (bResult == FALSE)
1366  {
1367  DPRINT("WriteFile() returned FALSE\n");
1368 
1369  dwError = GetLastError();
1370  if (dwError == ERROR_IO_PENDING)
1371  {
1372  DPRINT("dwError: ERROR_IO_PENDING\n");
1373 
1374  dwError = WaitForSingleObject(hControlPipe,
1375  PipeTimeout);
1376  DPRINT("WaitForSingleObject() returned %lu\n", dwError);
1377 
1378  if (dwError == WAIT_TIMEOUT)
1379  {
1380  bResult = CancelIo(hControlPipe);
1381  if (bResult == FALSE)
1382  {
1383  DPRINT1("CancelIo() failed (Error: %lu)\n", GetLastError());
1384  }
1385 
1387  goto Done;
1388  }
1389  else if (dwError == WAIT_OBJECT_0)
1390  {
1391  bResult = GetOverlappedResult(hControlPipe,
1392  &Overlapped,
1393  &dwWriteCount,
1394  TRUE);
1395  if (bResult == FALSE)
1396  {
1397  dwError = GetLastError();
1398  DPRINT1("GetOverlappedResult() failed (Error %lu)\n", dwError);
1399 
1400  goto Done;
1401  }
1402  }
1403  }
1404  else
1405  {
1406  DPRINT1("WriteFile() failed (Error %lu)\n", dwError);
1407  goto Done;
1408  }
1409  }
1410 
1411  /* Read the reply */
1412  Overlapped.hEvent = (HANDLE) NULL;
1413 
1414  bResult = ReadFile(hControlPipe,
1415  &ReplyPacket,
1416  sizeof(SCM_REPLY_PACKET),
1417  &dwReadCount,
1418  &Overlapped);
1419  if (bResult == FALSE)
1420  {
1421  DPRINT("ReadFile() returned FALSE\n");
1422 
1423  dwError = GetLastError();
1424  if (dwError == ERROR_IO_PENDING)
1425  {
1426  DPRINT("dwError: ERROR_IO_PENDING\n");
1427 
1428  dwError = WaitForSingleObject(hControlPipe,
1429  PipeTimeout);
1430  DPRINT("WaitForSingleObject() returned %lu\n", dwError);
1431 
1432  if (dwError == WAIT_TIMEOUT)
1433  {
1434  bResult = CancelIo(hControlPipe);
1435  if (bResult == FALSE)
1436  {
1437  DPRINT1("CancelIo() failed (Error: %lu)\n", GetLastError());
1438  }
1439 
1441  goto Done;
1442  }
1443  else if (dwError == WAIT_OBJECT_0)
1444  {
1445  bResult = GetOverlappedResult(hControlPipe,
1446  &Overlapped,
1447  &dwReadCount,
1448  TRUE);
1449  if (bResult == FALSE)
1450  {
1451  dwError = GetLastError();
1452  DPRINT1("GetOverlappedResult() failed (Error %lu)\n", dwError);
1453 
1454  goto Done;
1455  }
1456  }
1457  }
1458  else
1459  {
1460  DPRINT1("ReadFile() failed (Error %lu)\n", dwError);
1461  goto Done;
1462  }
1463  }
1464 
1465 Done:
1466  /* Release the control packet */
1468  0,
1469  ControlPacket);
1470 
1471  if (dwReadCount == sizeof(SCM_REPLY_PACKET))
1472  {
1473  dwError = ReplyPacket.dwError;
1474  }
1475 
1477 
1478  DPRINT("ScmControlService() done\n");
1479 
1480  return dwError;
1481 }
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:403
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:402

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

◆ ScmCreateDefaultServiceSD()

DWORD ScmCreateDefaultServiceSD ( PSECURITY_DESCRIPTOR ppSecurityDescriptor)

Definition at line 319 of file security.c.

321 {
322  PSECURITY_DESCRIPTOR pRelativeSD = NULL;
323  DWORD dwBufferLength = 0;
325  DWORD dwError = ERROR_SUCCESS;
326 
327  /* Convert the absolute SD to a self-relative SD */
329  NULL,
330  &dwBufferLength);
332  {
333  dwError = RtlNtStatusToDosError(Status);
334  goto done;
335  }
336 
337  DPRINT("BufferLength %lu\n", dwBufferLength);
338 
339  pRelativeSD = RtlAllocateHeap(RtlGetProcessHeap(),
341  dwBufferLength);
342  if (pRelativeSD == NULL)
343  {
344  dwError = ERROR_OUTOFMEMORY;
345  goto done;
346  }
347  DPRINT("pRelativeSD %p\n", pRelativeSD);
348 
350  pRelativeSD,
351  &dwBufferLength);
352  if (!NT_SUCCESS(Status))
353  {
354  dwError = RtlNtStatusToDosError(Status);
355  goto done;
356  }
357 
358  *ppSecurityDescriptor = pRelativeSD;
359 
360 done:
361  if (dwError != ERROR_SUCCESS)
362  {
363  if (pRelativeSD != NULL)
364  RtlFreeHeap(RtlGetProcessHeap(), 0, pRelativeSD);
365  }
366 
367  return dwError;
368 }
#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:606
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
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:588
#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:26
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:4004
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 613 of file controlset.c.

614 {
615  DWORD dwCurrentControlSet, dwDefaultControlSet;
616  DWORD dwFailedControlSet, dwLastKnownGoodControlSet;
617  DWORD dwNewControlSet;
618  DWORD dwError;
619 
620  /* Get the control set values */
621  dwError = ScmGetControlSetValues(&dwCurrentControlSet,
622  &dwDefaultControlSet,
623  &dwFailedControlSet,
624  &dwLastKnownGoodControlSet);
625  if (dwError != ERROR_SUCCESS)
626  return dwError;
627 
628  /* First boot after setup? */
629  if ((ScmGetSetupInProgress() == 0) &&
630  (dwCurrentControlSet == dwLastKnownGoodControlSet))
631  {
632  DPRINT("First boot after setup!\n");
633 
634  /* Search for a new control set number */
635  for (dwNewControlSet = 1; dwNewControlSet < 1000; dwNewControlSet++)
636  {
637  if ((dwNewControlSet != dwCurrentControlSet) &&
638  (dwNewControlSet != dwDefaultControlSet) &&
639  (dwNewControlSet != dwFailedControlSet) &&
640  (dwNewControlSet != dwLastKnownGoodControlSet))
641  break;
642  }
643 
644  /* Fail if we did not find an unused control set!*/
645  if (dwNewControlSet >= 1000)
646  {
647  DPRINT1("Too many control sets!\n");
648  return ERROR_NO_MORE_ITEMS;
649  }
650 
651  /* Copy the current control set */
652  dwError = ScmCopyControlSet(dwCurrentControlSet,
653  dwNewControlSet);
654  if (dwError != ERROR_SUCCESS)
655  return dwError;
656 
657  /* Set the new 'LastKnownGood' control set */
658  dwError = ScmSetLastKnownGoodControlSet(dwNewControlSet);
659  if (dwError == ERROR_SUCCESS)
660  {
661  /*
662  * Accept the boot here in order to prevent the creation of
663  * another control set when a user is going to get logged on
664  */
666  }
667  }
668 
669  return dwError;
670 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
static DWORD ScmGetSetupInProgress(VOID)
Definition: controlset.c:470
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:95
static BOOL bBootAccepted
Definition: controlset.c:20
static DWORD ScmCopyControlSet(DWORD dwSourceControlSet, DWORD dwDestinationControlSet)
Definition: controlset.c:506
static DWORD ScmSetLastKnownGoodControlSet(DWORD dwControlSet)
Definition: controlset.c:440
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:357

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 }
SERVICE_STATUS Status
Definition: services.h:70
#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:63
#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:61
#define GetProcessHeap()
Definition: compat.h:403
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:67
LPWSTR lpServiceName
Definition: services.h:62
DWORD dwStartType
Definition: services.h:71
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:83
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmCreateServiceDatabase()

DWORD ScmCreateServiceDatabase ( VOID  )

Definition at line 1088 of file database.c.

1089 {
1090  WCHAR szSubKey[MAX_PATH];
1092  HKEY hServiceKey;
1093  DWORD dwSubKey;
1094  DWORD dwSubKeyLength;
1095  FILETIME ftLastChanged;
1096  DWORD dwError;
1097 
1098  DPRINT("ScmCreateServiceDatabase() called\n");
1099 
1100  /* Retrieve the NoInteractiveServies value */
1102 
1103  /* Create the service group list */
1104  dwError = ScmCreateGroupList();
1105  if (dwError != ERROR_SUCCESS)
1106  return dwError;
1107 
1108  /* Initialize image and service lists */
1111 
1112  /* Initialize the database lock */
1114 
1116  L"System\\CurrentControlSet\\Services",
1117  0,
1118  KEY_READ,
1119  &hServicesKey);
1120  if (dwError != ERROR_SUCCESS)
1121  return dwError;
1122 
1123  dwSubKey = 0;
1124  for (;;)
1125  {
1126  dwSubKeyLength = MAX_PATH;
1127  dwError = RegEnumKeyExW(hServicesKey,
1128  dwSubKey,
1129  szSubKey,
1130  &dwSubKeyLength,
1131  NULL,
1132  NULL,
1133  NULL,
1134  &ftLastChanged);
1135  if (dwError == ERROR_SUCCESS &&
1136  szSubKey[0] != L'{')
1137  {
1138  DPRINT("SubKeyName: '%S'\n", szSubKey);
1139 
1140  dwError = RegOpenKeyExW(hServicesKey,
1141  szSubKey,
1142  0,
1143  KEY_READ,
1144  &hServiceKey);
1145  if (dwError == ERROR_SUCCESS)
1146  {
1147  dwError = CreateServiceListEntry(szSubKey,
1148  hServiceKey);
1149 
1150  RegCloseKey(hServiceKey);
1151  }
1152  }
1153 
1154  if (dwError != ERROR_SUCCESS)
1155  break;
1156 
1157  dwSubKey++;
1158  }
1159 
1161 
1162  /* Wait for the LSA server */
1163  ScmWaitForLsa();
1164 
1165  /* Delete services that are marked for delete */
1167 
1168  DPRINT("ScmCreateServiceDatabase() done\n");
1169 
1170  return ERROR_SUCCESS;
1171 }
#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:118
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
static DWORD CreateServiceListEntry(LPCWSTR lpServiceName, HKEY hServiceKey)
Definition: database.c:857
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:3366
static VOID ScmGetNoInteractiveServicesValue(VOID)
Definition: database.c:1062
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:2527
DWORD ScmCreateGroupList(VOID)
Definition: groupdb.c:235
VOID ScmDeleteMarkedServices(VOID)
Definition: database.c:1021
#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:1091
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:3366
#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:69
smooth NULL
Definition: ftsmooth.c:416
PVOID pBuffer
#define GetProcessHeap()
Definition: compat.h:403
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:402
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmDeleteNamedPipeCriticalSection()

VOID ScmDeleteNamedPipeCriticalSection ( VOID  )

Definition at line 2469 of file database.c.

2470 {
2472 }
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:1237
#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:403
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:3686
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
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:2527
#define HeapFree(x, y, z)
Definition: compat.h:402
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

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

◆ 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)
842  HeapFree(GetProcessHeap(), 0, lpService->pSecurityDescriptor);
843 
844  /* Remove the Service from the List */
845  RemoveEntryList(&lpService->ServiceListEntry);
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 }
LPWSTR lpDisplayName
Definition: services.h:63
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
DWORD dwImageRunCount
Definition: services.h:49
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:61
#define GetProcessHeap()
Definition: compat.h:403
LPWSTR lpServiceName
Definition: services.h:62
PSECURITY_DESCRIPTOR pSecurityDescriptor
Definition: services.h:79
PSERVICE_IMAGE lpImage
Definition: services.h:65
#define HeapFree(x, y, z)
Definition: compat.h:402
VOID ScmRemoveServiceImage(PSERVICE_IMAGE pServiceImage)
Definition: database.c:622

Referenced by RCloseServiceHandle().

◆ 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->dwTag = ServiceTag;
761 
762  return ERROR_SUCCESS;
763 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
SERVICE_STATUS Status
Definition: services.h:70
#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:73
static DWORD ServiceTag
Definition: database.c:34

Referenced by CreateServiceListEntry(), and RCreateServiceW().

◆ ScmGetBootAndSystemDriverState()

VOID ScmGetBootAndSystemDriverState ( VOID  )

Definition at line 1285 of file database.c.

1286 {
1287  PLIST_ENTRY ServiceEntry;
1288  PSERVICE CurrentService;
1289 
1290  DPRINT("ScmGetBootAndSystemDriverState() called\n");
1291 
1292  ServiceEntry = ServiceListHead.Flink;
1293  while (ServiceEntry != &ServiceListHead)
1294  {
1295  CurrentService = CONTAINING_RECORD(ServiceEntry, SERVICE, ServiceListEntry);
1296 
1297  if (CurrentService->dwStartType == SERVICE_BOOT_START ||
1298  CurrentService->dwStartType == SERVICE_SYSTEM_START)
1299  {
1300  /* Check driver */
1301  DPRINT(" Checking service: %S\n", CurrentService->lpServiceName);
1302 
1303  ScmCheckDriver(CurrentService);
1304  }
1305 
1306  ServiceEntry = ServiceEntry->Flink;
1307  }
1308 
1309  DPRINT("ScmGetBootAndSystemDriverState() done\n");
1310 }
#define SERVICE_SYSTEM_START
Definition: cmtypes.h:974
static NTSTATUS ScmCheckDriver(PSERVICE Service)
Definition: database.c:1187
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:62
Definition: typedefs.h:117
DWORD dwStartType
Definition: services.h:71

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 }
LPWSTR lpDisplayName
Definition: services.h:63
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:2747
_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 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 }
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:62
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 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 }
LPWSTR lpDisplayName
Definition: services.h:63
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:67
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:33
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 372 of file security.c.

373 {
374  DWORD dwError;
375 
376  dwError = ScmCreateSids();
377  if (dwError != ERROR_SUCCESS)
378  return dwError;
379 
380  dwError = ScmCreateAcls();
381  if (dwError != ERROR_SUCCESS)
382  return dwError;
383 
384  dwError = ScmCreateDefaultSD();
385  if (dwError != ERROR_SUCCESS)
386  return dwError;
387 
388  dwError = ScmCreatePipeSD();
389  if (dwError != ERROR_SUCCESS)
390  return dwError;
391 
392  return ERROR_SUCCESS;
393 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static DWORD ScmCreatePipeSD(VOID)
Definition: security.c:270
static DWORD ScmCreateSids(VOID)
Definition: security.c:55
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD ScmCreateDefaultSD(VOID)
Definition: security.c:213
static DWORD ScmCreateAcls(VOID)
Definition: security.c:126

Referenced by wWinMain().

◆ ScmInitNamedPipeCriticalSection()

VOID ScmInitNamedPipeCriticalSection ( VOID  )

Definition at line 2441 of file database.c.

2442 {
2443  HKEY hKey;
2444  DWORD dwKeySize;
2445  DWORD dwError;
2446 
2448 
2450  L"SYSTEM\\CurrentControlSet\\Control",
2451  0,
2452  KEY_READ,
2453  &hKey);
2454  if (dwError == ERROR_SUCCESS)
2455  {
2456  dwKeySize = sizeof(PipeTimeout);
2457  RegQueryValueExW(hKey,
2458  L"ServicesPipeTimeout",
2459  0,
2460  NULL,
2461  (LPBYTE)&PipeTimeout,
2462  &dwKeySize);
2463  RegCloseKey(hKey);
2464  }
2465 }
#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:751
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:4116
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:3366
#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:4116
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 2420 of file database.c.

2421 {
2423 }
#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 2427 of file database.c.

2428 {
2430 }
#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 85 of file services.c.

89 {
90  HANDLE hLog;
91 
93  L"Service Control Manager");
94  if (hLog == NULL)
95  {
96  DPRINT1("ScmLogEvent: RegisterEventSourceW failed %lu\n", GetLastError());
97  return;
98  }
99 
100  if (!ReportEventW(hLog,
101  wType,
102  0,
103  dwEventId,
104  NULL,
105  wStrings,
106  0,
107  lpStrings,
108  NULL))
109  {
110  DPRINT1("ScmLogEvent: ReportEventW failed %lu\n", GetLastError());
111  }
112 
114 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
smooth NULL
Definition: ftsmooth.c:416
static HANDLE hLog
Definition: misc.cpp:14
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:4895
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
LPWSTR lpServiceName
Definition: services.h:62
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:3366
#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:2427
__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:92
struct _QUERY_SERVICE_LOCK_STATUSA QUERY_SERVICE_LOCK_STATUSA
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2434
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:2427
__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:92
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2434
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:403
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:402

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:606
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:588
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
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:3366
#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:403
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:4116
__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:402
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:2420
static PSTART_LOCK pServiceStartLock
Definition: lock.c:21
smooth NULL
Definition: ftsmooth.c:416
struct _START_LOCK * PSTART_LOCK
#define GetProcessHeap()
Definition: compat.h:403
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_INVALID_SERVICE_LOCK
Definition: winerror.h:622
VOID ScmUnlockDatabase(VOID)
Definition: database.c:2434
#define LOCK_TAG
Definition: services.h:87
DWORD Tag
Definition: services.h:91
#define HeapFree(x, y, z)
Definition: compat.h:402

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 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
HANDLE hToken
Definition: services.h:54
LIST_ENTRY ImageListEntry
Definition: services.h:46
static BOOL ScmEnableBackupRestorePrivileges(_In_ HANDLE hToken, _In_ BOOL bEnable)
Definition: database.c:312
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
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:403
HANDLE hProfile
Definition: services.h:55
#define DPRINT1
Definition: precomp.h:8
HANDLE hProcess
Definition: services.h:52
HANDLE hControlPipe
Definition: services.h:51
#define HeapFree(x, y, z)
Definition: compat.h:402

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

◆ ScmRunLastKnownGood()

DWORD ScmRunLastKnownGood ( VOID  )

Definition at line 740 of file controlset.c.

741 {
742  DPRINT("ScmRunLastKnownGood()\n");
743 
744  if (bBootAccepted)
745  {
746  DPRINT1("Boot has alread been accepted!\n");
748  }
749 
750  /* FIXME */
751 
752  return ERROR_SUCCESS;
753 }
#define ERROR_SUCCESS
Definition: deptool.c:10
static BOOL bBootAccepted
Definition: controlset.c:20
void DPRINT(...)
Definition: polytest.cpp:61
#define ERROR_BOOT_ALREADY_ACCEPTED
Definition: winerror.h:627
#define DPRINT1
Definition: precomp.h:8

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 }
#define ERROR_SUCCESS
Definition: deptool.c:10
LIST_ENTRY GroupListHead
Definition: groupdb.c:19
LPWSTR lpGroupName
Definition: services.h:33
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
PSERVICE_GROUP lpGroup
Definition: services.h:64
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
WCHAR szGroupName[1]
Definition: services.h:40
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:403
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:35
LIST_ENTRY GroupListEntry
Definition: services.h:32
PULONG TagArray
Definition: services.h:38
LIST_ENTRY UnknownGroupListHead
Definition: groupdb.c:20
ULONG TagCount
Definition: services.h:37
#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:402
_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:403
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:402

Referenced by RChangeServiceConfigW(), and RCreateServiceW().

◆ ScmShutdownSecurity()

VOID ScmShutdownSecurity ( VOID  )

Definition at line 397 of file security.c.

398 {
399  ScmFreePipeSD();
401  ScmFreeAcls();
402  ScmFreeSids();
403 }
static VOID ScmFreeAcls(VOID)
Definition: security.c:198
static VOID ScmFreePipeSD(VOID)
Definition: security.c:311
static VOID ScmFreeDefaultSD(VOID)
Definition: security.c:261
static VOID ScmFreeSids(VOID)
Definition: security.c:34

Referenced by wWinMain().

◆ ScmShutdownServiceDatabase()

VOID ScmShutdownServiceDatabase ( VOID  )

Definition at line 1175 of file database.c.

1176 {
1177  DPRINT("ScmShutdownServiceDatabase() called\n");
1178 
1181 
1182  DPRINT("ScmShutdownServiceDatabase() done\n");
1183 }
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:1021

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:1520
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:1116
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:927
#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 2131 of file database.c.

2134 {
2135  DWORD dwError = ERROR_SUCCESS;
2136  SC_RPC_LOCK Lock = NULL;
2137 
2138  DPRINT("ScmStartService() called\n");
2139  DPRINT("Start Service %p (%S)\n", Service, Service->lpServiceName);
2140 
2141  /* Acquire the service control critical section, to synchronize starts */
2143 
2144  /*
2145  * Acquire the user service start lock while the service is starting, if
2146  * needed (i.e. if we are not starting it during the initialization phase).
2147  * If we don't success, bail out.
2148  */
2149  if (!ScmInitialize)
2150  {
2151  dwError = ScmAcquireServiceStartLock(TRUE, &Lock);
2152  if (dwError != ERROR_SUCCESS) goto done;
2153  }
2154 
2155  /* Really start the service */
2156  dwError = ScmLoadService(Service, argc, argv);
2157 
2158  /* Release the service start lock, if needed, and the critical section */
2160 
2161 done:
2163 
2164  DPRINT("ScmStartService() done (Error %lu)\n", dwError);
2165 
2166  return dwError;
2167 }
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:2019
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 118 of file services.c.

119 {
120  HANDLE hEvent = CreateEventW(NULL, TRUE, FALSE, L"LSA_RPC_SERVER_ACTIVE");
121  if (hEvent == NULL)
122  {
123  DPRINT1("Failed to create or open the notification event (Error %lu)\n", GetLastError());
124  }
125  else
126  {
127  DPRINT("Wait for the LSA server!\n");
129  DPRINT("LSA server running!\n");
131  }
132 
133  DPRINT("ScmWaitForLsa() done\n");
134 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:406
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:651
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:4895
#define GetProcessHeap()
Definition: compat.h:403
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:2355
#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:402

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:1091
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:4895
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().

◆ SetSecurityServicesEvent()

DWORD SetSecurityServicesEvent ( VOID  )

Definition at line 53 of file services.c.

54 {
55  DWORD dwError;
56 
58  return ERROR_SUCCESS;
59 
60  /* Create or open the SECURITY_SERVICES_STARTED event */
62  TRUE,
63  FALSE,
64  L"SECURITY_SERVICES_STARTED");
66  {
67  dwError = GetLastError();
68  if (dwError != ERROR_ALREADY_EXISTS)
69  return dwError;
70 
72  FALSE,
73  L"SECURITY_SERVICES_STARTED");
75  return GetLastError();
76  }
77 
79 
80  return ERROR_SUCCESS;
81 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
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:651
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:682
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
static HANDLE hScmSecurityServicesEvent
Definition: services.c:31
#define EVENT_MODIFY_STATE
Definition: winbase.h:163
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80

Referenced by ScmCreateOrReferenceServiceImage().

Variable Documentation

◆ GroupListHead

◆ ImageListHead

◆ pPipeSD

Definition at line 27 of file security.c.

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

◆ ScmInitialize

BOOL ScmInitialize

Definition at line 28 of file services.c.

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

◆ ScmShutdown

◆ ServiceListHead