mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix #955
This commit is contained in:
parent
eebe681538
commit
40d3c59139
@ -205,9 +205,18 @@ func (clients *ClientManager) SetNick(client *Client, session *Session, newNick
|
|||||||
// 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 && session != nil {
|
||||||
// these conditions forbid reattaching to an existing session:
|
// these conditions forbid reattaching to an existing session:
|
||||||
if registered || !bouncerAllowed || account == "" || account != currentClient.Account() || client.HasMode(modes.TLS) != currentClient.HasMode(modes.TLS) {
|
if registered || !bouncerAllowed || account == "" || account != currentClient.Account() {
|
||||||
return "", errNicknameInUse
|
return "", errNicknameInUse
|
||||||
}
|
}
|
||||||
|
// check TLS modes
|
||||||
|
if client.HasMode(modes.TLS) != currentClient.HasMode(modes.TLS) {
|
||||||
|
if useAccountName {
|
||||||
|
// #955: this is fatal because they can't fix it by trying a different nick
|
||||||
|
return "", errInsecureReattach
|
||||||
|
} else {
|
||||||
|
return "", errNicknameInUse
|
||||||
|
}
|
||||||
|
}
|
||||||
reattachSuccessful, numSessions, lastSeen := currentClient.AddSession(session)
|
reattachSuccessful, numSessions, lastSeen := currentClient.AddSession(session)
|
||||||
if !reattachSuccessful {
|
if !reattachSuccessful {
|
||||||
return "", errNicknameInUse
|
return "", errNicknameInUse
|
||||||
|
@ -42,6 +42,7 @@ var (
|
|||||||
errNickMissing = errors.New("nick missing")
|
errNickMissing = errors.New("nick missing")
|
||||||
errNicknameInvalid = errors.New("invalid nickname")
|
errNicknameInvalid = errors.New("invalid nickname")
|
||||||
errNicknameInUse = errors.New("nickname in use")
|
errNicknameInUse = errors.New("nickname in use")
|
||||||
|
errInsecureReattach = errors.New("insecure reattach")
|
||||||
errNicknameReserved = errors.New("nickname is reserved")
|
errNicknameReserved = errors.New("nickname is reserved")
|
||||||
errNickAccountMismatch = errors.New(`Your nickname must match your account name; try logging out and logging back in with SASL`)
|
errNickAccountMismatch = errors.New(`Your nickname must match your account name; try logging out and logging back in with SASL`)
|
||||||
errNoExistingBan = errors.New("Ban does not exist")
|
errNoExistingBan = errors.New("Ban does not exist")
|
||||||
|
@ -25,12 +25,11 @@ var (
|
|||||||
restrictedSkeletons = make(map[string]bool)
|
restrictedSkeletons = make(map[string]bool)
|
||||||
)
|
)
|
||||||
|
|
||||||
// returns whether the change succeeded or failed
|
func performNickChange(server *Server, client *Client, target *Client, session *Session, nickname string, rb *ResponseBuffer) error {
|
||||||
func performNickChange(server *Server, client *Client, target *Client, session *Session, nickname string, rb *ResponseBuffer) bool {
|
|
||||||
currentNick := client.Nick()
|
currentNick := client.Nick()
|
||||||
details := target.Details()
|
details := target.Details()
|
||||||
if details.nick == nickname {
|
if details.nick == nickname {
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
hadNick := details.nick != "*"
|
hadNick := details.nick != "*"
|
||||||
origNickMask := details.nickMask
|
origNickMask := details.nickMask
|
||||||
@ -52,7 +51,7 @@ func performNickChange(server *Server, client *Client, target *Client, session *
|
|||||||
rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", fmt.Sprintf(client.t("Could not set or change nickname: %s"), err.Error()))
|
rb.Add(nil, server.name, ERR_UNKNOWNERROR, currentNick, "NICK", fmt.Sprintf(client.t("Could not set or change nickname: %s"), err.Error()))
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
message := utils.MakeMessage("")
|
message := utils.MakeMessage("")
|
||||||
@ -88,7 +87,7 @@ func performNickChange(server *Server, client *Client, target *Client, session *
|
|||||||
client.server.monitorManager.AlertAbout(target, true)
|
client.server.monitorManager.AlertAbout(target, true)
|
||||||
target.nickTimer.Touch(rb)
|
target.nickTimer.Touch(rb)
|
||||||
} // else: these will be deferred to the end of registration (see #572)
|
} // else: these will be deferred to the end of registration (see #572)
|
||||||
return true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) RandomlyRename(client *Client) {
|
func (server *Server) RandomlyRename(client *Client) {
|
||||||
@ -124,7 +123,7 @@ func fixupNickEqualsAccount(client *Client, rb *ResponseBuffer, config *Config)
|
|||||||
if !client.registered {
|
if !client.registered {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if !performNickChange(client.server, client, client, rb.session, client.AccountName(), rb) {
|
if performNickChange(client.server, client, client, rb.session, client.AccountName(), rb) != nil {
|
||||||
client.server.accounts.Logout(client)
|
client.server.accounts.Logout(client)
|
||||||
nsNotice(rb, client.t("A client is already using that account; try logging out and logging back in with SASL"))
|
nsNotice(rb, client.t("A client is already using that account; try logging out and logging back in with SASL"))
|
||||||
return false
|
return false
|
||||||
|
@ -343,11 +343,14 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rb := NewResponseBuffer(session)
|
rb := NewResponseBuffer(session)
|
||||||
nickAssigned := performNickChange(server, c, c, session, c.preregNick, rb)
|
nickError := performNickChange(server, c, c, session, c.preregNick, rb)
|
||||||
rb.Send(true)
|
rb.Send(true)
|
||||||
if !nickAssigned {
|
if nickError == errInsecureReattach {
|
||||||
|
c.Quit(c.t("You can't mix secure and insecure connections to this account"), nil)
|
||||||
|
return true
|
||||||
|
} else if nickError != nil {
|
||||||
c.preregNick = ""
|
c.preregNick = ""
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.client != c {
|
if session.client != c {
|
||||||
@ -355,7 +358,7 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
|
|||||||
// we'll play the reg burst later, on the new goroutine associated with
|
// we'll play the reg burst later, on the new goroutine associated with
|
||||||
// (thisSession, otherClient). This is to avoid having to transfer state
|
// (thisSession, otherClient). This is to avoid having to transfer state
|
||||||
// like nickname, hostname, etc. to show the correct values in the reg burst.
|
// like nickname, hostname, etc. to show the correct values in the reg burst.
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// check KLINEs
|
// check KLINEs
|
||||||
|
Loading…
Reference in New Issue
Block a user