Skip to content

Commit 1d246fe

Browse files
committed
check custom database-name against supported maximum length of username/databasename of used dbms, fixes #1258
Signed-off-by: Michael Kaufmann <[email protected]>
1 parent 10e87a9 commit 1d246fe

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/Froxlor/Api/Commands/Mysqls.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Mysqls extends ApiCommand implements ResourceEntity
5454
* @param string $description
5555
* optional, description for database
5656
* @param string $custom_suffix
57-
* optional, name for database
57+
* optional, name for database if customer.mysqlprefix setting is set to "DBNAME"
5858
* @param bool $sendinfomail
5959
* optional, send created resource-information to customer, default: false
6060
* @param int $customerid
@@ -110,6 +110,9 @@ public function add()
110110
$dbm = new DbManager($this->logger());
111111

112112
if (strtoupper(Settings::Get('customer.mysqlprefix')) == 'DBNAME' && !empty($databasename)) {
113+
if (strlen($newdb_params['loginname'] . '_' . $databasename) > Database::getSqlUsernameLength()) {
114+
throw new Exception("Database name cannot be longer than " . (Database::getSqlUsernameLength() - strlen($newdb_params['loginname'] . '_')) . " characters.", 406);
115+
}
113116
$username = $dbm->createDatabase($newdb_params['loginname'] . '_' . $databasename, $password, $dbserver);
114117
} else {
115118
$username = $dbm->createDatabase($newdb_params['loginname'], $password, $dbserver, $newdb_params['mysql_lastaccountnumber']);

lib/Froxlor/Database/DbManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
namespace Froxlor\Database;
2727

28+
use Exception;
2829
use Froxlor\Database\Manager\DbManagerMySQL;
2930
use Froxlor\Froxlor;
3031
use Froxlor\FroxlorLogger;
@@ -83,7 +84,7 @@ private function setManager()
8384
* @param array $mysql_access_host_array
8485
*
8586
* @return void
86-
* @throws \Exception
87+
* @throws Exception
8788
*/
8889
public static function correctMysqlUsers(array $mysql_access_host_array)
8990
{
@@ -150,6 +151,7 @@ public static function correctMysqlUsers(array $mysql_access_host_array)
150151
* @param int $last_accnumber
151152
*
152153
* @return string|bool $username if successful or false of username is equal to the password
154+
* @throws Exception
153155
*/
154156
public function createDatabase(string $loginname = null, string $password = null, int $dbserver = 0, int $last_accnumber = 0)
155157
{

0 commit comments

Comments
 (0)