1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-02-20 19:51:17 +00:00

Compare commits

..

No commits in common. "1520e78badeb630ec2d037e8c95c75a2f35c49b4" and "7e0ee7aba5f636257eb3511513af393747999c0a" have entirely different histories.

4 changed files with 9 additions and 11 deletions

View File

@ -20,7 +20,7 @@ type Options struct {
// Backend to log user in
type Backend interface {
Login(string, string) (bool, string, error)
Login(string, string) (bool, error)
Close()
}

View File

@ -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, string, error) {
func (a Basic) Login(username string, password string) (bool, 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, username, err
return err == nil, err
}
// Close has no connection to close

View File

@ -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, string, error) {
func (a LDAP) Login(username string, password string) (bool, error) {
aliasSplit := strings.SplitN(username, "__", 2)
potentialUsernames := []string{username}
if len(aliasSplit) == 2 {
for 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, string, error) {
err = a.Conn.Bind(bindDn, password)
if err == nil {
// Login succeeded if no error
return true, aliasSplit[0], nil
return true, nil
}
}
// Unable to log in
return err == nil, "", err
return err == nil, err
}
// Close LDAP connection

View File

@ -82,9 +82,7 @@ func Serve(streams *messaging.Streams, authBackend auth.Backend, cfg *Options) {
name, password := split[0], split[1]
if authBackend != nil {
// check password
ok, username, err := authBackend.Login(name, password)
name = username
if ok || err != nil {
if ok, err := authBackend.Login(name, password); !ok || err != nil {
log.Printf("Failed to authenticate for stream %s", name)
s.Close()
continue