-
-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes issues with openssh-win32 agent. #295
Changes from 3 commits
931d299
3abada0
37ba80d
edd12c0
893ec41
769c26f
e82cc14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -256,8 +256,7 @@ function Get-SshAgent() { | |
} else { | ||
$agentPid = $Env:SSH_AGENT_PID | ||
if ($agentPid) { | ||
$sshAgentProcess = Get-Process | Where-Object { $_.Id -eq $agentPid -and $_.Name -eq 'ssh-agent' } | ||
if ($null -ne $sshAgentProcess) { | ||
if (((Get-Process -Id $agentPid -FileVersionInfo -ErrorAction SilentlyContinue).Filename).Contains("Git")) { | ||
return $agentPid | ||
} else { | ||
setenv 'SSH_AGENT_PID', $null | ||
|
@@ -282,15 +281,30 @@ function Find-Pageant() { | |
|
||
# Attempt to guess $program's location. For ssh-agent/ssh-add. | ||
function Find-Ssh($program = 'ssh-agent') { | ||
$sshLocation = 'C:\Program Files\Git\usr\bin\' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has to be given as preference from user perspective. not sure where to keep this and how to import that var here. temp hardcoded There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this actually necessary? I would expect the existing code in |
||
|
||
if($sshLocation -and (get-command (join-path $sshLocation $program))){ | ||
return join-path $sshLocation $program | ||
} | ||
|
||
$sshLocation = Get-Command $program -TotalCount 1 -ErrorAction SilentlyContinue | ||
if($sshLocation){ | ||
return $sshLocation | ||
} | ||
|
||
Write-Verbose "$program not in path. Trying to guess location." | ||
$gitItem = Get-Command git -Erroraction SilentlyContinue | Get-Item | ||
if ($gitItem -eq $null) { Write-Warning 'git not in path'; return } | ||
|
||
$sshLocation = join-path $gitItem.directory.parent.fullname bin/$program | ||
if (get-command $sshLocation -Erroraction SilentlyContinue) { return $sshLocation } | ||
if (get-command $sshLocation -Erroraction SilentlyContinue) { | ||
return $sshLocation | ||
} | ||
|
||
$sshLocation = join-path $gitItem.directory.parent.fullname usr/bin/$program | ||
if (get-command $sshLocation -Erroraction SilentlyContinue) { return $sshLocation } | ||
if (get-command $sshLocation -Erroraction SilentlyContinue) { | ||
return $sshLocation | ||
} | ||
} | ||
|
||
# Loosely based on bash script from http://help.github.com/ssh-key-passphrases/ | ||
|
@@ -312,8 +326,7 @@ function Start-SshAgent([switch]$Quiet) { | |
if (!$pageant) { Write-Warning "Could not find Pageant."; return } | ||
Start-Process -NoNewWindow $pageant | ||
} else { | ||
$sshAgent = Get-Command ssh-agent -TotalCount 1 -ErrorAction SilentlyContinue | ||
$sshAgent = if ($sshAgent) {$sshAgent} else {Find-Ssh('ssh-agent')} | ||
$sshAgent = Find-Ssh('ssh-agent') | ||
if (!$sshAgent) { Write-Warning 'Could not find ssh-agent'; return } | ||
|
||
& $sshAgent | foreach { | ||
|
@@ -339,7 +352,6 @@ function Add-SshKey() { | |
if (!$pageant) { Write-Warning 'Could not find Pageant'; return } | ||
|
||
if ($args.Count -eq 0) { | ||
$keystring = "" | ||
$keyPath = Join-Path $Env:HOME ".ssh" | ||
$keys = Get-ChildItem $keyPath/"*.ppk" -ErrorAction SilentlyContinue | Select -ExpandProperty FullName | ||
& $pageant $keys | ||
|
@@ -349,10 +361,8 @@ function Add-SshKey() { | |
} | ||
} | ||
} else { | ||
$sshAdd = Get-Command ssh-add -TotalCount 1 -ErrorAction SilentlyContinue | ||
$sshAdd = if ($sshAdd) {$sshAdd} else {Find-Ssh('ssh-add')} | ||
$sshAdd = Find-Ssh('ssh-add') | ||
if (!$sshAdd) { Write-Warning 'Could not find ssh-add'; return } | ||
|
||
if ($args.Count -eq 0) { | ||
& $sshAdd | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
$agentPid
is valid but the process has been killed, this will blow up when you try to accessFilename
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Get-Process -Id 11111111 -FileVersionInfo -ErrorAction SilentlyContinue).Filename
doesn't throw any error. you will get empty data