Skip to content

Commit 21ee867

Browse files
authoredJan 14, 2025··
fix #2198 (#2199)
Add require-sasl support to KLINE / UBAN on NUH masks
1 parent 36e5451 commit 21ee867

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed
 

‎irc/handlers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ func klineHandler(server *Server, client *Client, msg ircmsg.Message, rb *Respon
16371637
// get comment(s)
16381638
reason, operReason := getReasonsFromParams(msg.Params, currentArg)
16391639

1640-
err = server.klines.AddMask(mask, duration, reason, operReason, operName)
1640+
err = server.klines.AddMask(mask, duration, false, reason, operReason, operName)
16411641
if err != nil {
16421642
rb.Notice(fmt.Sprintf(client.t("Could not successfully save new K-LINE: %s"), err.Error()))
16431643
return false

‎irc/kline.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,12 @@ func (km *KLineManager) AllBans() map[string]IPBanInfo {
6666
}
6767

6868
// AddMask adds to the blocked list.
69-
func (km *KLineManager) AddMask(mask string, duration time.Duration, reason, operReason, operName string) error {
69+
func (km *KLineManager) AddMask(mask string, duration time.Duration, requireSASL bool, reason, operReason, operName string) error {
7070
km.persistenceMutex.Lock()
7171
defer km.persistenceMutex.Unlock()
7272

7373
info := IPBanInfo{
74+
RequireSASL: requireSASL,
7475
Reason: reason,
7576
OperReason: operReason,
7677
OperName: operName,
@@ -208,13 +209,14 @@ func (km *KLineManager) CheckMasks(masks ...string) (isBanned bool, info IPBanIn
208209
for _, entryInfo := range km.entries {
209210
for _, mask := range masks {
210211
if entryInfo.Matcher.MatchString(mask) {
211-
return true, entryInfo.Info
212+
// apply the most stringent ban (unconditional bans override require-sasl)
213+
if !isBanned || info.RequireSASL {
214+
isBanned, info = true, entryInfo.Info
215+
}
212216
}
213217
}
214218
}
215219

216-
// no matches!
217-
isBanned = false
218220
return
219221
}
220222

‎irc/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
428428
// check KLINEs (#671: ignore KLINEs for loopback connections)
429429
if !session.IP().IsLoopback() || session.isTor {
430430
isBanned, info := server.klines.CheckMasks(c.AllNickmasks()...)
431-
if isBanned {
431+
if isBanned && !(info.RequireSASL && session.client.Account() != "") {
432432
c.setKlined()
433433
c.Quit(info.BanMessage(c.t("You are banned from this server (%s)")), nil)
434434
server.logger.Info("connect", session.connID, "Client rejected by k-line", c.NickMaskString())

‎irc/uban.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func ubanAddHandler(client *Client, target ubanTarget, params []string, rb *Resp
163163
case ubanCIDR:
164164
err = ubanAddCIDR(client, target, duration, requireSASL, operReason, rb)
165165
case ubanNickmask:
166-
err = ubanAddNickmask(client, target, duration, operReason, rb)
166+
err = ubanAddNickmask(client, target, duration, requireSASL, operReason, rb)
167167
case ubanNick:
168168
err = ubanAddAccount(client, target, duration, operReason, rb)
169169
}
@@ -242,8 +242,8 @@ func ubanAddCIDR(client *Client, target ubanTarget, duration time.Duration, requ
242242
return
243243
}
244244

245-
func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, operReason string, rb *ResponseBuffer) (err error) {
246-
err = client.server.klines.AddMask(target.nickOrMask, duration, "", operReason, client.Oper().Name)
245+
func ubanAddNickmask(client *Client, target ubanTarget, duration time.Duration, requireSASL bool, operReason string, rb *ResponseBuffer) (err error) {
246+
err = client.server.klines.AddMask(target.nickOrMask, duration, requireSASL, "", operReason, client.Oper().Name)
247247
if err == nil {
248248
rb.Notice(fmt.Sprintf(client.t("Successfully added UBAN for %s"), target.nickOrMask))
249249
} else {

0 commit comments

Comments
 (0)