Bläddra i källkod

fix #455

tags/v1.1.0-rc1
Shivaram Lingamneni 5 år sedan
förälder
incheckning
174115deb6
5 ändrade filer med 40 tillägg och 22 borttagningar
  1. 16
    4
      irc/client.go
  2. 2
    2
      irc/commands.go
  3. 2
    6
      irc/handlers.go
  4. 2
    0
      irc/idletimer.go
  5. 18
    10
      irc/server.go

+ 16
- 4
irc/client.go Visa fil

@@ -286,18 +286,30 @@ func (client *Client) doIdentLookup(conn net.Conn) {
286 286
 	}
287 287
 }
288 288
 
289
-func (client *Client) isAuthorized(config *Config) bool {
289
+type AuthOutcome uint
290
+
291
+const (
292
+	authSuccess AuthOutcome = iota
293
+	authFailPass
294
+	authFailTorSaslRequired
295
+	authFailSaslRequired
296
+)
297
+
298
+func (client *Client) isAuthorized(config *Config) AuthOutcome {
290 299
 	saslSent := client.account != ""
291 300
 	// PASS requirement
292 301
 	if (config.Server.passwordBytes != nil) && !client.sentPassCommand && !(config.Accounts.SkipServerPassword && saslSent) {
293
-		return false
302
+		return authFailPass
294 303
 	}
295 304
 	// Tor connections may be required to authenticate with SASL
296 305
 	if client.isTor && config.Server.TorListeners.RequireSasl && !saslSent {
297
-		return false
306
+		return authFailTorSaslRequired
298 307
 	}
299 308
 	// finally, enforce require-sasl
300
-	return !config.Accounts.RequireSasl.Enabled || saslSent || utils.IPInNets(client.IP(), config.Accounts.RequireSasl.exemptedNets)
309
+	if config.Accounts.RequireSasl.Enabled && !saslSent && !utils.IPInNets(client.IP(), config.Accounts.RequireSasl.exemptedNets) {
310
+		return authFailSaslRequired
311
+	}
312
+	return authSuccess
301 313
 }
302 314
 
303 315
 func (session *Session) resetFakelag() {

+ 2
- 2
irc/commands.go Visa fil

@@ -45,8 +45,8 @@ func (cmd *Command) Run(server *Server, client *Client, session *Session, msg ir
45 45
 	rb.Send(true)
46 46
 
47 47
 	// after each command, see if we can send registration to the client
48
-	if !client.registered {
49
-		server.tryRegister(client, session)
48
+	if !exiting && !client.registered {
49
+		exiting = server.tryRegister(client, session)
50 50
 	}
51 51
 
52 52
 	// most servers do this only for PING/PONG, but we'll do it for any command:

+ 2
- 6
irc/handlers.go Visa fil

@@ -2229,13 +2229,9 @@ func passHandler(server *Server, client *Client, msg ircmsg.IrcMessage, rb *Resp
2229 2229
 
2230 2230
 	// check the provided password
2231 2231
 	password := []byte(msg.Params[0])
2232
-	if bcrypt.CompareHashAndPassword(serverPassword, password) != nil {
2233
-		rb.Add(nil, server.name, ERR_PASSWDMISMATCH, client.nick, client.t("Password incorrect"))
2234
-		client.Quit(client.t("Password incorrect"), rb.session)
2235
-		return true
2236
-	}
2232
+	client.sentPassCommand = bcrypt.CompareHashAndPassword(serverPassword, password) == nil
2237 2233
 
2238
-	client.sentPassCommand = true
2234
+	// if they failed the check, we'll bounce them later when they try to complete registration
2239 2235
 	return false
2240 2236
 }
2241 2237
 

+ 2
- 0
irc/idletimer.go Visa fil

@@ -274,8 +274,10 @@ func (nt *NickTimer) Touch(rb *ResponseBuffer) {
274 274
 		for _, mSession := range nt.client.Sessions() {
275 275
 			if mSession == session {
276 276
 				rb.Add(nil, nsPrefix, "NOTICE", tnick, message)
277
+				rb.Add(nil, nt.client.server.name, "WARN", "*", "ACCOUNT_REQUIRED", message)
277 278
 			} else {
278 279
 				mSession.Send(nil, nsPrefix, "NOTICE", tnick, message)
280
+				mSession.Send(nil, nt.client.server.name, "WARN", "*", "ACCOUNT_REQUIRED", message)
279 281
 			}
280 282
 		}
281 283
 	} else if shouldRename {

+ 18
- 10
irc/server.go Visa fil

@@ -330,7 +330,7 @@ func (server *Server) createListener(addr string, tlsConfig *tls.Config, isTor b
330 330
 // server functionality
331 331
 //
332 332
 
333
-func (server *Server) tryRegister(c *Client, session *Session) {
333
+func (server *Server) tryRegister(c *Client, session *Session) (exiting bool) {
334 334
 	// if the session just sent us a RESUME line, try to resume
335 335
 	if session.resumeDetails != nil {
336 336
 		session.tryResume()
@@ -344,11 +344,19 @@ func (server *Server) tryRegister(c *Client, session *Session) {
344 344
 
345 345
 	// client MUST send PASS if necessary, or authenticate with SASL if necessary,
346 346
 	// before completing the other registration commands
347
-	config := server.Config()
348
-	if !c.isAuthorized(config) {
349
-		c.Quit(c.t("Bad password"), nil)
350
-		c.destroy(nil)
351
-		return
347
+	authOutcome := c.isAuthorized(server.Config())
348
+	var quitMessage string
349
+	switch authOutcome {
350
+	case authFailPass:
351
+		quitMessage = c.t("Password incorrect")
352
+		c.Send(nil, server.name, ERR_PASSWDMISMATCH, "*", quitMessage)
353
+	case authFailSaslRequired, authFailTorSaslRequired:
354
+		quitMessage = c.t("You must log in with SASL to join this server")
355
+		c.Send(nil, c.server.name, "FAIL", "*", "ACCOUNT_REQUIRED", quitMessage)
356
+	}
357
+	if authOutcome != authSuccess {
358
+		c.Quit(quitMessage, nil)
359
+		return true
352 360
 	}
353 361
 
354 362
 	rb := NewResponseBuffer(session)
@@ -363,8 +371,7 @@ func (server *Server) tryRegister(c *Client, session *Session) {
363 371
 	isBanned, info := server.klines.CheckMasks(c.AllNickmasks()...)
364 372
 	if isBanned {
365 373
 		c.Quit(info.BanMessage(c.t("You are banned from this server (%s)")), nil)
366
-		c.destroy(nil)
367
-		return
374
+		return true
368 375
 	}
369 376
 
370 377
 	if session.client != c {
@@ -377,12 +384,13 @@ func (server *Server) tryRegister(c *Client, session *Session) {
377 384
 
378 385
 	// registration has succeeded:
379 386
 	c.SetRegistered()
387
+
380 388
 	// count new user in statistics
381 389
 	server.stats.ChangeTotal(1)
390
+	server.monitorManager.AlertAbout(c, true)
382 391
 
383 392
 	server.playRegistrationBurst(session)
384
-
385
-	server.monitorManager.AlertAbout(c, true)
393
+	return false
386 394
 }
387 395
 
388 396
 func (server *Server) playRegistrationBurst(session *Session) {

Laddar…
Avbryt
Spara