mirror of
https://github.com/reactos/reactos.git
synced 2025-04-22 13:10:39 +00:00
Get SeRestorePrivilege before calling RegLoadKey
svn path=/trunk/; revision=31180
This commit is contained in:
parent
1468b24275
commit
c44ef93398
1 changed files with 81 additions and 4 deletions
|
@ -1,6 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* ReactOS kernel
|
* ReactOS kernel
|
||||||
* Copyright (C) 2004 ReactOS Team
|
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -16,13 +15,13 @@
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
/* $Id$
|
/*
|
||||||
*
|
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/userenv/profile.c
|
* FILE: lib/userenv/profile.c
|
||||||
* PURPOSE: User profile code
|
* PURPOSE: User profile code
|
||||||
* PROGRAMMER: Eric Kohl
|
* PROGRAMMERS: Eric Kohl
|
||||||
|
* Hervé Poussineau
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <precomp.h>
|
#include <precomp.h>
|
||||||
|
@ -101,6 +100,67 @@ CreateUserProfileA (PSID Sid,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static BOOL
|
||||||
|
AcquireRemoveRestorePrivilege(
|
||||||
|
IN BOOL bAcquire)
|
||||||
|
{
|
||||||
|
HANDLE Process;
|
||||||
|
HANDLE Token;
|
||||||
|
PTOKEN_PRIVILEGES TokenPriv;
|
||||||
|
BOOL bRet;
|
||||||
|
|
||||||
|
DPRINT("AcquireRemoveRestorePrivilege(%d)\n", bAcquire);
|
||||||
|
|
||||||
|
Process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
|
||||||
|
if (!Process)
|
||||||
|
{
|
||||||
|
DPRINT1("OpenProcess() failed with error %lu\n", GetLastError());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
bRet = OpenProcessToken(Process, TOKEN_ADJUST_PRIVILEGES, &Token);
|
||||||
|
CloseHandle(Process);
|
||||||
|
if (!bRet)
|
||||||
|
{
|
||||||
|
DPRINT1("OpenProcessToken() failed with error %lu\n", GetLastError());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
TokenPriv = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(TOKEN_PRIVILEGES, Privileges) + sizeof(LUID_AND_ATTRIBUTES));
|
||||||
|
if (!TokenPriv)
|
||||||
|
{
|
||||||
|
DPRINT1("Failed to allocate mem for token privileges\n");
|
||||||
|
CloseHandle(Token);
|
||||||
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
TokenPriv->PrivilegeCount = 1;
|
||||||
|
TokenPriv->Privileges[0].Attributes = bAcquire ? SE_PRIVILEGE_ENABLED : 0;
|
||||||
|
if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &TokenPriv->Privileges[0].Luid))
|
||||||
|
{
|
||||||
|
DPRINT1("LookupPrivilegeValue() failed with error %lu\n", GetLastError());
|
||||||
|
HeapFree(GetProcessHeap(), 0, TokenPriv);
|
||||||
|
CloseHandle(Token);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
bRet = AdjustTokenPrivileges(
|
||||||
|
Token,
|
||||||
|
FALSE,
|
||||||
|
TokenPriv,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL);
|
||||||
|
HeapFree(GetProcessHeap(), 0, TokenPriv);
|
||||||
|
CloseHandle(Token);
|
||||||
|
|
||||||
|
if (!bRet)
|
||||||
|
{
|
||||||
|
DPRINT1("AdjustTokenPrivileges() failed with error %lu\n", GetLastError());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BOOL WINAPI
|
BOOL WINAPI
|
||||||
CreateUserProfileW (PSID Sid,
|
CreateUserProfileW (PSID Sid,
|
||||||
LPCWSTR lpUserName)
|
LPCWSTR lpUserName)
|
||||||
|
@ -285,10 +345,19 @@ CreateUserProfileW (PSID Sid,
|
||||||
wcscpy (szBuffer, szUserProfilePath);
|
wcscpy (szBuffer, szUserProfilePath);
|
||||||
wcscat (szBuffer, L"\\ntuser.dat");
|
wcscat (szBuffer, L"\\ntuser.dat");
|
||||||
|
|
||||||
|
/* Acquire restore privilege */
|
||||||
|
if (!AcquireRemoveRestorePrivilege(TRUE))
|
||||||
|
{
|
||||||
|
DPRINT1("Error: %lu\n", Error);
|
||||||
|
LocalFree ((HLOCAL)SidString);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Create new user hive */
|
/* Create new user hive */
|
||||||
Error = RegLoadKeyW (HKEY_USERS,
|
Error = RegLoadKeyW (HKEY_USERS,
|
||||||
SidString,
|
SidString,
|
||||||
szBuffer);
|
szBuffer);
|
||||||
|
AcquireRemoveRestorePrivilege(FALSE);
|
||||||
if (Error != ERROR_SUCCESS)
|
if (Error != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DPRINT1("Error: %lu\n", Error);
|
DPRINT1("Error: %lu\n", Error);
|
||||||
|
@ -967,10 +1036,18 @@ LoadUserProfileW(
|
||||||
}
|
}
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
|
|
||||||
|
/* Acquire restore privilege */
|
||||||
|
if (!AcquireRemoveRestorePrivilege(TRUE))
|
||||||
|
{
|
||||||
|
DPRINT1("AcquireRemoveRestorePrivilege() failed (Error %ld)\n", GetLastError());
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/* Load user registry hive */
|
/* Load user registry hive */
|
||||||
Error = RegLoadKeyW(HKEY_USERS,
|
Error = RegLoadKeyW(HKEY_USERS,
|
||||||
SidString.Buffer,
|
SidString.Buffer,
|
||||||
szUserHivePath);
|
szUserHivePath);
|
||||||
|
AcquireRemoveRestorePrivilege(FALSE);
|
||||||
if (Error != ERROR_SUCCESS)
|
if (Error != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
DPRINT1("RegLoadKeyW() failed (Error %ld)\n", Error);
|
DPRINT1("RegLoadKeyW() failed (Error %ld)\n", Error);
|
||||||
|
|
Loading…
Reference in a new issue