Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/userenv/userenv_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/userenv/userenv_main.c b/dlls/userenv/userenv_main.c index b811c8315f..005166e5f4 100644 --- a/dlls/userenv/userenv_main.c +++ b/dlls/userenv/userenv_main.c @@ -281,7 +281,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
if (!GetEnvironmentVariableW(SystemDriveW, buf, UNICODE_STRING_MAX_CHARS)) { - if (!get_reg_value(env, hkey, SystemRootW, buf, UNICODE_STRING_MAX_CHARS)) + if (!get_reg_value(env, hkey, SystemDriveW, buf, UNICODE_STRING_MAX_CHARS)) { buf[0] = 0; WARN("SystemDrive variable not set\n");
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/userenv/userenv_main.c | 114 ++++++++++++------------------------ 1 file changed, 38 insertions(+), 76 deletions(-)
diff --git a/dlls/userenv/userenv_main.c b/dlls/userenv/userenv_main.c index 005166e5f4..9317c82735 100644 --- a/dlls/userenv/userenv_main.c +++ b/dlls/userenv/userenv_main.c @@ -95,10 +95,6 @@ static BOOL get_reg_value(WCHAR *env, HKEY hkey, const WCHAR *name, WCHAR *val,
static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_path) { - static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0}; - static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0}; - static const WCHAR PATHW[] = {'P','A','T','H',0}; - UNICODE_STRING us_name, us_value; WCHAR name[1024], value[1024]; DWORD ret, index, size; @@ -110,13 +106,13 @@ static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_ if (ret != ERROR_SUCCESS) break;
- if (!wcsicmp(name, SystemRootW)) continue; - if (!wcsicmp(name, SystemDriveW)) continue; + if (!wcsicmp(name, L"SystemRoot")) continue; + if (!wcsicmp(name, L"SystemDrive")) continue;
RtlInitUnicodeString(&us_name, name); us_value.Buffer = value; us_value.MaximumLength = sizeof(value); - if (!wcsnicmp(name, PATHW, ARRAY_SIZE(PATHW)) && + if (!wcsicmp(name, L"PATH") && !RtlQueryEnvironmentVariable_U(*env, &us_name, &us_value)) { if (!set_path) @@ -146,19 +142,6 @@ static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_
static void set_wow64_environment(WCHAR **env) { - static const WCHAR versionW[] = {'S','o','f','t','w','a','r','e','\', - 'M','i','c','r','o','s','o','f','t','\', - 'W','i','n','d','o','w','s','\', - 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0}; - static const WCHAR progdirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0}; - static const WCHAR progdir86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0}; - static const WCHAR progfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0}; - static const WCHAR progw6432W[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0}; - static const WCHAR commondirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0}; - static const WCHAR commondir86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0}; - static const WCHAR commonfilesW[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0}; - static const WCHAR commonw6432W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0}; - UNICODE_STRING nameW, valueW; WCHAR buf[64]; HKEY hkey; @@ -167,54 +150,54 @@ static void set_wow64_environment(WCHAR **env)
IsWow64Process( GetCurrentProcess(), &is_wow64 );
- if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, versionW, 0, - KEY_READ|KEY_WOW64_64KEY, &hkey)) + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\Microsoft\Windows\CurrentVersion", + 0, KEY_READ|KEY_WOW64_64KEY, &hkey)) return;
/* set the ProgramFiles variables */
- if (get_reg_value(*env, hkey, progdirW, buf, sizeof(buf))) + if (get_reg_value(*env, hkey, L"ProgramFilesDir", buf, sizeof(buf))) { if (is_win64 || is_wow64) { - RtlInitUnicodeString(&nameW, progw6432W); + RtlInitUnicodeString(&nameW, L"ProgramW6432"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); } if (is_win64 || !is_wow64) { - RtlInitUnicodeString(&nameW, progfilesW); + RtlInitUnicodeString(&nameW, L"ProgramFiles"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); } } - if (is_wow64 && get_reg_value(*env, hkey, progdir86W, buf, sizeof(buf))) + if (is_wow64 && get_reg_value(*env, hkey, L"ProgramFilesDir (x86)", buf, sizeof(buf))) { - RtlInitUnicodeString(&nameW, progfilesW); + RtlInitUnicodeString(&nameW, L"ProgramFiles"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); }
/* set the CommonProgramFiles variables */
- if (get_reg_value(*env, hkey, commondirW, buf, sizeof(buf))) + if (get_reg_value(*env, hkey, L"CommonFilesDir", buf, sizeof(buf))) { if (is_win64 || is_wow64) { - RtlInitUnicodeString(&nameW, commonw6432W); + RtlInitUnicodeString(&nameW, L"CommonProgramW6432"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); } if (is_win64 || !is_wow64) { - RtlInitUnicodeString(&nameW, commonfilesW); + RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); } } - if (is_wow64 && get_reg_value(*env, hkey, commondir86W, buf, sizeof(buf))) + if (is_wow64 && get_reg_value(*env, hkey, L"CommonFilesDir (x86)", buf, sizeof(buf))) { - RtlInitUnicodeString(&nameW, commonfilesW); + RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); RtlInitUnicodeString(&valueW, buf); RtlSetEnvironmentVariable(env, &nameW, &valueW); } @@ -225,28 +208,8 @@ static void set_wow64_environment(WCHAR **env) BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, HANDLE hToken, BOOL bInherit ) { - static const WCHAR env_keyW[] = {'S','y','s','t','e','m','\', - 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\', - 'C','o','n','t','r','o','l','\', - 'S','e','s','s','i','o','n',' ','M','a','n','a','g','e','r','\', - 'E','n','v','i','r','o','n','m','e','n','t',0}; - static const WCHAR profile_keyW[] = {'S','o','f','t','w','a','r','e','\', - 'M','i','c','r','o','s','o','f','t','\', - 'W','i','n','d','o','w','s',' ','N','T','\', - 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\', - 'P','r','o','f','i','l','e','L','i','s','t',0}; - static const WCHAR envW[] = {'E','n','v','i','r','o','n','m','e','n','t',0}; - static const WCHAR volatile_envW[] = {'V','o','l','a','t','i','l','e',' ','E','n','v','i','r','o','n','m','e','n','t',0}; - static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0}; - - static const WCHAR SystemRootW[] = {'S','y','s','t','e','m','R','o','o','t',0}; - static const WCHAR SystemDriveW[] = {'S','y','s','t','e','m','D','r','i','v','e',0}; - static const WCHAR PublicW[] = {'P','u','b','l','i','c',0}; - static const WCHAR ALLUSERSPROFILEW[] = {'A','L','L','U','S','E','R','S','P','R','O','F','I','L','E',0}; - static const WCHAR USERNAMEW[] = {'U','S','E','R','N','A','M','E',0}; - static const WCHAR USERPROFILEW[] = {'U','S','E','R','P','R','O','F','I','L','E',0}; - static const WCHAR DefaultW[] = {'D','e','f','a','u','l','t',0}; - static const WCHAR COMPUTERNAMEW[] = {'C','O','M','P','U','T','E','R','N','A','M','E',0}; + static const WCHAR env_keyW[] = L"System\CurrentControlSet\Control\Session Manager\Environment"; + static const WCHAR profile_keyW[] = L"Software\Microsoft\Windows NT\CurrentVersion\ProfileList";
WCHAR *env, buf[UNICODE_STRING_MAX_CHARS], profiles_dir[MAX_PATH]; UNICODE_STRING us_name, us_val; @@ -267,41 +230,41 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, return FALSE; }
- if (!GetEnvironmentVariableW(SystemRootW, buf, UNICODE_STRING_MAX_CHARS)) + if (!GetEnvironmentVariableW(L"SystemRoot", buf, UNICODE_STRING_MAX_CHARS)) { - if (!get_reg_value(env, hkey, SystemRootW, buf, UNICODE_STRING_MAX_CHARS)) + if (!get_reg_value(env, hkey, L"SystemRoot", buf, UNICODE_STRING_MAX_CHARS)) { buf[0] = 0; WARN("SystemRoot variable not set\n"); } } - RtlInitUnicodeString(&us_name, SystemRootW); + RtlInitUnicodeString(&us_name, L"SystemRoot"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val);
- if (!GetEnvironmentVariableW(SystemDriveW, buf, UNICODE_STRING_MAX_CHARS)) + if (!GetEnvironmentVariableW(L"SystemDrive", buf, UNICODE_STRING_MAX_CHARS)) { - if (!get_reg_value(env, hkey, SystemDriveW, buf, UNICODE_STRING_MAX_CHARS)) + if (!get_reg_value(env, hkey, L"SystemDrive", buf, UNICODE_STRING_MAX_CHARS)) { buf[0] = 0; WARN("SystemDrive variable not set\n"); } } - RtlInitUnicodeString(&us_name, SystemDriveW); + RtlInitUnicodeString(&us_name, L"SystemDrive"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val);
set_registry_variables(&env, hkey, REG_SZ, !bInherit); set_registry_variables(&env, hkey, REG_EXPAND_SZ, !bInherit);
- if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(hkey, L"Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) { set_registry_variables(&env, hsubkey, REG_SZ, !bInherit); set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit); RegCloseKey(hsubkey); }
- if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(hkey, L"Volatile Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) { set_registry_variables(&env, hsubkey, REG_SZ, !bInherit); set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit); @@ -311,7 +274,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, profile_keyW, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { - if (get_reg_value(env, hkey, ProfilesDirectoryW, profiles_dir, MAX_PATH-sizeof(WCHAR))) + if (get_reg_value(env, hkey, L"ProfilesDirectory", profiles_dir, MAX_PATH - sizeof(WCHAR))) { len = lstrlenW(profiles_dir); if (profiles_dir[len-1] != '\') @@ -320,9 +283,9 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, profiles_dir[len] = '\0'; }
- if (get_reg_value(env, hkey, PublicW, buf, UNICODE_STRING_MAX_CHARS)) + if (get_reg_value(env, hkey, L"Public", buf, UNICODE_STRING_MAX_CHARS)) { - RtlInitUnicodeString(&us_name, ALLUSERSPROFILEW); + RtlInitUnicodeString(&us_name, L"ALLUSERSPROFILE"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val); } @@ -338,7 +301,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, len = ARRAY_SIZE(buf); if (GetComputerNameW(buf, &len)) { - RtlInitUnicodeString(&us_name, COMPUTERNAMEW); + RtlInitUnicodeString(&us_name, L"COMPUTERNAME"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val); } @@ -350,18 +313,17 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, if (profiles_dir[0]) { len = lstrlenW(profiles_dir); - if (len*sizeof(WCHAR)+sizeof(DefaultW) < sizeof(buf)) + if (len * sizeof(WCHAR) + sizeof(L"Default") < sizeof(buf)) { - memcpy(buf, profiles_dir, len*sizeof(WCHAR)); - memcpy(buf+len, DefaultW, sizeof(DefaultW)); - RtlInitUnicodeString(&us_name, USERPROFILEW); + wcscpy(buf, profiles_dir); + wcscat(buf, L"Default"); + RtlInitUnicodeString(&us_name, L"USERPROFILE"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val); } }
- buf[0] = '.'; - memcpy(buf+1, DefaultW, sizeof(DefaultW)); + wcscpy(buf, L".Default"); } else { @@ -388,13 +350,13 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, if (LookupAccountSidW(NULL, token_user->User.Sid, buf+len, &size, NULL, &tmp, &use)) { - RtlInitUnicodeString(&us_name, USERNAMEW); + RtlInitUnicodeString(&us_name, L"USERNAME"); RtlInitUnicodeString(&us_val, buf+len); RtlSetEnvironmentVariable(&env, &us_name, &us_val);
if (len) { - RtlInitUnicodeString(&us_name, USERPROFILEW); + RtlInitUnicodeString(&us_name, L"USERPROFILE"); RtlInitUnicodeString(&us_val, buf); RtlSetEnvironmentVariable(&env, &us_name, &us_val); } @@ -407,14 +369,14 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
if (RegOpenKeyExW(HKEY_USERS, buf, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { - if (RegOpenKeyExW(hkey, envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(hkey, L"Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) { set_registry_variables(&env, hsubkey, REG_SZ, !bInherit); set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit); RegCloseKey(hsubkey); }
- if (RegOpenKeyExW(hkey, volatile_envW, 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) + if (RegOpenKeyExW(hkey, L"Volatile Environment", 0, KEY_READ, &hsubkey) == ERROR_SUCCESS) { set_registry_variables(&env, hsubkey, REG_SZ, !bInherit); set_registry_variables(&env, hsubkey, REG_EXPAND_SZ, !bInherit);
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/userenv/tests/userenv.c | 2 ++ dlls/userenv/userenv_main.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/dlls/userenv/tests/userenv.c b/dlls/userenv/tests/userenv.c index 79b4d59a61..f6cfcc79ec 100644 --- a/dlls/userenv/tests/userenv.c +++ b/dlls/userenv/tests/userenv.c @@ -104,6 +104,8 @@ static void test_create_env(void) { "USERPROFILE" } }; static const struct profile_item common_win64_vars[] = { + { "ProgramFiles(x86)" }, + { "CommonProgramFiles(x86)" }, { "ProgramW6432" }, { "CommonProgramW6432" } }; diff --git a/dlls/userenv/userenv_main.c b/dlls/userenv/userenv_main.c index 9317c82735..9f10cfa1d7 100644 --- a/dlls/userenv/userenv_main.c +++ b/dlls/userenv/userenv_main.c @@ -171,11 +171,20 @@ static void set_wow64_environment(WCHAR **env) RtlSetEnvironmentVariable(env, &nameW, &valueW); } } - if (is_wow64 && get_reg_value(*env, hkey, L"ProgramFilesDir (x86)", buf, sizeof(buf))) + if (get_reg_value(*env, hkey, L"ProgramFilesDir (x86)", buf, sizeof(buf))) { - RtlInitUnicodeString(&nameW, L"ProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); + if (is_win64 || is_wow64) + { + RtlInitUnicodeString(&nameW, L"ProgramFiles(x86)"); + RtlInitUnicodeString(&valueW, buf); + RtlSetEnvironmentVariable(env, &nameW, &valueW); + } + if (is_wow64) + { + RtlInitUnicodeString(&nameW, L"ProgramFiles"); + RtlInitUnicodeString(&valueW, buf); + RtlSetEnvironmentVariable(env, &nameW, &valueW); + } }
/* set the CommonProgramFiles variables */ @@ -195,11 +204,20 @@ static void set_wow64_environment(WCHAR **env) RtlSetEnvironmentVariable(env, &nameW, &valueW); } } - if (is_wow64 && get_reg_value(*env, hkey, L"CommonFilesDir (x86)", buf, sizeof(buf))) + if (get_reg_value(*env, hkey, L"CommonFilesDir (x86)", buf, sizeof(buf))) { - RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); + if (is_win64 || is_wow64) + { + RtlInitUnicodeString(&nameW, L"CommonProgramFiles(x86)"); + RtlInitUnicodeString(&valueW, buf); + RtlSetEnvironmentVariable(env, &nameW, &valueW); + } + if (is_wow64) + { + RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); + RtlInitUnicodeString(&valueW, buf); + RtlSetEnvironmentVariable(env, &nameW, &valueW); + } }
RegCloseKey(hkey);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=59235
Your paranoid android.
=== w1064v1809_ar (32 bit report) ===
userenv: userenv.c:354: Test failed: expected ERROR_INSUFFICIENT_BUFFER, got 87 userenv.c:355: Test failed: expected len > 0 userenv.c:361: Test failed: expected success 87 userenv.c:362: Test failed: expected len > 0 userenv.c:363: Test failed: length mismatch 0 != 0 - 1
Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/userenv/userenv_main.c | 116 +++++++++--------------------------- 1 file changed, 27 insertions(+), 89 deletions(-)
diff --git a/dlls/userenv/userenv_main.c b/dlls/userenv/userenv_main.c index 9f10cfa1d7..045bac0cfe 100644 --- a/dlls/userenv/userenv_main.c +++ b/dlls/userenv/userenv_main.c @@ -93,6 +93,15 @@ static BOOL get_reg_value(WCHAR *env, HKEY hkey, const WCHAR *name, WCHAR *val, return FALSE; }
+static void set_env_var( WCHAR **env, const WCHAR *name, const WCHAR *val ) +{ + UNICODE_STRING nameW, valW; + + RtlInitUnicodeString( &nameW, name ); + RtlInitUnicodeString( &valW, val ); + RtlSetEnvironmentVariable( env, &nameW, &valW ); +} + static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_path) { UNICODE_STRING us_name, us_value; @@ -124,25 +133,17 @@ static void set_registry_variables(WCHAR **env, HKEY hkey, DWORD type, BOOL set_ continue;
value[size] = ';'; - RtlInitUnicodeString(&us_value, value); - RtlSetEnvironmentVariable(env, &us_name, &us_value); + set_env_var(env, name, value); continue; }
- if (!get_reg_value(*env, hkey, name, value, sizeof(value))) - continue; - - if(!value[0]) - continue; - - RtlInitUnicodeString(&us_value, value); - RtlSetEnvironmentVariable(env, &us_name, &us_value); + if (get_reg_value(*env, hkey, name, value, sizeof(value)) && value[0]) + set_env_var(env, name, value); } }
static void set_wow64_environment(WCHAR **env) { - UNICODE_STRING nameW, valueW; WCHAR buf[64]; HKEY hkey; BOOL is_win64 = (sizeof(void *) > sizeof(int)); @@ -158,66 +159,26 @@ static void set_wow64_environment(WCHAR **env)
if (get_reg_value(*env, hkey, L"ProgramFilesDir", buf, sizeof(buf))) { - if (is_win64 || is_wow64) - { - RtlInitUnicodeString(&nameW, L"ProgramW6432"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } - if (is_win64 || !is_wow64) - { - RtlInitUnicodeString(&nameW, L"ProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } + if (is_win64 || is_wow64) set_env_var(env, L"ProgramW6432", buf); + if (is_win64 || !is_wow64) set_env_var(env, L"ProgramFiles", buf); } if (get_reg_value(*env, hkey, L"ProgramFilesDir (x86)", buf, sizeof(buf))) { - if (is_win64 || is_wow64) - { - RtlInitUnicodeString(&nameW, L"ProgramFiles(x86)"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } - if (is_wow64) - { - RtlInitUnicodeString(&nameW, L"ProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } + if (is_win64 || is_wow64) set_env_var(env, L"ProgramFiles(x86)", buf); + if (is_wow64) set_env_var(env, L"ProgramFiles", buf); }
/* set the CommonProgramFiles variables */
if (get_reg_value(*env, hkey, L"CommonFilesDir", buf, sizeof(buf))) { - if (is_win64 || is_wow64) - { - RtlInitUnicodeString(&nameW, L"CommonProgramW6432"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } - if (is_win64 || !is_wow64) - { - RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } + if (is_win64 || is_wow64) set_env_var(env, L"CommonProgramW6432", buf); + if (is_win64 || !is_wow64) set_env_var(env, L"CommonProgramFiles", buf); } if (get_reg_value(*env, hkey, L"CommonFilesDir (x86)", buf, sizeof(buf))) { - if (is_win64 || is_wow64) - { - RtlInitUnicodeString(&nameW, L"CommonProgramFiles(x86)"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } - if (is_wow64) - { - RtlInitUnicodeString(&nameW, L"CommonProgramFiles"); - RtlInitUnicodeString(&valueW, buf); - RtlSetEnvironmentVariable(env, &nameW, &valueW); - } + if (is_win64 || is_wow64) set_env_var(env, L"CommonProgramFiles(x86)", buf); + if (is_wow64) set_env_var(env, L"CommonProgramFiles", buf); }
RegCloseKey(hkey); @@ -230,7 +191,6 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, static const WCHAR profile_keyW[] = L"Software\Microsoft\Windows NT\CurrentVersion\ProfileList";
WCHAR *env, buf[UNICODE_STRING_MAX_CHARS], profiles_dir[MAX_PATH]; - UNICODE_STRING us_name, us_val; DWORD len; HKEY hkey, hsubkey;
@@ -256,9 +216,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, WARN("SystemRoot variable not set\n"); } } - RtlInitUnicodeString(&us_name, L"SystemRoot"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); + set_env_var(&env, L"SystemRoot", buf);
if (!GetEnvironmentVariableW(L"SystemDrive", buf, UNICODE_STRING_MAX_CHARS)) { @@ -268,9 +226,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, WARN("SystemDrive variable not set\n"); } } - RtlInitUnicodeString(&us_name, L"SystemDrive"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); + set_env_var(&env, L"SystemDrive", buf);
set_registry_variables(&env, hkey, REG_SZ, !bInherit); set_registry_variables(&env, hkey, REG_EXPAND_SZ, !bInherit); @@ -302,11 +258,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, }
if (get_reg_value(env, hkey, L"Public", buf, UNICODE_STRING_MAX_CHARS)) - { - RtlInitUnicodeString(&us_name, L"ALLUSERSPROFILE"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); - } + set_env_var(&env, L"ALLUSERSPROFILE", buf); } else { @@ -318,11 +270,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment,
len = ARRAY_SIZE(buf); if (GetComputerNameW(buf, &len)) - { - RtlInitUnicodeString(&us_name, L"COMPUTERNAME"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); - } + set_env_var(&env, L"COMPUTERNAME", buf);
set_wow64_environment(&env);
@@ -335,9 +283,7 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, { wcscpy(buf, profiles_dir); wcscat(buf, L"Default"); - RtlInitUnicodeString(&us_name, L"USERPROFILE"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); + set_env_var(&env, L"USERPROFILE", buf); } }
@@ -368,16 +314,8 @@ BOOL WINAPI CreateEnvironmentBlock( LPVOID* lpEnvironment, if (LookupAccountSidW(NULL, token_user->User.Sid, buf+len, &size, NULL, &tmp, &use)) { - RtlInitUnicodeString(&us_name, L"USERNAME"); - RtlInitUnicodeString(&us_val, buf+len); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); - - if (len) - { - RtlInitUnicodeString(&us_name, L"USERPROFILE"); - RtlInitUnicodeString(&us_val, buf); - RtlSetEnvironmentVariable(&env, &us_name, &us_val); - } + set_env_var(&env, L"USERNAME", buf+len); + if (len) set_env_var(&env, L"USERPROFILE", buf); }
HeapFree(GetProcessHeap(), 0, token_user);
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=40950 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntdll/env.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/dlls/ntdll/env.c b/dlls/ntdll/env.c index 87ab9bef62..03c0a20624 100644 --- a/dlls/ntdll/env.c +++ b/dlls/ntdll/env.c @@ -367,10 +367,12 @@ static void set_wow64_environment( WCHAR **env ) static const WCHAR progdirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0}; static const WCHAR progdir86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0}; static const WCHAR progfilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s',0}; + static const WCHAR progfiles86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','(','x','8','6',')',0}; static const WCHAR progw6432W[] = {'P','r','o','g','r','a','m','W','6','4','3','2',0}; static const WCHAR commondirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0}; static const WCHAR commondir86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0}; static const WCHAR commonfilesW[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s',0}; + static const WCHAR commonfiles86W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','F','i','l','e','s','(','8','6',')',0}; static const WCHAR commonw6432W[] = {'C','o','m','m','o','n','P','r','o','g','r','a','m','W','6','4','3','2',0}; static const WCHAR winedlldirW[] = {'W','I','N','E','D','L','L','D','I','R','%','u',0}; static const WCHAR winehomedirW[] = {'W','I','N','E','H','O','M','E','D','I','R',0}; @@ -435,9 +437,10 @@ static void set_wow64_environment( WCHAR **env ) if (is_win64 || !is_wow64) set_env_var( env, progfilesW, val ); RtlFreeHeap( GetProcessHeap(), 0, val ); } - if (is_wow64 && (val = get_registry_value( *env, hkey, progdir86W ))) + if ((val = get_registry_value( *env, hkey, progdir86W ))) { - set_env_var( env, progfilesW, val ); + if (is_win64 || is_wow64) set_env_var( env, progfiles86W, val ); + if (is_wow64) set_env_var( env, progfilesW, val ); RtlFreeHeap( GetProcessHeap(), 0, val ); }
@@ -449,9 +452,10 @@ static void set_wow64_environment( WCHAR **env ) if (is_win64 || !is_wow64) set_env_var( env, commonfilesW, val ); RtlFreeHeap( GetProcessHeap(), 0, val ); } - if (is_wow64 && (val = get_registry_value( *env, hkey, commondir86W ))) + if ((val = get_registry_value( *env, hkey, commondir86W ))) { - set_env_var( env, commonfilesW, val ); + if (is_win64 || is_wow64) set_env_var( env, commonfiles86W, val ); + if (is_wow64) set_env_var( env, commonfilesW, val ); RtlFreeHeap( GetProcessHeap(), 0, val ); } NtClose( hkey );