feat: unbind LDAP clients if not used any more

This commit is contained in:
Yang Luo
2023-12-02 17:51:25 +08:00
parent b25b5f0249
commit 85cb68eb66
4 changed files with 22 additions and 1 deletions

View File

@ -237,22 +237,28 @@ func checkLdapUserPassword(user *User, password string, lang string) error {
searchResult, err := conn.Conn.Search(searchReq)
if err != nil {
conn.Close()
return err
}
if len(searchResult.Entries) == 0 {
conn.Close()
continue
}
if len(searchResult.Entries) > 1 {
conn.Close()
return fmt.Errorf(i18n.Translate(lang, "check:Multiple accounts with same uid, please check your ldap server"))
}
hit = true
dn := searchResult.Entries[0].DN
if err := conn.Conn.Bind(dn, password); err == nil {
if err = conn.Conn.Bind(dn, password); err == nil {
ldapLoginSuccess = true
conn.Close()
break
}
conn.Close()
}
if !ldapLoginSuccess {