| 221 | } |
| 222 | |
| 223 | func directStreamLocalHandler(_ *ssh.Server, _ *gossh.ServerConn, newChan gossh.NewChannel, ctx ssh.Context) { |
| 224 | var reqPayload directStreamLocalPayload |
| 225 | err := gossh.Unmarshal(newChan.ExtraData(), &reqPayload) |
| 226 | if err != nil { |
| 227 | _ = newChan.Reject(gossh.ConnectionFailed, "could not parse direct-streamlocal@openssh.com channel payload") |
| 228 | return |
| 229 | } |
| 230 | |
| 231 | var dialer net.Dialer |
| 232 | dconn, err := dialer.DialContext(ctx, "unix", reqPayload.SocketPath) |
| 233 | if err != nil { |
| 234 | _ = newChan.Reject(gossh.ConnectionFailed, fmt.Sprintf("dial unix socket %q: %+v", reqPayload.SocketPath, err.Error())) |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | ch, reqs, err := newChan.Accept() |
| 239 | if err != nil { |
| 240 | _ = dconn.Close() |
| 241 | return |
| 242 | } |
| 243 | go gossh.DiscardRequests(reqs) |
| 244 | |
| 245 | Bicopy(ctx, ch, dconn) |
| 246 | } |
| 247 | |
| 248 | // unlink removes files and unlike os.Remove, directories are kept. |
| 249 | func unlink(path string) error { |