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

Commit

Permalink
(fix)MON-14742 Escape database name in CentACL (#11602)
Browse files Browse the repository at this point in the history
* fixed issue of using special chars in db names

* fix escape database name

* fixed security issue on sql requests
  • Loading branch information
dmyios authored Aug 24, 2022
1 parent 7224675 commit ebf4b1d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion www/class/centreon-partition/mysqlTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public function isValid()
public function exists()
{
try {
$DBRESULT = $this->db->query("use " . $this->schema);
$DBRESULT = $this->db->query("use `" . $this->schema . "`");
} catch (\PDOException $e) {
throw new Exception(
"SQL Error: Cannot use database "
Expand Down
16 changes: 8 additions & 8 deletions www/class/centreon-partition/partEngine.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private function createDailyPartitions($table, $createPastPartitions): string
*/
public function createParts($table, $db, $createPastPartitions): void
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();
if ($table->exists()) {
throw new Exception("Warning: Table " . $tableName . " already exists\n");
}
Expand All @@ -253,7 +253,7 @@ public function createParts($table, $db, $createPastPartitions): void
}

try {
$dbResult = $db->query("use " . $table->getSchema());
$dbResult = $db->query("use `" . $table->getSchema() . "`");
} catch (\PDOException $e) {
throw new Exception(
"SQL Error: Cannot use database "
Expand Down Expand Up @@ -325,7 +325,7 @@ public function purgeParts($table, $db)
$condition = $this->purgeDailyPartitionCondition($table);
}

$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();
if (!$table->exists()) {
throw new Exception("Error: Table " . $tableName . " does not exists\n");
}
Expand Down Expand Up @@ -364,7 +364,7 @@ public function purgeParts($table, $db)
*/
public function migrate($table, $db)
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();

$db->query("SET bulk_insert_buffer_size= 1024 * 1024 * 256");

Expand Down Expand Up @@ -411,7 +411,7 @@ public function migrate($table, $db)
*/
public function updateParts($table, $db)
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();

//verifying if table is partitioned
if ($this->isPartitioned($table, $db) === false) {
Expand All @@ -433,7 +433,7 @@ public function updateParts($table, $db)
*/
public function optimizeTablePartitions($table, $db)
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();
if (!$table->exists()) {
throw new Exception("Optimize error: Table " . $tableName . " does not exists\n");
}
Expand Down Expand Up @@ -472,7 +472,7 @@ public function optimizeTablePartitions($table, $db)
*/
public function listParts($table, $db, $throwException = true)
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();
if (!$table->exists()) {
throw new Exception("Parts list error: Table " . $tableName . " does not exists\n");
}
Expand Down Expand Up @@ -521,7 +521,7 @@ public function listParts($table, $db, $throwException = true)
*/
public function backupParts($table, $db)
{
$tableName = $table->getSchema() . "." . $table->getName();
$tableName = "`" . $table->getSchema() . "`." . $table->getName();
if (!$table->exists()) {
throw new Exception("Error: Table " . $tableName . " does not exists\n");
}
Expand Down
2 changes: 1 addition & 1 deletion www/install/steps/process/createDbUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@

// 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 . "'";
$query = "GRANT ALL PRIVILEGES ON `%s`.* TO '" . $parameters['db_user'] . "'@'" . $host . "'";
$flushQuery = "FLUSH PRIVILEGES";

try {
Expand Down
2 changes: 1 addition & 1 deletion www/install/steps/process/insertBaseConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* Create tables
*/
try {
$result = $link->query('use ' . $parameters['db_configuration']);
$result = $link->query(sprintf('use `%s`', $parameters['db_configuration']));
if (!$result) {
throw new \Exception('Cannot access to "' . $parameters['db_configuration'] . '" database');
}
Expand Down
4 changes: 2 additions & 2 deletions www/install/steps/process/installConfigurationDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
}

try {
$link->exec("CREATE DATABASE " . $parameters['db_configuration']);
$link->exec(sprintf('CREATE DATABASE `%s`', $parameters['db_configuration']));
} catch (\PDOException $e) {
if (!is_file('../../tmp/createTables')) {
$return['msg'] = $e->getMessage();
Expand All @@ -94,7 +94,7 @@
/**
* Create tables
*/
$link->exec('use ' . $parameters['db_configuration']);
$link->exec(sprintf('use `%s`', $parameters['db_configuration']));
$result = splitQueries('../../createTables.sql', ';', $link, '../../tmp/createTables');
if ("0" != $result) {
$return['msg'] = $result;
Expand Down
4 changes: 2 additions & 2 deletions www/install/steps/process/installStorageDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
}

try {
$link->exec("CREATE DATABASE " . $parameters['db_storage']);
$link->exec(sprintf('CREATE DATABASE `%s`', $parameters['db_storage']));
} catch (\PDOException $e) {
if (!is_file('../../tmp/createTablesCentstorage')) {
$return['msg'] = $e->getMessage();
Expand All @@ -79,7 +79,7 @@
);

try {
$result = $link->query('use ' . $parameters['db_storage']);
$result = $link->query(sprintf('use `%s`', $parameters['db_storage']));
if (!$result) {
throw new \Exception('Cannot access to "' . $parameters['db_storage'] . '" database');
}
Expand Down

0 comments on commit ebf4b1d

Please sign in to comment.