@ -30,7 +30,7 @@ type SSHServer struct {
func ( s * SSHServer ) ListenAndServe ( ) error {
func ( s * SSHServer ) ListenAndServe ( ) error {
ln , err := net . Listen ( "tcp" , s . Addr )
ln , err := net . Listen ( "tcp" , s . Addr )
if err != nil {
if err != nil {
glog . V ( 1 ) . Infoln ( "[ssh] Listen:" , err )
glog . V ( LWARNING ) . Infoln ( "[ssh] Listen:" , err )
return err
return err
}
}
defer ln . Close ( )
defer ln . Close ( )
@ -38,14 +38,14 @@ func (s *SSHServer) ListenAndServe() error {
for {
for {
conn , err := ln . Accept ( )
conn , err := ln . Accept ( )
if err != nil {
if err != nil {
glog . V ( 1 ) . Infoln ( "[ssh] Accept:" , err )
glog . V ( LWARNING ) . Infoln ( "[ssh] Accept:" , err )
return err
return err
}
}
go func ( conn net . Conn ) {
go func ( conn net . Conn ) {
sshConn , chans , reqs , err := ssh . NewServerConn ( conn , s . Config )
sshConn , chans , reqs , err := ssh . NewServerConn ( conn , s . Config )
if err != nil {
if err != nil {
glog . V ( 1 ) . Infof ( "[ssh] %s -> %s : %s" , conn . RemoteAddr ( ) , s . Addr , err )
glog . V ( LWARNING ) . Infof ( "[ssh] %s -> %s : %s" , conn . RemoteAddr ( ) , s . Addr , err )
return
return
}
}
defer sshConn . Close ( )
defer sshConn . Close ( )
@ -54,9 +54,9 @@ func (s *SSHServer) ListenAndServe() error {
s . Handler = s . handleSSHConn
s . Handler = s . handleSSHConn
}
}
glog . V ( 3 ) . Infof ( "[ssh] %s <-> %s" , conn . RemoteAddr ( ) , s . Addr )
glog . V ( LINFO ) . Infof ( "[ssh] %s <-> %s" , conn . RemoteAddr ( ) , s . Addr )
s . Handler ( sshConn , chans , reqs )
s . Handler ( sshConn , chans , reqs )
glog . V ( 3 ) . Infof ( "[ssh] %s >-< %s" , conn . RemoteAddr ( ) , s . Addr )
glog . V ( LINFO ) . Infof ( "[ssh] %s >-< %s" , conn . RemoteAddr ( ) , s . Addr )
} ( conn )
} ( conn )
}
}
}
}
@ -69,6 +69,7 @@ func (s *SSHServer) handleSSHConn(conn ssh.Conn, chans <-chan ssh.NewChannel, re
case RemoteForwardRequest :
case RemoteForwardRequest :
go s . tcpipForwardRequest ( conn , req , quit )
go s . tcpipForwardRequest ( conn , req , quit )
default :
default :
// glog.V(LWARNING).Infoln("unknown channel type:", req.Type)
if req . WantReply {
if req . WantReply {
req . Reply ( false , nil )
req . Reply ( false , nil )
}
}
@ -84,7 +85,7 @@ func (s *SSHServer) handleSSHConn(conn ssh.Conn, chans <-chan ssh.NewChannel, re
case DirectForwardRequest :
case DirectForwardRequest :
channel , requests , err := newChannel . Accept ( )
channel , requests , err := newChannel . Accept ( )
if err != nil {
if err != nil {
glog . V ( 3 ) . Infoln ( "[ssh] Could not accept channel:" , err )
glog . V ( LINFO ) . Infoln ( "[ssh] Could not accept channel:" , err )
continue
continue
}
}
p := directForward { }
p := directForward { }
@ -93,7 +94,7 @@ func (s *SSHServer) handleSSHConn(conn ssh.Conn, chans <-chan ssh.NewChannel, re
go ssh . DiscardRequests ( requests )
go ssh . DiscardRequests ( requests )
go s . directPortForwardChannel ( channel , fmt . Sprintf ( "%s:%d" , p . Host1 , p . Port1 ) )
go s . directPortForwardChannel ( channel , fmt . Sprintf ( "%s:%d" , p . Host1 , p . Port1 ) )
default :
default :
glog . V ( 3 ) . Infoln ( "[ssh] Unknown channel type:" , t )
glog . V ( LWARNING ) . Infoln ( "[ssh] Unknown channel type:" , t )
newChannel . Reject ( ssh . UnknownChannelType , fmt . Sprintf ( "unknown channel type: %s" , t ) )
newChannel . Reject ( ssh . UnknownChannelType , fmt . Sprintf ( "unknown channel type: %s" , t ) )
}
}
}
}
@ -118,18 +119,18 @@ func (p directForward) String() string {
func ( s * SSHServer ) directPortForwardChannel ( channel ssh . Channel , raddr string ) {
func ( s * SSHServer ) directPortForwardChannel ( channel ssh . Channel , raddr string ) {
defer channel . Close ( )
defer channel . Close ( )
glog . V ( 3 ) . Infof ( "[ssh-tcp] %s - %s" , s . Addr , raddr )
glog . V ( LINFO ) . Infof ( "[ssh-tcp] %s - %s" , s . Addr , raddr )
conn , err := s . Base . Chain . Dial ( raddr )
conn , err := s . Base . Chain . Dial ( raddr )
if err != nil {
if err != nil {
glog . V ( 3 ) . Infof ( "[ssh-tcp] %s - %s : %s" , s . Addr , raddr , err )
glog . V ( LINFO ) . Infof ( "[ssh-tcp] %s - %s : %s" , s . Addr , raddr , err )
return
return
}
}
defer conn . Close ( )
defer conn . Close ( )
glog . V ( 3 ) . Infof ( "[ssh-tcp] %s <-> %s" , s . Addr , raddr )
glog . V ( LINFO ) . Infof ( "[ssh-tcp] %s <-> %s" , s . Addr , raddr )
Transport ( conn , channel )
Transport ( conn , channel )
glog . V ( 3 ) . Infof ( "[ssh-tcp] %s >-< %s" , s . Addr , raddr )
glog . V ( LINFO ) . Infof ( "[ssh-tcp] %s >-< %s" , s . Addr , raddr )
}
}
// tcpipForward is structure for RFC 4254 7.1 "tcpip-forward" request
// tcpipForward is structure for RFC 4254 7.1 "tcpip-forward" request
@ -142,10 +143,10 @@ func (s *SSHServer) tcpipForwardRequest(sshConn ssh.Conn, req *ssh.Request, quit
t := tcpipForward { }
t := tcpipForward { }
ssh . Unmarshal ( req . Payload , & t )
ssh . Unmarshal ( req . Payload , & t )
addr := fmt . Sprintf ( "%s:%d" , t . Host , t . Port )
addr := fmt . Sprintf ( "%s:%d" , t . Host , t . Port )
glog . V ( 3 ) . Infoln ( "[ssh-rtcp] listening tcp" , addr )
glog . V ( LINFO ) . Infoln ( "[ssh-rtcp] listening tcp" , addr )
ln , err := net . Listen ( "tcp" , addr ) //tie to the client connection
ln , err := net . Listen ( "tcp" , addr ) //tie to the client connection
if err != nil {
if err != nil {
glog . V ( 1 ) . Infoln ( "[ssh-rtcp]" , err )
glog . V ( LWARNING ) . Infoln ( "[ssh-rtcp]" , err )
req . Reply ( false , nil )
req . Reply ( false , nil )
return
return
}
}
@ -165,7 +166,7 @@ func (s *SSHServer) tcpipForwardRequest(sshConn ssh.Conn, req *ssh.Request, quit
return req . Reply ( true , nil )
return req . Reply ( true , nil )
}
}
if err := replyFunc ( ) ; err != nil {
if err := replyFunc ( ) ; err != nil {
glog . V ( 1 ) . Infoln ( "[ssh-rtcp]" , err )
glog . V ( LWARNING ) . Infoln ( "[ssh-rtcp]" , err )
return
return
}
}
@ -199,9 +200,9 @@ func (s *SSHServer) tcpipForwardRequest(sshConn ssh.Conn, req *ssh.Request, quit
defer ch . Close ( )
defer ch . Close ( )
go ssh . DiscardRequests ( reqs )
go ssh . DiscardRequests ( reqs )
glog . V ( 3 ) . Infof ( "[ssh-rtcp] %s <-> %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) )
glog . V ( LINFO ) . Infof ( "[ssh-rtcp] %s <-> %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) )
Transport ( ch , conn )
Transport ( ch , conn )
glog . V ( 3 ) . Infof ( "[ssh-rtcp] %s >-< %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) )
glog . V ( LINFO ) . Infof ( "[ssh-rtcp] %s >-< %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) )
} ( conn )
} ( conn )
}
}
} ( )
} ( )
@ -229,7 +230,7 @@ func DefaultPasswordCallback(users []*url.Userinfo) PasswordCallbackFunc {
return nil , nil
return nil , nil
}
}
}
}
glog . V ( 3 ) . Infof ( "[ssh] %s -> %s : password rejected for %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) , conn . User ( ) )
glog . V ( LINFO ) . Infof ( "[ssh] %s -> %s : password rejected for %s" , conn . RemoteAddr ( ) , conn . LocalAddr ( ) , conn . User ( ) )
return nil , fmt . Errorf ( "password rejected for %s" , conn . User ( ) )
return nil , fmt . Errorf ( "password rejected for %s" , conn . User ( ) )
}
}
}
}