Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Server struct {
PublicKeyHandler PublicKeyHandler // public key authentication handler
PtyCallback PtyCallback // callback for allowing PTY sessions, allows all if nil
ConnCallback ConnCallback // optional callback for wrapping net.Conn before handling
DisconnectCallback DisconnectCallback // optional callback executed when net.Conn disconnects
LocalPortForwardingCallback LocalPortForwardingCallback // callback for allowing local port forwarding, denies all if nil
ReversePortForwardingCallback ReversePortForwardingCallback // callback for allowing reverse port forwarding, denies all if nil
ServerConfigCallback ServerConfigCallback // callback for configuring detailed SSH options
Expand Down Expand Up @@ -307,6 +308,11 @@ func (srv *Server) HandleConn(newConn net.Conn) {
conn.updateDeadline()
srv.trackConn(sshConn, true)
defer srv.trackConn(sshConn, false)
defer func() {
if srv.DisconnectCallback != nil {
srv.DisconnectCallback(ctx, conn)
}
}()

ctx.SetValue(ContextKeyConn, sshConn)
applyConnMetadata(ctx, sshConn)
Expand Down
5 changes: 5 additions & 0 deletions ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ 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)

// DisconnectCallback is a hook for reporting closed connections
// (that is, connection that did not fire ConnectionFailedCallback)
// Please note: the net.Conn is likely closed or unusable at this point
type DisconnectCallback func(ctx Context, conn net.Conn)

// Window represents the size of a PTY window.
type Window struct {
Width int
Expand Down