implemented EnterCriticalPolicySection() and LeaveCriticalPolicySection()
authorThomas Bluemel <thomas@reactsoft.com>
Thu, 12 Jan 2006 18:05:35 +0000 (18:05 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Thu, 12 Jan 2006 18:05:35 +0000 (18:05 +0000)
svn path=/trunk/; revision=20808

reactos/lib/userenv/gpolicy.c
reactos/lib/userenv/userenv.def

index a2d3122..2d93964 100644 (file)
@@ -44,7 +44,9 @@ typedef enum
 } GP_ACTION;
 
 static const WCHAR szLocalGPApplied[] = L"userenv: User Group Policy has been applied";
+static const WCHAR szLocalGPMutex[] = L"userenv: user policy mutex";
 static const WCHAR szMachineGPApplied[] = L"Global\\userenv: Machine Group Policy has been applied";
+static const WCHAR szMachineGPMutex[] = L"Global\\userenv: machine policy mutex";
 
 static CRITICAL_SECTION GPNotifyLock;
 static PGP_NOTIFY NotificationList = NULL;
@@ -409,3 +411,57 @@ UnregisterGPNotification(IN HANDLE hEvent)
 
     return Ret;
 }
+
+HANDLE WINAPI
+EnterCriticalPolicySection(IN BOOL bMachine)
+{
+    SECURITY_ATTRIBUTES SecurityAttributes;
+    PSECURITY_DESCRIPTOR lpSecurityDescriptor;
+    HANDLE hSection;
+
+    /* create or open the mutex */
+    lpSecurityDescriptor = CreateDefaultSecurityDescriptor();
+    if (lpSecurityDescriptor == NULL)
+    {
+        return NULL;
+    }
+
+    SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
+    SecurityAttributes.lpSecurityDescriptor = lpSecurityDescriptor;
+    SecurityAttributes.bInheritHandle = FALSE;
+
+    hSection = CreateMutexW(&SecurityAttributes,
+                            FALSE,
+                            (bMachine ? szMachineGPMutex : szLocalGPMutex));
+
+    if (hSection != NULL)
+    {
+        /* wait up to 10 seconds */
+        if (WaitForSingleObject(hSection,
+                                60000) != WAIT_FAILED)
+        {
+            return hSection;
+        }
+
+        CloseHandle(hSection);
+    }
+
+    return NULL;
+}
+
+BOOL WINAPI
+LeaveCriticalPolicySection(IN HANDLE hSection)
+{
+    BOOL Ret;
+
+    if (hSection == NULL)
+    {
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
+    Ret = ReleaseMutex(hSection);
+    CloseHandle(hSection);
+
+    return Ret;
+}
index f47a5e0..e01e4fa 100644 (file)
@@ -19,6 +19,7 @@ DeleteDesktopItemA@8 @115 NONAME
 DeleteDesktopItemW@8 @116 NONAME
 CreateEnvironmentBlock@12
 DestroyEnvironmentBlock@4
+EnterCriticalPolicySection@4
 ExpandEnvironmentStringsForUserA@16
 ExpandEnvironmentStringsForUserW@16
 GetAllUsersProfileDirectoryA@8
@@ -29,6 +30,7 @@ GetProfilesDirectoryA@8
 GetProfilesDirectoryW@8
 GetUserProfileDirectoryA@12
 GetUserProfileDirectoryW@12
+LeaveCriticalPolicySection@4
 LoadUserProfileA@8
 LoadUserProfileW@8
 RegisterGPNotification@8