diff options
-rw-r--r-- | apps/user_ldap/lib/Access.php | 17 | ||||
-rw-r--r-- | apps/user_ldap/tests/AccessTest.php | 7 |
2 files changed, 17 insertions, 7 deletions
diff --git a/apps/user_ldap/lib/Access.php b/apps/user_ldap/lib/Access.php index d1c738719b1..95710cd37f2 100644 --- a/apps/user_ldap/lib/Access.php +++ b/apps/user_ldap/lib/Access.php @@ -527,6 +527,7 @@ class Access extends LDAPUtility implements IUserTools { * @param bool|null $newlyMapped * @param array|null $record * @return false|string with with the name to use in Nextcloud + * @throws \Exception */ public function dn2ocname($fdn, $ldapName = null, $isUser = true, &$newlyMapped = null, array $record = null) { $newlyMapped = false; @@ -586,7 +587,7 @@ class Access extends LDAPUtility implements IUserTools { // outside of core user management will still cache the user as non-existing. $originalTTL = $this->connection->ldapCacheTTL; $this->connection->setConfiguration(array('ldapCacheTTL' => 0)); - if(($isUser && !\OCP\User::userExists($intName)) + if(($isUser && $intName !== '' && !\OCP\User::userExists($intName)) || (!$isUser && !\OC::$server->getGroupManager()->groupExists($intName))) { if($mapper->map($fdn, $intName, $uuid)) { $this->connection->setConfiguration(array('ldapCacheTTL' => $originalTTL)); @@ -830,7 +831,9 @@ class Access extends LDAPUtility implements IUserTools { $recordsToUpdate = array_filter($ldapRecords, function($record) use ($isBackgroundJobModeAjax) { $newlyMapped = false; $uid = $this->dn2ocname($record['dn'][0], null, true, $newlyMapped, $record); - $this->cacheUserExists($uid); + if(is_string($uid)) { + $this->cacheUserExists($uid); + } return ($uid !== false) && ($newlyMapped || $isBackgroundJobModeAjax); }); } @@ -1022,7 +1025,7 @@ class Access extends LDAPUtility implements IUserTools { * * @param $filter * @param $base - * @param null $attr + * @param string[]|string|null $attr * @param int $limit optional, maximum results to be counted * @param int $offset optional, a starting point * @return array|false array with the search result as first value and pagedSearchOK as @@ -1106,6 +1109,7 @@ class Access extends LDAPUtility implements IUserTools { /** * executes an LDAP search, but counts the results only + * * @param string $filter the LDAP filter for the search * @param array $base an array containing the LDAP subtree(s) that shall be searched * @param string|string[] $attr optional, array, one or more attributes that shall be @@ -1115,7 +1119,7 @@ class Access extends LDAPUtility implements IUserTools { * @param bool $skipHandling indicates whether the pages search operation is * completed * @return int|false Integer or false if the search could not be initialized - * + * @throws ServerNotAvailableException */ private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); @@ -1130,8 +1134,7 @@ class Access extends LDAPUtility implements IUserTools { $this->connection->getConnectionResource(); do { - $search = $this->executeSearch($filter, $base, $attr, - $limitPerPage, $offset); + $search = $this->executeSearch($filter, $base, $attr, $limitPerPage, $offset); if($search === false) { return $counter > 0 ? $counter : false; } @@ -1286,7 +1289,7 @@ class Access extends LDAPUtility implements IUserTools { */ public function sanitizeUsername($name) { if($this->connection->ldapIgnoreNamingRules) { - return $name; + return trim($name); } // Transliteration diff --git a/apps/user_ldap/tests/AccessTest.php b/apps/user_ldap/tests/AccessTest.php index d0693fe50e1..cbb695d779a 100644 --- a/apps/user_ldap/tests/AccessTest.php +++ b/apps/user_ldap/tests/AccessTest.php @@ -620,6 +620,13 @@ class AccessTest extends TestCase { ->method('writeToCache') ->with($this->stringStartsWith('userExists'), true); + $this->userMapper->expects($this->exactly($fakeLdapEntries['count'])) + ->method('getNameByDN') + ->willReturnCallback(function($fdn) { + $parts = ldap_explode_dn($fdn, false); + return $parts[0]; + }); + /** @noinspection PhpUnhandledExceptionInspection */ $list = $this->access->fetchListOfUsers($filter, $attrs); $this->assertSame($expected, $list); |