From ac0d3797dd972a256bd3c22adb11b9aee2af9f35 Mon Sep 17 00:00:00 2001 From: Thomas Bluemel Date: Thu, 12 Jan 2006 18:05:35 +0000 Subject: [PATCH] implemented EnterCriticalPolicySection() and LeaveCriticalPolicySection() svn path=/trunk/; revision=20808 --- reactos/lib/userenv/gpolicy.c | 56 +++++++++++++++++++++++++++++++++ reactos/lib/userenv/userenv.def | 2 ++ 2 files changed, 58 insertions(+) diff --git a/reactos/lib/userenv/gpolicy.c b/reactos/lib/userenv/gpolicy.c index a2d31221758..2d9396412ab 100644 --- a/reactos/lib/userenv/gpolicy.c +++ b/reactos/lib/userenv/gpolicy.c @@ -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; +} diff --git a/reactos/lib/userenv/userenv.def b/reactos/lib/userenv/userenv.def index f47a5e04d73..e01e4fa0792 100644 --- a/reactos/lib/userenv/userenv.def +++ b/reactos/lib/userenv/userenv.def @@ -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 -- 2.17.1