From 1d246fee02623cb399a53a31832a44dc14819a11 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Tue, 25 Jun 2024 10:37:49 +0200 Subject: [PATCH] check custom database-name against supported maximum length of username/databasename of used dbms, fixes #1258 Signed-off-by: Michael Kaufmann --- lib/Froxlor/Api/Commands/Mysqls.php | 5 ++++- lib/Froxlor/Database/DbManager.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/Froxlor/Api/Commands/Mysqls.php b/lib/Froxlor/Api/Commands/Mysqls.php index 8ef6c1e7de..dcebc412fe 100644 --- a/lib/Froxlor/Api/Commands/Mysqls.php +++ b/lib/Froxlor/Api/Commands/Mysqls.php @@ -54,7 +54,7 @@ class Mysqls extends ApiCommand implements ResourceEntity * @param string $description * optional, description for database * @param string $custom_suffix - * optional, name for database + * optional, name for database if customer.mysqlprefix setting is set to "DBNAME" * @param bool $sendinfomail * optional, send created resource-information to customer, default: false * @param int $customerid @@ -110,6 +110,9 @@ public function add() $dbm = new DbManager($this->logger()); if (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME' && !empty($databasename)) { + if (strlen($newdb_params['loginname'] . '_' . $databasename) > Database::getSqlUsernameLength()) { + throw new Exception("Database name cannot be longer than " . (Database::getSqlUsernameLength() - strlen($newdb_params['loginname'] . '_')) . " characters.", 406); + } $username = $dbm->createDatabase($newdb_params['loginname'] . '_' . $databasename, $password, $dbserver); } else { $username = $dbm->createDatabase($newdb_params['loginname'], $password, $dbserver, $newdb_params['mysql_lastaccountnumber']); diff --git a/lib/Froxlor/Database/DbManager.php b/lib/Froxlor/Database/DbManager.php index 4d56906ca5..2fdae1e6b5 100644 --- a/lib/Froxlor/Database/DbManager.php +++ b/lib/Froxlor/Database/DbManager.php @@ -25,6 +25,7 @@ namespace Froxlor\Database; +use Exception; use Froxlor\Database\Manager\DbManagerMySQL; use Froxlor\Froxlor; use Froxlor\FroxlorLogger; @@ -83,7 +84,7 @@ private function setManager() * @param array $mysql_access_host_array * * @return void - * @throws \Exception + * @throws Exception */ public static function correctMysqlUsers(array $mysql_access_host_array) { @@ -150,6 +151,7 @@ public static function correctMysqlUsers(array $mysql_access_host_array) * @param int $last_accnumber * * @return string|bool $username if successful or false of username is equal to the password + * @throws Exception */ public function createDatabase(string $loginname = null, string $password = null, int $dbserver = 0, int $last_accnumber = 0) {