diff --git a/README.md b/README.md index f206343d..0a36748a 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/sftpd/handler.go b/sftpd/handler.go index e5ea92d3..61ca3417 100644 --- a/sftpd/handler.go +++ b/sftpd/handler.go @@ -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 diff --git a/sftpd/server.go b/sftpd/server.go index 976994ca..82e2d3da 100644 --- a/sftpd/server.go +++ b/sftpd/server.go @@ -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) diff --git a/sftpd/sftpd.go b/sftpd/sftpd.go index 23f1b4c5..acd911b3 100644 --- a/sftpd/sftpd.go +++ b/sftpd/sftpd.go @@ -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) }