Skip to content

Commit

Permalink
Fixed for LDAP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
BetaPictoris committed Aug 6, 2023
1 parent 79b28ef commit 9c56bf6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/ctrlsubsonic/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (c *Controller) WithUser(next http.Handler) http.Handler {

// Now, we can try to connect to the LDAP server.
l, err := ldap.DialURL(fmt.Sprintf("%s://%s:%s", protocol, ldapFQDN, ldapPort))
defer l.Close()
if err != nil {
newLDAPUser = true

Expand All @@ -106,7 +105,8 @@ func (c *Controller) WithUser(next http.Handler) http.Handler {
_ = writeResp(w, r, spec.NewError(0, "Failed to connect to LDAP server."))
return
}

defer l.Close()

// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Username: fmt.Sprintf("uid=%s,%s", bindUID, baseDN),
Expand Down Expand Up @@ -177,14 +177,14 @@ func (c *Controller) WithUser(next http.Handler) http.Handler {

// Now, we can try to connect to the LDAP server.
l, err := ldap.DialURL(fmt.Sprintf("%s://%s:%s", protocol, ldapFQDN, ldapPort))
defer l.Close()
if err != nil {
// Warn the server and return a generic error.
log.Println("Failed to connect to LDAP server", err)

_ = writeResp(w, r, spec.NewError(0, "Failed to connect to LDAP server."))
return
}
defer l.Close()

// After we have a connection, let's try binding
_, err = l.SimpleBind(&ldap.SimpleBindRequest{
Expand Down

0 comments on commit 9c56bf6

Please sign in to comment.