Browse Source

accounts: Login to accounts properly

Avoids letting clients login to two accounts at once
tags/v0.7.0
Daniel Oaks 7 years ago
parent
commit
3d597a4fb3
2 changed files with 23 additions and 4 deletions
  1. 1
    0
      CHANGELOG.md
  2. 22
    4
      irc/accounts.go

+ 1
- 0
CHANGELOG.md View File

@@ -22,6 +22,7 @@ New release of Oragono!
22 22
 ### Removed
23 23
  
24 24
 ### Fixed
25
+* Fixed an account issue where clients could login to multiple accounts at once.
25 26
  
26 27
  
27 28
 ## [0.6.0] - 2017-01-19

+ 22
- 4
irc/accounts.go View File

@@ -222,8 +222,7 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
222 222
 			account = loadAccount(server, tx, accountKey)
223 223
 		}
224 224
 
225
-		account.Clients = append(account.Clients, client)
226
-		client.account = account
225
+		client.LoginToAccount(account)
227 226
 
228 227
 		return err
229 228
 	})
@@ -237,6 +236,26 @@ func authPlainHandler(server *Server, client *Client, mechanism string, value []
237 236
 	return false
238 237
 }
239 238
 
239
+// LoginToAccount logs the client into the given account.
240
+func (client *Client) LoginToAccount(account *ClientAccount) {
241
+	if client.account == account {
242
+		// already logged into this acct, no changing necessary
243
+		return
244
+	} else if client.account != nil {
245
+		// logout of existing acct
246
+		var newClientAccounts []*Client
247
+		for _, c := range account.Clients {
248
+			if c != client {
249
+				newClientAccounts = append(newClientAccounts, c)
250
+			}
251
+		}
252
+		account.Clients = newClientAccounts
253
+	}
254
+
255
+	account.Clients = append(account.Clients, client)
256
+	client.account = account
257
+}
258
+
240 259
 // authExternalHandler parses the SASL EXTERNAL mechanism.
241 260
 func authExternalHandler(server *Server, client *Client, mechanism string, value []byte) bool {
242 261
 	if client.certfp == "" {
@@ -275,8 +294,7 @@ func authExternalHandler(server *Server, client *Client, mechanism string, value
275 294
 			account = loadAccount(server, tx, accountKey)
276 295
 		}
277 296
 
278
-		account.Clients = append(account.Clients, client)
279
-		client.account = account
297
+		client.LoginToAccount(account)
280 298
 
281 299
 		return nil
282 300
 	})

Loading…
Cancel
Save