mirror of
				https://gitlab.crans.org/nounous/ghostream.git
				synced 2025-10-31 15:20:00 +01:00 
			
		
		
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			7e0ee7aba5
			...
			1520e78bad
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 1520e78bad | ||
|  | e47aefd6df | 
| @@ -20,7 +20,7 @@ type Options struct { | ||||
|  | ||||
| // Backend to log user in | ||||
| type Backend interface { | ||||
| 	Login(string, string) (bool, error) | ||||
| 	Login(string, string) (bool, string, error) | ||||
| 	Close() | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -23,15 +23,15 @@ type Basic struct { | ||||
|  | ||||
| // Login hashs password and compare | ||||
| // Returns (true, nil) if success | ||||
| func (a Basic) Login(username string, password string) (bool, error) { | ||||
| func (a Basic) Login(username string, password string) (bool, string, error) { | ||||
| 	hash, ok := a.Cfg.Credentials[username] | ||||
| 	if !ok { | ||||
| 		return false, errors.New("user not found in credentials") | ||||
| 		return false, "", errors.New("user not found in credentials") | ||||
| 	} | ||||
| 	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) | ||||
|  | ||||
| 	// Login succeeded if no error | ||||
| 	return err == nil, err | ||||
| 	return err == nil, username, err | ||||
| } | ||||
|  | ||||
| // Close has no connection to close | ||||
|   | ||||
| @@ -22,11 +22,11 @@ type LDAP struct { | ||||
|  | ||||
| // Login tries to bind to LDAP | ||||
| // Returns (true, nil) if success | ||||
| func (a LDAP) Login(username string, password string) (bool, error) { | ||||
| func (a LDAP) Login(username string, password string) (bool, string, error) { | ||||
| 	aliasSplit := strings.SplitN(username, "__", 2) | ||||
| 	potentialUsernames := []string{username} | ||||
|  | ||||
| 	for len(aliasSplit) == 2 { | ||||
| 	if len(aliasSplit) == 2 { | ||||
| 		alias := aliasSplit[0] | ||||
| 		trueUsername := aliasSplit[1] | ||||
| 		// Resolve stream alias if necessary | ||||
| @@ -45,12 +45,12 @@ func (a LDAP) Login(username string, password string) (bool, error) { | ||||
| 		err = a.Conn.Bind(bindDn, password) | ||||
| 		if err == nil { | ||||
| 			// Login succeeded if no error | ||||
| 			return true, nil | ||||
| 			return true, aliasSplit[0], nil | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Unable to log in | ||||
| 	return err == nil, err | ||||
| 	return err == nil, "", err | ||||
| } | ||||
|  | ||||
| // Close LDAP connection | ||||
|   | ||||
| @@ -82,7 +82,9 @@ func Serve(streams *messaging.Streams, authBackend auth.Backend, cfg *Options) { | ||||
| 			name, password := split[0], split[1] | ||||
| 			if authBackend != nil { | ||||
| 				// check password | ||||
| 				if ok, err := authBackend.Login(name, password); !ok || err != nil { | ||||
| 				ok, username, err := authBackend.Login(name, password) | ||||
| 				name = username | ||||
| 				if ok || err != nil { | ||||
| 					log.Printf("Failed to authenticate for stream %s", name) | ||||
| 					s.Close() | ||||
| 					continue | ||||
|   | ||||
		Reference in New Issue
	
	Block a user