aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-02-12 14:17:27 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-02-12 14:17:27 +0100
commitb15e4d518a6b1d41398386866ce8b45148bf7b3f (patch)
tree468e59a196e7d4ae1aecc1726d613e169b1c0291
parent61f58e8043557af9ce3907b474ef744174f07338 (diff)
downloadnextcloud-server-fix/do-not-throw-from-countusers.tar.gz
nextcloud-server-fix/do-not-throw-from-countusers.zip
fix(user_ldap): Do not block access to configuration page upon bad configurationfix/do-not-throw-from-countusers
It should be possible to access configuration page with the local admin user even when LDAP configuration is not valid. This prevent ldap backend from throwing in countUsers to allow this. Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
-rw-r--r--apps/user_ldap/lib/Connection.php1
-rw-r--r--apps/user_ldap/lib/User_LDAP.php18
2 files changed, 12 insertions, 7 deletions
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 37f7dcaea5c..4b890d8a311 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -241,6 +241,7 @@ class Connection extends LDAPUtility {
}
/**
+ * @throws ServerNotAvailableException When connection failed or configuration is invalid
* @return resource|\LDAP\Connection The LDAP resource
*/
public function getConnectionResource() {
diff --git a/apps/user_ldap/lib/User_LDAP.php b/apps/user_ldap/lib/User_LDAP.php
index d787bfea4d4..e014832b216 100644
--- a/apps/user_ldap/lib/User_LDAP.php
+++ b/apps/user_ldap/lib/User_LDAP.php
@@ -300,7 +300,7 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
* @param string|\OCA\User_LDAP\User\User $user either the Nextcloud user
* name or an instance of that user
* @throws \Exception
- * @throws \OC\ServerNotAvailableException
+ * @throws ServerNotAvailableException
*/
public function userExistsOnLDAP($user, bool $ignoreCache = false): bool {
if (is_string($user)) {
@@ -586,14 +586,18 @@ class User_LDAP extends BackendUtility implements IUserBackend, UserInterface, I
return $this->userPluginManager->countUsers();
}
- $filter = $this->access->getFilterForUserCount();
- $cacheKey = 'countUsers-'.$filter;
- if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
+ try {
+ $filter = $this->access->getFilterForUserCount();
+ $cacheKey = 'countUsers-'.$filter;
+ if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
+ return $entries;
+ }
+ $entries = $this->access->countUsers($filter);
+ $this->access->connection->writeToCache($cacheKey, $entries);
return $entries;
+ } catch (ServerNotAvailableException $e) {
+ return false;
}
- $entries = $this->access->countUsers($filter);
- $this->access->connection->writeToCache($cacheKey, $entries);
- return $entries;
}
public function countMappedUsers(): int {