Skip to content

Commit 002df12

Browse files
committed
fix(user_ldap): Do not map groups we do not know if they match filter
When nesting is enabled, filterValidGroups is supposed to check for each groups if it actually exist, because it may not be visible to Nextcloud. So in this codepath we disable automapping of groups. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com> (cherry picked from commit de77415)
1 parent f262fdf commit 002df12

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

apps/user_ldap/lib/Access.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,18 +387,19 @@ public function username2dn($name) {
387387
*
388388
* @param string $fdn the dn of the group object
389389
* @param string $ldapName optional, the display name of the object
390+
* @param bool $autoMapping Should the group be mapped if not yet mapped
390391
* @return string|false with the name to use in Nextcloud, false on DN outside of search DN
391392
* @throws \Exception
392393
*/
393-
public function dn2groupname($fdn, $ldapName = null) {
394+
public function dn2groupname($fdn, $ldapName = null, bool $autoMapping = true) {
394395
//To avoid bypassing the base DN settings under certain circumstances
395396
//with the group support, check whether the provided DN matches one of
396397
//the given Bases
397398
if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
398399
return false;
399400
}
400401

401-
return $this->dn2ocname($fdn, $ldapName, false);
402+
return $this->dn2ocname($fdn, $ldapName, false, autoMapping:$autoMapping);
402403
}
403404

404405
/**
@@ -428,10 +429,11 @@ public function dn2username($fdn, $ldapName = null) {
428429
* @param bool $isUser optional, whether it is a user object (otherwise group assumed)
429430
* @param bool|null $newlyMapped
430431
* @param array|null $record
432+
* @param bool $autoMapping Should the group be mapped if not yet mapped
431433
* @return false|string with with the name to use in Nextcloud
432434
* @throws \Exception
433435
*/
434-
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, ?array $record = null) {
436+
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, ?array $record = null, bool $autoMapping = true) {
435437
static $intermediates = [];
436438
if (isset($intermediates[($isUser ? 'user-' : 'group-') . $fdn])) {
437439
return false; // is a known intermediate
@@ -454,6 +456,11 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
454456
return $ncName;
455457
}
456458

459+
if (!$autoMapping) {
460+
/* If no auto mapping, stop there */
461+
return false;
462+
}
463+
457464
//second try: get the UUID and check if it is known. Then, update the DN and return the name.
458465
$uuid = $this->getUUID($fdn, $isUser, $record);
459466
if (is_string($uuid)) {

apps/user_ldap/lib/Group_LDAP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ protected function filterValidGroups(array $listOfGroups): array {
11821182
continue;
11831183
}
11841184
$name = $item[$this->access->connection->ldapGroupDisplayName][0] ?? null;
1185-
$gid = $this->access->dn2groupname($dn, $name);
1185+
$gid = $this->access->dn2groupname($dn, $name, false);
11861186
if (!$gid) {
11871187
continue;
11881188
}

0 commit comments

Comments
 (0)