diff --git a/install/updates/froxlor/update_2.2.inc.php b/install/updates/froxlor/update_2.2.inc.php index 4c4529b8..a5691e17 100644 --- a/install/updates/froxlor/update_2.2.inc.php +++ b/install/updates/froxlor/update_2.2.inc.php @@ -226,7 +226,7 @@ if (Froxlor::isDatabaseVersion('202411200')) { $current_allowed_mysqlserver = !empty($customer['allowed_mysqlserver']) ? json_decode($customer['allowed_mysqlserver'], true) : []; foreach ($current_allowed_mysqlserver as $dbserver) { // require privileged access for target db-server - Database::needRoot(true, $dbserver, true); + Database::needRoot(true, $dbserver, false); // get DbManager $dbm = new DbManager(FroxlorLogger::getInstanceOf()); foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) { diff --git a/lib/Froxlor/Database/Database.php b/lib/Froxlor/Database/Database.php index 2c42fb14..a8bf0bd4 100644 --- a/lib/Froxlor/Database/Database.php +++ b/lib/Froxlor/Database/Database.php @@ -377,6 +377,14 @@ class Database self::$link = null; } + /** + * get the currently used database-server (relevant for root-connection) + */ + public static function getServer() + { + return self::$dbserver; + } + /** * enable the temporary access to sql-access data * note: if you want root-sqldata you need to diff --git a/lib/Froxlor/Database/Manager/DbManagerMySQL.php b/lib/Froxlor/Database/Manager/DbManagerMySQL.php index b73992a4..1cf3f61c 100644 --- a/lib/Froxlor/Database/Manager/DbManagerMySQL.php +++ b/lib/Froxlor/Database/Manager/DbManagerMySQL.php @@ -327,11 +327,17 @@ class DbManagerMySQL */ private function grantCreateToCustomerDbs(string $username, string $access_host) { + // remember what (possible remote) db-server we're on + $currentDbServer = Database::getServer(); + // use "unprivileged" connection + Database::needRoot(); $cus_stmt = Database::prepare("SELECT customerid FROM `" . TABLE_PANEL_CUSTOMERS . "` WHERE loginname = :username"); $cust = Database::pexecute_first($cus_stmt, ['username' => $username]); if ($cust) { - $sel_stmt = Database::prepare("SELECT databasename FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid` = :cid"); - Database::pexecute($sel_stmt, ['cid' => $cust['customerid']]); + $sel_stmt = Database::prepare("SELECT databasename FROM `" . TABLE_PANEL_DATABASES . "` WHERE `customerid` = :cid AND `dbserver` = :dbserver"); + Database::pexecute($sel_stmt, ['cid' => $cust['customerid'], 'dbserver' => $currentDbServer]); + // reset to root-connection for used dbserver + Database::needRoot(true, $currentDbServer, false); while ($dbdata = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) { $stmt = Database::prepare(" GRANT ALL ON `" . $dbdata['databasename'] . "`.* TO :username@:host