Skip to content

Commit c15b158

Browse files
Merge pull request #50500 from nextcloud/backport/50480/stable29
[stable29] fix(user_ldap): Do not map groups we do not know if they match filter
2 parents c250c6c + b5da20e commit c15b158

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

apps/user_ldap/lib/Access.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,19 @@ public function username2dn($name) {
449449
*
450450
* @param string $fdn the dn of the group object
451451
* @param string $ldapName optional, the display name of the object
452+
* @param bool $autoMapping Should the group be mapped if not yet mapped
452453
* @return string|false with the name to use in Nextcloud, false on DN outside of search DN
453454
* @throws \Exception
454455
*/
455-
public function dn2groupname($fdn, $ldapName = null) {
456+
public function dn2groupname($fdn, $ldapName = null, bool $autoMapping = true) {
456457
//To avoid bypassing the base DN settings under certain circumstances
457458
//with the group support, check whether the provided DN matches one of
458459
//the given Bases
459460
if (!$this->isDNPartOfBase($fdn, $this->connection->ldapBaseGroups)) {
460461
return false;
461462
}
462463

463-
return $this->dn2ocname($fdn, $ldapName, false);
464+
return $this->dn2ocname($fdn, $ldapName, false, autoMapping:$autoMapping);
464465
}
465466

466467
/**
@@ -490,10 +491,11 @@ public function dn2username($fdn, $ldapName = null) {
490491
* @param bool $isUser optional, whether it is a user object (otherwise group assumed)
491492
* @param bool|null $newlyMapped
492493
* @param array|null $record
494+
* @param bool $autoMapping Should the group be mapped if not yet mapped
493495
* @return false|string with with the name to use in Nextcloud
494496
* @throws \Exception
495497
*/
496-
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, ?array $record = null) {
498+
public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, ?array $record = null, bool $autoMapping = true) {
497499
static $intermediates = [];
498500
if (isset($intermediates[($isUser ? 'user-' : 'group-') . $fdn])) {
499501
return false; // is a known intermediate
@@ -516,6 +518,11 @@ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped
516518
return $ncName;
517519
}
518520

521+
if (!$autoMapping) {
522+
/* If no auto mapping, stop there */
523+
return false;
524+
}
525+
519526
//second try: get the UUID and check if it is known. Then, update the DN and return the name.
520527
$uuid = $this->getUUID($fdn, $isUser, $record);
521528
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
@@ -1219,7 +1219,7 @@ protected function filterValidGroups(array $listOfGroups): array {
12191219
continue;
12201220
}
12211221
$name = $item[$this->access->connection->ldapGroupDisplayName][0] ?? null;
1222-
$gid = $this->access->dn2groupname($dn, $name);
1222+
$gid = $this->access->dn2groupname($dn, $name, false);
12231223
if (!$gid) {
12241224
continue;
12251225
}

0 commit comments

Comments
 (0)