diff --git a/ChangeLog b/ChangeLog index 5f84e38c9..48d6588ea 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ phpMyAdmin - Changelog $Id$ $Source$ +2002-12-25 Alexander M. Turek + * server_privileges.php3: + - Made the script compatible to MySQL < 3.22.11; + - Fixed the missing "LOCK TABLES" option in the privilege editor. + 2002-12-23 Alexander M. Turek * lang/italian-*.inc.php3: Updates, thanks again to Pietro Danesi (danone). diff --git a/server_privileges.php3 b/server_privileges.php3 index 3a24f10d0..19bfb926b 100644 --- a/server_privileges.php3 +++ b/server_privileges.php3 @@ -66,7 +66,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = FALSE) } else { $privs[] = 'USAGE'; } - } else if ($allPrivileges && (!isset($GLOBALS['grant_count']) || count($privs) == $GLOBALS['grant_count'])) { + } else if ($allPrivileges && isset($GLOBALS['grant_count']) && count($privs) == $GLOBALS['grant_count']) { if ($enableHTML) { $privs = array('ALL PRIVILEGES'); } else { @@ -83,36 +83,53 @@ if (!empty($update_privs)) { if (empty($hostname)) { $hostname = '%'; } - $sql_query0 = 'REVOKE ALL PRIVILEGES ON *.* FROM "' . $username . '"@"' . $hostname . '";'; - $sql_query1 = 'REVOKE GRANT OPTION ON *.* FROM "' . $username . '"@"' . $hostname . '";'; - $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO "' . $username . '"@"' . $hostname . '"'; - if (isset($Grant_priv) || isset($max_questions) || isset($max_connections) || isset($max_updates)) { - $sql_query2 .= 'WITH'; - if (isset($Grant_priv) && $Grant_priv == 'Y') { - $sql_query2 .= ' GRANT OPTION'; + if (PMA_MYSQL_INT_VERSION >= 32211) { + $sql_query0 = 'REVOKE ALL PRIVILEGES ON *.* FROM "' . $username . '"@"' . $hostname . '";'; + $sql_query1 = 'REVOKE GRANT OPTION ON *.* FROM "' . $username . '"@"' . $hostname . '";'; + $sql_query2 = 'GRANT ' . join(', ', PMA_extractPrivInfo()) . ' ON *.* TO "' . $username . '"@"' . $hostname . '"'; + if (isset($Grant_priv) || isset($max_questions) || isset($max_connections) || isset($max_updates)) { + $sql_query2 .= 'WITH'; + if (isset($Grant_priv) && $Grant_priv == 'Y') { + $sql_query2 .= ' GRANT OPTION'; + } + if (isset($max_questions)) { + $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions; + } + if (isset($max_connections)) { + $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections; + } + if (isset($max_updates)) { + $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates; + } } - if (isset($max_questions)) { - $sql_query2 .= ' MAX_QUERIES_PER_HOUR ' . (int)$max_questions; + $sql_query2 .= ';'; + if (!@PMA_mysql_query($sql_query0, $userlink)) { + PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query0); } - if (isset($max_connections)) { - $sql_query2 .= ' MAX_CONNECTIONS_PER_HOUR ' . (int)$max_connections; + if (!@PMA_mysql_query($sql_query1, $userlink)) { + PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query1); } - if (isset($max_updates)) { - $sql_query2 .= ' MAX_UPDATES_PER_HOUR ' . (int)$max_updates; + if (!@PMA_mysql_query($sql_query2, $userlink)) { + PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query2); } + $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2; + $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\''); + } else { + $sql_query = 'SHOW COLUMNS FROM `user`;'; + $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + $grants = array(); + while ($row = PMA_mysql_fetch_row($res)) { + if (substr($row[0], -5) == '_priv') { + $grants[] = PMA_backquote($row[0]) . ' = "' . (empty($$row[0]) ? 'N' : 'Y') . '"'; + } + } + mysql_free_result($res); + unset($res); + unset($row); + $sql_query = 'UPDATE `user` SET ' . join(', ', $grants) . ' WHERE `User` = "' . $username . '" AND `Host` = "' . $hostname . '";'; + PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink)); + $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\'') . '
' . "\n" . $strRememberReload; } - $sql_query2 .= ';'; - if (!@PMA_mysql_query($sql_query0, $userlink)) { - PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query0); - } - if (!@PMA_mysql_query($sql_query1, $userlink)) { - PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query1); - } - if (!@PMA_mysql_query($sql_query2, $userlink)) { - PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query2); - } - $sql_query = $sql_query0 . ' ' . $sql_query1 . ' ' . $sql_query2; - $message = sprintf($strUpdatePrivMessage, '\'' . $username . '\'@\'' . $hostname . '\''); } /** @@ -356,9 +373,6 @@ if (!isset($username) && !isset($hostname)) { array('Delete', 'DELETE', $strPrivDescDelete), array('File', 'FILE', $strPrivDescFile) ); - if (isset($row['Lock_tables_priv'])) { - $privDataAccess[1][] = array('Lock_tables', 'LOCK TABLES', $strPrivDescLockTables); - } $privTable[1] = array( array('Create', 'CREATE', $strPrivDescCreateDb), array('Alter', 'ALTER', $strPrivDescAlter), @@ -383,6 +397,9 @@ if (!isset($username) && !isset($hostname)) { if (isset($row['Show_db_priv'])) { $privTable[2][] = array('Show_db', 'SHOW DATABASES', $strPrivDescShowDb); } + if (isset($row['Lock_tables_priv'])) { + $privTable[2][] = array('Lock_tables', 'LOCK TABLES', $strPrivDescLockTables); + } $privTable[2][] = array('References', 'REFERENCES', $strPrivDescReferences); if (isset($row['Execute_priv'])) { $privTable[2][] = array('Execute', 'EXECUTE', $strPrivDescExecute); @@ -397,11 +414,11 @@ if (!isset($username) && !isset($hostname)) { . ' ' . "\n" . ' ' . "\n" . ' ' . "\n" - . ' ' . "\n"; + . ' ' . "\n"; if ($hostname != '%') { - echo ' ' . "\n"; + echo ' ' . "\n"; } - echo ' ' . "\n" + echo ' ' . "\n" . ' ' . $strEditPrivileges . '
' . "\n" . ' ' . "\n" . ' ' . "\n"