Merge pull request #2189 from dexidp/ldap-unauth-bind

Fix anonymous ldap bind
This commit is contained in:
Márk Sági-Kazár 2021-06-28 19:17:57 +02:00 committed by GitHub
commit cfc8d198ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -331,10 +331,11 @@ func (c *ldapConnector) do(_ context.Context, f func(c *ldap.Conn) error) error
defer conn.Close() defer conn.Close()
// If bindDN and bindPW are empty this will default to an anonymous bind. // If bindDN and bindPW are empty this will default to an anonymous bind.
if err := conn.Bind(c.BindDN, c.BindPW); err != nil { if c.BindDN == "" && c.BindPW == "" {
if c.BindDN == "" && c.BindPW == "" { if err := conn.UnauthenticatedBind(""); err != nil {
return fmt.Errorf("ldap: initial anonymous bind failed: %v", err) return fmt.Errorf("ldap: initial anonymous bind failed: %v", err)
} }
} else if err := conn.Bind(c.BindDN, c.BindPW); err != nil {
return fmt.Errorf("ldap: initial bind for user %q failed: %v", c.BindDN, err) return fmt.Errorf("ldap: initial bind for user %q failed: %v", c.BindDN, err)
} }