Changeset 729 in code for trunk


Ignore:
Timestamp:
Nov 30, 2021, 11:02:54 AM (4 years ago)
Author:
contact
Message:

Add support for draft/account-registration proxying

This adds support for the draft/account-registration extension [1].
This allows downstreams to register on upstream networks.

[1]: https://ircv3.net/specs/extensions/account-registration

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r727 r729  
    10801080        }
    10811081
     1082        if uc := dc.upstream(); uc != nil && uc.caps["draft/account-registration"] {
     1083                // Strip "before-connect", because we require downstreams to be fully
     1084                // connected before attempting account registration.
     1085                values := strings.Split(uc.supportedCaps["draft/account-registration"], ",")
     1086                for i, v := range values {
     1087                        if v == "before-connect" {
     1088                                values = append(values[:i], values[i+1:]...)
     1089                                break
     1090                        }
     1091                }
     1092                dc.setSupportedCap("draft/account-registration", strings.Join(values, ","))
     1093        } else {
     1094                dc.unsetSupportedCap("draft/account-registration")
     1095        }
     1096
    10821097        if _, ok := dc.user.msgStore.(chatHistoryMessageStore); ok && dc.network != nil {
    10831098                dc.setSupportedCap("draft/event-playback", "")
     
    24092424                if uc == nil || !uc.caps["sasl"] {
    24102425                        return ircError{&irc.Message{
    2411                                 Prefix:  dc.srv.prefix(),
    24122426                                Command: irc.ERR_SASLFAIL,
    24132427                                Params:  []string{dc.nick, "Upstream network authentication not supported"},
     
    24372451                        })
    24382452                }
     2453        case "REGISTER", "VERIFY":
     2454                // Check number of params here, since we'll use that to save the
     2455                // credentials on command success
     2456                if (msg.Command == "REGISTER" && len(msg.Params) < 3) || (msg.Command == "VERIFY" && len(msg.Params) < 2) {
     2457                        return newNeedMoreParamsError(msg.Command)
     2458                }
     2459
     2460                uc := dc.upstream()
     2461                if uc == nil || !uc.caps["draft/account-registration"] {
     2462                        return ircError{&irc.Message{
     2463                                Command: "FAIL",
     2464                                Params:  []string{msg.Command, "TEMPORARILY_UNAVAILABLE", "*", "Upstream network account registration not supported"},
     2465                        }}
     2466                }
     2467
     2468                uc.logger.Printf("starting %v with account name %v", msg.Command, msg.Params[0])
     2469                uc.enqueueCommand(dc, msg)
    24392470        case "MONITOR":
    24402471                // MONITOR is unsupported in multi-upstream mode
  • trunk/upstream.go

    r725 r729  
    3636        "setname":          true,
    3737
    38         "draft/extended-monitor": true,
     38        "draft/account-registration": true,
     39        "draft/extended-monitor":     true,
    3940}
    4041
     
    301302                                        Params:  []string{dc.nick, "SASL authentication aborted"},
    302303                                })
     304                        case "REGISTER", "VERIFY":
     305                                dc.SendMessage(&irc.Message{
     306                                        Prefix:  dc.srv.prefix(),
     307                                        Command: "FAIL",
     308                                        Params:  []string{pendingCmd.msg.Command, "TEMPORARILY_UNAVAILABLE", pendingCmd.msg.Params[0], "Command aborted"},
     309                                })
    303310                        default:
    304311                                panic(fmt.Errorf("Unsupported pending command %q", pendingCmd.msg.Command))
     
    319326func (uc *upstreamConn) enqueueCommand(dc *downstreamConn, msg *irc.Message) {
    320327        switch msg.Command {
    321         case "LIST", "WHO", "AUTHENTICATE":
     328        case "LIST", "WHO", "AUTHENTICATE", "REGISTER", "VERIFY":
    322329                // Supported
    323330        default:
     
    633640                                Params:  []string{"END"},
    634641                        })
     642                }
     643        case "REGISTER", "VERIFY":
     644                if dc, cmd := uc.dequeueCommand(msg.Command); dc != nil {
     645                        if msg.Command == "REGISTER" {
     646                                var account, password string
     647                                if err := parseMessageParams(msg, nil, &account); err != nil {
     648                                        return err
     649                                }
     650                                if err := parseMessageParams(cmd, nil, nil, &password); err != nil {
     651                                        return err
     652                                }
     653                                uc.network.autoSaveSASLPlain(context.TODO(), account, password)
     654                        }
     655
     656                        dc.SendMessage(msg)
    635657                }
    636658        case irc.RPL_WELCOME:
     
    15701592                }
    15711593
    1572                 if command == "LIST" || command == "WHO" {
    1573                         dc, _ := uc.dequeueCommand(command)
    1574                         if dc != nil && downstreamID == 0 {
    1575                                 downstreamID = dc.id
    1576                         }
     1594                if dc, _ := uc.dequeueCommand(command); dc != nil && downstreamID == 0 {
     1595                        downstreamID = dc.id
    15771596                }
    15781597
     
    15831602                                Params:  []string{dc.nick, command, reason},
    15841603                        })
     1604                })
     1605        case "FAIL":
     1606                var command string
     1607                if err := parseMessageParams(msg, &command); err != nil {
     1608                        return err
     1609                }
     1610
     1611                if dc, _ := uc.dequeueCommand(command); dc != nil && downstreamID == 0 {
     1612                        downstreamID = dc.id
     1613                }
     1614
     1615                uc.forEachDownstreamByID(downstreamID, func(dc *downstreamConn) {
     1616                        dc.SendMessage(msg)
    15851617                })
    15861618        case "ACK":
Note: See TracChangeset for help on using the changeset viewer.