refactored LDAP error handling

This commit is contained in:
Roland Gruber 2010-02-14 18:01:20 +00:00
parent 88ba2cfdff
commit e7103c46ff
2 changed files with 26 additions and 19 deletions

View File

@ -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() { function getLastLDAPError() {
return ldap_errno($_SESSION["ldap"]->server()); $errorNumber = ldap_errno($_SESSION["ldap"]->server());
} switch ($errorNumber) {
// all ok
/** case 0:
* Returns the error message of the last LDAP command. return null;
* break;
* @return String error message // size limit exceeded
*/ case 4:
function getLastLDAPErrorMessage() { $error = array("WARN", _("LDAP sizelimit exceeded, not all entries are shown."));
return ldap_error($_SESSION["ldap"]->server()); 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; return $entries;
} }
?> ?>

View File

@ -762,11 +762,9 @@ class lamList {
$filter = "(&" . $module_filter . $this->filterPart . ")"; $filter = "(&" . $module_filter . $this->filterPart . ")";
$attrs = $this->attrArray; $attrs = $this->attrArray;
$entries = searchLDAP($this->suffix, $filter, $attrs); $entries = searchLDAP($this->suffix, $filter, $attrs);
if (getLastLDAPErrorNumber() == 4) { $lastError = getLastLDAPError();
StatusMessage("WARN", _("LDAP sizelimit exceeded, not all entries are shown."), _("See the manual for instructions to solve this problem.")); if ($lastError != null) {
} call_user_func_array('StatusMessage', $lastError);
elseif (getLastLDAPErrorNumber() > 0) {
StatusMessage("ERROR", _("LDAP search failed! Please check your preferences."), getLastLDAPErrorMessage());
} }
$this->entries = $entries; $this->entries = $entries;
// generate list of possible suffixes // generate list of possible suffixes