From 359e364527270331d5dadda303c71017c4a1717a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Fri, 26 Aug 2016 09:08:43 +0200 Subject: [PATCH] Fixes #5098 Reorganized exceptions in their own file --- include/class_SnapshotHandler.inc | 2 +- include/class_config.inc | 2 +- include/class_exceptions.inc | 46 ++++++++++++++++++++ include/class_ldap.inc | 5 --- include/class_ldapGeneralizedTime.inc | 5 --- include/class_objects.inc | 6 --- include/class_plugin.inc | 2 - include/functions.inc | 2 +- include/simpleplugin/class_simplePlugin.inc | 4 +- plugins/addons/dashboard/class_dashBoard.inc | 2 +- setup/class_setupStep_Migrate.inc | 2 +- 11 files changed, 53 insertions(+), 25 deletions(-) create mode 100644 include/class_exceptions.inc diff --git a/include/class_SnapshotHandler.inc b/include/class_SnapshotHandler.inc index 9bf318d56..f119b4332 100644 --- a/include/class_SnapshotHandler.inc +++ b/include/class_SnapshotHandler.inc @@ -428,7 +428,7 @@ class SnapshotHandler { if (!$ldap->success()) { msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, "", get_class()), LDAP_ERROR); } - } catch (Exception $e) { + } catch (LDIFImportException $e) { msg_dialog::display(_('LDAP error'), $e->getMessage(), ERROR_DIALOG); } } diff --git a/include/class_config.inc b/include/class_config.inc index 3385aa015..044f87775 100644 --- a/include/class_config.inc +++ b/include/class_config.inc @@ -275,7 +275,7 @@ class config { try { $cache[$creds] = cred_decrypt($creds, $_SERVER['HTTP_FDKEY']); session::global_set('HTTP_FDKEY_CACHE', $cache); - } catch (Exception $e) { + } catch (FusionDirectoryException $e) { $msg = sprintf( _('It seems you are trying to decode something which is not encoded : %s<br/>'."\n". 'Please check you are not using a fusiondirectory.secrets file while your passwords are not encrypted.'), diff --git a/include/class_exceptions.inc b/include/class_exceptions.inc new file mode 100644 index 000000000..3e11f8310 --- /dev/null +++ b/include/class_exceptions.inc @@ -0,0 +1,46 @@ +<?php +/* + This code is part of FusionDirectory (http://www.fusiondirectory.org/) + Copyright (C) 2015-2016 FusionDirectory + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +/*! + * \file class_exceptions.inc + * Source code for Class LDAP + */ + +/*! \class FusionDirectoryException + \brief Parent class for all exceptions thrown in FusionDirectory +*/ +class FusionDirectoryException extends Exception {} + +/*! \class LDIFImportException + \brief Exception class which can be thrown by LDAP if the LDIF format is broken +*/ +class LDIFImportException extends FusionDirectoryException {} + +/*! \class LdapGeneralizedTimeBadFormatException + \brief Exception class which can be thrown by LdapGeneralizedTime if the format does not match +*/ +class LdapGeneralizedTimeBadFormatException extends FusionDirectoryException {}; + +class NonExistingObjectTypeException extends FusionDirectoryException {}; +class NonExistingBranchException extends FusionDirectoryException {}; +class NonExistingLdapNodeException extends FusionDirectoryException {}; +class EmptyFilterException extends FusionDirectoryException {}; +class NoManagementClassException extends FusionDirectoryException {}; +class LDAPFailureException extends FusionDirectoryException {}; diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 8082a5a05..56bc1d168 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -28,11 +28,6 @@ define("SPECIALS_OVERRIDE", FALSE); -/*! \class LdapGeneralizedTimeBadFormatException - \brief Exception class which can be thrown by LDAP if the LDIF format is broken -*/ -class LDIFImportException extends Exception {} - /*! * \brief This class contains all ldap function needed to make * ldap operations easy diff --git a/include/class_ldapGeneralizedTime.inc b/include/class_ldapGeneralizedTime.inc index 42effea12..0a1e7c662 100644 --- a/include/class_ldapGeneralizedTime.inc +++ b/include/class_ldapGeneralizedTime.inc @@ -32,11 +32,6 @@ '19941216101255,5Z' */ -/*! \class LdapGeneralizedTimeBadFormatException - \brief Exception class which can be thrown by LdapGeneralizedTime if the format does not match -*/ -class LdapGeneralizedTimeBadFormatException extends Exception {}; - /*! \class LdapGeneralizedTime \brief LdapGeneralizedTime allows you to convert from and to LDAPĂ‚ GeneralizedTime format PHP DateTime objects diff --git a/include/class_objects.inc b/include/class_objects.inc index dc753a5fc..d8db92bd0 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -19,12 +19,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class NonExistingObjectTypeException extends Exception {}; -class NonExistingBranchException extends Exception {}; -class EmptyFilterException extends Exception {}; -class NoManagementClassException extends Exception {}; -class LDAPFailureException extends Exception {}; - class objects { /*! diff --git a/include/class_plugin.inc b/include/class_plugin.inc index a8684b717..6f105e5f7 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -19,8 +19,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -class NonExistingLdapNodeException extends Exception {}; - /*! * \file class_plugin.inc * Source code for the class plugin diff --git a/include/functions.inc b/include/functions.inc index b120d0691..d4cae9a7c 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -3059,7 +3059,7 @@ function cred_decrypt($input, $password) /************************* Inspired by Crypt/CBC.pm *******************************/ $input = pack('H*', $input); if (substr($input, 0, 8) != 'Salted__') { - throw new Exception("Invalid hash header: expected 'Salted__', found '".substr($input, 0, 8)."'"); + throw new FusionDirectoryException("Invalid hash header: expected 'Salted__', found '".substr($input, 0, 8)."'"); } $salt = substr($input, 8, 8); $input = substr($input, 16); diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index 11bcc5021..171c6b47e 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -1055,7 +1055,7 @@ class simplePlugin extends plugin ); try { $refs[$dn]['link'] = objects::link($dn, $objectType); - } catch (Exception $e) { + } catch (FusionDirectoryException $e) { trigger_error("Could not create link to $dn: ".$e->getMessage()); $refs[$dn]['link'] = $dn; } @@ -1067,7 +1067,7 @@ class simplePlugin extends plugin ); try { $refs[$dn]['tabs'][$tab]['link'] = objects::link($dn, $objectType, "tab_$tab", sprintf(_('Tab "%s"'), $tab_infos['name'])); - } catch (Exception $e) { + } catch (FusionDirectoryException $e) { trigger_error("Could not create link to $dn $tab: ".$e->getMessage()); $refs[$dn]['tabs'][$tab]['link'] = $tab; } diff --git a/plugins/addons/dashboard/class_dashBoard.inc b/plugins/addons/dashboard/class_dashBoard.inc index cb89b3eff..9b250f7ca 100644 --- a/plugins/addons/dashboard/class_dashBoard.inc +++ b/plugins/addons/dashboard/class_dashBoard.inc @@ -67,7 +67,7 @@ class dashboard extends simplePlugin foreach ($config->data['OBJECTS'] as $type => $infos) { try { $nb = objects::count($type); - } catch (Exception $e) { + } catch (FusionDirectoryException $e) { $nb = 0; trigger_error("Problem with $type:".$e->getMessage()); } diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc index 83c4253be..c875bc42a 100644 --- a/setup/class_setupStep_Migrate.inc +++ b/setup/class_setupStep_Migrate.inc @@ -44,7 +44,7 @@ array_to_ldif - Create ldif output of an ldap result array ****************/ -class CheckFailedException extends Exception +class CheckFailedException extends FusionDirectoryException { private $error; -- GitLab