[MSIEXEC] Sync with Wine Staging 2.16. CORE-13762
[reactos.git] / base / system / services / groupdb.c
index fdd40fd..b64b59f 100644 (file)
@@ -14,7 +14,6 @@
 #define NDEBUG
 #include <debug.h>
 
-
 /* GLOBALS *******************************************************************/
 
 LIST_ENTRY GroupListHead;
@@ -23,6 +22,41 @@ LIST_ENTRY UnknownGroupListHead;
 
 /* FUNCTIONS *****************************************************************/
 
+PSERVICE_GROUP
+ScmGetServiceGroupByName(
+    _In_ LPCWSTR lpGroupName)
+{
+    PLIST_ENTRY GroupEntry;
+    PSERVICE_GROUP lpGroup;
+
+    DPRINT("ScmGetServiceGroupByName(%S)\n", lpGroupName);
+
+    GroupEntry = GroupListHead.Flink;
+    while (GroupEntry != &GroupListHead)
+    {
+        lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
+
+        if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
+            return lpGroup;
+
+        GroupEntry = GroupEntry->Flink;
+    }
+
+    GroupEntry = UnknownGroupListHead.Flink;
+    while (GroupEntry != &UnknownGroupListHead)
+    {
+        lpGroup = CONTAINING_RECORD(GroupEntry, SERVICE_GROUP, GroupListEntry);
+
+        if (!_wcsicmp(lpGroup->lpGroupName, lpGroupName))
+            return lpGroup;
+
+        GroupEntry = GroupEntry->Flink;
+    }
+
+    return NULL;
+}
+
+
 DWORD
 ScmSetServiceGroup(PSERVICE lpService,
                    LPCWSTR lpGroupName)
@@ -34,11 +68,26 @@ ScmSetServiceGroup(PSERVICE lpService,
 
     if (lpService->lpGroup != NULL)
     {
-        lpService->lpGroup->dwRefCount--;
-
-        /* FIXME: What do we have to do when dwRefCount is 0? */
+        ASSERT(lpService->lpGroup->dwRefCount != 0);
+        ASSERT(lpService->lpGroup->dwRefCount == (DWORD)-1 ||
+               lpService->lpGroup->dwRefCount < 10000);
+        if (lpService->lpGroup->dwRefCount != (DWORD)-1)
+        {
+            lpService->lpGroup->dwRefCount--;
+            if (lpService->lpGroup->dwRefCount == 0)
+            {
+                ASSERT(lpService->lpGroup->TagCount == 0);
+                ASSERT(lpService->lpGroup->TagArray == NULL);
+                RemoveEntryList(&lpService->lpGroup->GroupListEntry);
+                HeapFree(GetProcessHeap(), 0, lpService->lpGroup);
+                lpService->lpGroup = NULL;
+            }
+        }
     }
 
+    if (lpGroupName == NULL)
+        return ERROR_SUCCESS;
+
     GroupEntry = GroupListHead.Flink;
     while (GroupEntry != &GroupListHead)
     {
@@ -96,7 +145,7 @@ CreateGroupOrderListRoutine(PWSTR ValueName,
 {
     PSERVICE_GROUP Group;
 
-    DPRINT("CreateGroupOrderListRoutine(%S, %x, %x, %x, %x, %x)\n",
+    DPRINT("CreateGroupOrderListRoutine(%S, %x, %p, %x, %p, %p)\n",
            ValueName, ValueType, ValueData, ValueLength, Context, EntryContext);
 
     if (ValueType == REG_BINARY &&
@@ -172,7 +221,7 @@ CreateGroupListRoutine(PWSTR ValueName,
                                         QueryTable,
                                         (PVOID)Group,
                                         NULL);
-        DPRINT("%x %d %S\n", Status, Group->TagCount, (PWSTR)ValueData);
+        DPRINT("%x %lu %S\n", Status, Group->TagCount, (PWSTR)ValueData);
 
         InsertTailList(&GroupListHead,
                        &Group->GroupListEntry);