summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorRoland Tapken <roland@bitarbeiter.net>2018-02-07 15:49:40 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2019-03-05 11:07:40 +0100
commitafb182650e02ee0dd9ff18e8669d9077cdddef73 (patch)
tree1fe6a330b998f7aa5c6b49c38f81d583c221cf6c /apps/user_ldap/lib
parentc2d8a36d9a824791234cc4093b79c8a66ee55cbb (diff)
downloadnextcloud-server-afb182650e02ee0dd9ff18e8669d9077cdddef73.tar.gz
nextcloud-server-afb182650e02ee0dd9ff18e8669d9077cdddef73.zip
user_ldap: really resolve nested groups
The previous patch fixed the problem only for one level of indirection because groupsMatchFilter() had been applied on each recursive call (and thus there would be no second level if the first level fails the check). This new implementation replaces the recursive call with a stack that iterates all nested groups before filtering with groupsMatchFilter(). Signed-off-by: Roland Tapken <roland@bitarbeiter.net>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php33
1 files changed, 19 insertions, 14 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index b16cb953021..427245d4a06 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -252,28 +252,33 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
* @param array|null &$seen
* @return array
*/
- private function _getGroupDNsFromMemberOf($DN, &$seen = null) {
- if ($seen === null) {
- $seen = array();
- }
- if (array_key_exists($DN, $seen)) {
- // avoid loops
- return array();
- }
- $seen[$DN] = 1;
+ private function _getGroupDNsFromMemberOf($DN) {
$groups = $this->access->readAttribute($DN, 'memberOf');
if (!is_array($groups)) {
return array();
}
- $allGroups = $groups;
$nestedGroups = $this->access->connection->ldapNestedGroups;
if ((int)$nestedGroups === 1) {
- foreach ($groups as $group) {
- $subGroups = $this->_getGroupDNsFromMemberOf($group, $seen);
- $allGroups = array_merge($allGroups, $subGroups);
+ $seen = array();
+ while ($group = array_pop($groups)) {
+ if ($group === $DN || array_key_exists($group, $seen)) {
+ // Prevent loops
+ continue;
+ }
+ $seen[$group] = 1;
+
+ // Resolve nested groups
+ $nestedGroups = $this->access->readAttribute($group, 'memberOf');
+ if (is_array($nestedGroups)) {
+ foreach ($nestedGroups as $nestedGroup) {
+ array_push($groups, $nestedGroup);
+ }
+ }
}
+ // Get unique group DN's from those we have visited in the loop
+ $groups = array_keys($seen);
}
- return $this->access->groupsMatchFilter($allGroups);
+ return $this->access->groupsMatchFilter($groups);
}
/**