aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Accounts/AccountProperty.php31
-rw-r--r--lib/private/AppFramework/Bootstrap/Coordinator.php29
-rw-r--r--lib/private/AppFramework/Middleware/OCSMiddleware.php12
-rw-r--r--lib/private/AppFramework/Middleware/Security/CORSMiddleware.php9
-rw-r--r--lib/private/AppFramework/OCS/V1Response.php2
-rw-r--r--lib/private/DB/QueryBuilder/QueryBuilder.php19
-rw-r--r--lib/private/Files/Cache/Storage.php40
-rw-r--r--lib/private/Files/Config/UserMountCache.php20
-rw-r--r--lib/private/Files/Node/Folder.php197
-rw-r--r--lib/private/Files/Template/TemplateManager.php1
-rw-r--r--lib/private/Repair/NC21/ValidatePhoneNumber.php22
-rw-r--r--lib/private/Repair/NC22/LookupServerSendCheck.php4
-rw-r--r--lib/private/Security/Bruteforce/Capabilities.php5
-rw-r--r--lib/private/Security/Certificate.php23
-rw-r--r--lib/private/Security/CertificateManager.php22
-rw-r--r--lib/private/Security/CredentialsManager.php17
-rw-r--r--lib/private/Security/TrustedDomainHelper.php7
-rw-r--r--lib/private/Setup.php2
-rw-r--r--lib/private/Share20/Manager.php38
-rw-r--r--lib/private/Streamer.php2
-rw-r--r--lib/private/legacy/OC_App.php9
-rw-r--r--lib/private/legacy/OC_Files.php4
22 files changed, 250 insertions, 265 deletions
diff --git a/lib/private/Accounts/AccountProperty.php b/lib/private/Accounts/AccountProperty.php
index 850f39df9e3..0152137f6de 100644
--- a/lib/private/Accounts/AccountProperty.php
+++ b/lib/private/Accounts/AccountProperty.php
@@ -43,7 +43,7 @@ class AccountProperty implements IAccountProperty {
public function __construct(string $name, string $value, string $scope, string $verified) {
$this->name = $name;
$this->value = $value;
- $this->scope = $this->mapScopeToV2($scope);
+ $this->setScope($scope);
$this->verified = $verified;
}
@@ -78,7 +78,16 @@ class AccountProperty implements IAccountProperty {
* @return IAccountProperty
*/
public function setScope(string $scope): IAccountProperty {
- $this->scope = $this->mapScopeToV2($scope);
+ $newScope = $this->mapScopeToV2($scope);
+ if (!in_array($newScope, [
+ IAccountManager::SCOPE_LOCAL,
+ IAccountManager::SCOPE_FEDERATED,
+ IAccountManager::SCOPE_PRIVATE,
+ IAccountManager::SCOPE_PUBLISHED
+ ])) {
+ throw new \InvalidArgumentException('Invalid scope');
+ }
+ $this->scope = $newScope;
return $this;
}
@@ -128,21 +137,21 @@ class AccountProperty implements IAccountProperty {
return $this->scope;
}
- public static function mapScopeToV2($scope) {
+ public static function mapScopeToV2(string $scope): string {
if (strpos($scope, 'v2-') === 0) {
return $scope;
}
switch ($scope) {
- case IAccountManager::VISIBILITY_PRIVATE:
- return IAccountManager::SCOPE_LOCAL;
- case IAccountManager::VISIBILITY_CONTACTS_ONLY:
- return IAccountManager::SCOPE_FEDERATED;
- case IAccountManager::VISIBILITY_PUBLIC:
- return IAccountManager::SCOPE_PUBLISHED;
+ case IAccountManager::VISIBILITY_PRIVATE:
+ return IAccountManager::SCOPE_LOCAL;
+ case IAccountManager::VISIBILITY_CONTACTS_ONLY:
+ return IAccountManager::SCOPE_FEDERATED;
+ case IAccountManager::VISIBILITY_PUBLIC:
+ return IAccountManager::SCOPE_PUBLISHED;
+ default:
+ return $scope;
}
-
- return IAccountManager::SCOPE_LOCAL;
}
/**
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php
index 33b02c0291f..ad55ea3912e 100644
--- a/lib/private/AppFramework/Bootstrap/Coordinator.php
+++ b/lib/private/AppFramework/Bootstrap/Coordinator.php
@@ -113,21 +113,24 @@ class Coordinator {
*/
$appNameSpace = App::buildAppNamespace($appId);
$applicationClassName = $appNameSpace . '\\AppInfo\\Application';
- if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) {
- try {
- /** @var IBootstrap|App $application */
- $apps[$appId] = $application = $this->serverContainer->query($applicationClassName);
- } catch (QueryException $e) {
- // Weird, but ok
- continue;
- }
- try {
+ try {
+ if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) {
+ try {
+ /** @var IBootstrap|App $application */
+ $apps[$appId] = $application = $this->serverContainer->query($applicationClassName);
+ } catch (QueryException $e) {
+ // Weird, but ok
+ continue;
+ }
+
$application->register($this->registrationContext->for($appId));
- } catch (Throwable $e) {
- $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [
- 'exception' => $e,
- ]);
}
+ } catch (Throwable $e) {
+ $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [
+ 'exception' => $e,
+ 'app' => $appId,
+ ]);
+ continue;
}
}
diff --git a/lib/private/AppFramework/Middleware/OCSMiddleware.php b/lib/private/AppFramework/Middleware/OCSMiddleware.php
index f701f17a48e..ad461faef6f 100644
--- a/lib/private/AppFramework/Middleware/OCSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/OCSMiddleware.php
@@ -100,8 +100,7 @@ class OCSMiddleware extends Middleware {
* we need to catch the response and convert it to a proper OCS response.
*/
if ($controller instanceof OCSController && !($response instanceof BaseResponse)) {
- if ($response->getStatus() === Http::STATUS_UNAUTHORIZED ||
- $response->getStatus() === Http::STATUS_FORBIDDEN) {
+ if ($response->getStatus() === Http::STATUS_UNAUTHORIZED) {
$message = '';
if ($response instanceof JSONResponse) {
/** @var DataResponse $response */
@@ -110,6 +109,15 @@ class OCSMiddleware extends Middleware {
return $this->buildNewResponse($controller, OCSController::RESPOND_UNAUTHORISED, $message);
}
+ if ($response->getStatus() === Http::STATUS_FORBIDDEN) {
+ $message = '';
+ if ($response instanceof JSONResponse) {
+ /** @var DataResponse $response */
+ $message = $response->getData()['message'];
+ }
+
+ return $this->buildNewResponse($controller, Http::STATUS_FORBIDDEN, $message);
+ }
}
return $response;
diff --git a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
index 765311858de..392259fd20f 100644
--- a/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
+++ b/lib/private/AppFramework/Middleware/Security/CORSMiddleware.php
@@ -83,14 +83,13 @@ class CORSMiddleware extends Middleware {
public function beforeController($controller, $methodName) {
// ensure that @CORS annotated API routes are not used in conjunction
// with session authentication since this enables CSRF attack vectors
- if ($this->reflector->hasAnnotation('CORS') &&
- !$this->reflector->hasAnnotation('PublicPage')) {
- $user = $this->request->server['PHP_AUTH_USER'];
- $pass = $this->request->server['PHP_AUTH_PW'];
+ if ($this->reflector->hasAnnotation('CORS') && !$this->reflector->hasAnnotation('PublicPage')) {
+ $user = array_key_exists('PHP_AUTH_USER', $this->request->server) ? $this->request->server['PHP_AUTH_USER'] : null;
+ $pass = array_key_exists('PHP_AUTH_PW', $this->request->server) ? $this->request->server['PHP_AUTH_PW'] : null;
$this->session->logout();
try {
- if (!$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) {
+ if ($user === null || $pass === null || !$this->session->logClientIn($user, $pass, $this->request, $this->throttler)) {
throw new SecurityException('CORS requires basic auth', Http::STATUS_UNAUTHORIZED);
}
} catch (PasswordLoginForbiddenException $ex) {
diff --git a/lib/private/AppFramework/OCS/V1Response.php b/lib/private/AppFramework/OCS/V1Response.php
index 9ccff9ac98c..8ad36bada7e 100644
--- a/lib/private/AppFramework/OCS/V1Response.php
+++ b/lib/private/AppFramework/OCS/V1Response.php
@@ -37,7 +37,7 @@ class V1Response extends BaseResponse {
*/
public function getStatus() {
$status = parent::getStatus();
- if ($status === Http::STATUS_FORBIDDEN || $status === OCSController::RESPOND_UNAUTHORISED) {
+ if ($status === OCSController::RESPOND_UNAUTHORISED) {
return Http::STATUS_UNAUTHORIZED;
}
diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php
index 3549606c2db..ec2c3667fd6 100644
--- a/lib/private/DB/QueryBuilder/QueryBuilder.php
+++ b/lib/private/DB/QueryBuilder/QueryBuilder.php
@@ -309,9 +309,24 @@ class QueryBuilder implements IQueryBuilder {
throw new \RuntimeException('Invalid return type for query');
}
+ /**
+ * Monkey-patched compatibility layer for apps that were adapted for Nextcloud 22 before
+ * the first beta, where executeStatement was named executeUpdate.
+ *
+ * Static analysis should catch those misuses, but until then let's try to keep things
+ * running.
+ *
+ * @internal
+ * @deprecated
+ * @todo drop ASAP
+ */
public function executeUpdate(): int {
+ return $this->executeStatement();
+ }
+
+ public function executeStatement(): int {
if ($this->getType() === \Doctrine\DBAL\Query\QueryBuilder::SELECT) {
- throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE query');
+ throw new \RuntimeException('Invalid query type, expected INSERT, DELETE or UPDATE statement');
}
try {
@@ -321,7 +336,7 @@ class QueryBuilder implements IQueryBuilder {
}
if (!is_int($result)) {
- throw new \RuntimeException('Invalid return type for query');
+ throw new \RuntimeException('Invalid return type for statement');
}
return $result;
diff --git a/lib/private/Files/Cache/Storage.php b/lib/private/Files/Cache/Storage.php
index 173091f53b0..48313c96560 100644
--- a/lib/private/Files/Cache/Storage.php
+++ b/lib/private/Files/Cache/Storage.php
@@ -29,6 +29,7 @@
namespace OC\Files\Cache;
+use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Storage\IStorage;
use Psr\Log\LoggerInterface;
@@ -219,4 +220,43 @@ class Storage {
$query->execute();
}
}
+
+ /**
+ * remove the entry for the storage by the mount id
+ *
+ * @param int $mountId
+ */
+ public static function cleanByMountId(int $mountId) {
+ $db = \OC::$server->getDatabaseConnection();
+
+ try {
+ $db->beginTransaction();
+
+ $query = $db->getQueryBuilder();
+ $query->select('storage_id')
+ ->from('mounts')
+ ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
+ $storageIds = $query->executeQuery()->fetchAll(\PDO::FETCH_COLUMN);
+
+ $query = $db->getQueryBuilder();
+ $query->delete('filecache')
+ ->where($query->expr()->in('storage', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY)));
+ $query->executeStatement();
+
+ $query = $db->getQueryBuilder();
+ $query->delete('storages')
+ ->where($query->expr()->eq('numeric_id', $query->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY)));
+ $query->executeStatement();
+
+ $query = $db->getQueryBuilder();
+ $query->delete('mounts')
+ ->where($query->expr()->eq('mount_id', $query->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
+ $query->executeStatement();
+
+ $db->commit();
+ } catch (\Exception $e) {
+ $db->rollBack();
+ throw $e;
+ }
+ }
}
diff --git a/lib/private/Files/Config/UserMountCache.php b/lib/private/Files/Config/UserMountCache.php
index fddd2d956a1..29d3256d61b 100644
--- a/lib/private/Files/Config/UserMountCache.php
+++ b/lib/private/Files/Config/UserMountCache.php
@@ -326,18 +326,30 @@ class UserMountCache implements IUserMountCache {
} catch (NotFoundException $e) {
return [];
}
- $mountsForStorage = $this->getMountsForStorageId($storageId, $user);
+ $builder = $this->connection->getQueryBuilder();
+ $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path')
+ ->from('mounts', 'm')
+ ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
+ ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT)));
+ if ($user) {
+ $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
+ }
+
+ $result = $query->execute();
+ $rows = $result->fetchAll();
+ $result->closeCursor();
// filter mounts that are from the same storage but a different directory
- $filteredMounts = array_filter($mountsForStorage, function (ICachedMountInfo $mount) use ($internalPath, $fileId) {
- if ($fileId === $mount->getRootId()) {
+ $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) {
+ if ($fileId === (int)$row['root_id']) {
return true;
}
- $internalMountPath = $mount->getRootInternalPath();
+ $internalMountPath = isset($row['path']) ? $row['path'] : '';
return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
});
+ $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts));
return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
return new CachedMountFileInfo(
$mount->getUser(),
diff --git a/lib/private/Files/Node/Folder.php b/lib/private/Files/Node/Folder.php
index 14b663d4e16..f77c90b65a9 100644
--- a/lib/private/Files/Node/Folder.php
+++ b/lib/private/Files/Node/Folder.php
@@ -31,14 +31,10 @@
namespace OC\Files\Node;
-use OC\DB\QueryBuilder\Literal;
use OC\Files\Search\SearchBinaryOperator;
use OC\Files\Search\SearchComparison;
+use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
-use OC\Files\Storage\Wrapper\Jail;
-use OC\Files\Storage\Storage;
-use OCA\Files_Sharing\SharedStorage;
-use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Config\ICachedMountInfo;
use OCP\Files\FileInfo;
@@ -48,6 +44,7 @@ use OCP\Files\NotPermittedException;
use OCP\Files\Search\ISearchBinaryOperator;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOperator;
+use OCP\Files\Search\ISearchOrder;
use OCP\Files\Search\ISearchQuery;
use OCP\IUserManager;
@@ -266,8 +263,7 @@ class Folder extends Node implements \OCP\Files\Folder {
new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND, [
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'path', $internalPath . '%'),
$query->getSearchOperation(),
- ]
- ),
+ ]),
$subQueryLimit,
0,
$query->getOrder(),
@@ -309,7 +305,7 @@ class Folder extends Node implements \OCP\Files\Folder {
$order = $query->getOrder();
if ($order) {
- usort($files, function (FileInfo $a,FileInfo $b) use ($order) {
+ usort($files, function (FileInfo $a, FileInfo $b) use ($order) {
foreach ($order as $orderField) {
$cmp = $orderField->sortFileInfo($a, $b);
if ($cmp !== 0) {
@@ -492,158 +488,37 @@ class Folder extends Node implements \OCP\Files\Folder {
* @return \OCP\Files\Node[]
*/
public function getRecent($limit, $offset = 0) {
- $mimetypeLoader = \OC::$server->getMimeTypeLoader();
- $mounts = $this->root->getMountsIn($this->path);
- $mounts[] = $this->getMountPoint();
-
- $mounts = array_filter($mounts, function (IMountPoint $mount) {
- return $mount->getStorage() !== null;
- });
- $storageIds = array_map(function (IMountPoint $mount) {
- return $mount->getStorage()->getCache()->getNumericStorageId();
- }, $mounts);
- /** @var IMountPoint[] $mountMap */
- $mountMap = array_combine($storageIds, $mounts);
- $folderMimetype = $mimetypeLoader->getId(FileInfo::MIMETYPE_FOLDER);
-
- /*
- * Construct an array of the storage id with their prefix path
- * This helps us to filter in the final query
- */
- $filters = array_map(function (IMountPoint $mount) {
- $storage = $mount->getStorage();
-
- $storageId = $storage->getCache()->getNumericStorageId();
- $prefix = '';
-
- if ($storage->instanceOfStorage(Jail::class)) {
- $prefix = $storage->getUnJailedPath('');
- }
-
- return [
- 'storageId' => $storageId,
- 'pathPrefix' => $prefix,
- ];
- }, $mounts);
-
- // Search in batches of 500 entries
- $searchLimit = 500;
- $results = [];
- $searchResultCount = 0;
- $count = 0;
- do {
- $searchResult = $this->recentSearch($searchLimit, $offset, $folderMimetype, $filters);
-
- // Exit condition if there are no more results
- if (count($searchResult) === 0) {
- break;
- }
-
- $searchResultCount += count($searchResult);
-
- $parseResult = $this->recentParse($searchResult, $mountMap, $mimetypeLoader);
-
- foreach ($parseResult as $result) {
- $results[] = $result;
- }
-
- $offset += $searchLimit;
- $count++;
- } while (count($results) < $limit && ($searchResultCount < (3 * $limit) || $count < 5));
-
- return array_slice($results, 0, $limit);
- }
-
- private function recentSearch($limit, $offset, $folderMimetype, $filters) {
- $dbconn = \OC::$server->getDatabaseConnection();
- $builder = $dbconn->getQueryBuilder();
- $query = $builder
- ->select('f.*')
- ->from('filecache', 'f');
-
- /*
- * Here is where we construct the filtering.
- * Note that this is expensive filtering as it is a lot of like queries.
- * However the alternative is we do this filtering and parsing later in php with the risk of looping endlessly
- */
- $storageFilters = $builder->expr()->orX();
- foreach ($filters as $filter) {
- $storageFilter = $builder->expr()->andX(
- $builder->expr()->eq('f.storage', $builder->createNamedParameter($filter['storageId']))
- );
-
- if ($filter['pathPrefix'] !== '') {
- $storageFilter->add(
- $builder->expr()->like('f.path', $builder->createNamedParameter($dbconn->escapeLikeParameter($filter['pathPrefix']) . '/%'))
- );
- }
-
- $storageFilters->add($storageFilter);
- }
-
- $query->andWhere($storageFilters);
-
- $query->andWhere($builder->expr()->orX(
- // handle non empty folders separate
- $builder->expr()->neq('f.mimetype', $builder->createNamedParameter($folderMimetype, IQueryBuilder::PARAM_INT)),
- $builder->expr()->eq('f.size', new Literal(0))
- ))
- ->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_versions/%')))
- ->andWhere($builder->expr()->notLike('f.path', $builder->createNamedParameter('files_trashbin/%')))
- ->orderBy('f.mtime', 'DESC')
- ->setMaxResults($limit)
- ->setFirstResult($offset);
-
- $result = $query->execute();
- $rows = $result->fetchAll();
- $result->closeCursor();
-
- return $rows;
- }
-
- private function recentParse($result, $mountMap, $mimetypeLoader) {
- $files = array_filter(array_map(function (array $entry) use ($mountMap, $mimetypeLoader) {
- $mount = $mountMap[$entry['storage']];
- $entry['internalPath'] = $entry['path'];
- $entry['mimetype'] = $mimetypeLoader->getMimetypeById($entry['mimetype']);
- $entry['mimepart'] = $mimetypeLoader->getMimetypeById($entry['mimepart']);
- $path = $this->getAbsolutePath($mount, $entry['path']);
- if (is_null($path)) {
- return null;
- }
- $fileInfo = new \OC\Files\FileInfo($path, $mount->getStorage(), $entry['internalPath'], $entry, $mount);
- return $this->root->createNode($fileInfo->getPath(), $fileInfo);
- }, $result));
-
- return array_values(array_filter($files, function (Node $node) {
- $cacheEntry = $node->getMountPoint()->getStorage()->getCache()->get($node->getId());
- if (!$cacheEntry) {
- return false;
- }
- $relative = $this->getRelativePath($node->getPath());
- return $relative !== null && $relative !== '/'
- && ($cacheEntry->getPermissions() & \OCP\Constants::PERMISSION_READ) === \OCP\Constants::PERMISSION_READ;
- }));
- }
-
- private function getAbsolutePath(IMountPoint $mount, $path) {
- $storage = $mount->getStorage();
- if ($storage->instanceOfStorage('\OC\Files\Storage\Wrapper\Jail')) {
- if ($storage->instanceOfStorage(SharedStorage::class)) {
- $storage->getSourceStorage();
- }
- /** @var \OC\Files\Storage\Wrapper\Jail $storage */
- $jailRoot = $storage->getUnjailedPath('');
- $rootLength = strlen($jailRoot) + 1;
- if ($path === $jailRoot) {
- return $mount->getMountPoint();
- } elseif (substr($path, 0, $rootLength) === $jailRoot . '/') {
- return $mount->getMountPoint() . substr($path, $rootLength);
- } else {
- return null;
- }
- } else {
- return $mount->getMountPoint() . $path;
- }
+ $query = new SearchQuery(
+ new SearchBinaryOperator(
+ // filter out non empty folders
+ ISearchBinaryOperator::OPERATOR_OR,
+ [
+ new SearchBinaryOperator(
+ ISearchBinaryOperator::OPERATOR_NOT,
+ [
+ new SearchComparison(
+ ISearchComparison::COMPARE_EQUAL,
+ 'mimetype',
+ FileInfo::MIMETYPE_FOLDER
+ ),
+ ]
+ ),
+ new SearchComparison(
+ ISearchComparison::COMPARE_EQUAL,
+ 'size',
+ 0
+ ),
+ ]
+ ),
+ $limit,
+ $offset,
+ [
+ new SearchOrder(
+ ISearchOrder::DIRECTION_DESCENDING,
+ 'mtime'
+ ),
+ ]
+ );
+ return $this->search($query);
}
}
diff --git a/lib/private/Files/Template/TemplateManager.php b/lib/private/Files/Template/TemplateManager.php
index 0351e122658..c10c13c35b0 100644
--- a/lib/private/Files/Template/TemplateManager.php
+++ b/lib/private/Files/Template/TemplateManager.php
@@ -159,6 +159,7 @@ class TemplateManager implements ITemplateManager {
}
$folder = $userFolder->get(dirname($filePath));
$targetFile = $folder->newFile(basename($filePath));
+ $template = null;
if ($templateType === 'user' && $templateId !== '') {
$template = $userFolder->get($templateId);
$template->copy($targetFile->getPath());
diff --git a/lib/private/Repair/NC21/ValidatePhoneNumber.php b/lib/private/Repair/NC21/ValidatePhoneNumber.php
index 995c38602f3..ca79786f909 100644
--- a/lib/private/Repair/NC21/ValidatePhoneNumber.php
+++ b/lib/private/Repair/NC21/ValidatePhoneNumber.php
@@ -26,7 +26,6 @@ declare(strict_types=1);
namespace OC\Repair\NC21;
-use OC\Accounts\AccountManager;
use OCP\Accounts\IAccountManager;
use OCP\IConfig;
use OCP\IUser;
@@ -40,11 +39,11 @@ class ValidatePhoneNumber implements IRepairStep {
protected $config;
/** @var IUserManager */
protected $userManager;
- /** @var AccountManager */
+ /** @var IAccountManager */
private $accountManager;
public function __construct(IUserManager $userManager,
- AccountManager $accountManager,
+ IAccountManager $accountManager,
IConfig $config) {
$this->config = $config;
$this->userManager = $userManager;
@@ -55,10 +54,6 @@ class ValidatePhoneNumber implements IRepairStep {
return 'Validate the phone number and store it in a known format for search';
}
- private function shouldRun(): bool {
- return true;
- }
-
public function run(IOutput $output): void {
if ($this->config->getSystemValueString('default_phone_region', '') === '') {
throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file');
@@ -68,13 +63,16 @@ class ValidatePhoneNumber implements IRepairStep {
$numRemoved = 0;
$this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) {
- $account = $this->accountManager->getUser($user);
+ $account = $this->accountManager->getAccount($user);
+ $property = $account->getProperty(IAccountManager::PROPERTY_PHONE);
- if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') {
- $updated = $this->accountManager->updateUser($user, $account);
+ if ($property->getValue() !== '') {
+ $this->accountManager->updateAccount($account);
+ $updatedAccount = $this->accountManager->getAccount($user);
+ $updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE);
- if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== $updated[IAccountManager::PROPERTY_PHONE]['value']) {
- if ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') {
+ if ($property->getValue() !== $updatedProperty->getValue()) {
+ if ($updatedProperty->getValue() === '') {
$numRemoved++;
} else {
$numUpdated++;
diff --git a/lib/private/Repair/NC22/LookupServerSendCheck.php b/lib/private/Repair/NC22/LookupServerSendCheck.php
index 11533bf6416..de419c7857c 100644
--- a/lib/private/Repair/NC22/LookupServerSendCheck.php
+++ b/lib/private/Repair/NC22/LookupServerSendCheck.php
@@ -53,7 +53,9 @@ class LookupServerSendCheck implements IRepairStep {
$versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0');
// was added to 22.0.0.3
- return version_compare($versionFromBeforeUpdate, '22.0.0.3', '<');
+ return (version_compare($versionFromBeforeUpdate, '22.0.0.3', '<') && version_compare($versionFromBeforeUpdate, '22.0.0.0', '>='))
+ ||
+ (version_compare($versionFromBeforeUpdate, '21.0.1.2', '<') && version_compare($versionFromBeforeUpdate, '21.0.0.0', '>'));
}
public function run(IOutput $output): void {
diff --git a/lib/private/Security/Bruteforce/Capabilities.php b/lib/private/Security/Bruteforce/Capabilities.php
index 7547348ce34..7c4c2a13671 100644
--- a/lib/private/Security/Bruteforce/Capabilities.php
+++ b/lib/private/Security/Bruteforce/Capabilities.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2017 Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -46,7 +49,7 @@ class Capabilities implements IPublicCapability {
$this->throttler = $throttler;
}
- public function getCapabilities() {
+ public function getCapabilities(): array {
if (version_compare(\OC::$server->getConfig()->getSystemValue('version', '0.0.0.0'), '12.0.0.0', '<')) {
return [];
}
diff --git a/lib/private/Security/Certificate.php b/lib/private/Security/Certificate.php
index c89122f9a4b..e299f9d2b8f 100644
--- a/lib/private/Security/Certificate.php
+++ b/lib/private/Security/Certificate.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -49,7 +52,7 @@ class Certificate implements ICertificate {
* @param string $name
* @throws \Exception If the certificate could not get parsed
*/
- public function __construct($data, $name) {
+ public function __construct(string $data, string $name) {
$this->name = $name;
$gmt = new \DateTimeZone('GMT');
@@ -75,42 +78,42 @@ class Certificate implements ICertificate {
/**
* @return string
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
/**
* @return string|null
*/
- public function getCommonName() {
+ public function getCommonName(): ?string {
return $this->commonName;
}
/**
- * @return string
+ * @return string|null
*/
- public function getOrganization() {
+ public function getOrganization(): ?string {
return $this->organization;
}
/**
* @return \DateTime
*/
- public function getIssueDate() {
+ public function getIssueDate(): \DateTime {
return $this->issueDate;
}
/**
* @return \DateTime
*/
- public function getExpireDate() {
+ public function getExpireDate(): \DateTime {
return $this->expireDate;
}
/**
* @return bool
*/
- public function isExpired() {
+ public function isExpired(): bool {
$now = new \DateTime();
return $this->issueDate > $now or $now > $this->expireDate;
}
@@ -118,14 +121,14 @@ class Certificate implements ICertificate {
/**
* @return string|null
*/
- public function getIssuerName() {
+ public function getIssuerName(): ?string {
return $this->issuerName;
}
/**
* @return string|null
*/
- public function getIssuerOrganization() {
+ public function getIssuerOrganization(): ?string {
return $this->issuerOrganization;
}
}
diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php
index ef0c6563320..9734f9b6446 100644
--- a/lib/private/Security/CertificateManager.php
+++ b/lib/private/Security/CertificateManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -30,6 +33,7 @@
namespace OC\Security;
use OC\Files\Filesystem;
+use OCP\ICertificate;
use OCP\ICertificateManager;
use OCP\IConfig;
use OCP\ILogger;
@@ -78,7 +82,7 @@ class CertificateManager implements ICertificateManager {
*
* @return \OCP\ICertificate[]
*/
- public function listCertificates() {
+ public function listCertificates(): array {
if (!$this->config->getSystemValue('installed', false)) {
return [];
}
@@ -130,7 +134,7 @@ class CertificateManager implements ICertificateManager {
/**
* create the certificate bundle of all trusted certificated
*/
- public function createCertificateBundle() {
+ public function createCertificateBundle(): void {
$path = $this->getPathToCertificates();
$certs = $this->listCertificates();
@@ -182,7 +186,7 @@ class CertificateManager implements ICertificateManager {
* @return \OCP\ICertificate
* @throws \Exception If the certificate could not get added
*/
- public function addCertificate($certificate, $name) {
+ public function addCertificate(string $certificate, string $name): ICertificate {
if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) {
throw new \Exception('Filename is not valid');
}
@@ -209,7 +213,7 @@ class CertificateManager implements ICertificateManager {
* @param string $name
* @return bool
*/
- public function removeCertificate($name) {
+ public function removeCertificate(string $name): bool {
if (!Filesystem::isValidPath($name)) {
return false;
}
@@ -226,7 +230,7 @@ class CertificateManager implements ICertificateManager {
*
* @return string
*/
- public function getCertificateBundle() {
+ public function getCertificateBundle(): string {
return $this->getPathToCertificates() . 'rootcerts.crt';
}
@@ -235,7 +239,7 @@ class CertificateManager implements ICertificateManager {
*
* @return string
*/
- public function getAbsoluteBundlePath() {
+ public function getAbsoluteBundlePath(): string {
if (!$this->hasCertificates()) {
return \OC::$SERVERROOT . '/resources/config/ca-bundle.crt';
}
@@ -250,7 +254,7 @@ class CertificateManager implements ICertificateManager {
/**
* @return string
*/
- private function getPathToCertificates() {
+ private function getPathToCertificates(): string {
return '/files_external/';
}
@@ -259,7 +263,7 @@ class CertificateManager implements ICertificateManager {
*
* @return bool
*/
- private function needsRebundling() {
+ private function needsRebundling(): bool {
$targetBundle = $this->getCertificateBundle();
if (!$this->view->file_exists($targetBundle)) {
return true;
@@ -274,7 +278,7 @@ class CertificateManager implements ICertificateManager {
*
* @return int
*/
- protected function getFilemtimeOfCaBundle() {
+ protected function getFilemtimeOfCaBundle(): int {
return filemtime(\OC::$SERVERROOT . '/resources/config/ca-bundle.crt');
}
}
diff --git a/lib/private/Security/CredentialsManager.php b/lib/private/Security/CredentialsManager.php
index 7ba8a0020ff..4688bea8dcf 100644
--- a/lib/private/Security/CredentialsManager.php
+++ b/lib/private/Security/CredentialsManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -59,11 +62,11 @@ class CredentialsManager implements ICredentialsManager {
* @param string $identifier
* @param mixed $credentials
*/
- public function store($userId, $identifier, $credentials) {
+ public function store(string $userId, string $identifier, $credentials): void {
$value = $this->crypto->encrypt(json_encode($credentials));
$this->dbConnection->setValues(self::DB_TABLE, [
- 'user' => (string)$userId,
+ 'user' => $userId,
'identifier' => $identifier,
], [
'credentials' => $value,
@@ -77,7 +80,7 @@ class CredentialsManager implements ICredentialsManager {
* @param string $identifier
* @return mixed
*/
- public function retrieve($userId, $identifier) {
+ public function retrieve(string $userId, string $identifier) {
$qb = $this->dbConnection->getQueryBuilder();
$qb->select('credentials')
->from(self::DB_TABLE)
@@ -86,7 +89,7 @@ class CredentialsManager implements ICredentialsManager {
if ($userId === '') {
$qb->andWhere($qb->expr()->emptyString('user'));
} else {
- $qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId)));
+ $qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($userId)));
}
$qResult = $qb->execute();
@@ -108,7 +111,7 @@ class CredentialsManager implements ICredentialsManager {
* @param string $identifier
* @return int rows removed
*/
- public function delete($userId, $identifier) {
+ public function delete(string $userId, string $identifier): int {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::DB_TABLE)
->where($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)));
@@ -116,7 +119,7 @@ class CredentialsManager implements ICredentialsManager {
if ($userId === '') {
$qb->andWhere($qb->expr()->emptyString('user'));
} else {
- $qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter((string)$userId)));
+ $qb->andWhere($qb->expr()->eq('user', $qb->createNamedParameter($userId)));
}
return $qb->execute();
@@ -128,7 +131,7 @@ class CredentialsManager implements ICredentialsManager {
* @param string $userId
* @return int rows removed
*/
- public function erase($userId) {
+ public function erase(string $userId): int {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete(self::DB_TABLE)
->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
diff --git a/lib/private/Security/TrustedDomainHelper.php b/lib/private/Security/TrustedDomainHelper.php
index 8004bf7dc6f..f99b505157a 100644
--- a/lib/private/Security/TrustedDomainHelper.php
+++ b/lib/private/Security/TrustedDomainHelper.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -51,7 +54,7 @@ class TrustedDomainHelper {
* @param string $host
* @return string $host without appended port
*/
- private function getDomainWithoutPort($host) {
+ private function getDomainWithoutPort(string $host): string {
$pos = strrpos($host, ':');
if ($pos !== false) {
$port = substr($host, $pos + 1);
@@ -71,7 +74,7 @@ class TrustedDomainHelper {
* @return bool true if the given domain is trusted or if no trusted domains
* have been configured
*/
- public function isTrustedDomain($domainWithPort) {
+ public function isTrustedDomain(string $domainWithPort): bool {
// overwritehost is always trusted
if ($this->config->getSystemValue('overwritehost') !== '') {
return true;
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index fe658b2eedd..43bc430486b 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -303,7 +303,7 @@ class Setup {
// validate the data directory
if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir)) {
- $error[] = $l->t("Can't create or write into the data directory %s", [$dataDir]);
+ $error[] = $l->t("Cannot create or write into the data directory %s", [$dataDir]);
}
if (!empty($error)) {
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 00020c3a8f6..983653b7661 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -252,7 +252,7 @@ class Manager implements IManager {
} elseif ($share->getShareType() === IShare::TYPE_ROOM) {
} elseif ($share->getShareType() === IShare::TYPE_DECK) {
} else {
- // We can't handle other types yet
+ // We cannot handle other types yet
throw new \InvalidArgumentException('unknown share type');
}
@@ -264,7 +264,7 @@ class Manager implements IManager {
// Cannot share with yourself
if ($share->getShareType() === IShare::TYPE_USER &&
$share->getSharedWith() === $share->getSharedBy()) {
- throw new \InvalidArgumentException('Can’t share with yourself');
+ throw new \InvalidArgumentException('Cannot share with yourself');
}
// The path should be set
@@ -278,14 +278,14 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Path should be either a file or a folder');
}
- // And you can't share your rootfolder
+ // And you cannot share your rootfolder
if ($this->userManager->userExists($share->getSharedBy())) {
$userFolder = $this->rootFolder->getUserFolder($share->getSharedBy());
} else {
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner());
}
if ($userFolder->getId() === $share->getNode()->getId()) {
- throw new \InvalidArgumentException('You can’t share your root folder');
+ throw new \InvalidArgumentException('You cannot share your root folder');
}
// Check if we actually have share permissions
@@ -349,7 +349,7 @@ class Manager implements IManager {
// Check that we do not share with more permissions than we have
if ($share->getPermissions() & ~$permissions) {
$path = $userFolder->getRelativePath($share->getNode()->getPath());
- $message_t = $this->l->t('Can’t increase permissions of %s', [$path]);
+ $message_t = $this->l->t('Cannot increase permissions of %s', [$path]);
throw new GenericShareException($message_t, $message_t, 404);
}
@@ -365,11 +365,11 @@ class Manager implements IManager {
if ($share->getNode() instanceof \OCP\Files\File) {
if ($share->getPermissions() & \OCP\Constants::PERMISSION_DELETE) {
- $message_t = $this->l->t('Files can’t be shared with delete permissions');
+ $message_t = $this->l->t('Files cannot be shared with delete permissions');
throw new GenericShareException($message_t);
}
if ($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE) {
- $message_t = $this->l->t('Files can’t be shared with create permissions');
+ $message_t = $this->l->t('Files cannot be shared with create permissions');
throw new GenericShareException($message_t);
}
}
@@ -441,7 +441,7 @@ class Manager implements IManager {
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
if ($date < $expirationDate) {
- $message = $this->l->n('Can’t set expiration date more than %n day in the future', 'Can’t set expiration date more than %n days in the future', $defaultExpireDays);
+ $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays);
throw new GenericShareException($message, $message, 404);
}
}
@@ -517,7 +517,7 @@ class Manager implements IManager {
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
if ($date < $expirationDate) {
- $message = $this->l->n('Can’t set expiration date more than %n day in the future', 'Can’t set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays());
+ $message = $this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $this->shareApiLinkDefaultExpireDays());
throw new GenericShareException($message, $message, 404);
}
}
@@ -796,7 +796,7 @@ class Manager implements IManager {
// Cannot share with the owner
if ($share->getShareType() === IShare::TYPE_USER &&
$share->getSharedWith() === $share->getShareOwner()) {
- throw new \InvalidArgumentException('Can’t share with the share owner');
+ throw new \InvalidArgumentException('Cannot share with the share owner');
}
// Generate the target
@@ -964,9 +964,9 @@ class Manager implements IManager {
throw new \InvalidArgumentException('Share does not have a full id');
}
- // We can't change the share type!
+ // We cannot change the share type!
if ($share->getShareType() !== $originalShare->getShareType()) {
- throw new \InvalidArgumentException('Can’t change share type');
+ throw new \InvalidArgumentException('Cannot change share type');
}
// We can only change the recipient on user shares
@@ -978,7 +978,7 @@ class Manager implements IManager {
// Cannot share with the owner
if ($share->getShareType() === IShare::TYPE_USER &&
$share->getSharedWith() === $share->getShareOwner()) {
- throw new \InvalidArgumentException('Can’t share with the share owner');
+ throw new \InvalidArgumentException('Cannot share with the share owner');
}
$this->generalCreateChecks($share);
@@ -1013,7 +1013,7 @@ class Manager implements IManager {
* Cannot enable the getSendPasswordByTalk if there is no password set
*/
if (empty($plainTextPassword) && $share->getSendPasswordByTalk()) {
- throw new \InvalidArgumentException('Can’t enable sending the password by Talk with an empty password');
+ throw new \InvalidArgumentException('Cannot enable sending the password by Talk with an empty password');
}
/**
@@ -1023,10 +1023,10 @@ class Manager implements IManager {
*/
if (!$updatedPassword && $share->getShareType() === IShare::TYPE_EMAIL) {
if (!$originalShare->getSendPasswordByTalk() && $share->getSendPasswordByTalk()) {
- throw new \InvalidArgumentException('Can’t enable sending the password by Talk without setting a new password');
+ throw new \InvalidArgumentException('Cannot enable sending the password by Talk without setting a new password');
}
if ($originalShare->getSendPasswordByTalk() && !$share->getSendPasswordByTalk()) {
- throw new \InvalidArgumentException('Can’t disable sending the password by Talk without setting a new password');
+ throw new \InvalidArgumentException('Cannot disable sending the password by Talk without setting a new password');
}
}
@@ -1246,7 +1246,7 @@ class Manager implements IManager {
public function moveShare(IShare $share, $recipientId) {
if ($share->getShareType() === IShare::TYPE_LINK
|| $share->getShareType() === IShare::TYPE_EMAIL) {
- throw new \InvalidArgumentException('Can’t change target of link share');
+ throw new \InvalidArgumentException('Cannot change target of link share');
}
if ($share->getShareType() === IShare::TYPE_USER && $share->getSharedWith() !== $recipientId) {
@@ -1447,7 +1447,7 @@ class Manager implements IManager {
* @throws ShareNotFound
*/
public function getShareByToken($token) {
- // tokens can't be valid local user names
+ // tokens cannot be valid local user names
if ($this->userManager->userExists($token)) {
throw new ShareNotFound();
}
@@ -1665,7 +1665,7 @@ class Manager implements IManager {
return $al;
}
- //Get node for the owner and correct the owner in case of external storages
+ //Get node for the owner and correct the owner in case of external storage
$userFolder = $this->rootFolder->getUserFolder($owner);
if ($path->getId() !== $userFolder->getId() && !$userFolder->isSubNode($path)) {
$nodes = $userFolder->getById($path->getId());
diff --git a/lib/private/Streamer.php b/lib/private/Streamer.php
index 0e3018f77b7..e76ad2afee3 100644
--- a/lib/private/Streamer.php
+++ b/lib/private/Streamer.php
@@ -78,7 +78,7 @@ class Streamer {
* larger than 4GiB), but it should not happen in the real world.
*
* We also have to check for a size above 0. As negative sizes could be
- * from not fully scanned external storages. And then things fall apart
+ * from not fully scanned external storage. And then things fall apart
* if somebody tries to package to much.
*/
if ($size > 0 && $size < 4 * 1000 * 1000 * 1000 && $numberOfFiles < 65536) {
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index 65365c85e36..ed85253b649 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -135,7 +135,14 @@ class OC_App {
ob_start();
foreach ($apps as $app) {
if (!isset(self::$loadedApps[$app]) && ($types === [] || self::isType($app, $types))) {
- self::loadApp($app);
+ try {
+ self::loadApp($app);
+ } catch (\Throwable $e) {
+ \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: ' . $e->getMessage(), [
+ 'exception' => $e,
+ 'app' => $app,
+ ]);
+ }
}
}
ob_end_clean();
diff --git a/lib/private/legacy/OC_Files.php b/lib/private/legacy/OC_Files.php
index addee2358dd..b46fc8c3768 100644
--- a/lib/private/legacy/OC_Files.php
+++ b/lib/private/legacy/OC_Files.php
@@ -216,13 +216,13 @@ class OC_Files {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('lib');
- \OC_Template::printErrorPage($l->t('Can\'t read file'), $ex->getMessage(), 200);
+ \OC_Template::printErrorPage($l->t('Cannot read file'), $ex->getMessage(), 200);
} catch (\Exception $ex) {
self::unlockAllTheFiles($dir, $files, $getType, $view, $filename);
OC::$server->getLogger()->logException($ex);
$l = \OC::$server->getL10N('lib');
$hint = method_exists($ex, 'getHint') ? $ex->getHint() : '';
- \OC_Template::printErrorPage($l->t('Can\'t read file'), $hint, 200);
+ \OC_Template::printErrorPage($l->t('Cannot read file'), $hint, 200);
}
}