From: Arthur Schiwon Date: Tue, 8 Oct 2013 09:19:55 +0000 (+0200) Subject: Cleanup code, sort results X-Git-Tag: v6.0.0beta2~46^2~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5c99645f7df70c930c3fbfca3de1a446eca66b2d;p=nextcloud-server.git Cleanup code, sort results --- diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php index 0dbd8c92021..7e3dfa8610f 100644 --- a/apps/user_ldap/lib/wizard.php +++ b/apps/user_ldap/lib/wizard.php @@ -73,53 +73,18 @@ class Wizard extends LDAPUtility { } $obclasses = array('posixGroup', 'group', '*'); - $groups = $this->determineFeature($obclasses, - 'cn', - 'ldap_userfilter_groups', - 'ldapUserFilterGroups'); + $this->determineFeature($obclasses, + 'cn', + 'ldap_userfilter_groups', + 'ldapUserFilterGroups'); - $isMemberOfWorking = $this->testMemberOf($groups); - if(!$isMemberOfWorking) { + if(!$this->testMemberOf()) { throw new \Exception('memberOf is not supported by the server'); } return $this->result; } - private function testMemberOf($groups) { - $cr = $this->getConnection(); - if(!$cr) { - throw new \Excpetion('Could not connect to LDAP'); - } - if(!is_array($this->configuration->ldapBase) - || !isset($this->configuration->ldapBase[0])) { - return false; - } - $base = $this->configuration->ldapBase[0]; - $filterPrefix = '(&(objectclass=*)(memberOf='; - - foreach($this->resultCache as $dn => $properties) { - if(!isset($properties['cn'])) { - //assuming only groups have their cn cached :) - continue; - } - $filter = strtolower($filterPrefix . $dn.'))'); - $rr = $this->ldap->search($cr, $base, $filter, array('dn')); - if(!$this->ldap->isResource($rr)) { - continue; - } - $entries = $this->ldap->countEntries($cr, $rr); - //we do not know which groups are empty, so test any and return - //success on the first match that returns at least one user - if(($entries !== false) && ($entries > 0)) { - return true; - } - } - - - return false; - } - /** * @brief detects the available object classes * @returns the instance's WizardResult instance @@ -290,6 +255,46 @@ class Wizard extends LDAPUtility { return ($entries !== false) && ($entries > 0); } + /** + * @brief Checks whether the server supports memberOf in LDAP Filter. + * Requires that groups are determined, thus internally called from within + * determineGroups() + * @return bool, true if it does, false otherwise + */ + private function testMemberOf() { + $cr = $this->getConnection(); + if(!$cr) { + throw new \Excpetion('Could not connect to LDAP'); + } + if(!is_array($this->configuration->ldapBase) + || !isset($this->configuration->ldapBase[0])) { + return false; + } + $base = $this->configuration->ldapBase[0]; + $filterPrefix = '(&(objectclass=*)(memberOf='; + $filterSuffix = '))'; + + foreach($this->resultCache as $dn => $properties) { + if(!isset($properties['cn'])) { + //assuming only groups have their cn cached :) + continue; + } + $filter = strtolower($filterPrefix . $dn . $filterSuffix); + $rr = $this->ldap->search($cr, $base, $filter, array('dn')); + if(!$this->ldap->isResource($rr)) { + continue; + } + $entries = $this->ldap->countEntries($cr, $rr); + //we do not know which groups are empty, so test any and return + //success on the first match that returns at least one user + if(($entries !== false) && ($entries > 0)) { + return true; + } + } + + return false; + } + /** * Connects and Binds to an LDAP Server * @param $port the port to connect with @@ -461,7 +466,10 @@ class Wizard extends LDAPUtility { true, $maxEntryObjC); if(is_array($availableFeatures) && count($availableFeatures) > 0) { - $this->result->addOptions($dbkey, $availableFeatures); + natcasesort($availableFeatures); + //natcasesort keeps indices, but we must get rid of them for proper + //sorting in the web UI. Therefore: array_values + $this->result->addOptions($dbkey, array_values($availableFeatures)); } else { throw new \Exception(self::$l->t('Could not find the desired feature')); }