Author: dchapyshev Date: Mon Aug 1 14:26:12 2016 New Revision: 72072
URL: http://svn.reactos.org/svn/reactos?rev=72072&view=rev Log: [USERENV] - Create separate function for setup session manager variables - Fixed a regression in msi package winetest after r72066
Modified: trunk/reactos/dll/win32/userenv/environment.c
Modified: trunk/reactos/dll/win32/userenv/environment.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/userenv/environme... ============================================================================== --- trunk/reactos/dll/win32/userenv/environment.c [iso-8859-1] (original) +++ trunk/reactos/dll/win32/userenv/environment.c [iso-8859-1] Mon Aug 1 14:26:12 2016 @@ -372,7 +372,7 @@ &dwValueDataLength); if (Error == ERROR_SUCCESS) { - if (!_wcsicmp (lpValueName, L"path")) + if (!_wcsicmp(lpValueName, L"path")) { /* Append 'Path' environment variable */ AppendUserEnvironmentVariable(lpEnvironment, @@ -406,6 +406,117 @@ }
+static +BOOL +SetSystemEnvironment(LPVOID *lpEnvironment) +{ + HKEY hEnvKey; + DWORD dwValues; + DWORD dwMaxValueNameLength; + DWORD dwMaxValueDataLength; + DWORD dwValueNameLength; + DWORD dwValueDataLength; + DWORD dwType; + DWORD i; + LPWSTR lpValueName; + LPWSTR lpValueData; + LONG Error; + + Error = RegOpenKeyExW(HKEY_LOCAL_MACHINE, + L"SYSTEM\CurrentControlSet\Control\Session Manager\Environment", + 0, + KEY_QUERY_VALUE, + &hEnvKey); + if (Error != ERROR_SUCCESS) + { + DPRINT1("RegOpenKeyExW() failed (Error %ld)\n", Error); + return FALSE; + } + + Error = RegQueryInfoKey(hEnvKey, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + &dwValues, + &dwMaxValueNameLength, + &dwMaxValueDataLength, + NULL, + NULL); + if (Error != ERROR_SUCCESS) + { + DPRINT1("RegQueryInforKey() failed (Error %ld)\n", Error); + RegCloseKey(hEnvKey); + return FALSE; + } + + if (dwValues == 0) + { + RegCloseKey(hEnvKey); + return TRUE; + } + + /* Allocate buffers */ + dwMaxValueNameLength++; + lpValueName = LocalAlloc(LPTR, + dwMaxValueNameLength * sizeof(WCHAR)); + if (lpValueName == NULL) + { + RegCloseKey(hEnvKey); + return FALSE; + } + + lpValueData = LocalAlloc(LPTR, + dwMaxValueDataLength); + if (lpValueData == NULL) + { + LocalFree(lpValueName); + RegCloseKey(hEnvKey); + return FALSE; + } + + /* Enumerate values */ + for (i = 0; i < dwValues; i++) + { + dwValueNameLength = dwMaxValueNameLength; + dwValueDataLength = dwMaxValueDataLength; + + Error = RegEnumValueW(hEnvKey, + i, + lpValueName, + &dwValueNameLength, + NULL, + &dwType, + (LPBYTE)lpValueData, + &dwValueDataLength); + if (Error == ERROR_SUCCESS) + { + /* Set environment variable */ + SetUserEnvironmentVariable(lpEnvironment, + lpValueName, + lpValueData, + (dwType == REG_EXPAND_SZ)); + } + else + { + LocalFree(lpValueData); + LocalFree(lpValueName); + RegCloseKey(hEnvKey); + + return FALSE; + } + } + + LocalFree(lpValueData); + LocalFree(lpValueName); + RegCloseKey(hEnvKey); + + return TRUE; +} + + BOOL WINAPI CreateEnvironmentBlock(LPVOID *lpEnvironment, @@ -433,7 +544,7 @@
Status = RtlCreateEnvironment((BOOLEAN)bInherit, (PWSTR*)lpEnvironment); - if (!NT_SUCCESS (Status)) + if (!NT_SUCCESS(Status)) { DPRINT1("RtlCreateEnvironment() failed (Status %lx)\n", Status); SetLastError(RtlNtStatusToDosError(Status)); @@ -464,9 +575,11 @@ }
/* Set variables from Session Manager */ - SetUserEnvironment(lpEnvironment, - HKEY_LOCAL_MACHINE, - L"System\CurrentControlSet\Control\Session Manager\Environment"); + if (!SetSystemEnvironment(lpEnvironment)) + { + RtlDestroyEnvironment(*lpEnvironment); + return FALSE; + }
/* Set 'COMPUTERNAME' variable */ Length = MAX_PATH;