diff --git a/libraries/display_change_password.lib.php b/libraries/display_change_password.lib.php index d6164f86e3..2feb070612 100644 --- a/libraries/display_change_password.lib.php +++ b/libraries/display_change_password.lib.php @@ -14,12 +14,14 @@ if (! defined('PHPMYADMIN')) { /** * Get HTML for the Change password dialog * + * @param string $mode where is the function being called? + * values : 'change_pw' or 'edit_other' * @param string $username username * @param string $hostname hostname * * @return string html snippet */ -function PMA_getHtmlForChangePassword($username, $hostname) +function PMA_getHtmlForChangePassword($mode, $username, $hostname) { /** * autocomplete feature of IE kills the "onchange" event handler and it @@ -80,62 +82,60 @@ function PMA_getHtmlForChangePassword($username, $hostname) . '' . ''; - $html .= '' - . '' . __('Password Hashing:') . ''; - $serverType = PMA\libraries\Util::getServerType(); $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( 'change', $username, $hostname ); + $is_superuser = $GLOBALS['dbi']->isSuperuser(); if (($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507) || ($serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) ) { - $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( - $username, $hostname, $orig_auth_plugin, 'change_pw', 'new' - ); + // Provide this option only for 5.7.6+ + // OR for privileged users in 5.5.7+ + if (($serverType == 'MySQL' + && PMA_MYSQL_INT_VERSION >= 50706) + || ($is_superuser && $mode == 'edit_other') + ) { + $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( + $username, $hostname, $orig_auth_plugin, 'change_pw', 'new' + ); - $html .= $auth_plugin_dropdown; - $html .= ''; - $html .= ''; - $html .= ''; + $html .= '' + . '' . __('Password Hashing:') . ''; + $html .= $auth_plugin_dropdown; + $html .= '' + . '' + . ''; - $html .= '
' - . Message::notice( - __( - 'This method requires using an \'SSL connection\' ' - . 'or an \'unencrypted connection that encrypts the password ' - . 'using RSA\'; while connecting to the server.' - ) - . PMA\libraries\Util::showMySQLDocu('sha256-authentication-plugin') - ) - ->getDisplay() - . '
'; - - $html .= '
' - . Message::notice( - __( - 'This method requires using an \'SSL connection\' ' - . 'or an \'unencrypted connection that encrypts the password ' - . 'using RSA\'; while connecting to the server.' + $html .= '
' + . Message::notice( + __( + 'This method requires using an \'SSL connection\' ' + . 'or an \'unencrypted connection that encrypts the password ' + . 'using RSA\'; while connecting to the server.' + ) + . PMA\libraries\Util::showMySQLDocu('sha256-authentication-plugin') ) - . PMA\libraries\Util::showMySQLDocu('sha256-authentication-plugin') - ) - ->getDisplay() - . '
'; + ->getDisplay() + . '
'; + } else { + $html .= '' + . ''; + } } else { $auth_plugin_dropdown = PMA_getHtmlForAuthPluginsDropdown( $username, $hostname, $orig_auth_plugin, 'change_pw', 'old' ); + $html .= '' + . '' . __('Password Hashing:') . ''; $html .= $auth_plugin_dropdown . '' . '' . ''; diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 39ad19e108..1b40bb0899 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -2035,6 +2035,7 @@ function PMA_updatePassword($err_url, $username, $hostname) { // similar logic in user_password.php $message = ''; + $is_superuser = $GLOBALS['dbi']->isSuperuser(); if (empty($_REQUEST['nopass']) && isset($_POST['pma_pw']) @@ -2050,8 +2051,9 @@ function PMA_updatePassword($err_url, $username, $hostname) // here $nopass could be == 1 if (empty($message)) { $hashing_function = 'PASSWORD'; + $serverType = Util::getServerType(); - if (Util::getServerType() == 'MySQL' + if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 ) { if (isset($_REQUEST['authentication_plugin']) @@ -2075,10 +2077,11 @@ function PMA_updatePassword($err_url, $username, $hostname) $local_query = $query_prefix . Util::sqlAddSlashes($_POST['pma_pw']) . "'"; - } else if ((Util::getServerType() == 'MySQL' + } else if (($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION >= 50507) - || (Util::getServerType() == 'MariaDB' + || ($serverType == 'MariaDB' && PMA_MYSQL_INT_VERSION >= 50200) + && $is_superuser ) { // Backup the old value, to be reset later $row = $GLOBALS['dbi']->fetchSingleRow( @@ -2086,6 +2089,21 @@ function PMA_updatePassword($err_url, $username, $hostname) ); $orig_value = $row['@@old_passwords']; + $update_plugin_query = "UPDATE `mysql`.`user` SET" + . " `plugin` = '" . $_REQUEST['authentication_plugin'] . "'" + . " WHERE `User` = '" . $username . "' AND Host = '" + . $hostname . "';"; + + // Update the plugin for the user + $GLOBALS['dbi']->tryQuery($update_plugin_query) + or PMA_Util::mysqlDie( + $GLOBALS['dbi']->getError(), + $update_plugin_query, + false, $err_url + ); + + $GLOBALS['dbi']->tryQuery("FLUSH PRIVILEGES;"); + if (isset($_REQUEST['authentication_plugin']) && $_REQUEST['authentication_plugin'] == 'mysql_native_password' ) { @@ -2101,19 +2119,6 @@ function PMA_updatePassword($err_url, $username, $hostname) $GLOBALS['dbi']->tryQuery('SET `old_passwords` = 2;'); } - $update_plugin_query = "UPDATE `mysql`.`user` SET" - . " `plugin` = '" . $_REQUEST['authentication_plugin'] . "'" - . " WHERE `User` = '" . $username . "' AND Host = '" - . $hostname . "';"; - - // Update the plugin for the user - $GLOBALS['dbi']->tryQuery($update_plugin_query) - or PMA_Util::mysqlDie( - $GLOBALS['dbi']->getError(), - $update_plugin_query, - false, $err_url - ); - $sql_query = 'SET PASSWORD FOR \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\' = ' @@ -4789,7 +4794,6 @@ function PMA_getHtmlForUserProperties($dbname_is_wildcard,$url_dbname, __('The selected user was not found in the privilege table.') )->getDisplay(); $html_output .= PMA_getHtmlForLoginInformationFields(); - //exit; } $_params = array( @@ -4850,7 +4854,7 @@ function PMA_getHtmlForUserProperties($dbname_is_wildcard,$url_dbname, && ! $user_does_not_exists ) { //change login information - $html_output .= PMA_getHtmlForChangePassword($username, $hostname); + $html_output .= PMA_getHtmlForChangePassword('edit_other', $username, $hostname); $html_output .= PMA_getChangeLoginInformationHtmlForm($username, $hostname); } $html_output .= ''; diff --git a/test/libraries/PMA_display_change_password_test.php b/test/libraries/PMA_display_change_password_test.php index a44c77b191..fbd5d6cd16 100644 --- a/test/libraries/PMA_display_change_password_test.php +++ b/test/libraries/PMA_display_change_password_test.php @@ -50,6 +50,7 @@ class PMA_DisplayChangePassword_Test extends PHPUnit_Framework_TestCase $GLOBALS['cfg']['Server']['user'] = "pma_user"; $GLOBALS['cfg']['ShowHint'] = true; $GLOBALS['cfg']['ActionLinksMode'] = 'icons'; + $GLOBALS['cfg']['Server']['DisableIS'] = false; $GLOBALS['PMA_PHP_SELF'] = "server_privileges.php"; $GLOBALS['server'] = 0; $GLOBALS['pmaThemeImage'] = 'image'; @@ -71,7 +72,7 @@ class PMA_DisplayChangePassword_Test extends PHPUnit_Framework_TestCase $hostname = "pma_hostname"; //Call the test function - $html = PMA_getHtmlForChangePassword($username, $hostname); + $html = PMA_getHtmlForChangePassword('change_pw', $username, $hostname); //PMA_PHP_SELF $this->assertContains( diff --git a/user_password.php b/user_password.php index 269d517111..d1e249edaa 100644 --- a/user_password.php +++ b/user_password.php @@ -68,7 +68,7 @@ if (isset($msg)) { require_once './libraries/display_change_password.lib.php'; -echo PMA_getHtmlForChangePassword($username, $hostname); +echo PMA_getHtmlForChangePassword('change_pw', $username, $hostname); exit; /** @@ -146,46 +146,40 @@ function PMA_changePassword($password, $message, $change_password_message) $serverType = PMA\libraries\Util::getServerType(); + if (isset($_REQUEST['authentication_plugin']) + && ! empty($_REQUEST['authentication_plugin']) + ) { + $orig_auth_plugin = $_REQUEST['authentication_plugin']; + } else { + $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( + 'change', $username, $hostname + ); + } + if ($serverType === 'MySQL' && PMA_MYSQL_INT_VERSION >= 50706 ) { - - if (isset($_REQUEST['authentication_plugin']) - && ! empty($_REQUEST['authentication_plugin']) - ) { - $orig_auth_plugin = $_REQUEST['authentication_plugin']; - } else { - $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( - 'change', $username, $hostname - ); - } - $sql_query = 'ALTER USER \'' . $username . '\'@\'' . $hostname . '\' IDENTIFIED WITH ' . $orig_auth_plugin . ' BY ' . (($password == '') ? '\'\'' : '\'***\''); - } else { + } else if (($serverType == 'MySQL' + && PMA_MYSQL_INT_VERSION >= 50507) + || ($serverType == 'MariaDB' + && PMA_MYSQL_INT_VERSION >= 50200) + ) { // For MySQL versions 5.5.7+ and MariaDB versions 5.2+, // explicitly set value of `old_passwords` so that // it does not give an error while using // the PASSWORD() function - if (($serverType == 'MySQL' - && PMA_MYSQL_INT_VERSION >= 50507) - || ($serverType == 'MariaDB' - && PMA_MYSQL_INT_VERSION >= 50200) - ) { - $orig_auth_plugin = PMA_getCurrentAuthenticationPlugin( - 'change', $username, $hostname - ); - if ($orig_auth_plugin == 'sha256_password') { - $value = 2; - } else { - $value = 0; - } - $GLOBALS['dbi']->tryQuery('SET `old_passwords` = ' . $value . ';'); + if ($orig_auth_plugin == 'sha256_password') { + $value = 2; + } else { + $value = 0; } + $GLOBALS['dbi']->tryQuery('SET `old_passwords` = ' . $value . ';'); + } $sql_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'***\')'); - } PMA_changePassUrlParamsAndSubmitQuery( $username, $hostname, $password, $sql_query, $hashing_function, $orig_auth_plugin @@ -203,7 +197,9 @@ function PMA_changePassword($password, $message, $change_password_message) */ function PMA_changePassHashingFunction() { - if (PMA_isValid($_REQUEST['pw_hash'], 'identical', 'old')) { + if (PMA_isValid( + $_REQUEST['authentication_plugin'], 'identical', 'mysql_old_password' + )) { $hashing_function = 'OLD_PASSWORD'; } else { $hashing_function = 'PASSWORD';