diff --git a/db_operations.php b/db_operations.php index 7ba8b094e1f3..591aff3582f0 100644 --- a/db_operations.php +++ b/db_operations.php @@ -261,7 +261,7 @@ // Don't even try to drop information_schema. // You won't be able to. Believe me. You won't. // Don't allow to easily drop mysql database, RFE #1327514. - if (($is_superuser || $GLOBALS['cfg']['AllowUserDropDatabase']) + if (($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) && ! $db_is_system_schema && $GLOBALS['db'] != 'mysql' ) { diff --git a/import.php b/import.php index 1e00db8e1bc2..0f522176498e 100644 --- a/import.php +++ b/import.php @@ -683,7 +683,7 @@ // Check if User is allowed to issue a 'DROP DATABASE' Statement if (Sql::hasNoRightsToDropDatabase( - $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['is_superuser'] + $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['dbi']->isSuperuser() )) { PhpMyAdmin\Util::mysqlDie( __('"DROP DATABASE" statements are disabled.'), diff --git a/libraries/check_user_privileges.inc.php b/libraries/check_user_privileges.inc.php index 976776676c50..61caf8d13033 100644 --- a/libraries/check_user_privileges.inc.php +++ b/libraries/check_user_privileges.inc.php @@ -11,8 +11,6 @@ use PhpMyAdmin\CheckUserPrivileges; -$GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser(); - list($username, $hostname) = $GLOBALS['dbi']->getCurrentUserAndHost(); if ($username === '') { // MySQL is started with --skip-grant-tables $GLOBALS['is_create_db_priv'] = true; diff --git a/libraries/classes/Controllers/Server/ServerDatabasesController.php b/libraries/classes/Controllers/Server/ServerDatabasesController.php index 1748e14da76d..74b4e6d7190d 100644 --- a/libraries/classes/Controllers/Server/ServerDatabasesController.php +++ b/libraries/classes/Controllers/Server/ServerDatabasesController.php @@ -63,7 +63,7 @@ public function indexAction() if (isset($_REQUEST['drop_selected_dbs']) && $response->isAjax() - && ($GLOBALS['is_superuser'] || $GLOBALS['cfg']['AllowUserDropDatabase']) + && ($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) ) { $this->dropDatabasesAction(); return; @@ -384,7 +384,7 @@ private function _getColumnOrder() */ private function _getHtmlForTableFooterButtons() { - if (! $GLOBALS['is_superuser'] + if (! $GLOBALS['dbi']->isSuperuser() && ! $GLOBALS['cfg']['AllowUserDropDatabase'] ) { return ''; diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index 2ad9849ba5f8..13a1ae6fa551 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -295,7 +295,6 @@ public function indexAction() $db = $this->db; $table = $this->table; $cfg = $GLOBALS['cfg']; - $is_superuser = $GLOBALS['dbi']->isSuperuser(); $pmaThemeImage = $GLOBALS['pmaThemeImage']; include 'sql.php'; $GLOBALS['reload'] = true; diff --git a/libraries/classes/Display/ChangePassword.php b/libraries/classes/Display/ChangePassword.php index 4284b80915e5..0c3fc688a7d6 100644 --- a/libraries/classes/Display/ChangePassword.php +++ b/libraries/classes/Display/ChangePassword.php @@ -97,7 +97,6 @@ public static function getHtml($mode, $username, $hostname) $username, $hostname ); - $is_superuser = $GLOBALS['dbi']->isSuperuser(); if (($serverType == 'MySQL' && $serverVersion >= 50507) @@ -108,7 +107,7 @@ public static function getHtml($mode, $username, $hostname) // OR for privileged users in 5.5.7+ if (($serverType == 'MySQL' && $serverVersion >= 50706) - || ($is_superuser && $mode == 'edit_other') + || ($GLOBALS['dbi']->isSuperuser() && $mode == 'edit_other') ) { $auth_plugin_dropdown = Privileges::getHtmlForAuthPluginsDropdown( $orig_auth_plugin, 'change_pw', 'new' diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index f3b81f2efc9b..1d87c186f087 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -179,7 +179,7 @@ public static function runQuery($sql = '', $full = '', array &$sql_data = array( global $import_run_buffer, $go_sql, $complete_query, $display_query, $sql_query, $error, $reload, $result, $msg, $skip_queries, $executed_queries, $max_sql_len, $read_multiply, - $cfg, $sql_query_disabled, $db, $run_query, $is_superuser; + $cfg, $sql_query_disabled, $db, $run_query; $read_multiply = 1; if (!isset($import_run_buffer)) { // Do we have something to push into buffer? diff --git a/libraries/classes/Rte/RteList.php b/libraries/classes/Rte/RteList.php index 752cedcabc50..cb69e1cd1647 100644 --- a/libraries/classes/Rte/RteList.php +++ b/libraries/classes/Rte/RteList.php @@ -231,7 +231,7 @@ public static function getRoutineRow(array $routine, $rowclass = '') // CREATE ROUTINE privilege to avoid lost procedures. if ((Util::currentUserHasPrivilege('CREATE ROUTINE', $db) && $curr_user == $routine_definer) - || $GLOBALS['is_superuser'] + || $GLOBALS['dbi']->isSuperuser() ) { $retval .= ' \n"; if ((Util::currentUserHasPrivilege('CREATE ROUTINE', $db) && $curr_user == $routine_definer) - || $GLOBALS['is_superuser'] + || $GLOBALS['dbi']->isSuperuser() ) { $retval .= ' = 50200 - && $is_superuser + && $GLOBALS['dbi']->isSuperuser() ) { // Use 'UPDATE `mysql`.`user` ...' Syntax for MariaDB 5.2+ if ($authentication_plugin == 'mysql_native_password') { @@ -2346,7 +2345,8 @@ public static function getHtmlTableBodyForSpecificDbRoutinePrivs($db, $index_che public static function getHtmlForSpecificDbPrivileges($db) { $html_output = ''; - if ($GLOBALS['is_superuser']) { + + if ($GLOBALS['dbi']->isSuperuser()) { // check the privileges for a particular database. $html_output = '
'; $html_output .= Url::getHiddenInputs($db); @@ -2422,7 +2422,7 @@ public static function getHtmlForSpecificDbPrivileges($db) public static function getHtmlForSpecificTablePrivileges($db, $table) { $html_output = ''; - if ($GLOBALS['is_superuser']) { + if ($GLOBALS['dbi']->isSuperuser()) { // check the privileges for a particular table. $html_output = ''; $html_output .= Url::getHiddenInputs($db, $table); diff --git a/libraries/classes/Server/Users.php b/libraries/classes/Server/Users.php index 6e8231dc4249..bd5058982ccc 100644 --- a/libraries/classes/Server/Users.php +++ b/libraries/classes/Server/Users.php @@ -33,7 +33,7 @@ public static function getHtmlForSubMenusOnUsersPage($selfUrl) ) ); - if ($GLOBALS['is_superuser']) { + if ($GLOBALS['dbi']->isSuperuser()) { $items[] = array( 'name' => __('User groups'), 'url' => 'server_user_groups.php', diff --git a/libraries/common.inc.php b/libraries/common.inc.php index ca2ae9e59fc0..e50bacdf353b 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -754,11 +754,6 @@ Core::fatalError(__('possible exploit')); } -// here, the function does not exist with this configuration: -// $cfg['ServerDefault'] = 0; -$GLOBALS['is_superuser'] - = isset($GLOBALS['dbi']) && $GLOBALS['dbi']->isSuperuser(); - if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { /** * include subform target page diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index 54f5f051ffdf..97c9ff96bbae 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -34,11 +34,10 @@ /** * @global boolean Checks for superuser privileges */ -$GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser(); $GLOBALS['is_grantuser'] = $GLOBALS['dbi']->isUserType('grant'); $GLOBALS['is_createuser'] = $GLOBALS['dbi']->isUserType('create'); // now, select the mysql db -if ($GLOBALS['is_superuser']) { +if ($GLOBALS['dbi']->isSuperuser()) { $GLOBALS['dbi']->selectDb('mysql', $GLOBALS['userlink']); } diff --git a/server_privileges.php b/server_privileges.php index 77228113dca9..9a1fd540ffff 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -129,7 +129,7 @@ /** * Checks if the user is allowed to do what he tries to... */ -if (!$GLOBALS['is_superuser'] && !$GLOBALS['is_grantuser'] +if (!$GLOBALS['dbi']->isSuperuser() && !$GLOBALS['is_grantuser'] && !$GLOBALS['is_createuser'] ) { $response->addHTML(Common::getHtmlForSubPageHeader('privileges', '', false)); @@ -241,7 +241,7 @@ * Assign users to user groups */ if (! empty($_REQUEST['changeUserGroup']) && $cfgRelation['menuswork'] - && $GLOBALS['is_superuser'] && $GLOBALS['is_createuser'] + && $GLOBALS['dbi']->isSuperuser() && $GLOBALS['is_createuser'] ) { Privileges::setUserGroup($username, $_REQUEST['userGroup']); $message = Message::success(); diff --git a/server_replication.php b/server_replication.php index 832f7ad74b55..3e33c3232aa5 100644 --- a/server_replication.php +++ b/server_replication.php @@ -30,7 +30,7 @@ /** * Checks if the user is allowed to do what he tries to... */ -if (! $is_superuser) { +if (! $GLOBALS['dbi']->isSuperuser()) { $html = Common::getHtmlForSubPageHeader('replication'); $html .= PhpMyAdmin\Message::error(__('No Privileges'))->getDisplay(); $response->addHTML($html); diff --git a/server_user_groups.php b/server_user_groups.php index 737662e386cb..3f11f59fcba3 100644 --- a/server_user_groups.php +++ b/server_user_groups.php @@ -25,7 +25,7 @@ /** * Only allowed to superuser */ -if (! $GLOBALS['is_superuser']) { +if (! $GLOBALS['dbi']->isSuperuser()) { $response->addHTML( PhpMyAdmin\Message::error(__('No Privileges')) ->getDisplay() diff --git a/sql.php b/sql.php index c441b7d81c3d..d9edaa498027 100644 --- a/sql.php +++ b/sql.php @@ -152,7 +152,7 @@ * into account this case. */ if (Sql::hasNoRightsToDropDatabase( - $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $is_superuser + $analyzed_sql_results, $cfg['AllowUserDropDatabase'], $GLOBALS['dbi']->isSuperuser() )) { Util::mysqlDie( __('"DROP DATABASE" statements are disabled.'), diff --git a/templates/server/databases/table_footer.phtml b/templates/server/databases/table_footer.phtml index 0534f1d3a003..2f1f45fd7887 100644 --- a/templates/server/databases/table_footer.phtml +++ b/templates/server/databases/table_footer.phtml @@ -1,6 +1,6 @@ - + isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']): ?> @@ -39,4 +39,4 @@ - \ No newline at end of file + diff --git a/templates/server/databases/table_header.phtml b/templates/server/databases/table_header.phtml index f103127012d4..1e3772c9deae 100644 --- a/templates/server/databases/table_header.phtml +++ b/templates/server/databases/table_header.phtml @@ -1,6 +1,6 @@ - + isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']): ?> diff --git a/templates/server/databases/table_row.phtml b/templates/server/databases/table_row.phtml index 679294068ddf..37fe4a1d4267 100644 --- a/templates/server/databases/table_row.phtml +++ b/templates/server/databases/table_row.phtml @@ -1,5 +1,5 @@ > - + isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']): ?> enableBc(); - $GLOBALS['is_superuser'] = true; $GLOBALS['table'] = "table"; $GLOBALS['replication_info']['master']['status'] = false; diff --git a/test/classes/Server/PrivilegesTest.php b/test/classes/Server/PrivilegesTest.php index 5be2963a529a..a421b2a63803 100644 --- a/test/classes/Server/PrivilegesTest.php +++ b/test/classes/Server/PrivilegesTest.php @@ -127,7 +127,6 @@ public function setUp() ->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; - $GLOBALS['is_superuser'] = true; $GLOBALS['is_grantuser'] = true; $GLOBALS['is_createuser'] = true; $GLOBALS['is_reload_priv'] = true; @@ -1475,6 +1474,8 @@ public function testPMAGetHtmlForSpecificDbPrivileges() array('COLUMN_NAME' => 'Host', 'CHARACTER_MAXIMUM_LENGTH' => 80), array('COLUMN_NAME' => 'User', 'CHARACTER_MAXIMUM_LENGTH' => 40), ); + $dbi->expects($this->any())->method('isSuperuser') + ->will($this->returnValue(true)); $dbi->expects($this->any())->method('fetchResult') ->will($this->returnValue($fields_info)); $dbi->expects($this->any()) @@ -1558,6 +1559,8 @@ public function testPMAGetHtmlForSpecificTablePrivileges() $dbi->expects($this->any()) ->method('escapeString') ->will($this->returnArgument(0)); + $dbi->expects($this->any())->method('isSuperuser') + ->will($this->returnValue(true)); $GLOBALS['dbi'] = $dbi; diff --git a/test/classes/Server/UsersTest.php b/test/classes/Server/UsersTest.php index c3fbb0596426..a9577a1004c2 100644 --- a/test/classes/Server/UsersTest.php +++ b/test/classes/Server/UsersTest.php @@ -26,6 +26,7 @@ class UsersTest extends TestCase */ public function testGetHtmlForSubMenusOnUsersPage() { + $GLOBALS['server'] = 1; $html = Users::getHtmlForSubMenusOnUsersPage('server_privileges.php'); //validate 1: topmenu2