sshconn: use a generic io.Closer instead of a net.Conn

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-04-02 18:52:06 +02:00
parent 3cae004e6b
commit 5954d4ae20
2 changed files with 5 additions and 4 deletions

View File

@@ -19,6 +19,7 @@ import (
"context"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
@@ -899,12 +900,12 @@ func getProxyPolicy(allowed, skipped []func(net.IP) bool, def proxyproto.Policy)
// Each SSH connection can open several channels for SFTP or SSH commands
type SSHConnection struct {
id string
conn net.Conn
conn io.Closer
lastActivity atomic.Int64
}
// NewSSHConnection returns a new SSHConnection
func NewSSHConnection(id string, conn net.Conn) *SSHConnection {
func NewSSHConnection(id string, conn io.Closer) *SSHConnection {
c := &SSHConnection{
id: id,
conn: conn,

View File

@@ -592,7 +592,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
conn.SetDeadline(time.Time{}) //nolint:errcheck
go ssh.DiscardRequests(reqs)
defer conn.Close()
defer sconn.Close()
var user dataprovider.User
@@ -615,7 +615,7 @@ func (c *Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Serve
dataprovider.UpdateLastLogin(&user)
sshConnection := common.NewSSHConnection(connectionID, conn)
sshConnection := common.NewSSHConnection(connectionID, sconn)
common.Connections.AddSSHConnection(sshConnection)
defer common.Connections.RemoveSSHConnection(connectionID)