From d7bfd9898512224d1f6ad7ea255e93613913c936 Mon Sep 17 00:00:00 2001 From: Chuck Hagenbuch Date: Tue, 14 Jul 2009 00:30:46 -0400 Subject: [PATCH] don't catch exceptions and throw them away unless we are really, really sure we want to mask errors --- framework/Auth/lib/Horde/Auth.php | 30 +++++++++++++----------------- framework/Auth/lib/Horde/Auth/Driver.php | 12 +++++------- framework/Auth/lib/Horde/Auth/Msad.php | 15 +++------------ framework/Auth/lib/Horde/Auth/Signup.php | 13 +++---------- framework/Core/lib/Horde/Registry.php | 8 ++++---- 5 files changed, 28 insertions(+), 50 deletions(-) diff --git a/framework/Auth/lib/Horde/Auth.php b/framework/Auth/lib/Horde/Auth.php index 976ab2957..91bb640b4 100644 --- a/framework/Auth/lib/Horde/Auth.php +++ b/framework/Auth/lib/Horde/Auth.php @@ -512,14 +512,12 @@ class Horde_Auth $userId = self::addHook(trim($userId)); if (!empty($GLOBALS['conf']['hooks']['postauthenticate'])) { - try { - if (!Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde')) { - if (self::getAuthError() != self::REASON_MESSAGE) { - self::setAuthError(self::REASON_FAILED); - } - return false; + if (Horde::callHook('_horde_hook_postauthenticate', array($userId, $credentials, $realm), 'horde') === false) { + if (self::getAuthError() != self::REASON_MESSAGE) { + self::setAuthError(self::REASON_FAILED); } - } catch (Horde_Exception $e) {} + return false; + } } /* If we're already set with this userId, don't continue. */ @@ -578,14 +576,14 @@ class Horde_Auth : $_SERVER['HTTP_X_FORWARDED_FOR']; if (class_exists('Net_DNS')) { - $resolver = new Net_DNS_Resolver(); - $resolver->retry = isset($GLOBALS['conf']['dns']['retry']) ? $GLOBALS['conf']['dns']['retry'] : 1; - $resolver->retrans = isset($GLOBALS['conf']['dns']['retrans']) ? $GLOBALS['conf']['dns']['retrans'] : 1; - $response = $resolver->query($host, 'PTR'); - $ptrdname = $response ? $response->answer[0]->ptrdname : $host; - } else { - $ptrdname = @gethostbyaddr($host); - } + $resolver = new Net_DNS_Resolver(); + $resolver->retry = isset($GLOBALS['conf']['dns']['retry']) ? $GLOBALS['conf']['dns']['retry'] : 1; + $resolver->retrans = isset($GLOBALS['conf']['dns']['retrans']) ? $GLOBALS['conf']['dns']['retrans'] : 1; + $response = $resolver->query($host, 'PTR'); + $ptrdname = $response ? $response->answer[0]->ptrdname : $host; + } else { + $ptrdname = @gethostbyaddr($host); + } $last_login = array('time' => time(), 'host' => $ptrdname); $GLOBALS['prefs']->setValue('last_login', serialize($last_login)); @@ -688,7 +686,6 @@ class Horde_Auth * @param string $userId The authentication backend's user name. * * @return string The internal Horde user name. - * @throws Horde_Exception */ static public function addHook($userId) { @@ -709,7 +706,6 @@ class Horde_Auth * @param string $userId The internal Horde user name. * * @return string The authentication backend's user name. - * @throws Horde_Exception */ static public function removeHook($userId) { diff --git a/framework/Auth/lib/Horde/Auth/Driver.php b/framework/Auth/lib/Horde/Auth/Driver.php index e1e70e5f7..7583bcb43 100644 --- a/framework/Auth/lib/Horde/Auth/Driver.php +++ b/framework/Auth/lib/Horde/Auth/Driver.php @@ -74,14 +74,12 @@ class Horde_Auth_Driver $userId = trim($userId); if (!empty($GLOBALS['conf']['hooks']['preauthenticate'])) { - try { - if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde')) { - if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) { - Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED); - } - return false; + if (!Horde::callHook('_horde_hook_preauthenticate', array($userId, $credentials, $realm), 'horde')) { + if (Horde_Auth::getAuthError() != Horde_Auth::REASON_MESSAGE) { + Horde_Auth::setAuthError(Horde_Auth::REASON_FAILED); } - } catch (Horde_Exception $e) {} + return false; + } } /* Store the credentials being checked so that subclasses can modify diff --git a/framework/Auth/lib/Horde/Auth/Msad.php b/framework/Auth/lib/Horde/Auth/Msad.php index 93d94f944..f46a5ea93 100644 --- a/framework/Auth/lib/Horde/Auth/Msad.php +++ b/framework/Auth/lib/Horde/Auth/Msad.php @@ -76,10 +76,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - try { - $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde'); - } catch (Horde_Exception $e) {} - + $entry = Horde::callHook('_horde_hook_authmsad', array($accountName, $credentials), 'horde'); if (!is_null($entry)) { $dn = $entry['dn']; unset($entry['dn']); @@ -135,10 +132,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - try { - $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde'); - } catch (Horde_Exception $e) {} - + $entry = Horde::callHook('_horde_hook_authmsad', array($accountName), 'horde'); $dn = is_null($entry) /* Search for the user's full DN. */ ? $this->_findDN($accountName) @@ -167,10 +161,7 @@ class Horde_Auth_Msad extends Horde_Auth_Ldap /* Connect to the MSAD server. */ $this->_connect(); - try { - $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde'); - } catch (Horde_Exception $e) {} - + $entry = Horde::callHook('_horde_hook_authmsad', array($oldId, $credentials), 'horde'); if (!is_null($entry)) { $olddn = $entry['dn']; unset($entry['dn']); diff --git a/framework/Auth/lib/Horde/Auth/Signup.php b/framework/Auth/lib/Horde/Auth/Signup.php index bcf3b0536..36bd7aa66 100644 --- a/framework/Auth/lib/Horde/Auth/Signup.php +++ b/framework/Auth/lib/Horde/Auth/Signup.php @@ -115,9 +115,7 @@ class Horde_Auth_Signup // Perform any preprocessing if requested. if ($conf['signup']['preprocess']) { - try { - $info = Horde::callHook('_horde_hook_signup_preprocess', array($info)); - } catch (Horde_Exception $e) {} + $info = Horde::callHook('_horde_hook_signup_preprocess', array($info)); } // Check to see if the username already exists. @@ -143,9 +141,7 @@ class Horde_Auth_Signup } if ($conf['signup']['queue']) { - try { - $result = Horde::callHook('_horde_hook_signup_queued', array($info['user_name'], $info)); - } catch (Horde_Exception $e) {} + $result = Horde::callHook('_horde_hook_signup_queued', array($info['user_name'], $info)); } if (!empty($conf['signup']['email'])) { @@ -254,10 +250,7 @@ class HordeSignupForm extends Horde_Form { $this->addHidden('', 'url', 'text', false); /* Use hooks get any extra fields required in signing up. */ - try { - $extra = Horde::callHook('_horde_hook_signup_getextra'); - } catch (Horde_Exception $e) {} - + $extra = Horde::callHook('_horde_hook_signup_getextra'); if (!empty($extra)) { if (!isset($extra['user_name'])) { $this->addVariable(_("Choose a username"), 'user_name', 'text', true); diff --git a/framework/Core/lib/Horde/Registry.php b/framework/Core/lib/Horde/Registry.php index 094a34351..34caabc71 100644 --- a/framework/Core/lib/Horde/Registry.php +++ b/framework/Core/lib/Horde/Registry.php @@ -159,7 +159,9 @@ class Horde_Registry if (Horde_Auth::getAuth()) { try { $this->_cacheob = Horde_Cache::singleton($conf['cache']['driver'], Horde::getDriverConfig('cache', $conf['cache']['driver'])); - } catch (Horde_Exception $e) {} + } catch (Horde_Exception $e) { + // @TODO Log error + } } $this->_regmtime = max(filemtime(HORDE_BASE . '/config/registry.php'), @@ -819,9 +821,7 @@ class Horde_Registry $this->_appStack[] = $app; /* Call post-push hook. */ - try { - Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde'); - } catch (Horde_Exception $e) {} + Horde::callHook('_horde_hook_post_pushapp', array($app), 'horde'); return true; } -- 2.11.0