diff --git a/auth/auth.go b/auth/auth.go index ba30a8b..ec1316b 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -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() } diff --git a/auth/basic/basic.go b/auth/basic/basic.go index 00df8cd..8a80cd6 100644 --- a/auth/basic/basic.go +++ b/auth/basic/basic.go @@ -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 diff --git a/auth/ldap/ldap.go b/auth/ldap/ldap.go index 368ae94..52fb55e 100644 --- a/auth/ldap/ldap.go +++ b/auth/ldap/ldap.go @@ -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 diff --git a/stream/srt/srt.go b/stream/srt/srt.go index 160ef5c..e551459 100644 --- a/stream/srt/srt.go +++ b/stream/srt/srt.go @@ -82,7 +82,7 @@ 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 { + if ok, name, err := authBackend.Login(name, password); !ok || err != nil { log.Printf("Failed to authenticate for stream %s", name) s.Close() continue