sshd: map each channel with a new connection

Fixes #169
This commit is contained in:
Nicola Murino
2020-09-18 10:52:53 +02:00
parent 98a6d138d4
commit 2df0dd1f70
10 changed files with 57 additions and 61 deletions

View File

@@ -23,7 +23,6 @@ type Connection struct {
ClientVersion string
// Remote address for this connection
RemoteAddr net.Addr
netConn net.Conn
channel ssh.Channel
command string
}
@@ -38,11 +37,6 @@ func (c *Connection) GetRemoteAddress() string {
return c.RemoteAddr.String()
}
// SetConnDeadline sets a deadline on the network connection so it will be eventually closed
func (c *Connection) SetConnDeadline() {
c.netConn.SetDeadline(time.Now().Add(2 * time.Minute)) //nolint:errcheck
}
// GetCommand returns the SSH command, if any
func (c *Connection) GetCommand() string {
return c.command
@@ -413,11 +407,7 @@ func (c *Connection) handleSFTPUploadToExistingFile(pflags sftp.FileOpenFlags, r
// Disconnect disconnects the client closing the network connection
func (c *Connection) Disconnect() error {
if c.channel != nil {
err := c.channel.Close()
c.Log(logger.LevelInfo, "channel close, err: %v", err)
}
return c.netConn.Close()
return c.channel.Close()
}
func getOSOpenFlags(requestFlags sftp.FileOpenFlags) (flags int) {