diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2022-08-30 17:45:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 17:45:29 +0200 |
commit | 4503adc70d4022985afbae94283827c1be693d1c (patch) | |
tree | f715e0bc3deb3697eeec1e27b2e1f6ca646456d4 /lib | |
parent | ec9a9e571375a6daefce1e72e33b751fbd6b18cc (diff) | |
parent | be5c39321b152606f1791ff13e615e65d462dff1 (diff) | |
download | nextcloud-server-4503adc70d4022985afbae94283827c1be693d1c.tar.gz nextcloud-server-4503adc70d4022985afbae94283827c1be693d1c.zip |
Merge pull request #33514 from nextcloud/backport/33513/stable24
[stable24] Recover installation when creating the database user fails and improve password strength
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Setup/MySQL.php | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 920baf3e4ee..2c16cac3d26 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -129,6 +129,7 @@ class MySQL extends AbstractDatabase { 'exception' => $ex, 'app' => 'mysql.setup', ]); + throw $ex; } } @@ -138,6 +139,19 @@ class MySQL extends AbstractDatabase { * @return array */ private function createSpecificUser($username, $connection) { + $rootUser = $this->dbUser; + $rootPassword = $this->dbPassword; + + //create a random password so we don't need to store the admin password in the config file + $saveSymbols = str_replace(['\"', '\\', '\'', '`'], '', ISecureRandom::CHAR_SYMBOLS); + $password = $this->random->generate(22, ISecureRandom::CHAR_ALPHANUMERIC . $saveSymbols) + . $this->random->generate(2, ISecureRandom::CHAR_UPPER) + . $this->random->generate(2, ISecureRandom::CHAR_LOWER) + . $this->random->generate(2, ISecureRandom::CHAR_DIGITS) + . $this->random->generate(2, $saveSymbols) + ; + $this->dbPassword = str_shuffle($password); + try { //user already specified in config $oldUser = $this->config->getValue('dbuser', false); @@ -160,10 +174,6 @@ class MySQL extends AbstractDatabase { if (count($data) === 0) { //use the admin login data for the new database user $this->dbUser = $adminUser; - - //create a random password so we don't need to store the admin password in the config file - $this->dbPassword = $this->random->generate(30, ISecureRandom::CHAR_ALPHANUMERIC); - $this->createDBUser($connection); break; @@ -180,6 +190,9 @@ class MySQL extends AbstractDatabase { 'exception' => $ex, 'app' => 'mysql.setup', ]); + // Restore the original credentials + $this->dbUser = $rootUser; + $this->dbPassword = $rootPassword; } $this->config->setValues([ |