diff --git a/db_operations.php b/db_operations.php index 76a6368e02..4af05332b9 100644 --- a/db_operations.php +++ b/db_operations.php @@ -13,6 +13,7 @@ */ declare(strict_types=1); +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; @@ -33,10 +34,8 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -/** - * functions implementation for this script - */ -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; +$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$checkUserPrivileges->getPrivileges(); // add a javascript file for jQuery functions to handle Ajax actions $response = Response::getInstance(); diff --git a/db_routines.php b/db_routines.php index 584f168996..c460f7c264 100644 --- a/db_routines.php +++ b/db_routines.php @@ -7,6 +7,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\CheckUserPrivileges; + if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } @@ -16,10 +18,8 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -/** - * Include all other files - */ -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; +$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$checkUserPrivileges->getPrivileges(); /** * Do the magic diff --git a/index.php b/index.php index 942c501734..74cbf767d5 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,7 @@ declare(strict_types=1); use PhpMyAdmin\Charsets; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Config; use PhpMyAdmin\Core; use PhpMyAdmin\Display\GitRevision; @@ -232,7 +233,8 @@ if ($server > 0 || count($cfg['Servers']) > 1 * Displays the mysql server related links */ if ($server > 0) { - include_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); // Logout for advanced authentication if (($cfg['Server']['auth_type'] != 'config') && $cfg['ShowChgPassword']) { diff --git a/libraries/check_user_privileges.inc.php b/libraries/check_user_privileges.inc.php deleted file mode 100644 index 4e913765ae..0000000000 --- a/libraries/check_user_privileges.inc.php +++ /dev/null @@ -1,31 +0,0 @@ -getCurrentUserAndHost(); -if ($username === '') { // MySQL is started with --skip-grant-tables - $GLOBALS['is_create_db_priv'] = true; - $GLOBALS['is_reload_priv'] = true; - $GLOBALS['db_to_create'] = ''; - $GLOBALS['dbs_where_create_table_allowed'] = ['*']; - $GLOBALS['dbs_to_test'] = false; - $GLOBALS['db_priv'] = true; - $GLOBALS['col_priv'] = true; - $GLOBALS['table_priv'] = true; - $GLOBALS['proc_priv'] = true; -} else { - $checkUserPrivileges->analyseShowGrant(); -} diff --git a/libraries/classes/CheckUserPrivileges.php b/libraries/classes/CheckUserPrivileges.php index cb4d9c1094..0614675ca5 100644 --- a/libraries/classes/CheckUserPrivileges.php +++ b/libraries/classes/CheckUserPrivileges.php @@ -172,7 +172,7 @@ class CheckUserPrivileges * * @return void */ - public function analyseShowGrant(): void + private function analyseShowGrant(): void { if (Util::cacheExists('is_create_db_priv')) { $GLOBALS['is_create_db_priv'] = Util::cacheGet( @@ -338,5 +338,35 @@ class CheckUserPrivileges Util::cacheSet('table_priv', $GLOBALS['table_priv']); Util::cacheSet('col_priv', $GLOBALS['col_priv']); Util::cacheSet('db_priv', $GLOBALS['db_priv']); - } // end function + } + + /** + * Get user's global privileges and some db-specific privileges + * + * @return void + */ + public function getPrivileges(): void + { + $username = ''; + + $current = $this->dbi->getCurrentUserAndHost(); + if (! empty($current)) { + list($username, ) = $current; + } + + // If MySQL is started with --skip-grant-tables + if ($username === '') { + $GLOBALS['is_create_db_priv'] = true; + $GLOBALS['is_reload_priv'] = true; + $GLOBALS['db_to_create'] = ''; + $GLOBALS['dbs_where_create_table_allowed'] = ['*']; + $GLOBALS['dbs_to_test'] = false; + $GLOBALS['db_priv'] = true; + $GLOBALS['col_priv'] = true; + $GLOBALS['table_priv'] = true; + $GLOBALS['proc_priv'] = true; + } else { + $this->analyseShowGrant(); + } + } } diff --git a/libraries/classes/Controllers/Server/ServerDatabasesController.php b/libraries/classes/Controllers/Server/ServerDatabasesController.php index 041473dba4..a1c372605d 100644 --- a/libraries/classes/Controllers/Server/ServerDatabasesController.php +++ b/libraries/classes/Controllers/Server/ServerDatabasesController.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Server; use PhpMyAdmin\Charsets; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Controllers\Controller; use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Message; @@ -57,7 +58,8 @@ class ServerDatabasesController extends Controller */ public function indexAction() { - include_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + $checkUserPrivileges = new CheckUserPrivileges($this->dbi); + $checkUserPrivileges->getPrivileges(); $response = Response::getInstance(); diff --git a/libraries/classes/Controllers/Table/TableStructureController.php b/libraries/classes/Controllers/Table/TableStructureController.php index a622a97edd..17bed21931 100644 --- a/libraries/classes/Controllers/Table/TableStructureController.php +++ b/libraries/classes/Controllers/Table/TableStructureController.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Controllers\Table; use PhpMyAdmin\CentralColumns; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\Controllers\TableController; use PhpMyAdmin\Core; @@ -148,10 +149,8 @@ class TableStructureController extends TableController { PageSettings::showGroup('TableStructure'); - /** - * Function implementations for this script - */ - include_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + $checkUserPrivileges = new CheckUserPrivileges($this->dbi); + $checkUserPrivileges->getPrivileges(); $this->response->getHeader()->getScripts()->addFiles( [ @@ -556,7 +555,9 @@ class TableStructureController extends TableController /** * Form for changing properties. */ - include_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + $checkUserPrivileges = new CheckUserPrivileges($this->dbi); + $checkUserPrivileges->getPrivileges(); + include ROOT_PATH . 'libraries/tbl_columns_definition_form.inc.php'; } diff --git a/libraries/classes/Display/CreateTable.php b/libraries/classes/Display/CreateTable.php index 4cece09d15..d984e556e5 100644 --- a/libraries/classes/Display/CreateTable.php +++ b/libraries/classes/Display/CreateTable.php @@ -28,10 +28,9 @@ declare(strict_types=1); namespace PhpMyAdmin\Display; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Template; -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; - /** * PhpMyAdmin\Display\CreateTable class * @@ -48,6 +47,9 @@ class CreateTable */ public static function getHtml($db) { + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); + $template = new Template(); return $template->render('database/create_table', ['db' => $db]); } diff --git a/libraries/classes/Import.php b/libraries/classes/Import.php index 1fa743bee3..7fddf2d9a2 100644 --- a/libraries/classes/Import.php +++ b/libraries/classes/Import.php @@ -55,7 +55,9 @@ class Import public function __construct() { $GLOBALS['cfg']['Server']['DisableIS'] = false; - require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); } /** diff --git a/libraries/classes/ListDatabase.php b/libraries/classes/ListDatabase.php index 9fad38f483..0d83fa0b76 100644 --- a/libraries/classes/ListDatabase.php +++ b/libraries/classes/ListDatabase.php @@ -12,8 +12,6 @@ namespace PhpMyAdmin; use PhpMyAdmin\ListAbstract; use PhpMyAdmin\Util; -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; - /** * handles database lists * @@ -34,6 +32,10 @@ class ListDatabase extends ListAbstract public function __construct() { parent::__construct(); + + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); + $this->build(); } diff --git a/libraries/classes/Navigation/NavigationTree.php b/libraries/classes/Navigation/NavigationTree.php index c478cbe9a6..c5844230f1 100644 --- a/libraries/classes/Navigation/NavigationTree.php +++ b/libraries/classes/Navigation/NavigationTree.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Navigation; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Navigation\Nodes\Node; use PhpMyAdmin\Navigation\Nodes\NodeDatabase; use PhpMyAdmin\Navigation\Nodes\NodeTable; @@ -19,8 +20,6 @@ use PhpMyAdmin\Response; use PhpMyAdmin\Util; use PhpMyAdmin\Url; -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; - /** * Displays a collapsible of database objects in the navigation frame * @@ -94,6 +93,9 @@ class NavigationTree */ public function __construct() { + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); + // Save the position at which we are in the database list if (isset($_POST['pos'])) { $this->_pos = (int) $_POST['pos']; diff --git a/libraries/classes/Navigation/Nodes/NodeDatabaseContainer.php b/libraries/classes/Navigation/Nodes/NodeDatabaseContainer.php index 654eba13d5..9b5746f090 100644 --- a/libraries/classes/Navigation/Nodes/NodeDatabaseContainer.php +++ b/libraries/classes/Navigation/Nodes/NodeDatabaseContainer.php @@ -9,11 +9,10 @@ declare(strict_types=1); namespace PhpMyAdmin\Navigation\Nodes; +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Navigation\NodeFactory; use PhpMyAdmin\Util; -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; - /** * Represents a container for database nodes in the navigation tree * @@ -28,6 +27,9 @@ class NodeDatabaseContainer extends Node */ public function __construct($name) { + $checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); + $checkUserPrivileges->getPrivileges(); + parent::__construct($name, Node::CONTAINER); if ($GLOBALS['is_create_db_priv'] diff --git a/server_privileges.php b/server_privileges.php index a5435940f9..1ac5a5958d 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Core; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; @@ -25,10 +26,8 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -/** - * functions implementation for this script - */ -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; +$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$checkUserPrivileges->getPrivileges(); $relation = new Relation($GLOBALS['dbi']); $cfgRelation = $relation->getRelationsParam(); diff --git a/sql.php b/sql.php index 6acb7930aa..5d140e5b09 100644 --- a/sql.php +++ b/sql.php @@ -9,6 +9,7 @@ */ declare(strict_types=1); +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Response; @@ -24,7 +25,9 @@ if (! defined('ROOT_PATH')) { * Gets some core libraries */ require_once ROOT_PATH . 'libraries/common.inc.php'; -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; + +$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$checkUserPrivileges->getPrivileges(); PageSettings::showGroup('Browse'); diff --git a/tbl_operations.php b/tbl_operations.php index 08d0fc653b..bcd702fddd 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -7,6 +7,7 @@ */ declare(strict_types=1); +use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Partition; @@ -20,15 +21,10 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * - */ require_once ROOT_PATH . 'libraries/common.inc.php'; -/** - * functions implementation for this script - */ -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; +$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$checkUserPrivileges->getPrivileges(); $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']); diff --git a/test/classes/Navigation/NavigationTreeTest.php b/test/classes/Navigation/NavigationTreeTest.php index 619b138dd4..efb95a977e 100644 --- a/test/classes/Navigation/NavigationTreeTest.php +++ b/test/classes/Navigation/NavigationTreeTest.php @@ -14,15 +14,6 @@ use PhpMyAdmin\Navigation\NavigationTree; use PhpMyAdmin\Tests\PmaTestCase; use PhpMyAdmin\Theme; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; -$GLOBALS['cfg']['Server']['DisableIS'] = false; - -require_once ROOT_PATH . 'libraries/check_user_privileges.inc.php'; - /** * Tests for PhpMyAdmin\Navigation\NavigationTree class * diff --git a/test/classes/Plugins/Import/ImportMediawikiTest.php b/test/classes/Plugins/Import/ImportMediawikiTest.php index 58e92348c4..294f108569 100644 --- a/test/classes/Plugins/Import/ImportMediawikiTest.php +++ b/test/classes/Plugins/Import/ImportMediawikiTest.php @@ -12,12 +12,6 @@ use PhpMyAdmin\File; use PhpMyAdmin\Plugins\Import\ImportMediawiki; use PhpMyAdmin\Tests\PmaTestCase; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; - /** * Tests for PhpMyAdmin\Plugins\Import\ImportMediawiki class * @@ -39,6 +33,7 @@ class ImportMediawikiTest extends PmaTestCase */ protected function setUp() { + $GLOBALS['server'] = 0; $GLOBALS['plugin_param'] = 'database'; $this->object = new ImportMediawiki(); diff --git a/test/classes/Plugins/Import/ImportOdsTest.php b/test/classes/Plugins/Import/ImportOdsTest.php index a2969182b0..b4b3195951 100644 --- a/test/classes/Plugins/Import/ImportOdsTest.php +++ b/test/classes/Plugins/Import/ImportOdsTest.php @@ -12,12 +12,6 @@ use PhpMyAdmin\File; use PhpMyAdmin\Plugins\Import\ImportOds; use PhpMyAdmin\Tests\PmaTestCase; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; - /** * Tests for PhpMyAdmin\Plugins\Import\ImportOds class * @@ -39,6 +33,7 @@ class ImportOdsTest extends PmaTestCase */ protected function setUp() { + $GLOBALS['server'] = 0; $GLOBALS['plugin_param'] = "csv"; $this->object = new ImportOds(); diff --git a/test/classes/Plugins/Import/ImportShpTest.php b/test/classes/Plugins/Import/ImportShpTest.php index d3638eacd3..bf8a0c2623 100644 --- a/test/classes/Plugins/Import/ImportShpTest.php +++ b/test/classes/Plugins/Import/ImportShpTest.php @@ -12,12 +12,6 @@ use PhpMyAdmin\File; use PhpMyAdmin\Plugins\Import\ImportShp; use PhpMyAdmin\Tests\PmaTestCase; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; - /** * Tests for PhpMyAdmin\Plugins\Import\ImportShp class * @@ -43,6 +37,7 @@ class ImportShpTest extends PmaTestCase if (! defined('PMA_IS_WINDOWS')) { define('PMA_IS_WINDOWS', false); } + $GLOBALS['server'] = 0; //setting $GLOBALS['plugin_param'] = 'table'; $GLOBALS['finished'] = false; diff --git a/test/classes/Plugins/Import/ImportSqlTest.php b/test/classes/Plugins/Import/ImportSqlTest.php index 7fa5767191..601b34e51c 100644 --- a/test/classes/Plugins/Import/ImportSqlTest.php +++ b/test/classes/Plugins/Import/ImportSqlTest.php @@ -12,12 +12,6 @@ use PhpMyAdmin\File; use PhpMyAdmin\Plugins\Import\ImportSql; use PhpMyAdmin\Tests\PmaTestCase; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; - /** * Tests for PhpMyAdmin\Plugins\Import\ImportSql class * @@ -39,6 +33,8 @@ class ImportSqlTest extends PmaTestCase */ protected function setUp() { + $GLOBALS['server'] = 0; + $this->object = new ImportSql(); //setting diff --git a/test/classes/Plugins/Import/ImportXmlTest.php b/test/classes/Plugins/Import/ImportXmlTest.php index 320d829cef..905963fad5 100644 --- a/test/classes/Plugins/Import/ImportXmlTest.php +++ b/test/classes/Plugins/Import/ImportXmlTest.php @@ -12,12 +12,6 @@ use PhpMyAdmin\File; use PhpMyAdmin\Plugins\Import\ImportXml; use PhpMyAdmin\Tests\PmaTestCase; -/* - * we must set $GLOBALS['server'] here - * since 'check_user_privileges.inc.php' will use it globally - */ -$GLOBALS['server'] = 0; - /** * Tests for PhpMyAdmin\Plugins\Import\ImportXml class * @@ -39,6 +33,8 @@ class ImportXmlTest extends PmaTestCase */ protected function setUp() { + $GLOBALS['server'] = 0; + $this->object = new ImportXml(); //setting