ReactOS  0.4.14-dev-115-g4576127
lock.c File Reference
#include "services.h"
#include <time.h>
#include <debug.h>
Include dependency graph for lock.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

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)
 

Variables

static PSTART_LOCK pServiceStartLock = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file lock.c.

Function Documentation

◆ 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:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ERROR_SERVICE_DATABASE_LOCKED
Definition: winerror.h:606
struct _SID * PSID
Definition: eventlog.c:35
PSID LockOwnerSid
Definition: services.h: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().

◆ 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().

◆ 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:395
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:394

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

Variable Documentation

◆ pServiceStartLock