1
0
Fork 0
forked from forgejo/forgejo
This commit is contained in:
techknowlogick 2021-02-28 18:08:33 -05:00 committed by GitHub
parent 030646eea4
commit 47f6a4ec3f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
947 changed files with 26119 additions and 7062 deletions

View file

@ -27,17 +27,40 @@ import (
"net"
"sync"
"github.com/Microsoft/go-winio"
"golang.org/x/crypto/ssh/agent"
)
const (
sshAgentPipe = `\\.\pipe\openssh-ssh-agent`
)
// Available returns true if Pageant is running
func Available() bool {
if pageantWindow() != 0 {
return true
}
conn, err := winio.DialPipe(sshAgentPipe, nil)
if err != nil {
return false
}
conn.Close()
return true
}
// New returns a new agent.Agent and the (custom) connection it uses
// to communicate with a running pagent.exe instance (see README.md)
func New() (agent.Agent, net.Conn, error) {
if !Available() {
return nil, nil, errors.New("SSH agent requested but Pageant not running")
if pageantWindow() != 0 {
return agent.NewClient(&conn{}), nil, nil
}
return agent.NewClient(&conn{}), nil, nil
conn, err := winio.DialPipe(sshAgentPipe, nil)
if err != nil {
return nil, nil, errors.New(
"SSH agent requested, but could not detect Pageant or Windows native SSH agent",
)
}
return agent.NewClient(conn), nil, nil
}
type conn struct {