Selaa lähdekoodia

Merge pull request #822 from slingamn/issue821_alwayson_mismatch.2

fix #821, maybe
tags/v2.0.0-rc1
Shivaram Lingamneni 4 vuotta sitten
vanhempi
commit
e9a6864499
No account linked to committer's email address
4 muutettua tiedostoa jossa 41 lisäystä ja 10 poistoa
  1. 11
    0
      irc/accounts.go
  2. 1
    0
      irc/errors.go
  3. 27
    10
      irc/nickserv.go
  4. 2
    0
      irc/server.go

+ 11
- 0
irc/accounts.go Näytä tiedosto

@@ -935,6 +935,12 @@ func (am *AccountManager) checkPassphrase(accountName, passphrase string) (accou
935 935
 }
936 936
 
937 937
 func (am *AccountManager) AuthenticateByPassphrase(client *Client, accountName string, passphrase string) (err error) {
938
+	if client.registered {
939
+		if clientAlready := am.server.clients.Get(accountName); clientAlready != nil && clientAlready.AlwaysOn() {
940
+			return errNickAccountMismatch
941
+		}
942
+	}
943
+
938 944
 	var account ClientAccount
939 945
 
940 946
 	defer func() {
@@ -1210,6 +1216,11 @@ func (am *AccountManager) AuthenticateByCertFP(client *Client, certfp, authzid s
1210 1216
 	} else if !clientAccount.Verified {
1211 1217
 		return errAccountUnverified
1212 1218
 	}
1219
+	if client.registered {
1220
+		if clientAlready := am.server.clients.Get(clientAccount.Name); clientAlready != nil && clientAlready.AlwaysOn() {
1221
+			return errNickAccountMismatch
1222
+		}
1223
+	}
1213 1224
 	am.Login(client, clientAccount)
1214 1225
 	return nil
1215 1226
 }

+ 1
- 0
irc/errors.go Näytä tiedosto

@@ -42,6 +42,7 @@ var (
42 42
 	errNicknameInUse                  = errors.New("nickname in use")
43 43
 	errNicknameReserved               = errors.New("nickname is reserved")
44 44
 	errCantChangeNick                 = errors.New(`Always-on clients can't change nicknames`)
45
+	errNickAccountMismatch            = errors.New(`Your nickname doesn't match your account name`)
45 46
 	errNoExistingBan                  = errors.New("Ban does not exist")
46 47
 	errNoSuchChannel                  = errors.New(`No such channel`)
47 48
 	errChannelPurged                  = errors.New(`This channel was purged by the server operators and cannot be used`)

+ 27
- 10
irc/nickserv.go Näytä tiedosto

@@ -471,14 +471,26 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
471 471
 			}
472 472
 		}
473 473
 	case "always-on":
474
-		var newValue PersistentStatus
475
-		newValue, err = persistentStatusFromString(params[1])
476
-		// "opt-in" and "opt-out" don't make sense as user preferences
477
-		if err == nil && newValue != PersistentOptIn && newValue != PersistentOptOut {
478
-			munger = func(in AccountSettings) (out AccountSettings, err error) {
479
-				out = in
480
-				out.AlwaysOn = newValue
481
-				return
474
+		// #821: it's problematic to alter the value of always-on if you're not
475
+		// the (actual or potential) always-on client yourself. make an exception
476
+		// for `saset` to give operators an escape hatch (any consistency problems
477
+		// can probably be fixed by restarting the server):
478
+		if command != "saset" {
479
+			details := client.Details()
480
+			if details.nick != details.accountName {
481
+				err = errNickAccountMismatch
482
+			}
483
+		}
484
+		if err == nil {
485
+			var newValue PersistentStatus
486
+			newValue, err = persistentStatusFromString(params[1])
487
+			// "opt-in" and "opt-out" don't make sense as user preferences
488
+			if err == nil && newValue != PersistentOptIn && newValue != PersistentOptOut {
489
+				munger = func(in AccountSettings) (out AccountSettings, err error) {
490
+					out = in
491
+					out.AlwaysOn = newValue
492
+					return
493
+				}
482 494
 			}
483 495
 		}
484 496
 	case "autoreplay-missed":
@@ -515,6 +527,8 @@ func nsSetHandler(server *Server, client *Client, command string, params []strin
515 527
 		displaySetting(params[0], finalSettings, client, rb)
516 528
 	case errInvalidParams, errAccountDoesNotExist, errFeatureDisabled, errAccountUnverified, errAccountUpdateFailed:
517 529
 		nsNotice(rb, client.t(err.Error()))
530
+	case errNickAccountMismatch:
531
+		nsNotice(rb, fmt.Sprintf(client.t("Your nickname must match your account name %s exactly to modify this setting. Try changing it with /NICK, or logging out and back in with the correct nickname."), client.AccountName()))
518 532
 	default:
519 533
 		// unknown error
520 534
 		nsNotice(rb, client.t("An error occurred"))
@@ -601,6 +615,7 @@ func nsIdentifyHandler(server *Server, client *Client, command string, params []
601 615
 		return
602 616
 	}
603 617
 
618
+	var err error
604 619
 	loginSuccessful := false
605 620
 
606 621
 	var username, passphrase string
@@ -623,18 +638,20 @@ func nsIdentifyHandler(server *Server, client *Client, command string, params []
623 638
 		if !nsLoginThrottleCheck(client, rb) {
624 639
 			return
625 640
 		}
626
-		err := server.accounts.AuthenticateByPassphrase(client, username, passphrase)
641
+		err = server.accounts.AuthenticateByPassphrase(client, username, passphrase)
627 642
 		loginSuccessful = (err == nil)
628 643
 	}
629 644
 
630 645
 	// try certfp
631 646
 	if !loginSuccessful && rb.session.certfp != "" {
632
-		err := server.accounts.AuthenticateByCertFP(client, rb.session.certfp, "")
647
+		err = server.accounts.AuthenticateByCertFP(client, rb.session.certfp, "")
633 648
 		loginSuccessful = (err == nil)
634 649
 	}
635 650
 
636 651
 	if loginSuccessful {
637 652
 		sendSuccessfulAccountAuth(client, rb, true, true)
653
+	} else if err == errNickAccountMismatch {
654
+		nsNotice(rb, client.t("That account is set to always-on; try logging out and logging back in with SASL"))
638 655
 	} else {
639 656
 		nsNotice(rb, client.t("Could not login with your TLS certificate or supplied username/password"))
640 657
 	}

+ 2
- 0
irc/server.go Näytä tiedosto

@@ -584,6 +584,8 @@ func (server *Server) applyConfig(config *Config) (err error) {
584 584
 			return fmt.Errorf("Datastore path cannot be changed after launching the server, rehash aborted")
585 585
 		} else if globalCasemappingSetting != config.Server.Casemapping {
586 586
 			return fmt.Errorf("Casemapping cannot be changed after launching the server, rehash aborted")
587
+		} else if oldConfig.Accounts.Multiclient.AlwaysOn != config.Accounts.Multiclient.AlwaysOn {
588
+			return fmt.Errorf("Default always-on setting cannot be changed after launching the server, rehash aborted")
587 589
 		}
588 590
 	}
589 591
 

Loading…
Peruuta
Tallenna