diff options
author | Unknwon <u@gogs.io> | 2015-09-10 14:55:29 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-10 14:55:29 -0400 |
commit | cbd6276200751f4b64a203767f0f454c3346fca1 (patch) | |
tree | 9f0ad4f59e40dbb4f3cdad045611fce382fa9f8e /modules/auth/ldap/ldap.go | |
parent | 52ec80fa18bf991c6356b7aa972a1d3983aa20c3 (diff) | |
parent | b954a22ce28d74021f0d4896e281aabc93eed938 (diff) | |
download | gitea-cbd6276200751f4b64a203767f0f454c3346fca1.tar.gz gitea-cbd6276200751f4b64a203767f0f454c3346fca1.zip |
Merge branch 'develop' of https://github.com/SergioBenitez/gogs into develop
# Conflicts:
# modules/bindata/bindata.go
Diffstat (limited to 'modules/auth/ldap/ldap.go')
-rw-r--r-- | modules/auth/ldap/ldap.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/modules/auth/ldap/ldap.go b/modules/auth/ldap/ldap.go index de1108fd98..61cfca90b5 100644 --- a/modules/auth/ldap/ldap.go +++ b/modules/auth/ldap/ldap.go @@ -22,6 +22,7 @@ type Ldapsource struct { BindDN string // DN to bind with BindPassword string // Bind DN password UserBase string // Base search path for users + UserDN string // Template for the DN of the user for simple auth AttributeName string // First name attribute AttributeSurname string // Surname attribute AttributeMail string // E-mail attribute @@ -78,10 +79,19 @@ func (ls Ldapsource) FindUserDN(name string) (string, bool) { } // searchEntry : search an LDAP source if an entry (name, passwd) is valid and in the specific filter -func (ls Ldapsource) SearchEntry(name, passwd string) (string, string, string, bool, bool) { - userDN, found := ls.FindUserDN(name) - if !found { - return "", "", "", false, false +func (ls Ldapsource) SearchEntry(name, passwd string, directBind bool) (string, string, string, bool, bool) { + var userDN string + if directBind { + log.Trace("LDAP will bind directly via UserDN template: %s", ls.UserDN) + userDN = fmt.Sprintf(ls.UserDN, name) + } else { + log.Trace("LDAP will use BindDN.") + + var found bool + userDN, found = ls.FindUserDN(name) + if !found { + return "", "", "", false, false + } } l, err := ldapDial(ls) @@ -112,7 +122,12 @@ func (ls Ldapsource) SearchEntry(name, passwd string) (string, string, string, b log.Error(4, "LDAP Search failed unexpectedly! (%v)", err) return "", "", "", false, false } else if len(sr.Entries) < 1 { - log.Error(4, "LDAP Search failed unexpectedly! (0 entries)") + if directBind { + log.Error(4, "User filter inhibited user login.") + } else { + log.Error(4, "LDAP Search failed unexpectedly! (0 entries)") + } + return "", "", "", false, false } |