From 012c4d5746a1c15b9cd06bac7db0e0d9760ca62c Mon Sep 17 00:00:00 2001 From: Benoit Mortier <benoit.mortier@opensides.be> Date: Sun, 4 Dec 2016 00:01:04 +0100 Subject: [PATCH] Fixes: #5099 Exception should be reorganized Signed-off-by: Benoit Mortier <benoit.mortier@opensides.be> --- include/class_SnapshotHandler.inc | 2 +- include/class_config.inc | 2 +- include/class_exceptions.inc | 46 ++++++++++++++++++++ include/class_ldapGeneralizedTime.inc | 5 --- include/class_objects.inc | 4 -- include/class_plugin.inc | 2 - include/functions.inc | 2 +- plugins/addons/dashboard/class_dashBoard.inc | 2 +- setup/class_setupStep_Migrate.inc | 2 +- 9 files changed, 51 insertions(+), 16 deletions(-) create mode 100644 include/class_exceptions.inc diff --git a/include/class_SnapshotHandler.inc b/include/class_SnapshotHandler.inc index 8d1dece31..954d95fee 100644 --- a/include/class_SnapshotHandler.inc +++ b/include/class_SnapshotHandler.inc @@ -459,7 +459,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 cb1f6c659..444318dcb 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..7bbb356c9 --- /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 FusionDirectory exceptions + */ + +/*! \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_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 6019aa122..2c9e96ea5 100644 --- a/include/class_objects.inc +++ b/include/class_objects.inc @@ -19,10 +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 objects { /*! diff --git a/include/class_plugin.inc b/include/class_plugin.inc index b77085fb4..ae9e550f1 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 a5b57336b..6a22ebfa9 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -3022,7 +3022,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/plugins/addons/dashboard/class_dashBoard.inc b/plugins/addons/dashboard/class_dashBoard.inc index 21a24d48e..56e0eba91 100644 --- a/plugins/addons/dashboard/class_dashBoard.inc +++ b/plugins/addons/dashboard/class_dashBoard.inc @@ -68,7 +68,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 02d6f68c0..b7f27772c 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