mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
use net.Conn instead of ssh.Conn to close connections
This commit is contained in:
parent
c1effdf701
commit
784f75f45b
4 changed files with 6 additions and 9 deletions
|
@ -114,7 +114,7 @@ The `sftpgo` configuration file contains the following sections:
|
|||
- **"sftpd"**, the configuration for the SFTP server
|
||||
- `bind_port`, integer. The port used for serving SFTP requests. Default: 2022
|
||||
- `bind_address`, string. Leave blank to listen on all available network interfaces. Default: ""
|
||||
- `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. Default: 15
|
||||
- `idle_timeout`, integer. Time in minutes after which an idle client will be disconnected. 0 menas disabled. Default: 15
|
||||
- `max_auth_tries` integer. Maximum number of authentication attempts permitted per connection. If set to a negative number, the number of attempts are unlimited. If set to zero, the number of attempts are limited to 6.
|
||||
- `umask`, string. Umask for the new files and directories. This setting has no effect on Windows. Default: "0022"
|
||||
- `banner`, string. Identification string used by the server. Default "SFTPGo"
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
|
||||
"github.com/drakkan/sftpgo/dataprovider"
|
||||
"github.com/drakkan/sftpgo/logger"
|
||||
"golang.org/x/crypto/ssh"
|
||||
|
||||
"github.com/pkg/sftp"
|
||||
)
|
||||
|
@ -37,7 +36,7 @@ type Connection struct {
|
|||
lastActivity time.Time
|
||||
protocol string
|
||||
lock *sync.Mutex
|
||||
sshConn *ssh.ServerConn
|
||||
netConn net.Conn
|
||||
}
|
||||
|
||||
// Log outputs a log entry to the configured logger
|
||||
|
|
|
@ -197,7 +197,6 @@ func (c Configuration) configureLoginBanner(serverConfig *ssh.ServerConfig, conf
|
|||
|
||||
// AcceptInboundConnection handles an inbound connection to the server instance and determines if the request should be served or not.
|
||||
func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.ServerConfig) {
|
||||
defer conn.Close()
|
||||
|
||||
// Before beginning a handshake must be performed on the incoming net.Conn
|
||||
sconn, chans, reqs, err := ssh.NewServerConn(conn, config)
|
||||
|
@ -205,7 +204,6 @@ func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Server
|
|||
logger.Warn(logSender, "", "failed to accept an incoming connection: %v", err)
|
||||
return
|
||||
}
|
||||
defer sconn.Close()
|
||||
|
||||
logger.Debug(logSender, "", "accepted inbound connection, ip: %v", conn.RemoteAddr().String())
|
||||
|
||||
|
@ -230,7 +228,7 @@ func (c Configuration) AcceptInboundConnection(conn net.Conn, config *ssh.Server
|
|||
StartTime: time.Now(),
|
||||
lastActivity: time.Now(),
|
||||
lock: new(sync.Mutex),
|
||||
sshConn: sconn,
|
||||
netConn: conn,
|
||||
}
|
||||
connection.Log(logger.LevelInfo, logSender, "User id: %d, logged in with: %#v, username: %#v, home_dir: %#v",
|
||||
user.ID, loginType, user.Username, user.HomeDir)
|
||||
|
|
|
@ -173,8 +173,8 @@ func CloseActiveConnection(connectionID string) bool {
|
|||
defer mutex.RUnlock()
|
||||
for _, c := range openConnections {
|
||||
if c.ID == connectionID {
|
||||
c.Log(logger.LevelDebug, logSender, "closing connection")
|
||||
c.sshConn.Close()
|
||||
err := c.netConn.Close()
|
||||
c.Log(logger.LevelDebug, logSender, "close connection requested, err: %v", err)
|
||||
result = true
|
||||
break
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ func CheckIdleConnections() {
|
|||
}
|
||||
if idleTime > idleTimeout {
|
||||
c.Log(logger.LevelInfo, logSender, "close idle connection, idle time: %v", idleTime)
|
||||
err := c.sshConn.Close()
|
||||
err := c.netConn.Close()
|
||||
if err != nil {
|
||||
c.Log(logger.LevelWarn, logSender, "idle connection close failed: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue