Skip to content

Commit

Permalink
ldap-auth: extract username form BindDN by stripping domain component
Browse files Browse the repository at this point in the history
  • Loading branch information
equinox0815 committed Jan 31, 2024
1 parent 30de3dd commit 53904ab
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/whawty-auth/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ package main
import (
"crypto/tls"
"net"
"strings"

"github.com/glauth/ldap"
)
Expand All @@ -42,7 +43,8 @@ type ldapHandler struct {
}

func (h ldapHandler) Bind(bindDN, bindSimplePw string, conn net.Conn) (ldap.LDAPResultCode, error) {
if ok, _, _, _ := h.store.Authenticate(bindDN, bindSimplePw); !ok {
username, _, _ := strings.Cut(bindDN, "@")
if ok, _, _, _ := h.store.Authenticate(username, bindSimplePw); !ok {
return ldap.LDAPResultInvalidCredentials, nil
}
return ldap.LDAPResultSuccess, nil
Expand Down

0 comments on commit 53904ab

Please sign in to comment.