Skip to content

Commit

Permalink
check custom database-name against supported maximum length of userna…
Browse files Browse the repository at this point in the history
…me/databasename of used dbms, fixes #1258

Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Jun 25, 2024
1 parent 10e87a9 commit 1d246fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/Froxlor/Api/Commands/Mysqls.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand Down
4 changes: 3 additions & 1 deletion lib/Froxlor/Database/DbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace Froxlor\Database;

use Exception;
use Froxlor\Database\Manager\DbManagerMySQL;
use Froxlor\Froxlor;
use Froxlor\FroxlorLogger;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 1d246fe

Please sign in to comment.