Skip to content

Commit

Permalink
adjust permissions for customer global mysql user to access existing …
Browse files Browse the repository at this point in the history
…databases

Signed-off-by: Michael Kaufmann <[email protected]>
  • Loading branch information
d00p committed Dec 3, 2024
1 parent 079047b commit a839d76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion install/updates/froxlor/update_2.2.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Froxlor\Database\Database;
use Froxlor\Database\DbManager;
use Froxlor\Froxlor;
use Froxlor\FroxlorLogger;
use Froxlor\Install\Update;
use Froxlor\Settings;

Expand Down Expand Up @@ -227,7 +228,7 @@
// require privileged access for target db-server
Database::needRoot(true, $dbserver, true);
// get DbManager
$dbm = new DbManager($this->logger());
$dbm = new DbManager(FroxlorLogger::getInstanceOf());
foreach (array_map('trim', explode(',', Settings::Get('system.mysql_access_host'))) as $mysql_access_host) {
if ($dbm->getManager()->userExistsOnHost($customer['loginname'], $mysql_access_host)) {
// deactivate temporarily
Expand Down
5 changes: 3 additions & 2 deletions lib/Froxlor/Database/Manager/DbManagerMySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ private function grantCreateToCustomerDbs(string $username, string $access_host)
Database::pexecute($sel_stmt, ['cid' => $cust['customerid']]);
while ($dbdata = $sel_stmt->fetch(\PDO::FETCH_ASSOC)) {
$stmt = Database::prepare("
GRANT CREATE ON `" . $dbdata['databasename'] . "`.* TO :username@:host
GRANT ALL ON `" . $dbdata['databasename'] . "`.* TO :username@:host
");
Database::pexecute($stmt, [
"username" => $username,
Expand All @@ -348,14 +348,15 @@ private function grantCreateToCustomerDbs(string $username, string $access_host)
* grant "CREATE" for prefix user to all existing databases of that customer
*
* @param string $username
* @param string $database
* @param string $access_host
* @return void
* @throws \Exception
*/
public function grantCreateToDb(string $username, string $database, string $access_host)
{
$stmt = Database::prepare("
GRANT CREATE ON `" . $database . "`.* TO :username@:host
GRANT ALL ON `" . $database . "`.* TO :username@:host
");
Database::pexecute($stmt, [
"username" => $username,
Expand Down

0 comments on commit a839d76

Please sign in to comment.