From e03efb63b2b6e78b4318041d4da2a1021020dfdc Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sat, 8 May 2010 16:30:56 +0000 Subject: [PATCH] [WINLOGON] - Move environment creation to a separate file. - Impersonate the new user and create the 'Volatile Environment' key for the new user. svn path=/trunk/; revision=47129 --- reactos/base/system/winlogon/environment.c | 129 +++++++++++++++++++ reactos/base/system/winlogon/sas.c | 51 +------- reactos/base/system/winlogon/winlogon.h | 6 + reactos/base/system/winlogon/winlogon.rbuild | 1 + 4 files changed, 138 insertions(+), 49 deletions(-) create mode 100644 reactos/base/system/winlogon/environment.c diff --git a/reactos/base/system/winlogon/environment.c b/reactos/base/system/winlogon/environment.c new file mode 100644 index 00000000000..f0beeba90bd --- /dev/null +++ b/reactos/base/system/winlogon/environment.c @@ -0,0 +1,129 @@ +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS Winlogon + * FILE: base/system/winlogon/environment.c + * PURPOSE: User environment routines + * PROGRAMMERS: Thomas Weidenmueller (w3seek@users.sourceforge.net) + * Hervé Poussineau (hpoussin@reactos.org) + * Eric Kohl + */ + +/* INCLUDES *****************************************************************/ + +#include "winlogon.h" + +#include + +WINE_DEFAULT_DEBUG_CHANNEL(winlogon); + +/* GLOBALS ******************************************************************/ + + +/* FUNCTIONS ****************************************************************/ + +BOOL +CreateUserEnvironment(IN PWLSESSION Session, + IN LPVOID *lpEnvironment, + IN LPWSTR *lpFullEnv) +{ + LPCWSTR wstr; + SIZE_T EnvBlockSize = 0, ProfileSize = 0; + LPVOID lpEnviron = NULL; + LPWSTR lpFullEnviron = NULL; + HKEY hKey; + DWORD dwDisp; + LONG lError; + HKEY hKeyCurrentUser; + + TRACE("WL: CreateUserEnvironment called\n"); + + /* Create environment block for the user */ + if (!CreateEnvironmentBlock(&lpEnviron, + Session->UserToken, + TRUE)) + { + WARN("WL: CreateEnvironmentBlock() failed\n"); + return FALSE; + } + + if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 && Session->Profile->pszEnvironment) + { + /* Count required size for full environment */ + wstr = (LPCWSTR)lpEnviron; + while (*wstr != UNICODE_NULL) + { + SIZE_T size = wcslen(wstr) + 1; + wstr += size; + EnvBlockSize += size; + } + + wstr = Session->Profile->pszEnvironment; + while (*wstr != UNICODE_NULL) + { + SIZE_T size = wcslen(wstr) + 1; + wstr += size; + ProfileSize += size; + } + + /* Allocate enough memory */ + lpFullEnviron = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) * sizeof(WCHAR)); + if (!lpFullEnviron) + { + TRACE("HeapAlloc() failed\n"); + return FALSE; + } + + /* Fill user environment block */ + CopyMemory(lpFullEnviron, + lpEnviron, + EnvBlockSize * sizeof(WCHAR)); + CopyMemory(&lpFullEnviron[EnvBlockSize], + Session->Profile->pszEnvironment, + ProfileSize * sizeof(WCHAR)); + lpFullEnviron[EnvBlockSize + ProfileSize] = UNICODE_NULL; + } + else + { + lpFullEnviron = (LPWSTR)lpEnviron; + } + + /* Impersonate the new user */ + ImpersonateLoggedOnUser(Session->UserToken); + + /* Open the new users HKCU key */ + lError = RegOpenCurrentUser(KEY_CREATE_SUB_KEY, + &hKeyCurrentUser); + if (lError == ERROR_SUCCESS) + { + /* Create the 'Volatile Environment' key */ + lError = RegCreateKeyExW(hKeyCurrentUser, + L"Volatile Environment", + 0, + NULL, + REG_OPTION_VOLATILE, + KEY_WRITE, + NULL, + &hKey, + &dwDisp); + if (lError == ERROR_SUCCESS) + { + RegCloseKey(hKey); + } + else + { + WARN("WL: RegCreateKeyExW() failed (Error: %ld)\n", lError); + } + + RegCloseKey(hKeyCurrentUser); + } + + /* Revert the impersonation */ + RevertToSelf(); + + *lpEnvironment = lpEnviron; + *lpFullEnv = lpFullEnviron; + + TRACE("WL: CreateUserEnvironment done\n"); + + return TRUE; +} diff --git a/reactos/base/system/winlogon/sas.c b/reactos/base/system/winlogon/sas.c index f560187d702..baecf988a73 100644 --- a/reactos/base/system/winlogon/sas.c +++ b/reactos/base/system/winlogon/sas.c @@ -171,8 +171,6 @@ HandleLogon( PROFILEINFOW ProfileInfo; LPVOID lpEnvironment = NULL; LPWSTR lpFullEnv = NULL; - LPCWSTR wstr; - SIZE_T EnvBlockSize = 0, ProfileSize = 0; BOOLEAN Old; BOOL ret = FALSE; @@ -210,57 +208,12 @@ HandleLogon( } /* Create environment block for the user */ - if (!CreateEnvironmentBlock( - &lpEnvironment, - Session->UserToken, - TRUE)) + if (!CreateUserEnvironment(Session, &lpEnvironment, &lpFullEnv)) { - WARN("WL: CreateEnvironmentBlock() failed\n"); + WARN("WL: SetUserEnvironment() failed\n"); goto cleanup; } - if (Session->Profile->dwType == WLX_PROFILE_TYPE_V2_0 && Session->Profile->pszEnvironment) - { - /* Count required size for full environment */ - wstr = (LPCWSTR)lpEnvironment; - while (*wstr != UNICODE_NULL) - { - SIZE_T size = wcslen(wstr) + 1; - wstr += size; - EnvBlockSize += size; - } - wstr = Session->Profile->pszEnvironment; - while (*wstr != UNICODE_NULL) - { - SIZE_T size = wcslen(wstr) + 1; - wstr += size; - ProfileSize += size; - } - - /* Allocate enough memory */ - lpFullEnv = HeapAlloc(GetProcessHeap, 0, (EnvBlockSize + ProfileSize + 1) * sizeof(WCHAR)); - if (!lpFullEnv) - { - TRACE("HeapAlloc() failed\n"); - goto cleanup; - } - - /* Fill user environment block */ - CopyMemory( - lpFullEnv, - lpEnvironment, - EnvBlockSize * sizeof(WCHAR)); - CopyMemory( - &lpFullEnv[EnvBlockSize], - Session->Profile->pszEnvironment, - ProfileSize * sizeof(WCHAR)); - lpFullEnv[EnvBlockSize + ProfileSize] = UNICODE_NULL; - } - else - { - lpFullEnv = (LPWSTR)lpEnvironment; - } - DisplayStatusMessage(Session, Session->WinlogonDesktop, IDS_APPLYINGYOURPERSONALSETTINGS); UpdatePerUserSystemParameters(0, TRUE); diff --git a/reactos/base/system/winlogon/winlogon.h b/reactos/base/system/winlogon/winlogon.h index 2df4e3aec03..c03bf697925 100644 --- a/reactos/base/system/winlogon/winlogon.h +++ b/reactos/base/system/winlogon/winlogon.h @@ -180,6 +180,12 @@ BOOL WINAPI UpdatePerUserSystemParameters(DWORD dwUnknown, DWORD dwReserved); +/* environment.c */ +BOOL +CreateUserEnvironment(IN PWLSESSION Session, + IN LPVOID *lpEnvironment, + IN LPWSTR *lpFullEnv); + /* sas.c */ BOOL SetDefaultLanguage( diff --git a/reactos/base/system/winlogon/winlogon.rbuild b/reactos/base/system/winlogon/winlogon.rbuild index 6a75ed19015..cc5b2a33ddc 100644 --- a/reactos/base/system/winlogon/winlogon.rbuild +++ b/reactos/base/system/winlogon/winlogon.rbuild @@ -8,6 +8,7 @@ advapi32 userenv secur32 + environment.c sas.c screensaver.c setup.c