Skip to content

Commit 612bd1a

Browse files
committed
Add repair job that will ensure that secret and passwordsalt are set
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 9422d80 commit 612bd1a

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

lib/composer/composer/autoload_classmap.php

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

0 commit comments

Comments
 (0)