diff --git a/src/main/ldap.go b/src/main/ldap.go index 1a0916c..8954561 100644 --- a/src/main/ldap.go +++ b/src/main/ldap.go @@ -21,13 +21,12 @@ type LDAPSearch struct { LDAPSearch *ldap.SearchResult } -func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServer, error) { +func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) *LDAPServer { logging.Debugf("Connecting to LDAP server %s", URL) l, err := ldap.DialURL(URL) if err != nil { logging.Fatal("Failed to connect to LDAP server") logging.Fatal(err.Error()) - return nil, err } logging.Infof("Connected to LDAP server") @@ -44,7 +43,7 @@ func connectToLDAPServer(URL string, starttls bool, ignore_cert bool) (*LDAPServ URL: URL, StartTLS: starttls, IgnoreInsecureCert: ignore_cert, - }, nil + } } func reconnectToLDAPServer(server *LDAPServer) { @@ -119,7 +118,11 @@ func modifyLDAPAttribute(server *LDAPServer, userDN string, attribute string, da func closeLDAPServer(server *LDAPServer) { if server != nil && server.Connection != nil { - server.Connection.Close() + logging.Debug("Closing connection to LDAP server") + err := server.Connection.Close() + if err != nil { + logging.Errorf("Failed to close LDAP server %s", err.Error()) + } } } diff --git a/src/main/main.go b/src/main/main.go index e1f9b26..861f8a7 100644 --- a/src/main/main.go +++ b/src/main/main.go @@ -321,13 +321,9 @@ func main() { } ldapServerMutex.Lock() - server, err := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert) + server := connectToLDAPServer(serverConfig.LDAPConfig.LDAPURL, serverConfig.LDAPConfig.Security == "tls", serverConfig.LDAPConfig.IgnoreInvalidCert) ldapServer = server ldapServerMutex.Unlock() - if err != nil { - log.Fatal(err) - return - } defer closeLDAPServer(ldapServer) createWorker(time.Minute*5, cleanupSessions) diff --git a/src/main/worker.go b/src/main/worker.go index 1b8f954..1a82216 100644 --- a/src/main/worker.go +++ b/src/main/worker.go @@ -2,9 +2,12 @@ package main import ( "time" + + "astraltech.xyz/accountmanager/src/logging" ) func createWorker(interval time.Duration, task func()) { + logging.Debugf("Creating worker that runs on a %s interval", interval.String()) go func() { ticker := time.NewTicker(interval) defer ticker.Stop()