3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 18:52:41 +01:00

enforce nick protection immediately after verification

This commit is contained in:
Shivaram Lingamneni 2020-04-06 00:06:06 -04:00
parent 7929d82e09
commit d6e3f188cf
2 changed files with 18 additions and 1 deletions

View File

@ -750,6 +750,7 @@ func (am *AccountManager) dispatchMailtoCallback(client *Client, casefoldedAccou
func (am *AccountManager) Verify(client *Client, account string, code string) error { func (am *AccountManager) Verify(client *Client, account string, code string) error {
casefoldedAccount, err := CasefoldName(account) casefoldedAccount, err := CasefoldName(account)
var skeleton string
if err != nil || account == "" || account == "*" { if err != nil || account == "" || account == "*" {
return errAccountVerificationFailed return errAccountVerificationFailed
} }
@ -820,7 +821,7 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
}) })
if err == nil { if err == nil {
skeleton, _ := Skeleton(raw.Name) skeleton, _ = Skeleton(raw.Name)
am.Lock() am.Lock()
am.nickToAccount[casefoldedAccount] = casefoldedAccount am.nickToAccount[casefoldedAccount] = casefoldedAccount
am.skeletonToAccount[skeleton] = casefoldedAccount am.skeletonToAccount[skeleton] = casefoldedAccount
@ -845,6 +846,18 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
if client != nil { if client != nil {
am.Login(client, clientAccount) am.Login(client, clientAccount)
} }
_, method := am.EnforcementStatus(casefoldedAccount, skeleton)
if method != NickEnforcementNone {
currentClient := am.server.clients.Get(casefoldedAccount)
if currentClient == nil || currentClient == client || currentClient.Account() == casefoldedAccount {
return nil
}
if method == NickEnforcementStrict {
am.server.RandomlyRename(currentClient)
} else if method == NickEnforcementWithTimeout {
currentClient.nickTimer.Touch(nil)
}
}
return nil return nil
} }

View File

@ -98,6 +98,10 @@ func (server *Server) RandomlyRename(client *Client) {
nick := strings.Replace(format, "*", utils.B32Encoder.EncodeToString(buf), -1) nick := strings.Replace(format, "*", utils.B32Encoder.EncodeToString(buf), -1)
sessions := client.Sessions() sessions := client.Sessions()
if len(sessions) == 0 { if len(sessions) == 0 {
// this can happen if they are anonymous and BRB (in general, an always-on
// client has title to its nickname and will never be the victim of
// a call to RandomlyRename)
client.destroy(nil)
return return
} }
// XXX arbitrarily pick the first session to receive error messages; // XXX arbitrarily pick the first session to receive error messages;