MCPcopy
hub / github.com/gliderlabs/ssh / ForwardAgentConnections

Function ForwardAgentConnections

agent.go:53–83  ·  view source on GitHub ↗

ForwardAgentConnections takes connections from a listener to proxy into the session on the OpenSSH channel for agent connections. It blocks and services connections until the listener stop accepting.

(l net.Listener, s Session)

Source from the content-addressed store, hash-verified

51// session on the OpenSSH channel for agent connections. It blocks and services
52// connections until the listener stop accepting.
53func ForwardAgentConnections(l net.Listener, s Session) {
54 sshConn := s.Context().Value(ContextKeyConn).(gossh.Conn)
55 for {
56 conn, err := l.Accept()
57 if err != nil {
58 return
59 }
60 go func(conn net.Conn) {
61 defer conn.Close()
62 channel, reqs, err := sshConn.OpenChannel(agentChannelType, nil)
63 if err != nil {
64 return
65 }
66 defer channel.Close()
67 go gossh.DiscardRequests(reqs)
68 var wg sync.WaitGroup
69 wg.Add(2)
70 go func() {
71 io.Copy(conn, channel)
72 conn.(*net.UnixConn).CloseWrite()
73 wg.Done()
74 }()
75 go func() {
76 io.Copy(channel, conn)
77 channel.CloseWrite()
78 wg.Done()
79 }()
80 wg.Wait()
81 }(conn)
82 }
83}

Callers 1

mainFunction · 0.92

Calls 3

ValueMethod · 0.80
ContextMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…