Changeset 725 in code for trunk


Ignore:
Timestamp:
Nov 21, 2021, 3:28:38 PM (4 years ago)
Author:
contact
Message:

Remove sasl cap after registration if network doesn't support it

This will stop clients from trying to issue AUTHENTICATE requests
after connection registration.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r724 r725  
    191191        "invite-notify": "",
    192192        "message-tags":  "",
    193         "sasl":          "PLAIN",
    194193        "server-time":   "",
    195194        "setname":       "",
     
    300299                dc.supportedCaps[k] = v
    301300        }
     301        dc.supportedCaps["sasl"] = "PLAIN"
    302302        // TODO: this is racy, we should only enable chathistory after
    303303        // authentication and then check that user.msgStore implements
     
    10371037                        dc.unsetSupportedCap(cap)
    10381038                }
     1039        }
     1040
     1041        if uc := dc.upstream(); uc != nil && uc.supportsSASL("PLAIN") {
     1042                dc.setSupportedCap("sasl", "PLAIN")
     1043        } else if dc.network != nil {
     1044                dc.unsetSupportedCap("sasl")
    10391045        }
    10401046
  • trunk/upstream.go

    r724 r725  
    17321732}
    17331733
     1734func (uc *upstreamConn) supportsSASL(mech string) bool {
     1735        v, ok := uc.supportedCaps["sasl"]
     1736        if !ok {
     1737                return false
     1738        }
     1739
     1740        if v == "" {
     1741                return true
     1742        }
     1743
     1744        mechanisms := strings.Split(v, ",")
     1745        for _, mech := range mechanisms {
     1746                if strings.EqualFold(mech, mech) {
     1747                        return true
     1748                }
     1749        }
     1750        return false
     1751}
     1752
    17341753func (uc *upstreamConn) requestSASL() bool {
    17351754        if uc.network.SASL.Mechanism == "" {
    17361755                return false
    17371756        }
    1738 
    1739         v, ok := uc.supportedCaps["sasl"]
    1740         if !ok {
    1741                 return false
    1742         }
    1743         if v != "" {
    1744                 mechanisms := strings.Split(v, ",")
    1745                 found := false
    1746                 for _, mech := range mechanisms {
    1747                         if strings.EqualFold(mech, uc.network.SASL.Mechanism) {
    1748                                 found = true
    1749                                 break
    1750                         }
    1751                 }
    1752                 if !found {
    1753                         return false
    1754                 }
    1755         }
    1756 
    1757         return true
     1757        return uc.supportsSASL(uc.network.SASL.Mechanism)
    17581758}
    17591759
Note: See TracChangeset for help on using the changeset viewer.