diff options
author | Andy Scherzinger <info@andy-scherzinger.de> | 2024-09-23 21:07:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 21:07:08 +0200 |
commit | 6044c9f5122976ed9cce88b3df372fe12c6a65e1 (patch) | |
tree | 67b27b66d1f6cb678b3c2f549bbad8c242fa100c /lib/private | |
parent | ea1833b48a78cb59ebceb67787cd627bc1019716 (diff) | |
parent | 9a34a6c4c4f556ccc6f1b6cb6d0cf8a651840fb0 (diff) | |
download | nextcloud-server-6044c9f5122976ed9cce88b3df372fe12c6a65e1.tar.gz nextcloud-server-6044c9f5122976ed9cce88b3df372fe12c6a65e1.zip |
Merge pull request #48285 from nextcloud/backport/48207/stable30
[stable30] fix: Don't crash if disabled user is missing in the database
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/User/LazyUser.php | 9 | ||||
-rw-r--r-- | lib/private/User/Manager.php | 18 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/private/User/LazyUser.php b/lib/private/User/LazyUser.php index cd3e268be48..92a0c735215 100644 --- a/lib/private/User/LazyUser.php +++ b/lib/private/User/LazyUser.php @@ -36,9 +36,12 @@ class LazyUser implements IUser { $this->user = $this->userManager->get($this->uid); } } - /** @var IUser */ - $user = $this->user; - return $user; + + if ($this->user === null) { + throw new NoUserException('User not found in backend'); + } + + return $this->user; } public function getUID() { diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php index 2c8cc10dc15..dbfa2f8351c 100644 --- a/lib/private/User/Manager.php +++ b/lib/private/User/Manager.php @@ -68,6 +68,7 @@ class Manager extends PublicEmitter implements IUserManager { private IConfig $config, ICacheFactory $cacheFactory, private IEventDispatcher $eventDispatcher, + private LoggerInterface $logger, ) { $this->cache = new WithLocalCache($cacheFactory->createDistributed('user_backend_map')); $this->listen('\OC\User', 'postDelete', function (IUser $user): void { @@ -201,7 +202,7 @@ class Manager extends PublicEmitter implements IUserManager { $result = $this->checkPasswordNoLogging($loginName, $password); if ($result === false) { - \OCP\Server::get(LoggerInterface::class)->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); + $this->logger->warning('Login failed: \''. $loginName .'\' (Remote IP: \''. \OC::$server->getRequest()->getRemoteAddress(). '\')', ['app' => 'core']); } return $result; @@ -319,11 +320,16 @@ class Manager extends PublicEmitter implements IUserManager { if ($search !== '') { $users = array_filter( $users, - fn (IUser $user): bool => - mb_stripos($user->getUID(), $search) !== false || - mb_stripos($user->getDisplayName(), $search) !== false || - mb_stripos($user->getEMailAddress() ?? '', $search) !== false, - ); + function (IUser $user) use ($search): bool { + try { + return mb_stripos($user->getUID(), $search) !== false || + mb_stripos($user->getDisplayName(), $search) !== false || + mb_stripos($user->getEMailAddress() ?? '', $search) !== false; + } catch (NoUserException $ex) { + $this->logger->error('Error while filtering disabled users', ['exception' => $ex, 'userUID' => $user->getUID()]); + return false; + } + }); } $tempLimit = ($limit === null ? null : $limit + $offset); |