From d09533cf2888ccd8b995add8012ef32d92efbca4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Aug 2022 09:43:38 +0200 Subject: Recover installation when creating the user failed Signed-off-by: Joas Schilling --- lib/private/Setup/MySQL.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib') diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 920baf3e4ee..491419dfaf6 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,9 @@ class MySQL extends AbstractDatabase { * @return array */ private function createSpecificUser($username, $connection) { + $rootUser = $this->dbUser; + $rootPassword = $this->dbPassword; + try { //user already specified in config $oldUser = $this->config->getValue('dbuser', false); @@ -180,6 +184,9 @@ class MySQL extends AbstractDatabase { 'exception' => $ex, 'app' => 'mysql.setup', ]); + // Restore the original credentials + $this->dbUser = $rootUser; + $this->dbPassword = $rootPassword; } $this->config->setValues([ -- cgit v1.2.3 From be5c39321b152606f1791ff13e615e65d462dff1 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Aug 2022 10:03:19 +0200 Subject: Create more secure passwords by default Signed-off-by: Joas Schilling --- lib/private/Setup/MySQL.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 491419dfaf6..2c16cac3d26 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -142,6 +142,16 @@ class MySQL extends AbstractDatabase { $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); @@ -164,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; -- cgit v1.2.3