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

Merge pull request #929 from slingamn/verify_rename.1

enforce nick protection immediately after verification
This commit is contained in:
Shivaram Lingamneni 2020-04-06 07:51:53 -07:00 committed by GitHub
commit ae2a92ca9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -744,6 +744,7 @@ func (am *AccountManager) dispatchMailtoCallback(client *Client, account string,
func (am *AccountManager) Verify(client *Client, account string, code string) error {
casefoldedAccount, err := CasefoldName(account)
var skeleton string
if err != nil || account == "" || account == "*" {
return errAccountVerificationFailed
}
@ -814,7 +815,7 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
})
if err == nil {
skeleton, _ := Skeleton(raw.Name)
skeleton, _ = Skeleton(raw.Name)
am.Lock()
am.nickToAccount[casefoldedAccount] = casefoldedAccount
am.skeletonToAccount[skeleton] = casefoldedAccount
@ -839,6 +840,18 @@ func (am *AccountManager) Verify(client *Client, account string, code string) er
if client != nil {
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
}

View File

@ -98,6 +98,10 @@ func (server *Server) RandomlyRename(client *Client) {
nick := strings.Replace(format, "*", utils.B32Encoder.EncodeToString(buf), -1)
sessions := client.Sessions()
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
}
// XXX arbitrarily pick the first session to receive error messages;