Handle Path Variable: Prepend System path to User path (#563)

This commit is contained in:
Vivian Thiebaut 2022-02-07 18:00:39 -05:00 committed by GitHub
parent c2765de0f7
commit 602a02995a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -24,7 +24,7 @@ if ($TestFilePath) {
# convert to bash format
$TestFilePath = $TestFilePath -replace "\\","/"
}
$OriginalUserPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
$OriginalSystemPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::Machine)
# Make sure config.h exists. It is used in some bashstests (Ex - sftp-glob.sh, cfgparse.sh)
# first check in $BashTestsPath folder. If not then it's parent folder. If not then in the $OpenSSHBinPath
@ -104,7 +104,7 @@ try
# Prepend shell path to User PATH in the registry so that SSHD authenticated child process can inherit it.
# We can probably delete the logic above to add it to the process PATH, but there is no need.
[System.Environment]::SetEnvironmentVariable('Path', $TEST_SHELL_DIR + ";" + $OriginalUserPath, [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('Path', $TEST_SHELL_DIR + ";" + $OriginalSystemPath, [System.EnvironmentVariableTarget]::Machine)
$BashTestsPath = $BashTestsPath -replace "\\","/"
Push-location $BashTestsPath
@ -260,7 +260,7 @@ try
finally
{
# Restore User Path variable in the registry once the tests finish running.
[System.Environment]::SetEnvironmentVariable('Path', $OriginalUserPath, [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('Path', $OriginalSystemPath, [System.EnvironmentVariableTarget]::Machine)
# remove temp test directory
if (!$SkipCleanup)
{

View File

@ -196,14 +196,14 @@ setup_session_user_vars(wchar_t* profile_path)
}
}
/* Path is a special case. The System Path value is appended to the User Path value */
/* Path is a special case. The System Path value is preppended to the User Path value */
if (_wcsicmp(name, L"PATH") == 0 && j == 1) {
if ((required = GetEnvironmentVariableW(L"PATH", NULL, 0)) != 0) {
size_t user_path_size = wcslen(to_apply);
path_value = xmalloc((required + user_path_size + 2) * 2);
GOTO_CLEANUP_ON_ERR(memcpy_s(path_value, (user_path_size + 1) * 2, to_apply, (user_path_size + 1) * 2));
path_value[user_path_size] = L';';
GetEnvironmentVariableW(L"PATH", path_value + user_path_size + 1, required);
size_t user_path_size = wcslen(to_apply) + 1;
path_value = xmalloc((required + user_path_size) * 2);
GetEnvironmentVariableW(L"PATH", path_value, required);
path_value[required - 1] = L';';
GOTO_CLEANUP_ON_ERR(memcpy_s(path_value + required, user_path_size * 2, to_apply, user_path_size * 2));
to_apply = path_value;
}
}