Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(install): check mariaDB version before using ALTER USER #8068

Merged
merged 2 commits into from
Nov 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions www/install/steps/process/createDbUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@
$host = explode(":", $getIpQuery->fetchAll(PDO::FETCH_COLUMN)[0])[0];
}

// Compatibility adaptation for mysql 8 with php7.1 before 7.1.16, or php7.2 before 7.2.4.
$createUser = "CREATE USER :dbUser@:host IDENTIFIED BY :dbPass";
$alterQuery = "ALTER USER :dbUser@:host IDENTIFIED WITH mysql_native_password BY :dbPass";

$queryValues = [];
$queryValues[':dbUser'] = $parameters['db_user'];
$queryValues[':host'] = $host;
$queryValues[':dbPass'] = $parameters['db_password'];

// Compatibility adaptation for mysql 8 with php7.1 before 7.1.16, or php7.2 before 7.2.4.
$createUser = "CREATE USER :dbUser@:host IDENTIFIED BY :dbPass";

// As ALTER USER won't work on a mariaDB < 10.2, we need to check it before trying this request
$checkMysqlVersion = "SHOW VARIABLES WHERE Variable_name LIKE 'version%'";

// creating the user - mandatory for MySQL DB
$alterQuery = "ALTER USER :dbUser@:host IDENTIFIED WITH mysql_native_password BY :dbPass";
$query = "GRANT ALL PRIVILEGES ON `%s`.* TO " . $parameters['db_user'] . "@" . $host . " WITH GRANT OPTION";
$flushQuery = "FLUSH PRIVILEGES";

Expand All @@ -90,11 +94,29 @@
}
// creating the user
$prepareCreate->execute();

// checking mysql version before trying to alter the password plugin
$prepareCheckVersion = $link->prepare($checkMysqlVersion);
sc979 marked this conversation as resolved.
Show resolved Hide resolved
$prepareCheckVersion->execute();
while ($row = $prepareCheckVersion->fetch()) {
if (!isset($versionNumber) && $row['Variable_name'] === "version") {
$versionNumber = $row['version'];
} elseif (!isset($versionName) && $row['Variable_name'] === "version_comment") {
$versionName = $row['version_comment'];
}
}
if ((strpos($versionName, "MariaDB") !== false && version_compare($versionNumber, '10.2.0') >= 0)
Copy link
Contributor Author

@sc979 sc979 Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we need to ALTER the centreon's user, on a MariaDB, as the deprecated "plugin" problem may affect only mysql >= 8.0

|| (strpos($versionName, "MySQL") !== false && version_compare($versionNumber, '8.0.0') >= 0)
) {
// altering the mysql's password plugin using the ALTER USER request
$prepareAlter->execute();
}

// granting privileges
$link->exec(sprintf($query, $parameters['db_configuration']));
$link->exec(sprintf($query, $parameters['db_storage']));
// altering the mysql's password plugin
$prepareAlter->execute();

// enabling the new parameters
$link->exec($flushQuery);
} catch (\PDOException $e) {
$return['msg'] = $e->getMessage();
Expand Down