Host.go: assign registered nicks to users upon connection.

This commit is contained in:
nato 2023-02-05 15:09:09 -08:00
parent 043b45dbbe
commit fedad0f216
2 changed files with 22 additions and 0 deletions

13
auth.go
View File

@ -67,6 +67,7 @@ type Auth struct {
settingsMu sync.RWMutex settingsMu sync.RWMutex
allowlistMode bool allowlistMode bool
keynamesMode bool
opLoader KeyLoader opLoader KeyLoader
allowlistLoader KeyLoader allowlistLoader KeyLoader
} }
@ -96,6 +97,18 @@ func (a *Auth) SetAllowlistMode(value bool) {
a.allowlistMode = value a.allowlistMode = value
} }
func (a *Auth) SetKeynamesMode(value bool) {
a.settingsMu.Lock()
defer a.settingsMu.Unlock()
a.keynamesMode = value
}
func (a *Auth) Keyname(key ssh.PublicKey) string {
fingerprint := sshd.Fingerprint(key)
name := a.keynamesByFingerprint[fingerprint]
return name
}
// SetPassphrase enables passphrase authentication with the given passphrase. // SetPassphrase enables passphrase authentication with the given passphrase.
// If an empty passphrase is given, disable passphrase authentication. // If an empty passphrase is given, disable passphrase authentication.
func (a *Auth) SetPassphrase(passphrase string) { func (a *Auth) SetPassphrase(passphrase string) {

View File

@ -101,6 +101,15 @@ func (h *Host) isOp(conn sshd.Connection) bool {
// Connect a specific Terminal to this host and its room. // Connect a specific Terminal to this host and its room.
func (h *Host) Connect(term *sshd.Terminal) { func (h *Host) Connect(term *sshd.Terminal) {
id := NewIdentity(term.Conn) id := NewIdentity(term.Conn)
if h.auth.keynamesMode {
name := h.auth.Keyname(id.PublicKey())
if len(name) >0 {
id.SetName(name)
id.SetSymbol("✓")
}
}
user := message.NewUserScreen(id, term) user := message.NewUserScreen(id, term)
user.OnChange = func() { user.OnChange = func() {
term.SetPrompt(GetPrompt(user)) term.SetPrompt(GetPrompt(user))