aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-07-11 20:53:37 +0200
committerAndy Scherzinger <info@andy-scherzinger.de>2024-08-08 22:08:42 +0200
commit0563757ea43b853770305f80c763a547525abf66 (patch)
treec07ae092b92002e7a2f98fcdb55449e6306d092f /lib/private
parent8c0bece57aee2aca571650e6c2decad27088a5ae (diff)
downloadnextcloud-server-0563757ea43b853770305f80c763a547525abf66.tar.gz
nextcloud-server-0563757ea43b853770305f80c763a547525abf66.zip
fix(SetupCheck): Properly check public access to data directory
When checking for public (web) access to the data directory the status is not enough as you might have a webserver that forwards to e.g. a login page. So instead check that the content of the file matches. For this the `.ncdata` file (renamed from `.ocdata`¹) has minimal text content to allow checking. ¹The file was renamed from the legacy `.ocdata`, there is a repair step to remove the old one. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Repair.php2
-rw-r--r--lib/private/Repair/NC30/RemoveLegacyDatadirFile.php32
-rw-r--r--lib/private/Setup.php7
-rw-r--r--lib/private/Updater.php7
-rw-r--r--lib/private/User/Manager.php2
-rw-r--r--lib/private/legacy/OC_Util.php8
6 files changed, 49 insertions, 9 deletions
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index 942cd77e5cb..d1904e08431 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -41,6 +41,7 @@ use OC\Repair\NC21\ValidatePhoneNumber;
use OC\Repair\NC22\LookupServerSendCheck;
use OC\Repair\NC24\AddTokenCleanupJob;
use OC\Repair\NC25\AddMissingSecretJob;
+use OC\Repair\NC30\RemoveLegacyDatadirFile;
use OC\Repair\OldGroupMembershipShares;
use OC\Repair\Owncloud\CleanPreviews;
use OC\Repair\Owncloud\DropAccountTermsTable;
@@ -187,6 +188,7 @@ class Repair implements IOutput {
\OCP\Server::get(AddMetadataGenerationJob::class),
\OCP\Server::get(AddAppConfigLazyMigration::class),
\OCP\Server::get(RepairLogoDimension::class),
+ \OCP\Server::get(RemoveLegacyDatadirFile::class),
];
}
diff --git a/lib/private/Repair/NC30/RemoveLegacyDatadirFile.php b/lib/private/Repair/NC30/RemoveLegacyDatadirFile.php
new file mode 100644
index 00000000000..623163927bd
--- /dev/null
+++ b/lib/private/Repair/NC30/RemoveLegacyDatadirFile.php
@@ -0,0 +1,32 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OC\Repair\NC30;
+
+use OCP\IConfig;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class RemoveLegacyDatadirFile implements IRepairStep {
+
+ public function __construct(
+ private IConfig $config,
+ ) {
+ }
+
+ public function getName(): string {
+ return 'Remove legacy ".ocdata" file';
+ }
+
+ public function run(IOutput $output): void {
+ $ocdata = $this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata';
+ if (file_exists($ocdata)) {
+ unlink($ocdata);
+ }
+ }
+}
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index a67d74bd032..62db4879bbc 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -360,9 +360,12 @@ class Setup {
Installer::installShippedApps(false, $output);
// create empty file in data dir, so we can later find
- // out that this is indeed an ownCloud data directory
+ // out that this is indeed a Nextcloud data directory
$this->outputDebug($output, 'Setup data directory');
- file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
+ file_put_contents(
+ $config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ncdata',
+ "# Nextcloud data directory\n# Do not change this file",
+ );
// Update .htaccess files
self::updateHtaccess();
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index 6d23e81aa63..e26faf86f92 100644
--- a/lib/private/Updater.php
+++ b/lib/private/Updater.php
@@ -208,9 +208,12 @@ class Updater extends BasicEmitter {
}
// create empty file in data dir, so we can later find
- // out that this is indeed an ownCloud data directory
+ // out that this is indeed a Nextcloud data directory
// (in case it didn't exist before)
- file_put_contents($this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
+ file_put_contents(
+ $this->config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ncdata',
+ "# Nextcloud data directory\n# Do not change this file",
+ );
// pre-upgrade repairs
$repair = \OCP\Server::get(Repair::class);
diff --git a/lib/private/User/Manager.php b/lib/private/User/Manager.php
index 639ce507f4d..2c8cc10dc15 100644
--- a/lib/private/User/Manager.php
+++ b/lib/private/User/Manager.php
@@ -783,7 +783,7 @@ class Manager extends PublicEmitter implements IUserManager {
'.htaccess',
'files_external',
'__groupfolders',
- '.ocdata',
+ '.ncdata',
'owncloud.log',
'nextcloud.log',
'updater.log',
diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php
index d8045e8343d..3b5222fee64 100644
--- a/lib/private/legacy/OC_Util.php
+++ b/lib/private/legacy/OC_Util.php
@@ -687,7 +687,7 @@ class OC_Util {
/**
* Check that the data directory exists and is valid by
- * checking the existence of the ".ocdata" file.
+ * checking the existence of the ".ncdata" file.
*
* @param string $dataDirectory data directory path
* @return array errors found
@@ -701,11 +701,11 @@ class OC_Util {
'hint' => $l->t('Check the value of "datadirectory" in your configuration.')
];
}
- if (!file_exists($dataDirectory . '/.ocdata')) {
+
+ if (!file_exists($dataDirectory . '/.ncdata')) {
$errors[] = [
'error' => $l->t('Your data directory is invalid.'),
- 'hint' => $l->t('Ensure there is a file called ".ocdata"' .
- ' in the root of the data directory.')
+ 'hint' => $l->t('Ensure there is a file called "%1$s" in the root of the data directory. It should have the content: "%2$s"', ['.ncdata', '# Nextcloud data directory']),
];
}
return $errors;