[Pkg-owncloud-commits] [owncloud] 06/21: Wizard: get really all groups from LDAP by power of Paged Search

David Prévot taffit at moszumanska.debian.org
Sat Jun 28 18:44:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch 6.0
in repository owncloud.

commit c491fa272e3904b27ed4618954d56231c5400f3a
Author: Arthur Schiwon <blizzz at owncloud.com>
Date:   Wed Jun 11 21:38:16 2014 +0200

    Wizard: get really all groups from LDAP by power of Paged Search
---
 apps/user_ldap/lib/wizard.php | 60 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index 27099e5..c5e9eb6 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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list