2021-04-19 22:30:27 +00:00
|
|
|
package ldap
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
2021-05-12 16:49:15 +00:00
|
|
|
"strings"
|
2021-04-19 22:30:27 +00:00
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
"github.com/nmcclain/ldap"
|
2021-04-19 22:30:27 +00:00
|
|
|
)
|
|
|
|
|
2021-05-04 19:49:15 +00:00
|
|
|
func (ls *LDAPServer) Bind(bindDN string, bindPW string, conn net.Conn) (ldap.LDAPResultCode, error) {
|
2021-05-12 16:49:15 +00:00
|
|
|
ls.log.WithField("bindDN", bindDN).Info("bind")
|
|
|
|
bindDN = strings.ToLower(bindDN)
|
2021-04-26 09:53:06 +00:00
|
|
|
for _, instance := range ls.providers {
|
|
|
|
username, err := instance.getUsername(bindDN)
|
|
|
|
if err == nil {
|
2021-05-12 16:49:15 +00:00
|
|
|
return instance.Bind(username, bindDN, bindPW, conn)
|
2021-05-07 09:46:26 +00:00
|
|
|
} else {
|
|
|
|
ls.log.WithError(err).Debug("Username not for instance")
|
2021-04-25 20:07:12 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-12 16:49:15 +00:00
|
|
|
ls.log.WithField("bindDN", bindDN).WithField("request", "bind").Warning("No provider found for request")
|
2021-04-26 09:53:06 +00:00
|
|
|
return ldap.LDAPResultOperationsError, nil
|
2021-04-19 22:30:27 +00:00
|
|
|
}
|