From cc3b67b71ae6fd7aaa83a69fccd9223aa552c8bf Mon Sep 17 00:00:00 2001 From: Deon George Date: Wed, 12 Aug 2009 23:54:01 +1000 Subject: [PATCH] More login processing fixes --- lib/ds.php | 43 ++++++++++++++++++++++++++++++++++++------- lib/ds_ldap.php | 28 +++++++--------------------- lib/ds_ldap_pla.php | 11 ----------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/lib/ds.php b/lib/ds.php index f77f991..66f0e9e 100644 --- a/lib/ds.php +++ b/lib/ds.php @@ -146,6 +146,13 @@ abstract class DS { public function getLogin($method=null) { $method = $this->getMethod($method); + # For anonymous binds + if ($method == 'anon') + if (isset($_SESSION['USER'][$this->index][$method]['name'])) + return ''; + else + return null; + switch ($this->getAuthType()) { case 'config': if (! isset($_SESSION['USER'][$this->index][$method]['name'])) @@ -203,8 +210,12 @@ abstract class DS { protected function getPassword($method=null) { $method = $this->getMethod($method); + # For anonymous binds if ($method == 'anon') - return ''; + if (isset($_SESSION['USER'][$this->index][$method]['name'])) + return ''; + else + return null; switch ($this->getAuthType()) { case 'config': @@ -357,22 +368,40 @@ abstract class DS { * @return string Connection Method */ protected function getMethod($method=null) { - static $CACHE = null; + static $CACHE = array(); # Immediately return if method is set. if (! is_null($method)) return $method; # If we have been here already, then return our result - if (! is_null($CACHE)) - return $CACHE; + if (isset($CACHE[$this->index]) && ! is_null($CACHE)) + return $CACHE[$this->index]; - $CACHE = 'anon'; + $CACHE[$this->index] = 'anon'; if ($this->isLoggedIn('user')) - $CACHE = 'user'; + $CACHE[$this->index] = 'user'; - return $CACHE; + return $CACHE[$this->index]; + } + + /** + * This method should be overridden in application specific ds files + */ + public function isSessionValid() { + return true; + } + + /** + * Return the time left in seconds until this connection times out. If there is not timeout, + * this function will return null. + */ + public function inactivityTime() { + if ($this->isLoggedIn() && ! in_array($this->getAuthType(),array('config','http'))) + return time()+($this->getValue('login','timeout')*60); + else + return null; } } diff --git a/lib/ds_ldap.php b/lib/ds_ldap.php index 84081a6..4ea31d8 100644 --- a/lib/ds_ldap.php +++ b/lib/ds_ldap.php @@ -144,9 +144,6 @@ class ldap extends DS { $bind['id'] = is_null($this->getLogin($method)) && $method != 'anon' ? $this->getLogin('user') : $this->getLogin($method); $bind['pass'] = is_null($this->getPassword($method)) && $method != 'anon' ? $this->getPassword('user') : $this->getPassword($method); - if ($method == 'anon' && $bind['id']) - debug_dump_backtrace('Anon should not have an id',1); - # If our bind id is still null, we are not logged in. if (is_null($bind['id']) && $method != 'anon') return null; @@ -255,28 +252,17 @@ class ldap extends DS { # Get the userDN from the username. if (! is_null($user)) { - if ($method == 'user') { - # If login,attr is set to DN, then user should be a DN - if ($this->getValue('login','attr') == 'dn') - $userDN = $user; - else - $userDN = $this->getLoginID($user,'anon'); - - if (! $userDN) - return false; - - } elseif (is_dn_string($user)) { + # If login,attr is set to DN, then user should be a DN + if ($this->getValue('login','attr') == 'dn') $userDN = $user; + else + $userDN = $this->getLoginID($user,'anon'); - # Invalid User, so we'll blank out the username/password - } else { - $userDN = ''; - $pass = ''; - $method = 'anon'; - } + if (! $userDN) + return false; } else { - if ($method == 'user') { + if (in_array($method,array('user','anon'))) { $method = 'anon'; $userDN = ''; $pass = ''; diff --git a/lib/ds_ldap_pla.php b/lib/ds_ldap_pla.php index e6c6cef..afcbbc7 100644 --- a/lib/ds_ldap_pla.php +++ b/lib/ds_ldap_pla.php @@ -374,17 +374,6 @@ class ldap_pla extends ldap { return false; } - /** - * Return the time left in seconds until this connection times out. If there is not timeout, - * this function will return null. - */ - public function inactivityTime() { - if ($this->isLoggedIn() && ! in_array($this->getAuthType(),array('config','http'))) - return time()+($this->getValue('login','timeout')*60); - else - return null; - } - /** * Add objects */