fix: Remove static var is Access class

It’s actually more correct to cache this per-instance.
What’s less clear is whether this can always fit in memory.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-04-07 16:23:22 +02:00
parent b1f07e887e
commit 18dddbc3b5
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A

View file

@ -49,6 +49,7 @@ class Access extends LDAPUtility {
protected $groupMapper;
private string $lastCookie = '';
private array $intermediates = [];
public function __construct(
ILDAPWrapper $ldap,
@ -484,8 +485,7 @@ class Access extends LDAPUtility {
* @throws \Exception
*/
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, ?array $record = null, bool $autoMapping = true) {
static $intermediates = [];
if (isset($intermediates[($isUser ? 'user-' : 'group-') . $fdn])) {
if (isset($this->intermediates[($isUser ? 'user-' : 'group-') . $fdn])) {
return false; // is a known intermediate
}
@ -532,7 +532,7 @@ class Access extends LDAPUtility {
$record = $this->readAttributes($fdn, $attributesToRead, $filter);
if ($record === false) {
$this->logger->debug('Cannot read attributes for ' . $fdn . '. Skipping.', ['filter' => $filter]);
$intermediates[($isUser ? 'user-' : 'group-') . $fdn] = true;
$this->intermediates[($isUser ? 'user-' : 'group-') . $fdn] = true;
return false;
}
}
@ -579,7 +579,7 @@ class Access extends LDAPUtility {
$ldapName = $record[$nameAttribute];
if (!isset($ldapName[0]) || empty($ldapName[0])) {
$this->logger->debug('No or empty name for ' . $fdn . ' with filter ' . $filter . '.', ['app' => 'user_ldap']);
$intermediates['group-' . $fdn] = true;
$this->intermediates['group-' . $fdn] = true;
return false;
}
$ldapName = $ldapName[0];