Changeset 716 in code for trunk/downstream.go


Ignore:
Timestamp:
Nov 18, 2021, 8:40:23 AM (4 years ago)
Author:
hubert
Message:

Allow AUTHENTICATE before NICK

Now that dc.nick is not blank during registration, sasl replies from the
server are correct and cap handling can be a bit simplified.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r711 r716  
    179179
    180180// ' ' and ':' break the IRC message wire format, '@' and '!' break prefixes,
    181 // '*' and '?' break masks, '$' breaks server masks in PRIVMSG/NOTICE
     181// '*' and '?' break masks, '$' breaks server masks in PRIVMSG/NOTICE,
     182// "*" is the reserved nickname for registration
    182183const illegalNickChars = " :@!*?$"
    183184
     
    281282                conn:          *newConn(srv, ic, &options),
    282283                id:            id,
     284                nick:          "*",
     285                nickCM:        "*",
    283286                supportedCaps: make(map[string]string),
    284287                caps:          make(map[string]bool),
     
    685688                if !dc.caps["sasl"] {
    686689                        return ircError{&irc.Message{
     690                                Prefix:  dc.srv.prefix(),
    687691                                Command: irc.ERR_SASLFAIL,
    688692                                Params:  []string{"*", "AUTHENTICATE requires the \"sasl\" capability to be enabled"},
     
    691695                if len(msg.Params) == 0 {
    692696                        return ircError{&irc.Message{
     697                                Prefix:  dc.srv.prefix(),
    693698                                Command: irc.ERR_SASLFAIL,
    694699                                Params:  []string{"*", "Missing AUTHENTICATE argument"},
    695                         }}
    696                 }
    697                 if dc.nick == "" {
    698                         return ircError{&irc.Message{
    699                                 Command: irc.ERR_SASLFAIL,
    700                                 Params:  []string{"*", "Expected NICK command before AUTHENTICATE"},
    701700                        }}
    702701                }
     
    706705                        dc.saslServer = nil
    707706                        return ircError{&irc.Message{
     707                                Prefix:  dc.srv.prefix(),
    708708                                Command: irc.ERR_SASLABORTED,
    709709                                Params:  []string{"*", "SASL authentication aborted"},
     
    721721                        default:
    722722                                return ircError{&irc.Message{
     723                                        Prefix:  dc.srv.prefix(),
    723724                                        Command: irc.ERR_SASLFAIL,
    724725                                        Params:  []string{"*", fmt.Sprintf("Unsupported SASL mechanism %q", mech)},
     
    734735                                dc.saslServer = nil
    735736                                return ircError{&irc.Message{
     737                                        Prefix:  dc.srv.prefix(),
    736738                                        Command: irc.ERR_SASLFAIL,
    737739                                        Params:  []string{"*", "Invalid base64-encoded response"},
     
    745747                        if ircErr, ok := err.(ircError); ok && ircErr.Message.Command == irc.ERR_PASSWDMISMATCH {
    746748                                return ircError{&irc.Message{
     749                                        Prefix:  dc.srv.prefix(),
    747750                                        Command: irc.ERR_SASLFAIL,
    748751                                        Params:  []string{"*", ircErr.Message.Params[1]},
     
    824827                return newUnknownCommandError(msg.Command)
    825828        }
    826         if dc.rawUsername != "" && dc.nick != "" && !dc.negotiatingCaps {
     829        if dc.rawUsername != "" && dc.nick != "*" && !dc.negotiatingCaps {
    827830                return dc.register(ctx)
    828831        }
     
    832835func (dc *downstreamConn) handleCapCommand(cmd string, args []string) error {
    833836        cmd = strings.ToUpper(cmd)
    834 
    835         replyTo := dc.nick
    836         if !dc.registered {
    837                 replyTo = "*"
    838         }
    839837
    840838        switch cmd {
     
    868866                        Prefix:  dc.srv.prefix(),
    869867                        Command: "CAP",
    870                         Params:  []string{replyTo, "LS", strings.Join(caps, " ")},
     868                        Params:  []string{dc.nick, "LS", strings.Join(caps, " ")},
    871869                })
    872870
     
    891889                        Prefix:  dc.srv.prefix(),
    892890                        Command: "CAP",
    893                         Params:  []string{replyTo, "LIST", strings.Join(caps, " ")},
     891                        Params:  []string{dc.nick, "LIST", strings.Join(caps, " ")},
    894892                })
    895893        case "REQ":
     
    897895                        return ircError{&irc.Message{
    898896                                Command: err_invalidcapcmd,
    899                                 Params:  []string{replyTo, cmd, "Missing argument in CAP REQ command"},
     897                                Params:  []string{dc.nick, cmd, "Missing argument in CAP REQ command"},
    900898                        }}
    901899                }
     
    937935                        Prefix:  dc.srv.prefix(),
    938936                        Command: "CAP",
    939                         Params:  []string{replyTo, reply, args[0]},
     937                        Params:  []string{dc.nick, reply, args[0]},
    940938                })
    941939
     
    948946                return ircError{&irc.Message{
    949947                        Command: err_invalidcapcmd,
    950                         Params:  []string{replyTo, cmd, "Unknown CAP command"},
     948                        Params:  []string{dc.nick, cmd, "Unknown CAP command"},
    951949                }}
    952950        }
     
    963961        }
    964962
    965         replyTo := dc.nick
    966         if !dc.registered {
    967                 replyTo = "*"
    968         }
    969 
    970963        cap := name
    971964        if value != "" && dc.capVersion >= 302 {
     
    976969                Prefix:  dc.srv.prefix(),
    977970                Command: "CAP",
    978                 Params:  []string{replyTo, "NEW", cap},
     971                Params:  []string{dc.nick, "NEW", cap},
    979972        })
    980973}
     
    989982        }
    990983
    991         replyTo := dc.nick
    992         if !dc.registered {
    993                 replyTo = "*"
    994         }
    995 
    996984        dc.SendMessage(&irc.Message{
    997985                Prefix:  dc.srv.prefix(),
    998986                Command: "CAP",
    999                 Params:  []string{replyTo, "DEL", name},
     987                Params:  []string{dc.nick, "DEL", name},
    1000988        })
    1001989}
Note: See TracChangeset for help on using the changeset viewer.