diff --git a/server.go b/server.go index 7dbaa0f..c3a73b3 100644 --- a/server.go +++ b/server.go @@ -51,6 +51,7 @@ type Server struct { SessionRequestCallback SessionRequestCallback // callback for allowing or denying SSH sessions ConnectionFailedCallback ConnectionFailedCallback // callback to report connection failures + ConnectionCloseCallback ConnectionCloseCallback // callback to report connection close HandshakeTimeout time.Duration // connection timeout until successful handshake, none if empty IdleTimeout time.Duration // connection timeout when no activity, none if empty @@ -296,6 +297,12 @@ func (srv *Server) HandleConn(newConn net.Conn) { } conn.updateDeadline() defer conn.Close() + defer func() { + if srv.ConnectionCloseCallback != nil { + srv.ConnectionCloseCallback(conn) + } + }() + sshConn, chans, reqs, err := gossh.NewServerConn(conn, srv.config(ctx)) if err != nil { if srv.ConnectionFailedCallback != nil { diff --git a/ssh.go b/ssh.go index 775b454..c727ce8 100644 --- a/ssh.go +++ b/ssh.go @@ -71,6 +71,9 @@ type ServerConfigCallback func(ctx Context) *gossh.ServerConfig // Please note: the net.Conn is likely to be closed at this point type ConnectionFailedCallback func(conn net.Conn, err error) +// ConnectionCloseCallback is a hook for reporting closed connections +type ConnectionCloseCallback func(conn net.Conn) + // Window represents the size of a PTY window. type Window struct { Width int