From f924f5f0aa77fffe0da901f99214a636ec92c963 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 13 Feb 2013 10:57:16 -0500
Subject: [PATCH] Improve group members listing + fix VLV index usage

---
 program/lib/Roundcube/rcube_ldap.php |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/program/lib/Roundcube/rcube_ldap.php b/program/lib/Roundcube/rcube_ldap.php
index 09fdde2..061e49b 100644
--- a/program/lib/Roundcube/rcube_ldap.php
+++ b/program/lib/Roundcube/rcube_ldap.php
@@ -194,7 +194,7 @@
         $this->cache = $rcube->get_cache('LDAP.' . asciiwords($this->prop['name']), 'db', 600);
 
         // initialize ldap wrapper object
-        $this->prop['attributes'] = array_unique(array_merge(array_values($this->fieldmap), $fetch_attributes));
+        $this->prop['attributes'] = array_merge(array_values($this->fieldmap), $fetch_attributes);
         $this->ldap = new rcube_ldap_generic($this->prop, true);
         $this->ldap->set_cache($this->cache);
 
@@ -567,7 +567,7 @@
             return $group_members;
 
         // read these attributes for all members
-        $attrib = $count ? array('dn') : $this->prop['attributes'];
+        $attrib = $count ? array('dn','objectClass') : $this->prop['attributes'];
         $attrib[] = 'member';
         $attrib[] = 'uniqueMember';
         $attrib[] = 'memberURL';
@@ -613,11 +613,11 @@
 
             // add search filter if any
             $filter = $this->filter ? '(&(' . $m[3] . ')(' . $this->filter . '))' : $m[3];
-            $attrs = $count ? array('dn') : $this->prop['attributes'];
+            $attrs = $count ? array('dn','objectClass') : $this->prop['attributes'];
             if ($result = $this->ldap->search($m[1], $filter, $m[2], $attrs, $this->group_data)) {
                 $entries = $result->entries();
                 for ($j = 0; $j < $entries['count']; $j++) {
-                    if ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count))
+                    if (self::is_group_entry($entries[$j]) && ($nested_group_members = $this->list_group_members($entries[$j]['dn'], $count)))
                         $group_members = array_merge($group_members, $nested_group_members);
                     else
                         $group_members[] = $entries[$j];
@@ -1286,7 +1286,7 @@
             $out[$this->primary_key] = self::dn_encode($rec['dn']);
 
         // determine record type
-        if (array_intersect(array('groupofuniquenames','kolabgroupofuniquenames'), array_map('strtolower', (array)$rec['objectclass']))) {
+        if (self::is_group_entry($rec)) {
             $out['_type'] = 'group';
             $out['readonly'] = true;
             $fieldmap['name'] = $this->prop['groups']['name_attr'];
@@ -1408,6 +1408,16 @@
         return (isset($aliases[$name]) ? $aliases[$name] : $name) . $suffix;
     }
 
+    /**
+     * Determines whether the given LDAP entry is a group record
+     */
+    private static function is_group_entry($entry)
+    {
+        return array_intersect(
+            array('group', 'groupofnames', 'kolabgroupofnames', 'groupofuniquenames','kolabgroupofuniquenames','groupofurls'),
+            array_map('strtolower', (array)$entry['objectclass'])
+        );
+    }
 
     /**
      * Prints debug info to the log

--
Gitblit v1.9.1