Skip to content

Commit 0d7ba73

Browse files
authored
Merge pull request #35377 from nextcloud/backport/35368/stable25
[stable25] Add repair job that will ensure that secret and passwordsalt are set
2 parents 4c99ba4 + 471369c commit 0d7ba73

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@
14631463
'OC\\Repair\\NC21\\ValidatePhoneNumber' => $baseDir . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
14641464
'OC\\Repair\\NC22\\LookupServerSendCheck' => $baseDir . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
14651465
'OC\\Repair\\NC24\\AddTokenCleanupJob' => $baseDir . '/lib/private/Repair/NC24/AddTokenCleanupJob.php',
1466+
'OC\\Repair\\NC25\\AddMissingSecretJob' => $baseDir . '/lib/private/Repair/NC25/AddMissingSecretJob.php',
14661467
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
14671468
'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
14681469
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
14961496
'OC\\Repair\\NC21\\ValidatePhoneNumber' => __DIR__ . '/../../..' . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
14971497
'OC\\Repair\\NC22\\LookupServerSendCheck' => __DIR__ . '/../../..' . '/lib/private/Repair/NC22/LookupServerSendCheck.php',
14981498
'OC\\Repair\\NC24\\AddTokenCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC24/AddTokenCleanupJob.php',
1499+
'OC\\Repair\\NC25\\AddMissingSecretJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC25/AddMissingSecretJob.php',
14991500
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
15001501
'OC\\Repair\\Owncloud\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviews.php',
15011502
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',

lib/private/Repair.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
use OC\Repair\NC21\ValidatePhoneNumber;
7272
use OC\Repair\NC22\LookupServerSendCheck;
7373
use OC\Repair\NC24\AddTokenCleanupJob;
74+
use OC\Repair\NC25\AddMissingSecretJob;
7475
use OC\Repair\OldGroupMembershipShares;
7576
use OC\Repair\Owncloud\CleanPreviews;
7677
use OC\Repair\Owncloud\DropAccountTermsTable;
@@ -209,6 +210,7 @@ public static function getRepairSteps(): array {
209210
\OCP\Server::get(LookupServerSendCheck::class),
210211
\OCP\Server::get(AddTokenCleanupJob::class),
211212
\OCP\Server::get(CleanUpAbandonedApps::class),
213+
\OCP\Server::get(AddMissingSecretJob::class),
212214
];
213215
}
214216

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2022 Carl Schwan <carl@carlschwan.eu>
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace OC\Repair\NC25;
24+
25+
use OCP\HintException;
26+
use OCP\IConfig;
27+
use OCP\Migration\IOutput;
28+
use OCP\Migration\IRepairStep;
29+
use OCP\Security\ISecureRandom;
30+
31+
class AddMissingSecretJob implements IRepairStep {
32+
private IConfig $config;
33+
private ISecureRandom $random;
34+
35+
public function __construct(IConfig $config, ISecureRandom $random) {
36+
$this->config = $config;
37+
$this->random = $random;
38+
}
39+
40+
public function getName(): string {
41+
return 'Add possibly missing system config';
42+
}
43+
44+
public function run(IOutput $output): void {
45+
$passwordSalt = $this->config->getSystemValue('passwordsalt', null);
46+
if ($passwordSalt === null || $passwordSalt === '') {
47+
try {
48+
$this->config->setSystemValue('passwordsalt', $this->random->generate(30));
49+
} catch (HintException $e) {
50+
$output->warning("passwordsalt is missing from your config.php and your config.php is read only. Please fix it manually.");
51+
}
52+
}
53+
54+
$secret = $this->config->getSystemValue('secret', null);
55+
if ($secret === null || $secret === '') {
56+
try {
57+
$this->config->setSystemValue('secret', $this->random->generate(48));
58+
} catch (HintException $e) {
59+
$output->warning("secret is missing from your config.php and your config.php is read only. Please fix it manually.");
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)