From e7103c46ff93dcc750ffddc16cfdb7e226a2bf56 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sun, 14 Feb 2010 18:01:20 +0000 Subject: [PATCH] refactored LDAP error handling --- lam/lib/account.inc | 37 +++++++++++++++++++++++-------------- lam/lib/lists.inc | 8 +++----- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/lam/lib/account.inc b/lam/lib/account.inc index 8c69963a..e1d3d20e 100644 --- a/lam/lib/account.inc +++ b/lam/lib/account.inc @@ -609,21 +609,31 @@ function searchLDAP($suffix, $filter, $attributes) { } /** - * Returns the error number of the last LDAP command. + * Returns the parameters for a StatusMessage of the last LDAP search. * - * @return int error number (0 if all was ok) + * @return array parameters for StatusMessage or null if all was ok */ -function getLastLDAPErrorNumber() { - return ldap_errno($_SESSION["ldap"]->server()); -} - -/** - * Returns the error message of the last LDAP command. - * - * @return String error message - */ -function getLastLDAPErrorMessage() { - return ldap_error($_SESSION["ldap"]->server()); +function getLastLDAPError() { + $errorNumber = ldap_errno($_SESSION["ldap"]->server()); + switch ($errorNumber) { + // all ok + case 0: + return null; + break; + // size limit exceeded + case 4: + $error = array("WARN", _("LDAP sizelimit exceeded, not all entries are shown.")); + if ($_SESSION['config']->get_searchLimit() == 0) { + // server limit exceeded + $error[] = _("See the manual for instructions to solve this problem."); + } + return $error; + break; + // other errors + default: + return array("ERROR", _("LDAP search failed! Please check your preferences."), ldap_error($_SESSION["ldap"]->server())); + break; + } } /** @@ -656,5 +666,4 @@ function cleanLDAPResult($entries) { return $entries; } - ?> diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index f4e0eac4..2fbef8fd 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -762,11 +762,9 @@ class lamList { $filter = "(&" . $module_filter . $this->filterPart . ")"; $attrs = $this->attrArray; $entries = searchLDAP($this->suffix, $filter, $attrs); - if (getLastLDAPErrorNumber() == 4) { - StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See the manual for instructions to solve this problem.")); - } - elseif (getLastLDAPErrorNumber() > 0) { - StatusMessage("ERROR", _("LDAP search failed! Please check your preferences."), getLastLDAPErrorMessage()); + $lastError = getLastLDAPError(); + if ($lastError != null) { + call_user_func_array('StatusMessage', $lastError); } $this->entries = $entries; // generate list of possible suffixes