Author: Nathan.Vonnahme
Date: 2010-02-04 21:41:33 +0100 (Thu, 04 Feb 2010)
New Revision: 27580

Modified:
   plugins/bhLDAPAuthPlugin/branches/1.0/lib/adLDAP.php
   plugins/bhLDAPAuthPlugin/branches/1.0/lib/bhLDAP.php
Log:
recursivity patch from 1_1 branch

Modified: plugins/bhLDAPAuthPlugin/branches/1.0/lib/adLDAP.php
===================================================================
--- plugins/bhLDAPAuthPlugin/branches/1.0/lib/adLDAP.php        2010-02-04 
20:36:31 UTC (rev 27579)
+++ plugins/bhLDAPAuthPlugin/branches/1.0/lib/adLDAP.php        2010-02-04 
20:41:33 UTC (rev 27580)
@@ -276,27 +276,37 @@
        }
        
        // Retun a complete list of "groups in groups"  
-       function recursive_groups($group){
-               if ($group==NULL){ return (false); }
 
-               $ret_groups=array();
-               
-               $groups=$this->group_info($group,array("memberof"));
+       // this version hacked by ben
+
+       public function recursive_groups($group){
+         if ($group===NULL){ return (false); }
+
+         $ret_groups=Array($group);
+         $new_groups=Array($group);
+
+         while(count($new_groups)>0) { // The list of groups that need to be 
checked for membership
+           $more_groups=Array();
+
+           foreach ($new_groups as $group_name) {
+             $grou...@$this->group_info($group_name,array("memberof")); // Get 
groups this group is a member of
+
+             if (array_key_exists("memberof", $groups[0])) {
                $groups=$groups[0]["memberof"];
-
                if ($groups){
-                       $group_names=$this->nice_names($groups);
-                       $ret_groups=array_merge($ret_groups,$group_names); 
//final groups to return
-                       
-                       foreach ($group_names as $id => $group_name){
-                               
$child_groups=$this->recursive_groups($group_name);
-                               
$ret_groups=array_merge($ret_groups,$child_groups);
-                       }
+                 $group_names=$this->nice_names($groups);
+                 
$more_groups=array_unique(array_merge($more_groups,$group_names)); //final 
groups to return
                }
+             }
 
-               return ($ret_groups);
+           }
+           $ret_groups = array_unique(array_merge($ret_groups,$more_groups)); 
// Add the groups to the main list
+           $new_groups=array_diff($more_groups,$ret_groups);
+         }
+         return ($ret_groups);
        }
-       
+
+
        
//*****************************************************************************************************************
        // USER FUNCTIONS
 
@@ -357,7 +367,7 @@
                if ($recursive){
                        foreach ($groups as $id => $group_name){
                                
$extra_groups=$this->recursive_groups($group_name);
-                               $groups=array_merge($groups,$extra_groups);
+                               
$groups=array_unique(array_merge($groups,$extra_groups));
                        }
                }
                

Modified: plugins/bhLDAPAuthPlugin/branches/1.0/lib/bhLDAP.php
===================================================================
--- plugins/bhLDAPAuthPlugin/branches/1.0/lib/bhLDAP.php        2010-02-04 
20:36:31 UTC (rev 27579)
+++ plugins/bhLDAPAuthPlugin/branches/1.0/lib/bhLDAP.php        2010-02-04 
20:41:33 UTC (rev 27580)
@@ -63,7 +63,25 @@
     $sr=ldap_search($ldap->_conn,$ldap->_base_dn,$filter,$fields);
     $entries = ldap_get_entries($ldap->_conn, $sr);
 
-    return $ldap->nice_names($entries[0]['memberof']);
+    $...@ldap_search($ldap->_conn,$ldap->_base_dn,$filter,$fields);
+    if (! $sr) return array();
+
+    $entries = @ldap_get_entries($ldap->_conn, $sr);
+    if (! (array_key_exists(0, $entries) && array_key_exists('memberof', 
$entries[0]))) 
+      return array();
+    self::debugDump($entries, "group entries for $username");
+
+    $groups = $ldap->nice_names($entries[0]['memberof']);
+    if ($recursive){
+      self::debug("checking recursive group memberships");
+      foreach ($groups as $id => $group_name){
+       $extra_grou...@$ldap->recursive_groups($group_name);
+       $groups=array_unique(array_merge($groups,$extra_groups));
+      }
+      self::debugDump($groups, "fully recursive list of groups for $username");
+    }
+
+    return $groups;
   }
   
   # all lowercase, for case-insensitive matching

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to