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) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) { if ($entries) {
$return = array_merge($return, cleanLDAPResult($entries)); cleanLDAPResult($entries);
$return = array_merge($return, $entries);
} }
@ldap_free_result($sr); @ldap_free_result($sr);
} }
@ -601,7 +602,8 @@ function searchLDAPByFilter($filter, $attributes, $scopes) {
if ($sr) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) { if ($entries) {
$return = array_merge($return, cleanLDAPResult($entries)); cleanLDAPResult($entries);
$return = array_merge($return, $entries);
} }
@ldap_free_result($sr); @ldap_free_result($sr);
} }
@ -624,9 +626,10 @@ function searchLDAP($suffix, $filter, $attributes) {
if ($sr) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) { if ($entries) {
$return = cleanLDAPResult($entries); cleanLDAPResult($entries);
@ldap_free_result($sr);
return $entries;
} }
@ldap_free_result($sr);
} }
return $return; return $return;
} }
@ -644,8 +647,8 @@ function ldapGetDN($dn, $attributes = array('dn')) {
if ($sr) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
if ($entries) { if ($entries) {
$return = cleanLDAPResult($entries); cleanLDAPResult($entries);
$return = $return[0]; $return = $entries[0];
} }
@ldap_free_result($sr); @ldap_free_result($sr);
} }
@ -685,14 +688,14 @@ function getLastLDAPError() {
* This will remove all 'count' entries and also all numeric array keys. * 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] * @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'])) { if (isset($entries['count'])) {
unset($entries['count']); unset($entries['count']);
} }
// iterate over all results // 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 // remove 'count' entries and numerical entries
for ($i = 0; $i < $entries[$e]['count']; $i++) { for ($i = 0; $i < $entries[$e]['count']; $i++) {
if (isset($entries[$e][$i])) { if (isset($entries[$e][$i])) {
@ -701,13 +704,13 @@ function cleanLDAPResult($entries) {
} }
unset($entries[$e]['count']); unset($entries[$e]['count']);
$attrNames = array_keys($entries[$e]); $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]])) { if (is_array($entries[$e][$attrNames[$i]])) {
unset($entries[$e][$attrNames[$i]]['count']); 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); $sr = @ldap_search($_SESSION["ldap"]->server(), escapeDN($suffix), "objectClass=organizationalunit", array("DN"), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) { if ($sr) {
$units = ldap_get_entries($_SESSION["ldap"]->server(), $sr); $units = ldap_get_entries($_SESSION["ldap"]->server(), $sr);
$units = cleanLDAPResult($units); cleanLDAPResult($units);
// extract Dns // extract Dns
for ($i = 0; $i < sizeof($units); $i++) { for ($i = 0; $i < sizeof($units); $i++) {
if ($units[$i]['dn']) $ret[] = $units[$i]['dn']; if ($units[$i]['dn']) $ret[] = $units[$i]['dn'];

View File

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

View File

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

View File

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

View File

@ -1453,7 +1453,7 @@ class inetOrgPerson extends baseModule implements passwordService {
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) { function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
$errors = array(); $errors = array();
// get list of existing users // 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++) { for ($e = 0; $e < sizeof($existingUsers); $e++) {
$existingUsers[$e] = $existingUsers[$e]['uid'][0]; $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); $sr = @ldap_search($_SESSION['ldapHandle'], escapeDN($this->selfServiceSettings->LDAPSuffix), '(&(objectClass=inetOrgPerson)(mail=*))', array('mail'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) { if ($sr) {
$result = ldap_get_entries($_SESSION['ldapHandle'], $sr); $result = ldap_get_entries($_SESSION['ldapHandle'], $sr);
$result = cleanLDAPResult($result); cleanLDAPResult($result);
for ($i = 0; $i < sizeof($result); $i++) { for ($i = 0; $i < sizeof($result); $i++) {
$delegates[] = $result[$i]['mail'][0]; $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); $sr = @ldap_list($_SESSION['ldap']->server(), $dn, 'objectClass=*', array('dn'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) { if ($sr) {
$entries = ldap_get_entries($_SESSION['ldap']->server(), $sr); $entries = ldap_get_entries($_SESSION['ldap']->server(), $sr);
$entries = cleanLDAPResult($entries); cleanLDAPResult($entries);
for ($i = 0; $i < sizeof($entries); $i++) { for ($i = 0; $i < sizeof($entries); $i++) {
// delete recursively // delete recursively
$subErrors = deleteDN($entries[$i]['dn']); $subErrors = deleteDN($entries[$i]['dn']);

View File

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