From 9c56bf61ab4167b37cf9728c4000621863309ecf Mon Sep 17 00:00:00 2001 From: BetaPictoris Date: Sun, 6 Aug 2023 03:00:00 -0700 Subject: [PATCH] Fixed for LDAP connection --- server/ctrlsubsonic/middleware.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/ctrlsubsonic/middleware.go b/server/ctrlsubsonic/middleware.go index 1256986b..ff77e6c9 100644 --- a/server/ctrlsubsonic/middleware.go +++ b/server/ctrlsubsonic/middleware.go @@ -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 @@ -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), @@ -177,7 +177,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 { // Warn the server and return a generic error. log.Println("Failed to connect to LDAP server", err) @@ -185,6 +184,7 @@ 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{