(sess ssh.Session)
| 79 | } |
| 80 | |
| 81 | func (s *Server) handler(sess ssh.Session) { |
| 82 | cmd, payload, err := s.getCommand(sess) |
| 83 | if err != nil { |
| 84 | s.exitWithError(sess, errors.Wrap(err, "construct command")) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | if ssh.AgentRequested(sess) { |
| 89 | l, err := ssh.NewAgentListener() |
| 90 | if err != nil { |
| 91 | s.exitWithError(sess, errors.Wrap(err, "start agent")) |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | defer l.Close() |
| 96 | go ssh.ForwardAgentConnections(l, sess) |
| 97 | cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", "SSH_AUTH_SOCK", l.Addr().String())) |
| 98 | } |
| 99 | |
| 100 | // start shell session |
| 101 | if payload.TTY && runtime.GOOS != "windows" { |
| 102 | winSizeChan := make(chan ssh.Window, 1) |
| 103 | winSizeChan <- ssh.Window{ |
| 104 | Width: payload.Width, |
| 105 | Height: payload.Height, |
| 106 | } |
| 107 | err = sshhelper.HandlePTY(sess, ssh.Pty{ |
| 108 | Term: "xterm", |
| 109 | Window: ssh.Window{ |
| 110 | Width: payload.Width, |
| 111 | Height: payload.Height, |
| 112 | }, |
| 113 | }, winSizeChan, cmd, func(reader io.Reader) io.Reader { |
| 114 | return reader |
| 115 | }) |
| 116 | } else { |
| 117 | err = sshhelper.HandleNonPTY(sess, cmd, func(reader io.Reader) io.Reader { |
| 118 | return NewRewriter(reader, s.rewriteMappings) |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | // exit session |
| 123 | s.exitWithError(sess, err) |
| 124 | } |
| 125 | |
| 126 | func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, *types.ProxyCommand, error) { |
| 127 | var cmd *exec.Cmd |
nothing calls this directly
no test coverage detected