diff --git a/lib/session.go b/lib/session.go index f1842d5..ca80800 100644 --- a/lib/session.go +++ b/lib/session.go @@ -52,8 +52,11 @@ type SSHSession struct { log *zap.Logger } -func NewSSHSession(state *SSHDState, conn *ssh.ServerConn) *SSHSession { - id := uuid.NewV4() +func NewSSHSession(state *SSHDState, conn *ssh.ServerConn) (*SSHSession, error) { + id, err := uuid.NewV4() + if err != nil { + return nil, err + } strID, _ := id.MarshalText() @@ -71,7 +74,7 @@ func NewSSHSession(state *SSHDState, conn *ssh.ServerConn) *SSHSession { Account: state.accounts[conn.User()], Conn: conn, log: state.log, - } + }, nil } func (s *SSHSession) handleChannels(chans <-chan ssh.NewChannel) { diff --git a/lib/sshd.go b/lib/sshd.go index bc8d3b3..70e1ecf 100644 --- a/lib/sshd.go +++ b/lib/sshd.go @@ -301,7 +301,12 @@ func (s *SSHDState) handleNewConnection(tcpConn net.Conn, sshConfig *ssh.ServerC } // Open the SSH session for the connection, and track it in our sessions mapping - session := NewSSHSession(s, sshConn) + session, err := NewSSHSession(s, sshConn) + if err != nil { + s.log.Warn("Failed to create an SSH sessoin", zap.Error(err)) + return + } + s.sessions[session.UUID] = session s.log.Info(