diff --git a/ldap.go b/ldap.go index 0f7ad15..c9e6b25 100644 --- a/ldap.go +++ b/ldap.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "crypto/tls" "encoding/base64" - "errors" "fmt" "strconv" "strings" @@ -99,8 +98,11 @@ func (l LDAPConn) SearchDN(username string, person bool) (string, error) { return "", err } - if len(sr.Entries) != 1 { - return "", errors.New("User does not exist or too many entries returned") + if len(sr.Entries) == 0 { + return "", fmt.Errorf("user %q not found", username) + } + if len(sr.Entries) > 1 { + return "", fmt.Errorf("multiple entries (%d) found for user %q", len(sr.Entries), username) } return sr.Entries[0].DN, nil @@ -118,8 +120,11 @@ func (l LDAPConn) GetEntry(dn string) ([]*ldap.EntryAttribute, error) { return nil, err } - if len(sr.Entries) != 1 { - return nil, errors.New("User does not exist or too many entries returned") + if len(sr.Entries) == 0 { + return nil, fmt.Errorf("entry not found for DN %q", dn) + } + if len(sr.Entries) > 1 { + return nil, fmt.Errorf("multiple entries (%d) found for DN %q", len(sr.Entries), dn) } return sr.Entries[0].Attributes, nil