3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-25 13:29:27 +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
}
// if nick reservation is enabled, you can only register your current nickname
// as an account; this prevents "land-grab" situations where someone else
// registers your nick out from under you and then NS GHOSTs you
// n.b. client is nil during a SAREGISTER
// n.b. if ForceGuestFormat, then there's no concern, because you can't
// register a guest nickname anyway, and the actual registration system
// will prevent any double-register
if client != nil {
if client.registered {
if config.Accounts.NickReservation.Enabled &&
!config.Accounts.NickReservation.ForceGuestFormat &&
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
}
// if nick reservation is enabled, don't let people reserve nicknames
// that they would not be eligible to take, e.g.,
// 1. a nickname that someone else is currently holding
// 2. a nickname confusable with an existing reserved nickname
// this has a lot of weird edge cases because of force-guest-format
// and the possibility of registering a nickname on an "unregistered connection"
// (i.e., pre-handshake).
if client != nil && config.Accounts.NickReservation.Enabled {
_, 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
}
if account == "" && config.Accounts.NickReservation.ForceGuestFormat {
if account == "" && config.Accounts.NickReservation.ForceGuestFormat && !dryRun {
newCfNick, err = CasefoldName(newNick)
if err != nil {
return "", errNicknameInvalid, false
@ -199,9 +199,10 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
currentClient := clients.byNick[newCfNick]
// 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:
if registered || !bouncerAllowed || account == "" || account != currentClient.Account() {
if registered || !bouncerAllowed || account == "" || account != currentClient.Account() ||
dryRun || session == nil {
return "", errNicknameInUse, false
}
// check TLS modes