Procházet zdrojové kódy

fix various bugs

tags/v2.1.0-rc1
Shivaram Lingamneni před 4 roky
rodič
revize
6d65335071
5 změnil soubory, kde provedl 40 přidání a 28 odebrání
  1. 4
    0
      irc/accounts.go
  2. 1
    2
      irc/errors.go
  3. 5
    1
      irc/handlers.go
  4. 22
    2
      irc/nickname.go
  5. 8
    23
      irc/nickserv.go

+ 4
- 0
irc/accounts.go Zobrazit soubor

@@ -943,6 +943,10 @@ func (am *AccountManager) checkPassphrase(accountName, passphrase string) (accou
943 943
 }
944 944
 
945 945
 func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName string, passphrase string) (err error) {
946
+	// XXX check this now, so we don't allow a redundant login for an always-on client
947
+	// even for a brief period. the other potential source of nick-account conflicts
948
+	// is from force-nick-equals-account, but those will be caught later by
949
+	// fixupNickEqualsAccount and if there is a conflict, they will be logged out.
946 950
 	if client.registered {
947 951
 		if clientAlready := am.server.clients.Get(accountName); clientAlready != nil && clientAlready.AlwaysOn() {
948 952
 			return errNickAccountMismatch

+ 1
- 2
irc/errors.go Zobrazit soubor

@@ -41,8 +41,7 @@ var (
41 41
 	errNicknameInvalid                = errors.New("invalid nickname")
42 42
 	errNicknameInUse                  = errors.New("nickname in use")
43 43
 	errNicknameReserved               = errors.New("nickname is reserved")
44
-	errCantChangeNick                 = errors.New(`You must use your account name as your nickname`)
45
-	errNickAccountMismatch            = errors.New(`Your nickname must match your account name`)
44
+	errNickAccountMismatch            = errors.New(`Your nickname must match your account name; try logging out and logging back in with SASL`)
46 45
 	errNoExistingBan                  = errors.New("Ban does not exist")
47 46
 	errNoSuchChannel                  = errors.New(`No such channel`)
48 47
 	errChannelPurged                  = errors.New(`This channel was purged by the server operators and cannot be used`)

+ 5
- 1
irc/handlers.go Zobrazit soubor

@@ -237,6 +237,8 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
237 237
 		msg := authErrorToMessage(server, err)
238 238
 		rb.Add(nil, server.name, ERR_SASLFAIL, client.Nick(), fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))
239 239
 		return false
240
+	} else if !fixupNickEqualsAccount(client, rb, server.Config()) {
241
+		return false
240 242
 	}
241 243
 
242 244
 	sendSuccessfulAccountAuth(client, rb, false, true)
@@ -245,7 +247,7 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
245 247
 
246 248
 func authErrorToMessage(server *Server, err error) (msg string) {
247 249
 	switch err {
248
-	case errAccountDoesNotExist, errAccountUnverified, errAccountInvalidCredentials, errAuthzidAuthcidMismatch:
250
+	case errAccountDoesNotExist, errAccountUnverified, errAccountInvalidCredentials, errAuthzidAuthcidMismatch, errNickAccountMismatch:
249 251
 		return err.Error()
250 252
 	default:
251 253
 		// don't expose arbitrary error messages to the user
@@ -280,6 +282,8 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value
280 282
 		msg := authErrorToMessage(server, err)
281 283
 		rb.Add(nil, server.name, ERR_SASLFAIL, client.nick, fmt.Sprintf("%s: %s", client.t("SASL authentication failed"), client.t(msg)))
282 284
 		return false
285
+	} else if !fixupNickEqualsAccount(client, rb, server.Config()) {
286
+		return false
283 287
 	}
284 288
 
285 289
 	sendSuccessfulAccountAuth(client, rb, false, true)

+ 22
- 2
irc/nickname.go Zobrazit soubor

@@ -37,9 +37,9 @@ func performNickChange(server *Server, client *Client, target *Client, session *
37 37
 
38 38
 	assignedNickname, err := client.server.clients.SetNick(target, session, nickname)
39 39
 	if err == errNicknameInUse {
40
-		rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, nickname, client.t("Nickname is already in use"))
40
+		rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, utils.SafeErrorParam(nickname), client.t("Nickname is already in use"))
41 41
 	} else if err == errNicknameReserved {
42
-		rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, nickname, client.t("Nickname is reserved by a different account"))
42
+		rb.Add(nil, server.name, ERR_NICKNAMEINUSE, currentNick, utils.SafeErrorParam(nickname), client.t("Nickname is reserved by a different account"))
43 43
 	} else if err == errNicknameInvalid {
44 44
 		rb.Add(nil, server.name, ERR_ERRONEUSNICKNAME, currentNick, utils.SafeErrorParam(nickname), client.t("Erroneous nickname"))
45 45
 	} else if err == errNickAccountMismatch {
@@ -108,3 +108,23 @@ func (server *Server) RandomlyRename(client *Client) {
108 108
 	// technically performNickChange can fail to change the nick,
109 109
 	// but if they're still delinquent, the timer will get them later
110 110
 }
111
+
112
+// if force-nick-equals-account is set, account name and nickname must be equal,
113
+// so we need to re-NICK automatically on every login event (IDENTIFY,
114
+// VERIFY, and a REGISTER that auto-verifies). if we can't get the nick
115
+// then we log them out (they will be able to reattach with SASL)
116
+func fixupNickEqualsAccount(client *Client, rb *ResponseBuffer, config *Config) (success bool) {
117
+	if !config.Accounts.NickReservation.ForceNickEqualsAccount {
118
+		return true
119
+	}
120
+	if !client.registered {
121
+		return true
122
+	}
123
+	// don't need to supply a nickname, SetNick will use the account name
124
+	if !performNickChange(client.server, client, client, rb.session, "", rb) {
125
+		client.server.accounts.Logout(client)
126
+		nsNotice(rb, client.t("A client is already using that account; try logging out and logging back in with SASL"))
127
+		return false
128
+	}
129
+	return true
130
+}

+ 8
- 23
irc/nickserv.go Zobrazit soubor

@@ -610,23 +610,6 @@ func nsLoginThrottleCheck(client *Client, rb *ResponseBuffer) (success bool) {
610 610
 	return true
611 611
 }
612 612
 
613
-// if force-nick-equals-account is set, account name and nickname must be equal,
614
-// so we need to re-NICK automatically on every login event (IDENTIFY,
615
-// VERIFY, and a REGISTER that auto-verifies). if we can't get the nick
616
-// then we log them out (they will be able to reattach with SASL)
617
-func nsFixNickname(client *Client, rb *ResponseBuffer, config *Config) (success bool) {
618
-	if !config.Accounts.NickReservation.ForceNickEqualsAccount {
619
-		return true
620
-	}
621
-	// don't need to supply a nickname, SetNick will use the account name
622
-	if !performNickChange(client.server, client, client, rb.session, "", rb) {
623
-		client.server.accounts.Logout(client)
624
-		nsNotice(rb, client.t("A client is already using that account; try logging out and logging back in with SASL"))
625
-		return false
626
-	}
627
-	return true
628
-}
629
-
630 613
 func nsIdentifyHandler(server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
631 614
 	if client.LoggedIntoAccount() {
632 615
 		nsNotice(rb, client.t("You're already logged into an account"))
@@ -666,17 +649,19 @@ func nsIdentifyHandler(server *Server, client *Client, command string, params []
666 649
 		loginSuccessful = (err == nil)
667 650
 	}
668 651
 
652
+	nickFixupFailed := false
669 653
 	if loginSuccessful {
670
-		if !nsFixNickname(client, rb, server.Config()) {
654
+		if !fixupNickEqualsAccount(client, rb, server.Config()) {
671 655
 			loginSuccessful = false
672
-			err = errNickAccountMismatch
656
+			// fixupNickEqualsAccount sends its own error message, don't send another
657
+			nickFixupFailed = true
673 658
 		}
674 659
 	}
675 660
 
676 661
 	if loginSuccessful {
677 662
 		sendSuccessfulAccountAuth(client, rb, true, true)
678
-	} else if err != errNickAccountMismatch {
679
-		nsNotice(rb, client.t("Could not login with your TLS certificate or supplied username/password"))
663
+	} else if !nickFixupFailed {
664
+		nsNotice(rb, fmt.Sprintf(client.t("Authentication failed: %s"), authErrorToMessage(server, err)))
680 665
 	}
681 666
 }
682 667
 
@@ -786,7 +771,7 @@ func nsRegisterHandler(server *Server, client *Client, command string, params []
786 771
 	if err == nil {
787 772
 		if callbackNamespace == "*" {
788 773
 			err = server.accounts.Verify(client, account, "")
789
-			if err == nil && nsFixNickname(client, rb, config) {
774
+			if err == nil && fixupNickEqualsAccount(client, rb, config) {
790 775
 				sendSuccessfulRegResponse(client, rb, true)
791 776
 			}
792 777
 		} else {
@@ -892,7 +877,7 @@ func nsVerifyHandler(server *Server, client *Client, command string, params []st
892 877
 		return
893 878
 	}
894 879
 
895
-	if nsFixNickname(client, rb, server.Config()) {
880
+	if fixupNickEqualsAccount(client, rb, server.Config()) {
896 881
 		sendSuccessfulRegResponse(client, rb, true)
897 882
 	}
898 883
 }

Načítá se…
Zrušit
Uložit