From 953b922a1371c5181158b2a50747b14237d82e7a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 19 Sep 2013 11:07:14 +0200 Subject: [PATCH 1/2] Instance caching added There was already a variable to cache the ldap driver instance, and a check if this variable was already set was there, too! But there was no code to return the cached instance if the function gets called twice! Maybe this was simply forgotten... --- inc/drivers_ldap.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index a6665297..a6f7211f 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -254,6 +254,10 @@ function getStaticLdap() { // If the instance is not there, create one if(!isset($instance)) { $ldapDrivers = new ldapDrivers($c->authenticate_hook['config']); + $instance = $ldapDrivers + } + else { + $ldapDrivers = $instance } return $ldapDrivers; } From ef365a5940d9146d00cf03c9da4315c360bf50a1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 19 Sep 2013 11:11:44 +0200 Subject: [PATCH 2/2] Only set the cached instance if driver is valid As I could see at other locations in the code, the ldap driver instance can be invalid. And if the instance is invalid, the getStaticLdap() function gets called again. Caching would prevent the function from retrying to initiate the ldapDrivers object. This commit adds conditional caching: only if the ldap driver instance is valid, the object gets cached. This ensures that a retry with this function would really try to create a new ldapDrivers object and not simply return the (invalid) cached one. --- inc/drivers_ldap.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index a6f7211f..1c080467 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -254,7 +254,10 @@ function getStaticLdap() { // If the instance is not there, create one if(!isset($instance)) { $ldapDrivers = new ldapDrivers($c->authenticate_hook['config']); - $instance = $ldapDrivers + + if ($ldapDrivers->valid) { + $instance = $ldapDrivers + } } else { $ldapDrivers = $instance