Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2021-12-09 13:51:13 +0300
committerCarl Schwan <carl@carlschwan.eu>2021-12-09 15:04:12 +0300
commitab9754c44944188fc68a6158118f7e2be5d5454b (patch)
treef51bee1bc2c25d78af2dbaee449aca51220d677c
parentf6c58d5c3a2de5032ea4227c26bc21c8f9e1fe1c (diff)
Unify a bit the types of the fetcher
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
-rw-r--r--apps/user_ldap/lib/Group_LDAP.php29
1 files changed, 19 insertions, 10 deletions
diff --git a/apps/user_ldap/lib/Group_LDAP.php b/apps/user_ldap/lib/Group_LDAP.php
index 62b0e41d7c3..77294f9659d 100644
--- a/apps/user_ldap/lib/Group_LDAP.php
+++ b/apps/user_ldap/lib/Group_LDAP.php
@@ -57,7 +57,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
/** @var string[][] $cachedGroupMembers array of users with gid as key */
protected $cachedGroupMembers;
- /** @var string[] $cachedGroupsByMember array of groups with uid as key */
+ /** @var string[][] $cachedGroupsByMember array of groups with uid as key */
protected $cachedGroupsByMember;
/** @var string[] $cachedNestedGroups array of groups with gid (DN) as key */
protected $cachedNestedGroups;
@@ -302,7 +302,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
$rawMemberReads[$dnGroup] = $members;
}
if (is_array($members)) {
- $fetcher = function ($memberDN) use (&$seen) {
+ $fetcher = function (string $memberDN) use (&$seen) {
return $this->_groupMembers($memberDN, $seen);
};
$allMembers = $this->walkNestedGroupsReturnDNs($dnGroup, $fetcher, $members, $seen);
@@ -339,7 +339,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
return [];
}
- $fetcher = function ($groupDN) {
+ $fetcher = function (string $groupDN) {
if (isset($this->cachedNestedGroups[$groupDN])) {
$nestedGroups = $this->cachedNestedGroups[$groupDN];
} else {
@@ -356,6 +356,10 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
return $this->filterValidGroups($groups);
}
+ /**
+ * @param list<array{dn: list<string>}|string> $list
+ * @param Closure(string) $fetcher
+ */
private function processListFromWalkingNestedGroups(array &$list, array &$seen, string $dn, Closure $fetcher): void {
while ($record = array_shift($list)) {
$recordDN = $record['dn'][0] ?? $record;
@@ -367,7 +371,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
$cacheKey = 'walkNestedGroups_' . $recordDN;
$fetched = $this->access->connection->getFromCache($cacheKey);
if ($fetched === null) {
- $fetched = $fetcher($record);
+ $fetched = $fetcher($recordDN);
$fetched = $this->access->connection->writeToCache($cacheKey, $fetched);
}
$list = array_merge($list, $fetched);
@@ -377,6 +381,10 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
}
}
+ /**
+ * @param list<array{dn: list<string>}|string> $list
+ * @param Closure(string) $fetcher
+ */
private function walkNestedGroupsReturnDNs(string $dn, Closure $fetcher, array $list, array &$seen = []): array {
$nesting = (int)$this->access->connection->ldapNestedGroups;
@@ -388,12 +396,16 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
return array_keys($seen);
}
+ /**
+ * @param list<array{dn: list<string>}> $list
+ * @param Closure(string) $fetcher
+ */
private function walkNestedGroupsReturnRecords(string $dn, Closure $fetcher, array $list, array &$seen = []): array {
$nesting = (int)$this->access->connection->ldapNestedGroups;
if ($nesting !== 1) {
// the keys are numeric, but should hold the DN
- return array_reduce($list, function ($transformed, $record) use ($dn) {
+ return array_reduce($list, function (array $transformed, array $record) use ($dn) {
if ($record['dn'][0] != $dn) {
$transformed[$record['dn'][0]] = $record;
}
@@ -882,10 +894,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
$groups = $this->access->fetchListOfGroups($filter,
[strtolower($this->access->connection->ldapGroupMemberAssocAttr), $this->access->connection->ldapGroupDisplayName, 'dn']);
if (is_array($groups)) {
- $fetcher = function ($dn) use (&$seen) {
- if (is_array($dn) && isset($dn['dn'][0])) {
- $dn = $dn['dn'][0];
- }
+ $fetcher = function (string $dn) use (&$seen) {
return $this->getGroupsByMember($dn, $seen);
};
@@ -1204,7 +1213,7 @@ class Group_LDAP extends BackendUtility implements GroupInterface, IGroupLDAP, I
$validGroupDNs = [];
foreach ($listOfGroups as $key => $item) {
$dn = is_string($item) ? $item : $item['dn'][0];
- if(is_array($item) && !isset($item[$this->access->connection->ldapGroupDisplayName][0])) {
+ if (is_array($item) && !isset($item[$this->access->connection->ldapGroupDisplayName][0])) {
continue;
}
$name = $item[$this->access->connection->ldapGroupDisplayName][0] ?? null;