Parcourir la source

Merge pull request #1849 from slingamn/bugs.2

fix some papercuts
tags/v2.9.0-rc1
Shivaram Lingamneni il y a 2 ans
Parent
révision
8ec9053448
Aucun compte lié à l'adresse e-mail de l'auteur
8 fichiers modifiés avec 70 ajouts et 3 suppressions
  1. 3
    1
      irc/accounts.go
  2. 2
    0
      irc/chanserv.go
  3. 8
    0
      irc/flatip/flatip.go
  4. 34
    0
      irc/flatip/flatip_test.go
  5. 5
    0
      irc/handlers.go
  6. 4
    0
      irc/hostserv.go
  7. 1
    0
      irc/nickserv.go
  8. 13
    2
      irc/uban.go

+ 3
- 1
irc/accounts.go Voir le fichier

@@ -16,6 +16,7 @@ import (
16 16
 	"unicode"
17 17
 
18 18
 	"github.com/ergochat/irc-go/ircutils"
19
+	"github.com/tidwall/buntdb"
19 20
 	"github.com/xdg-go/scram"
20 21
 
21 22
 	"github.com/ergochat/ergo/irc/connection_limits"
@@ -24,7 +25,6 @@ import (
24 25
 	"github.com/ergochat/ergo/irc/modes"
25 26
 	"github.com/ergochat/ergo/irc/passwd"
26 27
 	"github.com/ergochat/ergo/irc/utils"
27
-	"github.com/tidwall/buntdb"
28 28
 )
29 29
 
30 30
 const (
@@ -474,6 +474,8 @@ func (am *AccountManager) Register(client *Client, account string, callbackNames
474 474
 		am.Unregister(casefoldedAccount, true)
475 475
 		return &registrationCallbackError{underlying: err}
476 476
 	} else {
477
+		am.server.logger.Info("accounts",
478
+			fmt.Sprintf("nickname %s registered account %s, pending verification", client.Nick(), account))
477 479
 		return am.server.store.Update(func(tx *buntdb.Tx) error {
478 480
 			_, _, err = tx.Set(verificationCodeKey, code, setOptions)
479 481
 			return err

+ 2
- 0
irc/chanserv.go Voir le fichier

@@ -681,6 +681,7 @@ func csPurgeAddHandler(service *ircService, client *Client, params []string, ope
681 681
 			}
682 682
 		}
683 683
 		service.Notice(rb, fmt.Sprintf(client.t("Successfully purged channel %s from the server"), chname))
684
+		client.server.snomasks.Send(sno.LocalChannels, fmt.Sprintf("Operator %s purged channel %s [reason: %s]", operName, chname, reason))
684 685
 	case errInvalidChannelName:
685 686
 		service.Notice(rb, fmt.Sprintf(client.t("Can't purge invalid channel %s"), chname))
686 687
 	default:
@@ -698,6 +699,7 @@ func csPurgeDelHandler(service *ircService, client *Client, params []string, ope
698 699
 	switch client.server.channels.Unpurge(chname) {
699 700
 	case nil:
700 701
 		service.Notice(rb, fmt.Sprintf(client.t("Successfully unpurged channel %s from the server"), chname))
702
+		client.server.snomasks.Send(sno.LocalChannels, fmt.Sprintf("Operator %s removed purge of channel %s", operName, chname))
701 703
 	case errNoSuchChannel:
702 704
 		service.Notice(rb, fmt.Sprintf(client.t("Channel %s wasn't previously purged from the server"), chname))
703 705
 	default:

+ 8
- 0
irc/flatip/flatip.go Voir le fichier

@@ -155,6 +155,14 @@ func (cidr IPNet) Contains(ip IP) bool {
155 155
 	return cidr.IP == maskedIP
156 156
 }
157 157
 
158
+func (cidr IPNet) Size() (ones, bits int) {
159
+	if cidr.IP.IsIPv4() {
160
+		return int(cidr.PrefixLen) - 96, 32
161
+	} else {
162
+		return int(cidr.PrefixLen), 128
163
+	}
164
+}
165
+
158 166
 // FromNetIPnet converts a net.IPNet into an IPNet.
159 167
 func FromNetIPNet(network net.IPNet) (result IPNet) {
160 168
 	ones, _ := network.Mask.Size()

+ 34
- 0
irc/flatip/flatip_test.go Voir le fichier

@@ -2,8 +2,10 @@ package flatip
2 2
 
3 3
 import (
4 4
 	"bytes"
5
+	"fmt"
5 6
 	"math/rand"
6 7
 	"net"
8
+	"reflect"
7 9
 	"testing"
8 10
 	"time"
9 11
 )
@@ -86,6 +88,38 @@ func doMaskingTest(ip net.IP, t *testing.T) {
86 88
 	}
87 89
 }
88 90
 
91
+func assertEqual(found, expected interface{}) {
92
+	if !reflect.DeepEqual(found, expected) {
93
+		panic(fmt.Sprintf("expected %#v, found %#v", expected, found))
94
+	}
95
+}
96
+
97
+func TestSize(t *testing.T) {
98
+	_, net, err := ParseCIDR("8.8.8.8/24")
99
+	if err != nil {
100
+		panic(err)
101
+	}
102
+	ones, bits := net.Size()
103
+	assertEqual(ones, 24)
104
+	assertEqual(bits, 32)
105
+
106
+	_, net, err = ParseCIDR("2001::0db8/64")
107
+	if err != nil {
108
+		panic(err)
109
+	}
110
+	ones, bits = net.Size()
111
+	assertEqual(ones, 64)
112
+	assertEqual(bits, 128)
113
+
114
+	_, net, err = ParseCIDR("2001::0db8/96")
115
+	if err != nil {
116
+		panic(err)
117
+	}
118
+	ones, bits = net.Size()
119
+	assertEqual(ones, 96)
120
+	assertEqual(bits, 128)
121
+}
122
+
89 123
 func TestMasking(t *testing.T) {
90 124
 	for _, ipstr := range testIPStrs {
91 125
 		doMaskingTest(easyParseIP(ipstr), t)

+ 5
- 0
irc/handlers.go Voir le fichier

@@ -81,6 +81,10 @@ func registrationErrorToMessage(config *Config, client *Client, err error) (mess
81 81
 	return
82 82
 }
83 83
 
84
+func announcePendingReg(client *Client, rb *ResponseBuffer, accountName string) {
85
+	client.server.snomasks.Send(sno.LocalAccounts, fmt.Sprintf(ircfmt.Unescape("Client $c[grey][$r%s$c[grey]] attempted to register account $c[grey][$r%s$c[grey]] from IP %s, pending verification"), client.Nick(), accountName, rb.session.IP().String()))
86
+}
87
+
84 88
 // helper function to dispatch messages when a client successfully registers
85 89
 func sendSuccessfulRegResponse(service *ircService, client *Client, rb *ResponseBuffer) {
86 90
 	details := client.Details()
@@ -2632,6 +2636,7 @@ func registerHandler(server *Server, client *Client, msg ircmsg.Message, rb *Res
2632 2636
 		} else {
2633 2637
 			rb.Add(nil, server.name, "REGISTER", "VERIFICATION_REQUIRED", accountName, fmt.Sprintf(client.t("Account created, pending verification; verification code has been sent to %s"), callbackValue))
2634 2638
 			client.registerCmdSent = true
2639
+			announcePendingReg(client, rb, accountName)
2635 2640
 		}
2636 2641
 	case errAccountAlreadyRegistered, errAccountAlreadyUnregistered, errAccountMustHoldNick:
2637 2642
 		rb.Add(nil, server.name, "FAIL", "REGISTER", "USERNAME_EXISTS", accountName, client.t("Username is already registered or otherwise unavailable"))

+ 4
- 0
irc/hostserv.go Voir le fichier

@@ -10,6 +10,7 @@ import (
10 10
 
11 11
 	"github.com/ergochat/irc-go/ircfmt"
12 12
 
13
+	"github.com/ergochat/ergo/irc/sno"
13 14
 	"github.com/ergochat/ergo/irc/utils"
14 15
 )
15 16
 
@@ -159,6 +160,7 @@ func validateVhost(server *Server, vhost string, oper bool) error {
159 160
 }
160 161
 
161 162
 func hsSetHandler(service *ircService, server *Server, client *Client, command string, params []string, rb *ResponseBuffer) {
163
+	oper := client.Oper()
162 164
 	user := params[0]
163 165
 	var vhost string
164 166
 
@@ -176,8 +178,10 @@ func hsSetHandler(service *ircService, server *Server, client *Client, command s
176 178
 		service.Notice(rb, client.t("An error occurred"))
177 179
 	} else if vhost != "" {
178 180
 		service.Notice(rb, client.t("Successfully set vhost"))
181
+		server.snomasks.Send(sno.LocalVhosts, fmt.Sprintf("Operator %s set vhost %s on account %s", oper.Name, user, vhost))
179 182
 	} else {
180 183
 		service.Notice(rb, client.t("Successfully cleared vhost"))
184
+		server.snomasks.Send(sno.LocalVhosts, fmt.Sprintf("Operator %s cleared vhost on account %s", oper.Name, user))
181 185
 	}
182 186
 }
183 187
 

+ 1
- 0
irc/nickserv.go Voir le fichier

@@ -1004,6 +1004,7 @@ func nsRegisterHandler(service *ircService, server *Server, client *Client, comm
1004 1004
 			messageTemplate := client.t("Account created, pending verification; verification code has been sent to %s")
1005 1005
 			message := fmt.Sprintf(messageTemplate, callbackValue)
1006 1006
 			service.Notice(rb, message)
1007
+			announcePendingReg(client, rb, account)
1007 1008
 		}
1008 1009
 	} else {
1009 1010
 		// details could not be stored and relevant numerics have been dispatched, abort

+ 13
- 2
irc/uban.go Voir le fichier

@@ -366,7 +366,14 @@ func ubanInfoHandler(client *Client, target ubanTarget, params []string, rb *Res
366 366
 }
367 367
 
368 368
 func ubanInfoCIDR(client *Client, target ubanTarget, rb *ResponseBuffer) {
369
-	if target.cidr.PrefixLen == 128 {
369
+	config := client.server.Config()
370
+	// show connection limiter/throttler state if this CIDR is entirely
371
+	// contained in a single limiter/throttler bucket:
372
+	ones, bits := target.cidr.Size()
373
+	showLimiter := (bits == 32 && ones >= config.Server.IPLimits.CidrLenIPv4) ||
374
+		(bits == 128 && ones >= config.Server.IPLimits.CidrLenIPv6)
375
+	sendMaskWarning := (bits == 128 && ones > config.Server.IPLimits.CidrLenIPv6)
376
+	if showLimiter {
370 377
 		netName, status := client.server.connectionLimiter.Status(target.cidr.IP)
371 378
 		if status.Exempt {
372 379
 			rb.Notice(fmt.Sprintf(client.t("IP %s is exempt from connection limits"), target.cidr.IP.String()))
@@ -391,6 +398,10 @@ func ubanInfoCIDR(client *Client, target ubanTarget, rb *ResponseBuffer) {
391 398
 			rb.Notice(line)
392 399
 		}
393 400
 	}
401
+	if sendMaskWarning {
402
+		rb.Notice(fmt.Sprintf(client.t("Note: try evaluating a wider IPv6 CIDR like %s/%d"),
403
+			target.cidr.IP.String(), config.Server.IPLimits.CidrLenIPv6))
404
+	}
394 405
 }
395 406
 
396 407
 func ubanInfoNickmask(client *Client, target ubanTarget, rb *ResponseBuffer) {
@@ -434,7 +445,7 @@ func ubanInfoNick(client *Client, target ubanTarget, rb *ResponseBuffer) {
434 445
 			rb.Notice(fmt.Sprintf(client.t("Client %[1]s is unauthenticated and connected from %[2]s"), details.nick, ip.String()))
435 446
 			sendIPBanWarning = true
436 447
 		} else {
437
-			rb.Notice(fmt.Sprintf(client.t("Client %[1]s is logged into account %[2]s and has %[3]d active clients (see /NICKSERV CLIENTS LIST %[4]s for more info"), details.nick, details.accountName, len(mcl.Sessions()), details.nick))
448
+			rb.Notice(fmt.Sprintf(client.t("Client %[1]s is logged into account %[2]s and has %[3]d active clients (see /NICKSERV CLIENTS LIST %[4]s for more info)"), details.nick, details.accountName, len(mcl.Sessions()), details.nick))
438 449
 			if !ip.IsLoopback() && len(sessions) == 1 {
439 450
 				rb.Notice(fmt.Sprintf(client.t("Client %[1]s is associated with IP %[2]s"), details.nick, ip.String()))
440 451
 				sendIPBanWarning = true

Chargement…
Annuler
Enregistrer