diff options
author | Arthur Schiwon <blizzz@owncloud.com> | 2013-10-08 11:19:55 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@owncloud.com> | 2013-10-17 19:13:27 +0200 |
commit | 5c99645f7df70c930c3fbfca3de1a446eca66b2d (patch) | |
tree | a8db7956903d267e4115a820277aba1a7297bdbc /apps/user_ldap/lib | |
parent | 162bfb231aa31d7aa8c22543edff8aa9ceade3bd (diff) | |
download | nextcloud-server-5c99645f7df70c930c3fbfca3de1a446eca66b2d.tar.gz nextcloud-server-5c99645f7df70c930c3fbfca3de1a446eca66b2d.zip |
Cleanup code, sort results
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r-- | apps/user_ldap/lib/wizard.php | 90 |
1 files changed, 49 insertions, 41 deletions
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 @@ -291,6 +256,46 @@ class Wizard extends LDAPUtility { } /** + * @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 * @param $tls whether startTLS is to be used @@ -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')); } |