mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Added copy env vars from ProcessStartInfo to key/pair array used in creating ssh process (#7070)
This addresses issue #6207. During SSH remoting on Linux machines, when PowerShell on the client creates the SSH process to connect to the target machine, it was not passing in environment variables from the parent process, and this was preventing ssh-agent key management from working. This change adds a helper function to create environment variable key/value pairs for the created SSH process, based on the passed in ProcessStartInfo object.
This commit is contained in:
committed by
Travis Plunk
parent
8805ca20aa
commit
6fa1e86f2d
@@ -2182,7 +2182,7 @@ namespace System.Management.Automation.Runspaces
|
||||
|
||||
string filename = startInfo.FileName;
|
||||
string[] argv = ParseArgv(startInfo);
|
||||
string[] envp = new string[0];
|
||||
string[] envp = CopyEnvVariables(startInfo);
|
||||
string cwd = !string.IsNullOrWhiteSpace(startInfo.WorkingDirectory) ? startInfo.WorkingDirectory : null;
|
||||
|
||||
// Invoke the shim fork/execve routine. It will create pipes for all requested
|
||||
@@ -2239,6 +2239,20 @@ namespace System.Management.Automation.Runspaces
|
||||
access, StreamBufferSize, isAsync: false);
|
||||
}
|
||||
|
||||
/// <summary>Copies environment variables from ProcessStartInfo </summary>
|
||||
/// <param name="psi">ProcessStartInfo</param>
|
||||
/// <returns>String array of environment key/value pairs</returns>
|
||||
private static string[] CopyEnvVariables(ProcessStartInfo psi)
|
||||
{
|
||||
var envp = new string[psi.Environment.Count];
|
||||
int index = 0;
|
||||
foreach (var pair in psi.Environment)
|
||||
{
|
||||
envp[index++] = pair.Key + "=" + pair.Value;
|
||||
}
|
||||
return envp;
|
||||
}
|
||||
|
||||
/// <summary>Converts the filename and arguments information from a ProcessStartInfo into an argv array.</summary>
|
||||
/// <param name="psi">The ProcessStartInfo.</param>
|
||||
/// <returns>The argv array.</returns>
|
||||
|
||||
Reference in New Issue
Block a user