From 473a15261d5655a27cc7687609b01c6f53d7a4bb Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Thu, 5 Jul 2012 20:47:18 +0000 Subject: [PATCH] [REGEDIT] - Improve permission acquirement for loading/unloading hives. Patch by Hermes Belusca See issue #7159 for more details. svn path=/trunk/; revision=56835 --- reactos/base/applications/regedit/framewnd.c | 26 +++++--------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/reactos/base/applications/regedit/framewnd.c b/reactos/base/applications/regedit/framewnd.c index 57f67210b41..088052ca826 100644 --- a/reactos/base/applications/regedit/framewnd.c +++ b/reactos/base/applications/regedit/framewnd.c @@ -330,12 +330,10 @@ static BOOL EnablePrivilege(LPCTSTR lpszPrivilegeName, LPCTSTR lpszSystemName, B lpszPrivilegeName, &tp.Privileges[0].Luid)) { - bRet = AdjustTokenPrivileges(hToken, - FALSE, - &tp, - sizeof(tp), - NULL, - NULL); + bRet = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL); + + if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) + bRet = FALSE; } CloseHandle(hToken); @@ -374,16 +372,10 @@ static BOOL LoadHive(HWND hWnd) { LONG regLoadResult; - /* Enable the required privileges */ - EnablePrivilege(SE_BACKUP_NAME, NULL, TRUE); + /* Enable the 'restore' privilege, load the hive, disable the privilege */ EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE); - - /* Load the hive */ regLoadResult = RegLoadKey(hRootKey, xPath, ofn.lpstrFile); - - /* Disable the privileges */ EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE); - EnablePrivilege(SE_BACKUP_NAME, NULL, FALSE); if(regLoadResult == ERROR_SUCCESS) { @@ -418,16 +410,10 @@ static BOOL UnloadHive(HWND hWnd) /* load and set the caption and flags for dialog */ LoadString(hInst, IDS_UNLOAD_HIVE, Caption, COUNT_OF(Caption)); - /* Enable the required privileges */ - EnablePrivilege(SE_BACKUP_NAME, NULL, TRUE); + /* Enable the 'restore' privilege, unload the hive, disable the privilege */ EnablePrivilege(SE_RESTORE_NAME, NULL, TRUE); - - /* Unload the hive */ regUnloadResult = RegUnLoadKey(hRootKey, pszKeyPath); - - /* Disable the privileges */ EnablePrivilege(SE_RESTORE_NAME, NULL, FALSE); - EnablePrivilege(SE_BACKUP_NAME, NULL, FALSE); if(regUnloadResult == ERROR_SUCCESS) {