Prevent downstreams from changing their nick to service's

This commit prevents downstream from sending those commands:
- NICK BouncerServ
- NICK BouncerServ/<network>

The later is necessary because soju would otherwise save the nick change
and, in the event that the downstream connects in single-upstream mode
to <network>, it will end up with the nickname "BouncerServ".
This commit is contained in:
Hubert Hirtz 2020-11-23 17:09:31 +01:00 committed by Simon Ser
parent e797d90c59
commit 16c68b21b5
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -1068,11 +1068,12 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
Params: []string{dc.nick, "You may not reregister"}, Params: []string{dc.nick, "You may not reregister"},
}} }}
case "NICK": case "NICK":
var nick string var rawNick string
if err := parseMessageParams(msg, &nick); err != nil { if err := parseMessageParams(msg, &rawNick); err != nil {
return err return err
} }
nick := rawNick
var upstream *upstreamConn var upstream *upstreamConn
if dc.upstream() == nil { if dc.upstream() == nil {
uc, unmarshaledNick, err := dc.unmarshalEntity(nick) uc, unmarshaledNick, err := dc.unmarshalEntity(nick)
@ -1088,6 +1089,12 @@ func (dc *downstreamConn) handleMessageRegistered(msg *irc.Message) error {
Params: []string{dc.nick, nick, "contains illegal characters"}, Params: []string{dc.nick, nick, "contains illegal characters"},
}} }}
} }
if nick == serviceNick {
return ircError{&irc.Message{
Command: irc.ERR_NICKNAMEINUSE,
Params: []string{dc.nick, rawNick, "Nickname reserved for bouncer service"},
}}
}
var err error var err error
dc.forEachNetwork(func(n *network) { dc.forEachNetwork(func(n *network) {