Browse Source

review fixes

tags/v2.4.0-rc1
Shivaram Lingamneni 3 years ago
parent
commit
754fb79cdd
2 changed files with 15 additions and 25 deletions
  1. 11
    22
      irc/accounts.go
  2. 4
    3
      irc/client_lookup_set.go

+ 11
- 22
irc/accounts.go View File

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

+ 4
- 3
irc/client_lookup_set.go View File

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

Loading…
Cancel
Save