let's try to fix the mysql-user-create/update issue, fingers crossed; refs #758
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -78,13 +78,17 @@ class DbManagerMySQL
|
|||||||
public function grantPrivilegesTo($username = null, $password = null, $access_host = null, $p_encrypted = false, $update = false)
|
public function grantPrivilegesTo($username = null, $password = null, $access_host = null, $p_encrypted = false, $update = false)
|
||||||
{
|
{
|
||||||
if (! $update) {
|
if (! $update) {
|
||||||
// mysql8 compatibility
|
|
||||||
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '8.0.11', '>=')) {
|
|
||||||
// create user
|
// create user
|
||||||
if ($p_encrypted) {
|
if ($p_encrypted) {
|
||||||
|
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.0', '<')) {
|
||||||
|
$stmt = Database::prepare("
|
||||||
|
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY PASSWORD :password
|
||||||
|
");
|
||||||
|
} else {
|
||||||
$stmt = Database::prepare("
|
$stmt = Database::prepare("
|
||||||
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED WITH mysql_native_password AS :password
|
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED WITH mysql_native_password AS :password
|
||||||
");
|
");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$stmt = Database::prepare("
|
$stmt = Database::prepare("
|
||||||
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY :password
|
CREATE USER '" . $username . "'@'" . $access_host . "' IDENTIFIED BY :password
|
||||||
@@ -102,24 +106,7 @@ class DbManagerMySQL
|
|||||||
"host" => $access_host
|
"host" => $access_host
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// grant privileges
|
// set password
|
||||||
if ($p_encrypted) {
|
|
||||||
$stmt = Database::prepare("
|
|
||||||
GRANT ALL PRIVILEGES ON `" . $username . "`.* TO :username@:host IDENTIFIED WITH mysql_native_password AS :password
|
|
||||||
");
|
|
||||||
} else {
|
|
||||||
$stmt = Database::prepare("
|
|
||||||
GRANT ALL PRIVILEGES ON `" . $username . "`.* TO :username@:host IDENTIFIED BY :password
|
|
||||||
");
|
|
||||||
}
|
|
||||||
Database::pexecute($stmt, array(
|
|
||||||
"username" => $username,
|
|
||||||
"host" => $access_host,
|
|
||||||
"password" => $password
|
|
||||||
));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// set passoword
|
|
||||||
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) {
|
if (version_compare(Database::getAttribute(\PDO::ATTR_SERVER_VERSION), '5.7.6', '<')) {
|
||||||
if ($p_encrypted) {
|
if ($p_encrypted) {
|
||||||
$stmt = Database::prepare("SET PASSWORD FOR :username@:host = :password");
|
$stmt = Database::prepare("SET PASSWORD FOR :username@:host = :password");
|
||||||
@@ -174,7 +161,6 @@ class DbManagerMySQL
|
|||||||
), false);
|
), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$drop_stmt = Database::prepare("DROP DATABASE IF EXISTS `" . $dbname . "`");
|
$drop_stmt = Database::prepare("DROP DATABASE IF EXISTS `" . $dbname . "`");
|
||||||
Database::pexecute($drop_stmt);
|
Database::pexecute($drop_stmt);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,13 +183,21 @@ class MysqlsTest extends TestCase
|
|||||||
$this->assertNotEmpty($data['password'], 'No password for user "' . $user . '"');
|
$this->assertNotEmpty($data['password'], 'No password for user "' . $user . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (TRAVIS_CI == 0) {
|
||||||
|
// just to be sure, not required for travis as the vm is fresh every time
|
||||||
|
Database::needRoot(true);
|
||||||
|
Database::query("DROP USER IF EXISTS froxlor010@10.0.0.10;");
|
||||||
|
}
|
||||||
|
|
||||||
// grant privileges to another host
|
// grant privileges to another host
|
||||||
$testdata = $users['froxlor010'];
|
$testdata = $users['froxlor010'];
|
||||||
$dbm->getManager()->grantPrivilegesTo('froxlor010', $testdata['password'], '10.0.0.10', true);
|
$dbm->getManager()->grantPrivilegesTo('froxlor010', $testdata['password'], '10.0.0.10', true);
|
||||||
|
|
||||||
// select all entries from mysql.user for froxlor010 to compare password-hashes
|
// select all entries from mysql.user for froxlor010 to compare password-hashes
|
||||||
$sel_stmt = Database::prepare("SELECT * FROM mysql.user WHERE `User` = :usr");
|
$sel_stmt = Database::prepare("SELECT * FROM mysql.user WHERE `User` = :usr");
|
||||||
Database::pexecute($sel_stmt, ['usr' => 'froxlor010']);
|
Database::pexecute($sel_stmt, [
|
||||||
|
'usr' => 'froxlor010'
|
||||||
|
]);
|
||||||
$results = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
$results = $sel_stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||||
foreach ($results as $user) {
|
foreach ($results as $user) {
|
||||||
$passwd = $user['Password'] ?? $user['authentication_string'];
|
$passwd = $user['Password'] ?? $user['authentication_string'];
|
||||||
|
|||||||
Reference in New Issue
Block a user