@@ -1367,6 +1367,7 @@ public function getExtraDataForAjaxBehavior(
13671367 string $ hostname ,
13681368 string $ username ,
13691369 string |null $ dbname ,
1370+ bool $ isChangeCopyUser ,
13701371 ): array {
13711372 if ($ dbname !== null ) {
13721373 //if (preg_match('/\\\\(?:_|%)/i', $dbname)) {
@@ -1389,7 +1390,7 @@ public function getExtraDataForAjaxBehavior(
13891390 $ extraData ['sql_query ' ] = Generator::getMessage ('' , $ sqlQuery );
13901391 }
13911392
1392- if (isset ( $ _POST [ ' change_copy ' ]) ) {
1393+ if ($ isChangeCopyUser ) {
13931394 $ user = [
13941395 'name ' => $ username ,
13951396 'host ' => $ hostname ,
@@ -2068,68 +2069,60 @@ private function generateQueriesForUpdatePrivileges(
20682069 /**
20692070 * Get List of information: Changes / copies a user
20702071 */
2071- public function getDataForChangeOrCopyUser (string $ oldUsername , string $ oldHostname ): string |null
2072+ public function getDataForChangeOrCopyUser (string $ oldUsername , string $ oldHostname ): Message | string |null
20722073 {
2073- if (isset ($ _POST ['change_copy ' ])) {
2074- $ userHostCondition = $ this ->getUserHostCondition ($ oldUsername , $ oldHostname );
2075- $ row = $ this ->dbi ->fetchSingleRow ('SELECT * FROM `mysql`.`user` ' . $ userHostCondition . '; ' );
2076- if ($ row === []) {
2077- $ response = ResponseRenderer::getInstance ();
2078- $ response ->addHTML (
2079- Message::notice (__ ('No user found. ' ))->getDisplay (),
2080- );
2081- unset($ _POST ['change_copy ' ]);
2082- } else {
2083- $ this ->sslType = $ row ['ssl_type ' ];
2084- $ this ->sslCipher = $ row ['ssl_cipher ' ];
2085- $ this ->x509Issuer = $ row ['x509_issuer ' ];
2086- $ this ->x509Subject = $ row ['x509_subject ' ];
2087-
2088- $ serverVersion = $ this ->dbi ->getVersion ();
2089- // Recent MySQL versions have the field "Password" in mysql.user,
2090- // so the previous extract creates $row['Password'] but this script
2091- // uses $password
2092- if (! isset ($ row ['password ' ]) && isset ($ row ['Password ' ])) {
2093- $ row ['password ' ] = $ row ['Password ' ];
2094- }
2074+ $ userHostCondition = $ this ->getUserHostCondition ($ oldUsername , $ oldHostname );
2075+ $ row = $ this ->dbi ->fetchSingleRow ('SELECT * FROM `mysql`.`user` ' . $ userHostCondition . '; ' );
2076+ if ($ row === []) {
2077+ return Message::notice (__ ('No user found. ' ));
2078+ }
20952079
2096- if (
2097- Compatibility::isMySqlOrPerconaDb ($ this ->dbi )
2098- && $ serverVersion >= 50606
2099- && $ serverVersion < 50706
2100- && ((isset ($ row ['authentication_string ' ])
2101- && empty ($ row ['password ' ]))
2102- || (isset ($ row ['plugin ' ])
2103- && $ row ['plugin ' ] === 'sha256_password ' ))
2104- ) {
2105- $ row ['password ' ] = $ row ['authentication_string ' ];
2106- }
2080+ $ this ->sslType = $ row ['ssl_type ' ];
2081+ $ this ->sslCipher = $ row ['ssl_cipher ' ];
2082+ $ this ->x509Issuer = $ row ['x509_issuer ' ];
2083+ $ this ->x509Subject = $ row ['x509_subject ' ];
21072084
2108- if (
2109- Compatibility::isMariaDb ($ this ->dbi )
2110- && $ serverVersion >= 50500
2111- && isset ($ row ['authentication_string ' ])
2112- && empty ($ row ['password ' ])
2113- ) {
2114- $ row ['password ' ] = $ row ['authentication_string ' ];
2115- }
2085+ $ serverVersion = $ this ->dbi ->getVersion ();
2086+ // Recent MySQL versions have the field "Password" in mysql.user,
2087+ // so the previous extract creates $row['Password'] but this script
2088+ // uses $password
2089+ if (! isset ($ row ['password ' ]) && isset ($ row ['Password ' ])) {
2090+ $ row ['password ' ] = $ row ['Password ' ];
2091+ }
21162092
2117- // Always use 'authentication_string' column
2118- // for MySQL 5.7.6+ since it does not have
2119- // the 'password' column at all
2120- if (
2121- Compatibility::isMySqlOrPerconaDb ($ this ->dbi )
2122- && $ serverVersion >= 50706
2123- && isset ($ row ['authentication_string ' ])
2124- ) {
2125- $ row ['password ' ] = $ row ['authentication_string ' ];
2126- }
2093+ if (
2094+ Compatibility::isMySqlOrPerconaDb ($ this ->dbi )
2095+ && $ serverVersion >= 50606
2096+ && $ serverVersion < 50706
2097+ && ((isset ($ row ['authentication_string ' ])
2098+ && empty ($ row ['password ' ]))
2099+ || (isset ($ row ['plugin ' ])
2100+ && $ row ['plugin ' ] === 'sha256_password ' ))
2101+ ) {
2102+ $ row ['password ' ] = $ row ['authentication_string ' ];
2103+ }
21272104
2128- return $ row ['password ' ];
2129- }
2105+ if (
2106+ Compatibility::isMariaDb ($ this ->dbi )
2107+ && $ serverVersion >= 50500
2108+ && isset ($ row ['authentication_string ' ])
2109+ && empty ($ row ['password ' ])
2110+ ) {
2111+ $ row ['password ' ] = $ row ['authentication_string ' ];
21302112 }
21312113
2132- return null ;
2114+ // Always use 'authentication_string' column
2115+ // for MySQL 5.7.6+ since it does not have
2116+ // the 'password' column at all
2117+ if (
2118+ Compatibility::isMySqlOrPerconaDb ($ this ->dbi )
2119+ && $ serverVersion >= 50706
2120+ && isset ($ row ['authentication_string ' ])
2121+ ) {
2122+ $ row ['password ' ] = $ row ['authentication_string ' ];
2123+ }
2124+
2125+ return $ row ['password ' ];
21332126 }
21342127
21352128 /**
@@ -2139,9 +2132,9 @@ public function getDataForChangeOrCopyUser(string $oldUsername, string $oldHostn
21392132 *
21402133 * @return mixed[]
21412134 */
2142- public function getDataForDeleteUsers (array $ queries ): array
2135+ public function getDataForDeleteUsers (array $ queries, bool $ isChangeCopyUser ): array
21432136 {
2144- if (isset ( $ _POST [ ' change_copy ' ]) ) {
2137+ if ($ isChangeCopyUser ) {
21452138 $ selectedUsr = [$ _POST ['old_username ' ] . '&#27; ' . $ _POST ['old_hostname ' ]];
21462139 } else {
21472140 // null happens when no user was selected
@@ -2244,6 +2237,7 @@ public function addUser(
22442237 string $ hostname ,
22452238 string |null $ password ,
22462239 bool $ isMenuwork ,
2240+ bool $ isChangeCopyUser ,
22472241 ): array {
22482242 // Some reports were sent to the error reporting server with phpMyAdmin 5.1.0
22492243 // pred_username was reported to be not defined
@@ -2277,7 +2271,7 @@ public function addUser(
22772271 $ alterSqlQuery ,
22782272 ] = $ this ->getSqlQueriesForDisplayAndAddUser ($ username , $ hostname , $ password ?? '' );
22792273
2280- if (empty ( $ _POST [ ' change_copy ' ]) ) {
2274+ if (! $ isChangeCopyUser ) {
22812275 $ error = false ;
22822276
22832277 if (! $ this ->dbi ->tryQuery ($ createUserReal )) {
0 commit comments