memory and speed improvements

This commit is contained in:
Roland Gruber 2011-05-21 10:58:22 +00:00
parent 43bd56a328
commit 6814c76ac9
9 changed files with 26 additions and 25 deletions

View File

@ -576,7 +576,8 @@ function searchLDAPByAttribute($name, $value, $objectClass, $attributes, $scopes
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) {
$return = array_merge($return, cleanLDAPResult($entries));
cleanLDAPResult($entries);
$return = array_merge($return, $entries);
}
@ldap_free_result($sr);
}
@ -601,7 +602,8 @@ function searchLDAPByFilter($filter, $attributes, $scopes) {
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) {
$return = array_merge($return, cleanLDAPResult($entries));
cleanLDAPResult($entries);
$return = array_merge($return, $entries);
}
@ldap_free_result($sr);
}
@ -624,9 +626,10 @@ function searchLDAP($suffix, $filter, $attributes) {
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) {
$return = cleanLDAPResult($entries);
}
cleanLDAPResult($entries);
@ldap_free_result($sr);
return $entries;
}
}
return $return;
}
@ -644,8 +647,8 @@ function ldapGetDN($dn, $attributes = array('dn')) {
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) {
$return = cleanLDAPResult($entries);
$return = $return[0];
cleanLDAPResult($entries);
$return = $entries[0];
}
@ldap_free_result($sr);
}
@ -685,14 +688,14 @@ function getLastLDAPError() {
* This will remove all 'count' entries and also all numeric array keys.
*
* @param array $entries LDAP entries in format $entries[entry number][attribute name][attribute values]
* @return array cleaned entries
*/
function cleanLDAPResult($entries) {
function cleanLDAPResult(&$entries) {
if (isset($entries['count'])) {
unset($entries['count']);
}
// iterate over all results
for ($e = 0; $e < sizeof($entries); $e++) {
$count = sizeof($entries);
for ($e = 0; $e < $count; $e++) {
// remove 'count' entries and numerical entries
for ($i = 0; $i < $entries[$e]['count']; $i++) {
if (isset($entries[$e][$i])) {
@ -701,13 +704,13 @@ function cleanLDAPResult($entries) {
}
unset($entries[$e]['count']);
$attrNames = array_keys($entries[$e]);
for ($i = 0; $i < sizeof($attrNames); $i++) {
$attrCount = sizeof($attrNames);
for ($i = 0; $i < $attrCount; $i++) {
if (is_array($entries[$e][$attrNames[$i]])) {
unset($entries[$e][$attrNames[$i]]['count']);
}
}
}
return $entries;
}
/**

View File

@ -141,7 +141,7 @@ class baseType {
$sr = @ldap_search($_SESSION["ldap"]->server(), escapeDN($suffix), "objectClass=organizationalunit", array("DN"), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$units = ldap_get_entries($_SESSION["ldap"]->server(), $sr);
$units = cleanLDAPResult($units);
cleanLDAPResult($units);
// extract Dns
for ($i = 0; $i < sizeof($units); $i++) {
if ($units[$i]['dn']) $ret[] = $units[$i]['dn'];

View File

@ -156,7 +156,7 @@ class lamList {
}
// sort rows by sort column
if (isset($this->entries)) {
$this->entries = $this->listSort($this->entries);
$this->listSort($this->entries);
}
// insert HTML fragment from listDoPost
echo $postFragment;
@ -229,14 +229,12 @@ class lamList {
* Sorts an account list by a given attribute
*
* @param array $info the account list
* @return array sorted account list
*/
protected function listSort(&$info) {
if (!is_array($this->attrArray)) return $info;
if (!is_string($this->sortColumn)) return $info;
if (!is_array($this->attrArray)) return;
if (!is_string($this->sortColumn)) return;
// sort and return account list
usort($info, array($this, "cmp_array"));
return $info;
}
@ -838,12 +836,11 @@ class lamList {
$module_filter = get_ldap_filter($this->type); // basic filter is provided by modules
$filter = "(&" . $module_filter . $this->filterPart . ")";
$attrs = $this->attrArray;
$entries = searchLDAP($this->suffix, $filter, $attrs);
$this->entries = searchLDAP($this->suffix, $filter, $attrs);
$lastError = getLastLDAPError();
if ($lastError != null) {
call_user_func_array('StatusMessage', $lastError);
}
$this->entries = $entries;
// generate list of possible suffixes
$typeObj = new $this->type();
$this->possibleSuffixes = $typeObj->getSuffixList();

View File

@ -1376,7 +1376,8 @@ class accountContainer {
$this->rdn = explode("=", substr($dn, 0, strpos($dn, ',')));
$this->rdn = $this->rdn[0];
$attr = ldap_get_attributes($_SESSION['ldap']->server(), $entry);
$attr = cleanLDAPResult(array($attr));
$attr = array($attr);
cleanLDAPResult($attr);
$attr = $attr[0];
// fix spelling errors
$attr = $this->fixLDAPAttributes($attr, $modules);

View File

@ -197,7 +197,7 @@ class ddns extends baseModule {
if ($search) {
$info = @ldap_get_entries($ldap,$search);
if ($info) {
$info = cleanLDAPResult($info);
cleanLDAPResult($info);
if (sizeof($info) > 0) {
return true;
}

View File

@ -1453,7 +1453,7 @@ class inetOrgPerson extends baseModule implements passwordService {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array();
// get list of existing users
$existingUsers = searchLDAPByAttribute(null, null, 'inetOrgPerson', array('uid'), array('user'));
$existingUsers = searchLDAPByAttribute('uid', '*', 'inetOrgPerson', array('uid'), array('user'));
for ($e = 0; $e < sizeof($existingUsers); $e++) {
$existingUsers[$e] = $existingUsers[$e]['uid'][0];
}

View File

@ -837,7 +837,7 @@ class kolabUser extends baseModule {
$sr = @ldap_search($_SESSION['ldapHandle'], escapeDN($this->selfServiceSettings->LDAPSuffix), '(&(objectClass=inetOrgPerson)(mail=*))', array('mail'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$result = ldap_get_entries($_SESSION['ldapHandle'], $sr);
$result = cleanLDAPResult($result);
cleanLDAPResult($result);
for ($i = 0; $i < sizeof($result); $i++) {
$delegates[] = $result[$i]['mail'][0];
}

View File

@ -308,7 +308,7 @@ function deleteDN($dn) {
$sr = @ldap_list($_SESSION['ldap']->server(), $dn, 'objectClass=*', array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
$entries = cleanLDAPResult($entries);
cleanLDAPResult($entries);
for ($i = 0; $i < sizeof($entries); $i++) {
// delete recursively
$subErrors = deleteDN($entries[$i]['dn']);

View File

@ -464,7 +464,7 @@ if(!empty($_POST['checklogin'])) {
if ($searchResult) {
$searchInfo = @ldap_get_entries($searchLDAP->server(), $searchResult);
if ($searchInfo) {
$searchInfo = cleanLDAPResult($searchInfo);
cleanLDAPResult($searchInfo);
if (sizeof($searchInfo) == 0) {
$searchSuccess = false;
$searchError = _('Wrong password/user name combination. Please try again.');