aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2024-09-20 11:26:22 +0200
committerLouis <louis@chmn.me>2024-09-23 10:40:38 +0200
commit22d5d29c015aa62d9a0a0351eb82886ac7374fc8 (patch)
tree19c9910ec42d16dbad40a6bed210efae78cb9676 /lib
parentba41f32e3e5e0bdcfd7501da7088b417172e975f (diff)
downloadnextcloud-server-22d5d29c015aa62d9a0a0351eb82886ac7374fc8.tar.gz
nextcloud-server-22d5d29c015aa62d9a0a0351eb82886ac7374fc8.zip
fix(users): Don't crash if disabled user is missing in the databaseartonge/fix/prevent_missing_users_from_crashing_disabled_users_search
Signed-off-by: Louis Chemineau <louis@chmn.me>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/User/LazyUser.php9
-rw-r--r--lib/private/User/Manager.php18
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 e21759b1e98..3ee748a2775 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);