diff --git a/db_operations.php b/db_operations.php index 7099be344e..12b2e1d5d3 100644 --- a/db_operations.php +++ b/db_operations.php @@ -21,6 +21,7 @@ require_once 'libraries/mysql_charsets.inc.php'; /** * functions implementation for this script */ +require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/operations.lib.php'; // add a javascript file for jQuery functions to handle Ajax actions diff --git a/db_routines.php b/db_routines.php index c273b7b291..be7791c649 100644 --- a/db_routines.php +++ b/db_routines.php @@ -16,6 +16,7 @@ require_once 'libraries/mysql_charsets.inc.php'; /** * Include all other files */ +require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/rte/rte_routines.lib.php'; /** diff --git a/doc/faq.rst b/doc/faq.rst index 69d9d55bc5..0bba9ced12 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -2065,6 +2065,13 @@ Notes: *column-related privileges* for the columns inside the table are also adjusted to the table's new name. +* While adjusting privileges, the user performing the operation **must** have the following + privileges: + + * SELECT, INSERT, UPDATE, DELETE privileges on following tables: + `mysql`.`db`, `mysql`.`columns_priv`, `mysql`.`tables_priv`, `mysql`.`procs_priv` + * FLUSH privilege (GLOBAL) + Thus, if you want to replicate the database/table/column/procedure as it is while renaming/copying/moving these objects, make sure you have checked this option. diff --git a/libraries/check_user_privileges.lib.php b/libraries/check_user_privileges.lib.php index aa118617e2..d03bb34c31 100644 --- a/libraries/check_user_privileges.lib.php +++ b/libraries/check_user_privileges.lib.php @@ -14,6 +14,208 @@ if (! defined('PHPMYADMIN')) { */ $GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser(); +/** + * Check if user has required privileges for + * performing 'FLUSH PRIVILEGES' operation + * + * @return void + */ +function PMA_checkRequiredPrivilegesForFlushing() +{ + + $res = $GLOBALS['dbi']->tryQuery( + 'FLUSH PRIVILEGES' + ); + + // Save the value + $GLOBALS['flush_priv'] = $res; +} + +/** + * Check if user has required privileges for + * performing 'Adjust Privileges' operations + * + * @return void + */ +function PMA_checkRequiredPrivilgesForAdjust() +{ + $privs_available = true; + // FOR DB PRIVS + $select_privs_available = $GLOBALS['dbi']->tryQuery( + 'SELECT * FROM `mysql`.`db` LIMIT 1' + ); + + $privs_available = $select_privs_available && $privs_available; + + if ($privs_available) { + $delete_privs_available = $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`db` WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" LIMIT 1;' + ); + $privs_available = $delete_privs_available && $privs_available; + } + + if ($privs_available) { + $insert_privs_available = $GLOBALS['dbi']->tryQuery( + 'INSERT INTO `mysql`.`db`(`host`, `Db`, `User`) VALUES("pma_test_host", ' + . '"mysql", "pma_test_user");' + ); + // If successful test insert, delete the test row + if ($insert_privs_available) { + $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`db` WHERE host = "pma_test_host" AND ' + . 'Db = "mysql" AND User = "pma_test_user" LIMIT 1;' + ); + } + $privs_available = $insert_privs_available && $privs_available; + } + + if ($privs_available) { + $update_privs_available = $GLOBALS['dbi']->tryQuery( + 'UPDATE `mysql`.`db` SET `host` = "" WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" LIMIT 1;' + ); + $privs_available = $update_privs_available && $privs_available; + } + // save the value + $GLOBALS['db_priv'] = $privs_available; + // reset the value + $privs_available = true; + + // FOR COLUMNS_PRIV + $select_privs_available = $GLOBALS['dbi']->tryQuery( + 'SELECT * FROM `mysql`.`columns_priv` LIMIT 1' + ); + + $privs_available = $select_privs_available && $privs_available; + + if ($privs_available) { + $delete_privs_available = $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`columns_priv` WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" LIMIT 1;' + ); + $privs_available = $delete_privs_available && $privs_available; + } + + if ($privs_available) { + $insert_privs_available = $GLOBALS['dbi']->tryQuery( + 'INSERT INTO `mysql`.`columns_priv`(`host`, `Db`, `User`, `Table_name`,' + . ' `Column_name`) VALUES("pma_test_host", ' + . '"mysql", "pma_test_user", "", "")' + ); + // If successful test insert, delete the test row + if ($insert_privs_available) { + $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`columns_priv` WHERE host = "pma_test_host" AND ' + . 'Db = "mysql" AND User = "pma_test_user" AND Table_name = ""' + . ' AND Column_name = "" LIMIT 1;' + ); + } + $privs_available = $insert_privs_available && $privs_available; + } + + if ($privs_available) { + $update_privs_available = $GLOBALS['dbi']->tryQuery( + 'UPDATE `mysql`.`columns_priv` SET `host` = "" WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" AND Column_name = "" AND Table_name = "" LIMIT 1;' + ); + $privs_available = $update_privs_available && $privs_available; + + } + // Save the value + $GLOBALS['col_priv'] = $privs_available; + // Reset the value + $privs_available = true; + + // FOR TABLES_PRIV + $select_privs_available = $GLOBALS['dbi']->tryQuery( + 'SELECT * FROM `mysql`.`tables_priv` LIMIT 1' + ); + + $privs_available = $select_privs_available && $privs_available; + + if ($privs_available) { + $delete_privs_available = $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`tables_priv` WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" AND Table_name = "" LIMIT 1;' + ); + $privs_available = $delete_privs_available && $privs_available; + } + + if ($privs_available) { + $insert_privs_available = $GLOBALS['dbi']->tryQuery( + 'INSERT INTO `mysql`.`tables_priv`(`host`, `Db`, `User`, `Table_name`' + . ') VALUES("pma_test_host", ' + . '"mysql", "pma_test_user", "")' + ); + // If successful test insert, delete the test row + if ($insert_privs_available) { + $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`tables_priv` WHERE host = "pma_test_host" AND ' + . 'Db = "mysql" AND User = "pma_test_user" AND Table_name = "" LIMIT 1;' + ); + } + $privs_available = $insert_privs_available && $privs_available; + } + + if ($privs_available) { + $update_privs_available = $GLOBALS['dbi']->tryQuery( + 'UPDATE `mysql`.`tables_priv` SET `host` = "" WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" AND Table_name = "" LIMIT 1;' + ); + $privs_available = $update_privs_available && $privs_available; + + } + // Save the value + $GLOBALS['table_priv'] = $privs_available; + // Reset the value + $privs_available = true; + + // FOR PROCS_PRIV + $select_privs_available = $GLOBALS['dbi']->tryQuery( + 'SELECT * FROM `mysql`.`procs_priv` LIMIT 1' + ); + + $privs_available = $select_privs_available && $privs_available; + + if ($privs_available) { + $delete_privs_available = $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`procs_priv` WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" AND `Routine_name` = ""' + . ' AND `Routine_type` = "" LIMIT 1;' + ); + $privs_available = $delete_privs_available && $privs_available; + } + + if ($privs_available) { + $insert_privs_available = $GLOBALS['dbi']->tryQuery( + 'INSERT INTO `mysql`.`procs_priv`(`host`, `Db`, `User`, `Routine_name`,' + . ' `Routine_type`) VALUES("pma_test_host", ' + . '"mysql", "pma_test_user", "", "PROCEDURE")' + ); + // If successful test insert, delete the test row + if ($insert_privs_available) { + $GLOBALS['dbi']->tryQuery( + 'DELETE FROM `mysql`.`procs_priv` WHERE `host` = "pma_test_host" AND ' + . '`Db` = "mysql" AND `User` = "pma_test_user" AND `Routine_name` = ""' + . ' AND `Routine_type` = "PROCEDURE" LIMIT 1;' + ); + } + $privs_available = $insert_privs_available && $privs_available; + } + + if ($privs_available) { + $update_privs_available = $GLOBALS['dbi']->tryQuery( + 'UPDATE `mysql`.`procs_priv` SET `host` = "" WHERE `host` = "" AND ' + . '`Db` = "" AND `User` = "" AND `Routine_name` = "" LIMIT 1;' + ); + $privs_available = $update_privs_available && $privs_available; + } + // Save the value + $GLOBALS['proc_priv'] = $privs_available; + +} + /** * sets privilege information extracted from SHOW GRANTS result * @@ -185,6 +387,13 @@ if (!PMA_DRIZZLE) { } else { PMA_analyseShowGrant(); } + + // Check if privileges to 'mysql'.col_privs, 'mysql'.db, + // 'mysql'.table_privs, 'mysql'.proc_privs and privileges for + // flushing the privileges are available + PMA_checkRequiredPrivilegesForFlushing(); + PMA_checkRequiredPrivilgesForAdjust(); + } else { // todo: for simple_user_policy only database with user's login can be created // (unless logged in as root) diff --git a/libraries/dbi/DBIDummy.class.php b/libraries/dbi/DBIDummy.class.php index 10323afe6d..7ac4c44155 100644 --- a/libraries/dbi/DBIDummy.class.php +++ b/libraries/dbi/DBIDummy.class.php @@ -559,6 +559,26 @@ $GLOBALS['dummy_queries'] = array( array( 'query' => "SHOW EVENTS FROM `default`", 'result' => array() + ), + array( + 'query' => "FLUSH PRIVILEGES", + 'result' => array() + ), + array( + 'query' => "SELECT * FROM `mysql`.`db` LIMIT 1", + 'result' => array() + ), + array( + 'query' => "SELECT * FROM `mysql`.`columns_priv` LIMIT 1", + 'result' => array() + ), + array( + 'query' => "SELECT * FROM `mysql`.`tables_priv` LIMIT 1", + 'result' => array() + ), + array( + 'query' => "SELECT * FROM `mysql`.`procs_priv` LIMIT 1", + 'result' => array() ) ); /** diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 9b938e3c48..44f80bd2c8 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -77,11 +77,31 @@ function PMA_getHtmlForRenameDatabase($db) $html_output .= ''; - $html_output .= ''; - $html_output .= '
'; + + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['db_priv']) && $GLOBALS['db_priv'] + && isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + + $html_output .= '
'; + } + $html_output .= '' . '' . '
' @@ -205,11 +225,30 @@ function PMA_getHtmlForCopyDatabase($db) $html_output .= '
'; $html_output .= '
'; - $html_output .= ''; - $html_output .= '
'; + + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['db_priv']) && $GLOBALS['db_priv'] + && isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + $html_output .= '
'; + } + $html_output .= 'selectDb('mysql'); + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['db_priv']) && $GLOBALS['db_priv'] + && isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $GLOBALS['dbi']->selectDb('mysql'); - // For Db specific privileges - $query_db_specific = 'UPDATE ' . PMA_Util::backquote('db') - . 'SET Db = "' . $newname - . '" where Db = "' . $oldDb . '";'; - $GLOBALS['dbi']->query($query_db_specific); + // For Db specific privileges + $query_db_specific = 'UPDATE ' . PMA_Util::backquote('db') + . 'SET Db = "' . $newname + . '" where Db = "' . $oldDb . '";'; + $GLOBALS['dbi']->query($query_db_specific); - // For table specific privileges - $query_table_specific = 'UPDATE ' . PMA_Util::backquote('tables_priv') - . 'SET Db = "' . $newname - . '" where Db = "' . $oldDb . '";'; - $GLOBALS['dbi']->query($query_table_specific); + // For table specific privileges + $query_table_specific = 'UPDATE ' . PMA_Util::backquote('tables_priv') + . 'SET Db = "' . $newname + . '" where Db = "' . $oldDb . '";'; + $GLOBALS['dbi']->query($query_table_specific); - // For column specific privileges - $query_col_specific = 'UPDATE ' . PMA_Util::backquote('columns_priv') - . 'SET Db = "' . $newname - . '" where Db = "' . $oldDb . '";'; - $GLOBALS['dbi']->query($query_col_specific); + // For column specific privileges + $query_col_specific = 'UPDATE ' . PMA_Util::backquote('columns_priv') + . 'SET Db = "' . $newname + . '" where Db = "' . $oldDb . '";'; + $GLOBALS['dbi']->query($query_col_specific); - // For procedures specific privileges - $query_proc_specific = 'UPDATE ' . PMA_Util::backquote('procs_priv') - . 'SET Db = "' . $newname - . '" where Db = "' . $oldDb . '";'; - $GLOBALS['dbi']->query($query_proc_specific); - - // Finally FLUSH the new privileges - $flush_query = "FLUSH PRIVILEGES;"; - $GLOBALS['dbi']->query($flush_query); + // For procedures specific privileges + $query_proc_specific = 'UPDATE ' . PMA_Util::backquote('procs_priv') + . 'SET Db = "' . $newname + . '" where Db = "' . $oldDb . '";'; + $GLOBALS['dbi']->query($query_proc_specific); + // Finally FLUSH the new privileges + $flush_query = "FLUSH PRIVILEGES;"; + $GLOBALS['dbi']->query($flush_query); + } + } } /** @@ -586,85 +633,92 @@ function PMA_AdjustPrivileges_moveDB($oldDb, $newname) */ function PMA_AdjustPrivileges_copyDB($oldDb, $newname) { + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['db_priv']) && $GLOBALS['db_priv'] + && isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $GLOBALS['dbi']->selectDb('mysql'); - $GLOBALS['dbi']->selectDb('mysql'); + $query_db_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('db') . ' WHERE ' + . 'Db = "' . $oldDb . '";'; - $query_db_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('db') . ' WHERE ' - . 'Db = "' . $oldDb . '";'; + $old_privs_db = $GLOBALS['dbi']->fetchResult($query_db_specific_old, 0); - $old_privs_db = $GLOBALS['dbi']->fetchResult($query_db_specific_old, 0); + foreach ($old_privs_db as $old_priv) { + $newDb_db_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('db') . ' VALUES("' + . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' + . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '", "' . $old_priv[7] . '", "' . $old_priv[8] . '", "' + . $old_priv[9] . '", "' . $old_priv[10] . '", "' . $old_priv[11] . '", "' + . $old_priv[12] . '", "' . $old_priv[13] . '", "' . $old_priv[14] . '", "' + . $old_priv[15] . '", "' . $old_priv[16] . '", "' . $old_priv[17] . '", "' + . $old_priv[18] . '", "' . $old_priv[19] . '", "' . $old_priv[20] . '", "' + . $old_priv[21] . '");'; - foreach ($old_privs_db as $old_priv) { - $newDb_db_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('db') . ' VALUES("' - . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' - . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '", "' . $old_priv[7] . '", "' . $old_priv[8] . '", "' - . $old_priv[9] . '", "' . $old_priv[10] . '", "' . $old_priv[11] . '", "' - . $old_priv[12] . '", "' . $old_priv[13] . '", "' . $old_priv[14] . '", "' - . $old_priv[15] . '", "' . $old_priv[16] . '", "' . $old_priv[17] . '", "' - . $old_priv[18] . '", "' . $old_priv[19] . '", "' . $old_priv[20] . '", "' - . $old_priv[21] . '");'; + $GLOBALS['dbi']->query($newDb_db_privs_query); + } - $GLOBALS['dbi']->query($newDb_db_privs_query); + // For Table Specific privileges + $query_table_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('tables_priv') . ' WHERE ' + . 'Db = "' . $oldDb . '";'; + + $old_privs_table = $GLOBALS['dbi']->fetchResult($query_table_specific_old, 0); + + foreach ($old_privs_table as $old_priv) { + $newDb_table_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('tables_priv') . ' VALUES("' + . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' + . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '", "' . $old_priv[7] . '");'; + + $GLOBALS['dbi']->query($newDb_table_privs_query); + } + + // For Column Specific privileges + $query_col_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('columns_priv') . ' WHERE ' + . 'Db = "' . $oldDb . '";'; + + $old_privs_col = $GLOBALS['dbi']->fetchResult($query_col_specific_old, 0); + + foreach ($old_privs_col as $old_priv) { + $newDb_col_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('columns_priv') . ' VALUES("' + . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' + . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '");'; + + $GLOBALS['dbi']->query($newDb_col_privs_query); + } + + // For Procedure Specific privileges + $query_proc_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('procs_priv') . ' WHERE ' + . 'Db = "' . $oldDb . '";'; + + $old_privs_proc = $GLOBALS['dbi']->fetchResult($query_proc_specific_old, 0); + + foreach ($old_privs_proc as $old_priv) { + $newDb_proc_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('procs_priv') . ' VALUES("' + . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' + . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '", "' . $old_priv[7] . '");'; + + $GLOBALS['dbi']->query($newDb_proc_privs_query); + } + + // Finally FLUSH the new privileges + $flush_query = "FLUSH PRIVILEGES;"; + $GLOBALS['dbi']->query($flush_query); + } } - - // For Table Specific privileges - $query_table_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('tables_priv') . ' WHERE ' - . 'Db = "' . $oldDb . '";'; - - $old_privs_table = $GLOBALS['dbi']->fetchResult($query_table_specific_old, 0); - - foreach ($old_privs_table as $old_priv) { - $newDb_table_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('tables_priv') . ' VALUES("' - . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' - . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '", "' . $old_priv[7] . '");'; - - $GLOBALS['dbi']->query($newDb_table_privs_query); - } - - // For Column Specific privileges - $query_col_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('columns_priv') . ' WHERE ' - . 'Db = "' . $oldDb . '";'; - - $old_privs_col = $GLOBALS['dbi']->fetchResult($query_col_specific_old, 0); - - foreach ($old_privs_col as $old_priv) { - $newDb_col_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('columns_priv') . ' VALUES("' - . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' - . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '");'; - - $GLOBALS['dbi']->query($newDb_col_privs_query); - } - - // For Procedure Specific privileges - $query_proc_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('procs_priv') . ' WHERE ' - . 'Db = "' . $oldDb . '";'; - - $old_privs_proc = $GLOBALS['dbi']->fetchResult($query_proc_specific_old, 0); - - foreach ($old_privs_proc as $old_priv) { - $newDb_proc_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('procs_priv') . ' VALUES("' - . $old_priv[0] . '", "' . $newname . '", "' . $old_priv[2] . '", "' - . $old_priv[3] . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '", "' . $old_priv[7] . '");'; - - $GLOBALS['dbi']->query($newDb_proc_privs_query); - } - - // Finally FLUSH the new privileges - $flush_query = "FLUSH PRIVILEGES;"; - $GLOBALS['dbi']->query($flush_query); - } /** @@ -789,15 +843,30 @@ function PMA_getHtmlForMoveTable() . 'value="1" id="checkbox_auto_increment_mv" checked="checked" />' . '
' - . '' - . '
' - . '
'; + . '
'; - $html_output .= '
' + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + $html_output .= '
'; + } + + $html_output .= '
' . '' . '
' . '' @@ -868,14 +937,30 @@ function PMA_getHtmlForRenameTable() . 'value="' . htmlspecialchars($GLOBALS['table']) . '" required="required" />' . '' - . '' - . '' - . '' - . '' - . ''; + . ''; + + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + $html_output .= ''; + } + + $html_output .= ''; return $html_output; } @@ -1207,11 +1292,27 @@ function PMA_getHtmlForCopytable() } // endif $html_output .= '
'; - $html_output .= '' - . '
'; + + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $html_output .= ''; + } else { + $html_output .= ''; + } + $html_output .= '
'; + } if (isset($_COOKIE['pma_switch_to_new']) && $_COOKIE['pma_switch_to_new'] == 'true' @@ -1844,24 +1945,30 @@ function PMA_getQueryAndResultForPartition() */ function PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $newDb, $newTable) { - $GLOBALS['dbi']->selectDb('mysql'); + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $GLOBALS['dbi']->selectDb('mysql'); - // For table specific privileges - $query_table_specific = 'UPDATE ' . PMA_Util::backquote('tables_priv') - . 'SET Db = "' . $newDb . '", Table_name = "' . $newTable - . '" where Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; - $GLOBALS['dbi']->query($query_table_specific); + // For table specific privileges + $query_table_specific = 'UPDATE ' . PMA_Util::backquote('tables_priv') + . 'SET Db = "' . $newDb . '", Table_name = "' . $newTable + . '" where Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; + $GLOBALS['dbi']->query($query_table_specific); - // For column specific privileges - $query_col_specific = 'UPDATE ' . PMA_Util::backquote('columns_priv') - . 'SET Db = "' . $newDb . '", Table_name = "' . $newTable - . '" where Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; - $GLOBALS['dbi']->query($query_col_specific); - - // Finally FLUSH the new privileges - $flush_query = "FLUSH PRIVILEGES;"; - $GLOBALS['dbi']->query($flush_query); + // For column specific privileges + $query_col_specific = 'UPDATE ' . PMA_Util::backquote('columns_priv') + . 'SET Db = "' . $newDb . '", Table_name = "' . $newTable + . '" where Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; + $GLOBALS['dbi']->query($query_col_specific); + // Finally FLUSH the new privileges + $flush_query = "FLUSH PRIVILEGES;"; + $GLOBALS['dbi']->query($flush_query); + } + } } /** @@ -1876,46 +1983,52 @@ function PMA_AdjustPrivileges_renameOrMoveTable($oldDb, $oldTable, $newDb, $newT */ function PMA_AdjustPrivileges_copyTable($oldDb, $oldTable, $newDb, $newTable) { - $GLOBALS['dbi']->selectDb('mysql'); + if (! PMA_DRIZZLE) { + if (isset($GLOBALS['table_priv']) && $GLOBALS['table_priv'] + && isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $GLOBALS['dbi']->selectDb('mysql'); - // For Table Specific privileges - $query_table_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('tables_priv') . ' where ' - . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; + // For Table Specific privileges + $query_table_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('tables_priv') . ' where ' + . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; - $old_privs_table = $GLOBALS['dbi']->fetchResult($query_table_specific_old, 0); + $old_privs_table = $GLOBALS['dbi']->fetchResult($query_table_specific_old, 0); - foreach ($old_privs_table as $old_priv) { - $newDb_table_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('tables_priv') . ' VALUES("' - . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "' - . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '", "' . $old_priv[7] . '");'; + foreach ($old_privs_table as $old_priv) { + $newDb_table_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('tables_priv') . ' VALUES("' + . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "' + . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '", "' . $old_priv[7] . '");'; - $GLOBALS['dbi']->query($newDb_table_privs_query); + $GLOBALS['dbi']->query($newDb_table_privs_query); + } + + // For Column Specific privileges + $query_col_specific_old = 'SELECT * FROM ' + . PMA_Util::backquote('columns_priv') . ' WHERE ' + . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; + + $old_privs_col = $GLOBALS['dbi']->fetchResult($query_col_specific_old, 0); + + foreach ($old_privs_col as $old_priv) { + $newDb_col_privs_query = 'INSERT INTO ' + . PMA_Util::backquote('columns_priv') . ' VALUES("' + . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "' + . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' + . $old_priv[6] . '");'; + + $GLOBALS['dbi']->query($newDb_col_privs_query); + } + + // Finally FLUSH the new privileges + $flush_query = "FLUSH PRIVILEGES;"; + $GLOBALS['dbi']->query($flush_query); + } } - - // For Column Specific privileges - $query_col_specific_old = 'SELECT * FROM ' - . PMA_Util::backquote('columns_priv') . ' WHERE ' - . 'Db = "' . $oldDb . '" AND Table_name = "' . $oldTable . '";'; - - $old_privs_col = $GLOBALS['dbi']->fetchResult($query_col_specific_old, 0); - - foreach ($old_privs_col as $old_priv) { - $newDb_col_privs_query = 'INSERT INTO ' - . PMA_Util::backquote('columns_priv') . ' VALUES("' - . $old_priv[0] . '", "' . $newDb . '", "' . $old_priv[2] . '", "' - . $newTable . '", "' . $old_priv[4] . '", "' . $old_priv[5] . '", "' - . $old_priv[6] . '");'; - - $GLOBALS['dbi']->query($newDb_col_privs_query); - } - - // Finally FLUSH the new privileges - $flush_query = "FLUSH PRIVILEGES;"; - $GLOBALS['dbi']->query($flush_query); - } /** diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index eac86e3792..8f2db513ac 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -301,21 +301,28 @@ function PMA_RTN_handleEditor() $db, $_REQUEST['item_original_type'], $_REQUEST['item_original_name'] ); - // Backup the Old Privileges before dropping - // if $_REQUEST['item_adjust_privileges'] set - $privilegesBackup = array(); - if (isset($_REQUEST['item_adjust_privileges']) - && ! empty($_REQUEST['item_adjust_privileges']) - ) { - $privilegesBackupQuery = 'SELECT * FROM ' . PMA_Util::backquote('mysql') - . '.' . PMA_Util::backquote('procs_priv') - . ' where Routine_name = "' . $_REQUEST['item_original_name'] - . '" AND Routine_type = "' . $_REQUEST['item_original_type'] - . '";'; - $privilegesBackup = $GLOBALS['dbi']->fetchResult( - $privilegesBackupQuery, 0 - ); + if (! defined('PMA_DRIZZLE') || ! PMA_DRIZZLE) { + if (isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + // Backup the Old Privileges before dropping + // if $_REQUEST['item_adjust_privileges'] set + $privilegesBackup = array(); + if (isset($_REQUEST['item_adjust_privileges']) + && ! empty($_REQUEST['item_adjust_privileges']) + ) { + $privilegesBackupQuery = 'SELECT * FROM ' . PMA_Util::backquote('mysql') + . '.' . PMA_Util::backquote('procs_priv') + . ' where Routine_name = "' . $_REQUEST['item_original_name'] + . '" AND Routine_type = "' . $_REQUEST['item_original_type'] + . '";'; + + $privilegesBackup = $GLOBALS['dbi']->fetchResult( + $privilegesBackupQuery, 0 + ); + } + } } $drop_routine = "DROP {$_REQUEST['item_original_type']} " @@ -355,23 +362,30 @@ function PMA_RTN_handleEditor() // Default value $resultAdjust = false; - // Insert all the previous privileges - // but with the new name and the new type - foreach ($privilegesBackup as $priv) { - $adjustProcPrivilege = 'INSERT INTO ' - . PMA_Util::backquote('mysql') . '.' - . PMA_Util::backquote('procs_priv') - . ' VALUES("' . $priv[0] . '", "' - . $priv[1] . '", "' . $priv[2] . '", "' - . $_REQUEST['item_name'] . '", "' - . $_REQUEST['item_type'] . '", "' - . $priv[5] . '", "' - . $priv[6] . '", "' - . $priv[7] . '");'; - $resultAdjust = $GLOBALS['dbi']->query( - $adjustProcPrivilege - ); + if (! defined('PMA_DRIZZLE') || ! PMA_DRIZZLE) { + if (isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + // Insert all the previous privileges + // but with the new name and the new type + foreach ($privilegesBackup as $priv) { + $adjustProcPrivilege = 'INSERT INTO ' + . PMA_Util::backquote('mysql') . '.' + . PMA_Util::backquote('procs_priv') + . ' VALUES("' . $priv[0] . '", "' + . $priv[1] . '", "' . $priv[2] . '", "' + . $_REQUEST['item_name'] . '", "' + . $_REQUEST['item_type'] . '", "' + . $priv[5] . '", "' + . $priv[6] . '", "' + . $priv[7] . '");'; + $resultAdjust = $GLOBALS['dbi']->query( + $adjustProcPrivilege + ); + } + } } + if ($resultAdjust) { // Flush the Privileges $flushPrivQuery = 'FLUSH PRIVILEGES;'; @@ -1101,10 +1115,25 @@ function PMA_RTN_getEditorForm($mode, $operation, $routine) $retval .= " " . __('Adjust Privileges'); $retval .= PMA_Util::showDocu('faq', 'faq6-39'); $retval .= ""; - $retval .= " "; + if (! defined('PMA_DRIZZLE') || ! PMA_DRIZZLE) { + if (isset($GLOBALS['proc_priv']) && $GLOBALS['proc_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { + $retval .= " "; + } else { + $retval .= " "; + } + } $retval .= ""; } + $retval .= ""; $retval .= " " . __('Definer') . ""; $retval .= " selectDb('mysql'); + if (! defined('PMA_DRIZZLE') || ! PMA_DRIZZLE) { + if (isset($GLOBALS['col_priv']) && $GLOBALS['col_priv'] + && isset($GLOBALS['flush_priv']) && $GLOBALS['flush_priv'] + ) { - // For Column specific privileges - foreach ($adjust_privileges as $oldCol => $newCol) { - $query_adjust_col_privileges = 'UPDATE ' - . PMA_Util::backquote('columns_priv') . ' ' - . 'SET Column_name = "' . $newCol . '" ' - . 'WHERE Db = "' . $db . '" AND Table_name = "' . $table - . '" AND Column_name = "' . $oldCol . '";'; + $GLOBALS['dbi']->selectDb('mysql'); - $GLOBALS['dbi']->query($query_adjust_col_privileges); + // For Column specific privileges + foreach ($adjust_privileges as $oldCol => $newCol) { + $query_adjust_col_privileges = 'UPDATE ' + . PMA_Util::backquote('columns_priv') . ' ' + . 'SET Column_name = "' . $newCol . '" ' + . 'WHERE Db = "' . $db . '" AND Table_name = "' . $table + . '" AND Column_name = "' . $oldCol . '";'; - // i.e. if atleast one column privileges adjusted - $changed = true; - } + $GLOBALS['dbi']->query($query_adjust_col_privileges); - if ($changed) { - // Finally FLUSH the new privileges - $flushPrivQuery = "FLUSH PRIVILEGES;"; - $GLOBALS['dbi']->query($flushPrivQuery); + // i.e. if atleast one column privileges adjusted + $changed = true; + } + + if ($changed) { + // Finally FLUSH the new privileges + $flushPrivQuery = "FLUSH PRIVILEGES;"; + $GLOBALS['dbi']->query($flushPrivQuery); + } + } } return $changed; diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index 933536901a..96fbcafef8 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -411,7 +411,8 @@ $html = PMA\Template::get('columns_definitions/column_definitions_form') 'mimework' => $cfgRelation['mimework'], 'action' => $action, 'form_params' => $form_params, - 'content_cells' => $content_cells + 'content_cells' => $content_cells, + 'privs_available' => $privs_available )); unset($form_params); diff --git a/tbl_operations.php b/tbl_operations.php index d070298753..855a16e38a 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -14,6 +14,7 @@ require_once 'libraries/common.inc.php'; /** * functions implementation for this script */ +require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/operations.lib.php'; $pma_table = new PMA_Table($GLOBALS['table'], $GLOBALS['db']); diff --git a/tbl_structure.php b/tbl_structure.php index 53e023e43a..197495fc13 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -19,6 +19,7 @@ PMA_PageSettings::showGroup('TableStructure'); /** * Function implementations for this script */ +require_once 'libraries/check_user_privileges.lib.php'; require_once 'libraries/structure.lib.php'; require_once 'libraries/index.lib.php'; require_once 'libraries/sql.lib.php'; diff --git a/templates/columns_definitions/column_adjust_privileges.phtml b/templates/columns_definitions/column_adjust_privileges.phtml index a8397cfc84..6b90eff0d2 100644 --- a/templates/columns_definitions/column_adjust_privileges.phtml +++ b/templates/columns_definitions/column_adjust_privileges.phtml @@ -1,6 +1,18 @@ - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/templates/columns_definitions/column_attributes.phtml b/templates/columns_definitions/column_attributes.phtml index 10d832bd94..eb4049c463 100644 --- a/templates/columns_definitions/column_attributes.phtml +++ b/templates/columns_definitions/column_attributes.phtml @@ -84,14 +84,17 @@ $ci_offset = -1; 'columnMeta' => isset($columnMeta) ? $columnMeta : null )); ?> - + + render(array( 'columnNumber' => $columnNumber, 'ci' => $ci++, - 'ci_offset' => $ci_offset + 'ci_offset' => $ci_offset, + 'privs_available' => $privs_available )); ?>