mirror of
https://github.com/nextcloud/server.git
synced 2026-05-15 09:59:47 -04:00
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>
This commit is contained in:
parent
fe169b021d
commit
0997fd999e
1 changed files with 19 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue