Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2014-06-11 23:38:16 +0400
committerArthur Schiwon <blizzz@owncloud.com>2014-06-16 19:51:31 +0400
commitc491fa272e3904b27ed4618954d56231c5400f3a (patch)
tree6e17aa971d3a093bb4fff1b77afea1414dedc132 /apps
parente23e459c41f88d97388d52fa0890139a6c60b0a6 (diff)
Wizard: get really all groups from LDAP by power of Paged Search
Diffstat (limited to 'apps')
-rw-r--r--apps/user_ldap/lib/wizard.php60
1 files changed, 55 insertions, 5 deletions
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 27099e53817..c5e9eb6118e 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -78,9 +78,7 @@ class Wizard extends LDAPUtility {
throw new \Exception('Requirements not met', 400);
}
- $con = new Connection($this->ldap, '', null);
- $con->setConfiguration($this->configuration->getConfiguration());
- $ldapAccess = new Access($con, $this->ldap);
+ $ldapAccess = $this->getAccess();
if($type === 'groups') {
$result = $ldapAccess->countGroups($filter);
} else if($type === 'users') {
@@ -257,8 +255,7 @@ class Wizard extends LDAPUtility {
throw new \Exception('Could not connect to LDAP');
}
- $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', '*');
- $this->determineFeature($obclasses, 'cn', $dbkey, $confkey);
+ $this->fetchGroups($dbkey, $confkey);
if($testMemberOf) {
$this->configuration->hasMemberOfFilterSupport = $this->testMemberOf();
@@ -271,6 +268,48 @@ class Wizard extends LDAPUtility {
return $this->result;
}
+ /**
+ * fetches all groups from LDAP
+ * @param string $dbKey
+ * @param string $confKey
+ */
+ public function fetchGroups($dbKey, $confKey) {
+ $obclasses = array('posixGroup', 'group', 'zimbraDistributionList', 'groupOfNames');
+ $ldapAccess = $this->getAccess();
+
+ foreach($obclasses as $obclass) {
+ $filterParts[] = 'objectclass='.$obclass;
+ }
+ //we filter for everything
+ //- that looks like a group and
+ //- has the group display name set
+ $filter = $ldapAccess->combineFilterWithOr($filterParts);
+ $filter = $ldapAccess->combineFilterWithAnd(array($filter, 'cn=*'));
+
+ $limit = 400;
+ $offset = 0;
+ do {
+ $result = $ldapAccess->searchGroups($filter, array('cn'), $limit, $offset);
+ foreach($result as $item) {
+ $groups[] = $item[0];
+ }
+ $offset += $limit;
+ } while (count($groups) > 0 && count($groups) % $limit === 0);
+
+ if(count($groups) > 0) {
+ natsort($groups);
+ $this->result->addOptions($dbKey, array_values($groups));
+ } else {
+ throw new \Exception(self::$l->t('Could not find the desired feature'));
+ }
+
+ $setFeatures = $this->configuration->$confKey;
+ if(is_array($setFeatures) && !empty($setFeatures)) {
+ //something is already configured? pre-select it.
+ $this->result->addChange($dbKey, $setFeatures);
+ }
+ }
+
public function determineGroupMemberAssoc() {
if(!$this->checkRequirements(array('ldapHost',
'ldapPort',
@@ -1026,6 +1065,17 @@ class Wizard extends LDAPUtility {
}
}
+ /**
+ * creates and returns an Access instance
+ * @return \OCA\user_ldap\lib\Access
+ */
+ private function getAccess() {
+ $con = new Connection($this->ldap, '', null);
+ $con->setConfiguration($this->configuration->getConfiguration());
+ $ldapAccess = new Access($con, $this->ldap);
+ return $ldapAccess;
+ }
+
private function getConnection() {
if(!is_null($this->cr)) {
return $this->cr;