@@ -79,7 +79,7 @@ type Server struct {
7979}
8080
8181func (s * Server ) handler (sess ssh.Session ) {
82- cmd , err := s .getCommand (sess )
82+ cmd , payload , err := s .getCommand (sess )
8383 if err != nil {
8484 s .exitWithError (sess , errors .Wrap (err , "construct command" ))
8585 return
@@ -98,9 +98,19 @@ func (s *Server) handler(sess ssh.Session) {
9898 }
9999
100100 // start shell session
101- ptyReq , winCh , isPty := sess .Pty ()
102- if isPty && runtime .GOOS != "windows" {
103- err = sshhelper .HandlePTY (sess , ptyReq , winCh , cmd , func (reader io.Reader ) io.Reader {
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 {
104114 return reader
105115 })
106116 } else {
@@ -113,19 +123,19 @@ func (s *Server) handler(sess ssh.Session) {
113123 s .exitWithError (sess , err )
114124}
115125
116- func (s * Server ) getCommand (sess ssh.Session ) (* exec.Cmd , error ) {
126+ func (s * Server ) getCommand (sess ssh.Session ) (* exec.Cmd , * types. ProxyCommand , error ) {
117127 var cmd * exec.Cmd
118128 rawCommand := sess .RawCommand ()
119129 if len (rawCommand ) == 0 {
120- return nil , fmt .Errorf ("command required" )
130+ return nil , nil , fmt .Errorf ("command required" )
121131 }
122132
123133 command := & types.ProxyCommand {}
124134 err := json .Unmarshal ([]byte (rawCommand ), & command )
125135 if err != nil {
126- return nil , fmt .Errorf ("parse command: %v" , err )
136+ return nil , nil , fmt .Errorf ("parse command: %v" , err )
127137 } else if len (command .Args ) == 0 {
128- return nil , fmt .Errorf ("command is empty" )
138+ return nil , nil , fmt .Errorf ("command is empty" )
129139 }
130140
131141 var reverseCommand * latest.ProxyCommand
@@ -136,7 +146,7 @@ func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, error) {
136146 }
137147 }
138148 if reverseCommand == nil {
139- return nil , fmt .Errorf ("command not allowed" )
149+ return nil , nil , fmt .Errorf ("command not allowed" )
140150 }
141151
142152 c := reverseCommand .Command
@@ -166,9 +176,9 @@ func (s *Server) getCommand(sess ssh.Session) (*exec.Cmd, error) {
166176 }
167177
168178 s .log .Debugf ("run command '%s %s' locally" , c , strings .Join (args , " " ))
169- cmd .Env = append (cmd .Env , sess . Environ () ... )
179+ cmd .Env = append (cmd .Env , command . Env ... )
170180 cmd .Env = append (cmd .Env , os .Environ ()... )
171- return cmd , nil
181+ return cmd , command , nil
172182}
173183
174184func (s * Server ) transformPath (originalPath string ) string {
0 commit comments