(host, port string, stdin io.Reader, stdout io.Writer)
| 231 | } |
| 232 | |
| 233 | func proxyDirectWithIO(host, port string, stdin io.Reader, stdout io.Writer) error { |
| 234 | address := net.JoinHostPort(host, port) |
| 235 | addr, err := net.ResolveTCPAddr("tcp", address) |
| 236 | if err != nil { |
| 237 | return errors.Wrap(err, "error resolving address") |
| 238 | } |
| 239 | |
| 240 | conn, err := net.DialTCP("tcp", nil, addr) |
| 241 | if err != nil { |
| 242 | return errors.Wrapf(err, "error connecting to %s", address) |
| 243 | } |
| 244 | defer conn.Close() |
| 245 | |
| 246 | // Return as soon as either direction finishes. Waiting for both can |
| 247 | // deadlock when the server closes the connection while stdin stays open. |
| 248 | // See smallstep/cli#1641. Buffered so the slower goroutine never blocks |
| 249 | // sending after we've stopped receiving. |
| 250 | done := make(chan struct{}, 2) |
| 251 | go func() { |
| 252 | io.Copy(conn, stdin) |
| 253 | conn.CloseWrite() |
| 254 | done <- struct{}{} |
| 255 | }() |
| 256 | go func() { |
| 257 | io.Copy(stdout, conn) |
| 258 | conn.CloseRead() |
| 259 | done <- struct{}{} |
| 260 | }() |
| 261 | |
| 262 | <-done |
| 263 | return nil |
| 264 | } |
| 265 | |
| 266 | func proxyBastion(r *api.SSHBastionResponse, user, host, port string) error { |
| 267 | sshPath, err := exec.LookPath("ssh") |
searching dependent graphs…