diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result index 8b3948e093f..c47530cdc46 100644 --- a/mysql-test/r/grant.result +++ b/mysql-test/r/grant.result @@ -204,3 +204,27 @@ show grants for mysqltest_1@localhost; Grants for mysqltest_1@localhost GRANT USAGE ON *.* TO 'mysqltest_1'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' drop user mysqltest_1@localhost; +SET NAMES koi8r; +CREATE DATABASE бд; +USE бд; +CREATE TABLE таб (кол int); +GRANT SELECT ON бд.* TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +Grants for юзер@localhost +GRANT USAGE ON *.* TO 'юзер'@'localhost' +GRANT SELECT ON `бд`.* TO 'юзер'@'localhost' +REVOKE SELECT ON бд.* FROM юзер@localhost; +GRANT SELECT ON бд.таб TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +Grants for юзер@localhost +GRANT USAGE ON *.* TO 'юзер'@'localhost' +GRANT SELECT ON `бд`.`таб` TO 'юзер'@'localhost' +REVOKE SELECT ON бд.таб FROM юзер@localhost; +GRANT SELECT (кол) ON бд.таб TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +Grants for юзер@localhost +GRANT USAGE ON *.* TO 'юзер'@'localhost' +GRANT SELECT (кол) ON `бд`.`таб` TO 'юзер'@'localhost' +REVOKE SELECT (кол) ON бд.таб FROM юзер@localhost; +DROP DATABASE бд; +SET NAMES latin1; diff --git a/mysql-test/t/grant.test b/mysql-test/t/grant.test index 832541b0f86..6bd2fa0c703 100644 --- a/mysql-test/t/grant.test +++ b/mysql-test/t/grant.test @@ -148,3 +148,26 @@ grant usage on *.* to mysqltest_1@localhost identified by "password"; grant select, update, insert on test.* to mysqltest@localhost; show grants for mysqltest_1@localhost; drop user mysqltest_1@localhost; + +# +# Bug #3403 Wrong encodin in SHOW GRANTS output +# +SET NAMES koi8r; +CREATE DATABASE бд; +USE бд; +CREATE TABLE таб (кол int); + +GRANT SELECT ON бд.* TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +REVOKE SELECT ON бд.* FROM юзер@localhost; + +GRANT SELECT ON бд.таб TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +REVOKE SELECT ON бд.таб FROM юзер@localhost; + +GRANT SELECT (кол) ON бд.таб TO юзер@localhost; +SHOW GRANTS FOR юзер@localhost; +REVOKE SELECT (кол) ON бд.таб FROM юзер@localhost; + +DROP DATABASE бд; +SET NAMES latin1; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 9c7fe3e2993..880b6eb74ee 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3064,7 +3064,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) /* Add first global access grants */ { - String global(buff,sizeof(buff),&my_charset_latin1); + String global(buff,sizeof(buff),system_charset_info); global.length(0); global.append("GRANT ",6); @@ -3089,7 +3089,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) } } global.append (" ON *.* TO '",12); - global.append(lex_user->user.str,lex_user->user.length); + global.append(lex_user->user.str, lex_user->user.length, + system_charset_info); global.append ("'@'",3); global.append(lex_user->host.str,lex_user->host.length); global.append ('\''); @@ -3177,7 +3178,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) want_access=acl_db->access; if (want_access) { - String db(buff,sizeof(buff),&my_charset_latin1); + String db(buff,sizeof(buff),system_charset_info); db.length(0); db.append("GRANT ",6); @@ -3203,7 +3204,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) db.append (" ON ",4); append_identifier(thd, &db, acl_db->db, strlen(acl_db->db)); db.append (".* TO '",7); - db.append(lex_user->user.str,lex_user->user.length); + db.append(lex_user->user.str, lex_user->user.length, + system_charset_info); db.append ("'@'",3); db.append(lex_user->host.str, lex_user->host.length); db.append ('\''); @@ -3237,7 +3239,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) ulong table_access= grant_table->privs; if ((table_access | grant_table->cols) != 0) { - String global(buff,sizeof(buff),&my_charset_latin1); + String global(buff, sizeof(buff), system_charset_info); ulong test_access= (table_access | grant_table->cols) & ~GRANT_ACL; global.length(0); @@ -3291,7 +3293,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) else global.append(", ",2); global.append(grant_column->column, - grant_column->key_length); + grant_column->key_length, + system_charset_info); } } if (found_col) @@ -3307,7 +3310,8 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) append_identifier(thd, &global, grant_table->tname, strlen(grant_table->tname)); global.append(" TO '",5); - global.append(lex_user->user.str,lex_user->user.length); + global.append(lex_user->user.str, lex_user->user.length, + system_charset_info); global.append("'@'",3); global.append(lex_user->host.str,lex_user->host.length); global.append('\'');