froxlor / Froxlor

The server administration software for your needs - The official Froxlor development Git repository
http://www.froxlor.org
GNU General Public License v2.0
1.63k stars 454 forks source link

wrong MySQL/MariaDB version comparison in DbManagerMySQL.php #1265

Closed GuentherMair closed 1 month ago

GuentherMair commented 1 month ago

An SQL error is displayed when trying to remove a customer.

System information

To Reproduce Steps to reproduce the behavior:

  1. Go to 'Customers'
  2. Click on 'Delete'
  3. Confirm
  4. See error :-)

Expected behavior The user should be removed without stopping the execution.

Logfiles SQLSTATE[42000]: Syntax error or access violation: 1141 There is no such grant defined for user 'XYZ' on host 'A.B.C.D'

Additional context The code in lib/Froxlor/Database/Manager/DbManagerMySQL.php @ 190 compares the PDO::ATTR_SERVER_VERSION to the simple string '5.0.2':

if (Database::getAttribute(PDO::ATTR_SERVER_VERSION) < '5.0.2') {
        // Revoke privileges (only required for MySQL 4.1.2 - 5.0.1)
        $stmt = Database::prepare("REVOKE ALL PRIVILEGES ON * . * FROM `" . $username . "`@`" . $host . "`");
        Database::pexecute($stmt);
}

The comparison should make use of version_compare() as on line 196:

// as of MySQL 5.0.2 this also revokes privileges. (requires MySQL 4.1.2+)
if (version_compare(Database::getAttribute(PDO::ATTR_SERVER_VERSION), '5.7.0', '<')) {
        $stmt = Database::prepare("DROP USER :username@:host");
} else {
        $stmt = Database::prepare("DROP USER IF EXISTS :username@:host");
}
Database::pexecute($stmt, [
        "username" => $username,
        "host" => $host
]);
d00p commented 1 month ago

fixed in https://github.com/froxlor/Froxlor/commit/5d2ce4ecfb0e9c397ef5c73b107fb9a0e122e910