ldap login support anonymous search mode
This commit is contained in:
parent
7c86e8f58e
commit
a5be668359
|
@ -45,16 +45,17 @@ func ldapReq(user, pass string) (*ldap.SearchResult, error) {
|
|||
defer conn.Close()
|
||||
|
||||
if !lc.TLS && lc.StartTLS {
|
||||
err = conn.StartTLS(&tls.Config{InsecureSkipVerify: true})
|
||||
if err != nil {
|
||||
if err := conn.StartTLS(&tls.Config{InsecureSkipVerify: true}); err != nil {
|
||||
return nil, fmt.Errorf("ldap.conn startTLS fail: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
err = conn.Bind(lc.BindUser, lc.BindPass)
|
||||
if err != nil {
|
||||
//if bindUser is empty, anonymousSearch mode
|
||||
if lc.BindUser != "" {
|
||||
//BindSearch mode
|
||||
if err := conn.Bind(lc.BindUser, lc.BindPass); err != nil {
|
||||
return nil, fmt.Errorf("bind ldap fail: %v, use %s", err, lc.BindUser)
|
||||
}
|
||||
}
|
||||
|
||||
searchRequest := ldap.NewSearchRequest(
|
||||
lc.BaseDn, // The base dn to search
|
||||
|
|
Loading…
Reference in New Issue