Ver código fonte

add ip-check-script.exempt-sasl

tags/v2.9.0-rc1
Shivaram Lingamneni 2 anos atrás
pai
commit
0a59f41cf9
5 arquivos alterados com 43 adições e 11 exclusões
  1. 3
    0
      default.yaml
  2. 1
    1
      irc/authscript.go
  3. 11
    6
      irc/config.go
  4. 25
    4
      irc/server.go
  5. 3
    0
      traditional.yaml

+ 3
- 0
default.yaml Ver arquivo

@@ -300,6 +300,9 @@ server:
300 300
         kill-timeout: 1s
301 301
         # how many scripts are allowed to run at once? 0 for no limit:
302 302
         max-concurrency: 64
303
+        # if true, only check anonymous connections (not logged into an account)
304
+        # at the very end of the handshake:
305
+        exempt-sasl: false
303 306
 
304 307
     # IP cloaking hides users' IP addresses from other users and from channel admins
305 308
     # (but not from server admins), while still allowing channel admins to ban

+ 1
- 1
irc/authscript.go Ver arquivo

@@ -84,7 +84,7 @@ type IPScriptOutput struct {
84 84
 	Error        string `json:"error"`
85 85
 }
86 86
 
87
-func CheckIPBan(sem utils.Semaphore, config ScriptConfig, addr net.IP) (output IPScriptOutput, err error) {
87
+func CheckIPBan(sem utils.Semaphore, config IPCheckScriptConfig, addr net.IP) (output IPScriptOutput, err error) {
88 88
 	if sem != nil {
89 89
 		sem.Acquire()
90 90
 		defer sem.Release()

+ 11
- 6
irc/config.go Ver arquivo

@@ -348,6 +348,11 @@ type AuthScriptConfig struct {
348 348
 	Autocreate   bool
349 349
 }
350 350
 
351
+type IPCheckScriptConfig struct {
352
+	ScriptConfig `yaml:",inline"`
353
+	ExemptSASL   bool `yaml:"exempt-sasl"`
354
+}
355
+
351 356
 // AccountRegistrationConfig controls account registration.
352 357
 type AccountRegistrationConfig struct {
353 358
 	Enabled            bool
@@ -587,12 +592,12 @@ type Config struct {
587 592
 		supportedCapsWithoutSTS  *caps.Set
588 593
 		capValues                caps.Values
589 594
 		Casemapping              Casemapping
590
-		EnforceUtf8              bool         `yaml:"enforce-utf8"`
591
-		OutputPath               string       `yaml:"output-path"`
592
-		IPCheckScript            ScriptConfig `yaml:"ip-check-script"`
593
-		OverrideServicesHostname string       `yaml:"override-services-hostname"`
594
-		MaxLineLen               int          `yaml:"max-line-len"`
595
-		SuppressLusers           bool         `yaml:"suppress-lusers"`
595
+		EnforceUtf8              bool                `yaml:"enforce-utf8"`
596
+		OutputPath               string              `yaml:"output-path"`
597
+		IPCheckScript            IPCheckScriptConfig `yaml:"ip-check-script"`
598
+		OverrideServicesHostname string              `yaml:"override-services-hostname"`
599
+		MaxLineLen               int                 `yaml:"max-line-len"`
600
+		SuppressLusers           bool                `yaml:"suppress-lusers"`
596 601
 	}
597 602
 
598 603
 	Roleplay struct {

+ 25
- 4
irc/server.go Ver arquivo

@@ -200,7 +200,7 @@ func (server *Server) checkBans(config *Config, ipaddr net.IP, checkScripts bool
200 200
 		server.logger.Warning("internal", "unexpected ban result", err.Error())
201 201
 	}
202 202
 
203
-	if checkScripts && config.Server.IPCheckScript.Enabled {
203
+	if checkScripts && config.Server.IPCheckScript.Enabled && !config.Server.IPCheckScript.ExemptSASL {
204 204
 		output, err := CheckIPBan(server.semaphores.IPCheckScript, config.Server.IPCheckScript, ipaddr)
205 205
 		if err != nil {
206 206
 			server.logger.Error("internal", "couldn't check IP ban script", ipaddr.String(), err.Error())
@@ -267,9 +267,26 @@ func (server *Server) handleAlwaysOnExpirations() {
267 267
 	}
268 268
 }
269 269
 
270
-//
271
-// server functionality
272
-//
270
+// handles server.ip-check-script.exempt-sasl:
271
+// run the ip check script at the end of the handshake, only for anonymous connections
272
+func (server *Server) checkBanScriptExemptSASL(config *Config, session *Session) (outcome AuthOutcome) {
273
+	// TODO add caching for this; see related code in (*server).checkBans;
274
+	// we should probably just put an LRU around this instead of using the DLINE system
275
+	ipaddr := session.IP()
276
+	output, err := CheckIPBan(server.semaphores.IPCheckScript, config.Server.IPCheckScript, ipaddr)
277
+	if err != nil {
278
+		server.logger.Error("internal", "couldn't check IP ban script", ipaddr.String(), err.Error())
279
+		return authSuccess
280
+	}
281
+	if output.Result == IPBanned || output.Result == IPRequireSASL {
282
+		server.logger.Info("connect-ip", "Rejecting unauthenticated client due to ip-check-script", ipaddr.String())
283
+		if output.BanMessage != "" {
284
+			session.client.requireSASLMessage = output.BanMessage
285
+		}
286
+		return authFailSaslRequired
287
+	}
288
+	return authSuccess
289
+}
273 290
 
274 291
 func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
275 292
 	// XXX PROXY or WEBIRC MUST be sent as the first line of the session;
@@ -294,6 +311,10 @@ func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
294 311
 	// before completing the other registration commands
295 312
 	config := server.Config()
296 313
 	authOutcome := c.isAuthorized(server, config, session, c.requireSASL)
314
+	if authOutcome == authSuccess && c.account == "" &&
315
+		config.Server.IPCheckScript.Enabled && config.Server.IPCheckScript.ExemptSASL {
316
+		authOutcome = server.checkBanScriptExemptSASL(config, session)
317
+	}
297 318
 	var quitMessage string
298 319
 	switch authOutcome {
299 320
 	case authFailPass:

+ 3
- 0
traditional.yaml Ver arquivo

@@ -274,6 +274,9 @@ server:
274 274
         kill-timeout: 1s
275 275
         # how many scripts are allowed to run at once? 0 for no limit:
276 276
         max-concurrency: 64
277
+        # if true, only check anonymous connections (not logged into an account)
278
+        # at the very end of the handshake:
279
+        exempt-sasl: false
277 280
 
278 281
     # IP cloaking hides users' IP addresses from other users and from channel admins
279 282
     # (but not from server admins), while still allowing channel admins to ban

Carregando…
Cancelar
Salvar