https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a9b9800b1766b9301ea6…
commit 1a9b9800b1766b9301ea68d3dc5b882200c8f931
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sun Dec 30 14:09:54 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Sun Dec 30 14:27:04 2018 +0100
[SERVICES] Implement ScmGenerateServiceTag and call it on service creation
This allows assigning an unique ServiceTag to each Win32 service
---
base/system/services/database.c | 26 ++++++++++++++++++++++++++
base/system/services/rpcserver.c | 4 ++++
base/system/services/services.h | 2 ++
3 files changed, 32 insertions(+)
diff --git a/base/system/services/database.c b/base/system/services/database.c
index be6290bef6..26172a7a94 100644
--- a/base/system/services/database.c
+++ b/base/system/services/database.c
@@ -31,6 +31,7 @@ LIST_ENTRY ServiceListHead;
static RTL_RESOURCE DatabaseLock;
static DWORD ResumeCount = 1;
static DWORD NoInteractiveServices = 0;
+static DWORD ServiceTag = 0;
/* The critical section synchronizes service control requests */
static CRITICAL_SECTION ControlServiceCriticalSection;
@@ -634,6 +635,29 @@ ScmGetServiceEntryByResumeCount(DWORD dwResumeCount)
}
+DWORD
+ScmGenerateServiceTag(PSERVICE lpServiceRecord)
+{
+ /* Check for an overflow */
+ if (ServiceTag == -1)
+ {
+ return ERROR_INVALID_DATA;
+ }
+
+ /* This is only valid for Win32 services */
+ if (!(lpServiceRecord->Status.dwServiceType & SERVICE_WIN32))
+ {
+ return ERROR_INVALID_PARAMETER;
+ }
+
+ /* Increment the tag counter and set it */
+ ServiceTag = ServiceTag % 0xFFFFFFFF + 1;
+ lpServiceRecord->dwTag = ServiceTag;
+
+ return ERROR_SUCCESS;
+}
+
+
DWORD
ScmCreateNewServiceRecord(LPCWSTR lpServiceName,
PSERVICE *lpServiceRecord,
@@ -847,6 +871,8 @@ CreateServiceListEntry(LPCWSTR lpServiceName,
if (ScmIsDeleteFlagSet(hServiceKey))
lpService->bDeleted = TRUE;
+ else
+ ScmGenerateServiceTag(lpService);
if (lpService->Status.dwServiceType & SERVICE_WIN32)
{
diff --git a/base/system/services/rpcserver.c b/base/system/services/rpcserver.c
index b11db5ae0e..83d83dd9c9 100644
--- a/base/system/services/rpcserver.c
+++ b/base/system/services/rpcserver.c
@@ -2636,6 +2636,10 @@ RCreateServiceW(
goto done;
lpService->dwRefCount = 1;
+
+ /* Get the service tag (if Win32) */
+ ScmGenerateServiceTag(lpService);
+
DPRINT("CreateService - lpService->dwRefCount %u\n",
lpService->dwRefCount);
done:
diff --git a/base/system/services/services.h b/base/system/services/services.h
index 4e6f1f1810..9297c7ce99 100644
--- a/base/system/services/services.h
+++ b/base/system/services/services.h
@@ -200,6 +200,8 @@ 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);
+
/* driver.c */
DWORD ScmStartDriver(PSERVICE lpService);