Skip to content

Commit

Permalink
fix: remove caching in fetchListOfGroups
Browse files Browse the repository at this point in the history
When using nested groups without a memberof overlay, then fetchListOfGroups is called from getGroupsByMember without applying the group filter.

In some setups, the "unfiltered" result is then written back to the group mapping table. That might cause random "An administrator removed you from group" activities.

I was unable to replicate it locally, but we got the feedback that the random activities stopped with the patch applied.

Ref: #42195

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Sep 20, 2024
1 parent bc52227 commit afe91fb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
16 changes: 0 additions & 16 deletions apps/user_ldap/lib/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,22 +948,6 @@ public function fetchListOfGroups(string $filter, array $attr, ?int $limit = nul
}
$groupRecords = $this->searchGroups($filter, $attr, $limit, $offset);

$listOfDNs = array_reduce($groupRecords, function ($listOfDNs, $entry) {
$listOfDNs[] = $entry['dn'][0];
return $listOfDNs;
}, []);
$idsByDn = $this->getGroupMapper()->getListOfIdsByDn($listOfDNs);

array_walk($groupRecords, function (array $record) use ($idsByDn) {
$newlyMapped = false;
$gid = $idsByDn[$record['dn'][0]] ?? null;
if ($gid === null) {
$gid = $this->dn2ocname($record['dn'][0], null, false, $newlyMapped, $record);
}
if (!$newlyMapped && is_string($gid)) {
$this->cacheGroupExists($gid);
}
});
$listOfGroups = $this->fetchList($groupRecords, $this->manyAttributes($attr));
$this->connection->writeToCache($cacheKey, $listOfGroups);
return $listOfGroups;
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/tests/AccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ public function testFetchListOfGroupsKnown(): void {
$this->groupMapper->expects($this->never())
->method('getNameByDN');

$this->connection->expects($this->exactly(3))
$this->connection->expects($this->exactly(1))
->method('writeToCache');

$groups = $this->access->fetchListOfGroups($filter, $attributes);
Expand Down

0 comments on commit afe91fb

Please sign in to comment.