@@ -26,6 +26,7 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
2626 sshConn .Close ()
2727 return
2828 }
29+ defer sshConn .Close ()
2930
3031 sesschan := NewLogChannel (startTime , rawsesschan , sshConn .User ())
3132
@@ -53,6 +54,9 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
5354 sesschan .LogRequest (req )
5455 if req .Type == "auth-agent-req@openssh.com" {
5556 agentForwarding = true
57+ if req .WantReply {
58+ req .Reply (true , []byte {})
59+ }
5660 continue
5761 } else if (req .Type == "pty-req" ) && (req .WantReply ) {
5862 req .Reply (true , []byte {})
@@ -112,7 +116,8 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
112116 WriteAuthLog ("Connecting to remote for relay (%s) by %s from %s." , remote .ConnectPath , sshConn .User (), sshConn .RemoteAddr ())
113117 fmt .Fprintf (sesschan , "Connecting to %s\r \n " , remote_name )
114118
115- clientConfig := & ssh.ClientConfig {
119+ var clientConfig * ssh.ClientConfig
120+ clientConfig = & ssh.ClientConfig {
116121 User : sshConn .User (),
117122 Auth : []ssh.AuthMethod {
118123 ssh .PasswordCallback (func () (secret string , err error ) {
@@ -121,7 +126,7 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
121126 } else {
122127 //log.Printf("Prompting for password for remote...")
123128 t := terminal .NewTerminal (sesschan , "" )
124- s , err := t .ReadPassword (fmt .Sprintf ("%s@%s password: " , sshConn .User () , remote_name ))
129+ s , err := t .ReadPassword (fmt .Sprintf ("%s@%s password: " , clientConfig .User , remote_name ))
125130 //log.Printf("Got password for remote auth, err: %s", err)
126131 return s , err
127132 }
@@ -151,6 +156,10 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
151156 },
152157 }
153158
159+ if len (remote .LoginUser ) > 0 {
160+ clientConfig .User = remote .LoginUser
161+ }
162+
154163 // Set up the agent
155164 if agentForwarding {
156165 agentChan , agentReqs , err := sshConn .OpenChannel ("auth-agent@openssh.com" , nil )
@@ -173,6 +182,7 @@ func (s *SSHServer) SessionForward(startTime time.Time, sshConn *ssh.ServerConn,
173182 sesschan .Close ()
174183 return
175184 }
185+ defer client .Close ()
176186 log .Printf ("Dialled Remote SSH Successfully..." )
177187
178188 // Forward the session channel
0 commit comments