3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 21:39:25 +01:00

review fixes

This commit is contained in:
Shivaram Lingamneni 2020-10-07 08:54:46 -04:00
parent 9ed789f67c
commit 754fb79cdd
2 changed files with 15 additions and 25 deletions

View File

@ -403,28 +403,17 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
return errLimitExceeded return errLimitExceeded
} }
// if nick reservation is enabled, you can only register your current nickname // if nick reservation is enabled, don't let people reserve nicknames
// as an account; this prevents "land-grab" situations where someone else // that they would not be eligible to take, e.g.,
// registers your nick out from under you and then NS GHOSTs you // 1. a nickname that someone else is currently holding
// n.b. client is nil during a SAREGISTER // 2. a nickname confusable with an existing reserved nickname
// n.b. if ForceGuestFormat, then there's no concern, because you can't // this has a lot of weird edge cases because of force-guest-format
// register a guest nickname anyway, and the actual registration system // and the possibility of registering a nickname on an "unregistered connection"
// will prevent any double-register // (i.e., pre-handshake).
if client != nil { if client != nil && config.Accounts.NickReservation.Enabled {
if client.registered { _, nickAcquireError, _ := am.server.clients.SetNick(client, nil, account, true)
if config.Accounts.NickReservation.Enabled && if !(nickAcquireError == nil || nickAcquireError == errNoop) {
!config.Accounts.NickReservation.ForceGuestFormat && return errAccountMustHoldNick
client.NickCasefolded() != casefoldedAccount {
return errAccountMustHoldNick
}
} else {
// XXX this is a REGISTER command from a client who hasn't completed the
// initial handshake ("connection registration"). Do SetNick with dryRun=true,
// testing whether they are able to claim the nick
_, nickAcquireError, _ := am.server.clients.SetNick(client, nil, account, true)
if !(nickAcquireError == nil || nickAcquireError == errNoop) {
return errAccountMustHoldNick
}
} }
} }

View File

@ -142,7 +142,7 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
return "", errNickMissing, false return "", errNickMissing, false
} }
if account == "" && config.Accounts.NickReservation.ForceGuestFormat { if account == "" && config.Accounts.NickReservation.ForceGuestFormat && !dryRun {
newCfNick, err = CasefoldName(newNick) newCfNick, err = CasefoldName(newNick)
if err != nil { if err != nil {
return "", errNicknameInvalid, false return "", errNicknameInvalid, false
@ -199,9 +199,10 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
currentClient := clients.byNick[newCfNick] currentClient := clients.byNick[newCfNick]
// the client may just be changing case // the client may just be changing case
if currentClient != nil && currentClient != client && session != nil { if currentClient != nil && currentClient != client {
// these conditions forbid reattaching to an existing session: // these conditions forbid reattaching to an existing session:
if registered || !bouncerAllowed || account == "" || account != currentClient.Account() { if registered || !bouncerAllowed || account == "" || account != currentClient.Account() ||
dryRun || session == nil {
return "", errNicknameInUse, false return "", errNicknameInUse, false
} }
// check TLS modes // check TLS modes