@@ -353,8 +353,9 @@ static void update_hostname(acl_host_and_ip *host, const char *hostname);
353353static ulong get_sort (uint count,...);
354354static bool show_proxy_grants (THD *, const char *, const char *,
355355 char *, size_t );
356- static bool show_role_grants (THD *, const char *, const char *,
356+ static bool show_role_grants (THD *, const char *,
357357 ACL_USER_BASE *, char *, size_t );
358+ static bool show_default_role (THD *, ACL_USER *, char *, size_t );
358359static bool show_global_privileges (THD *, ACL_USER_BASE *,
359360 bool , char *, size_t );
360361static bool show_database_privileges (THD *, const char *, const char *,
@@ -8531,7 +8532,7 @@ static bool print_grants_for_role(THD *thd, ACL_ROLE * role)
85318532{
85328533 char buff[1024 ];
85338534
8534- if (show_role_grants (thd, role-> user . str , " " , role, buff, sizeof (buff)))
8535+ if (show_role_grants (thd, " " , role, buff, sizeof (buff)))
85358536 return TRUE ;
85368537
85378538 if (show_global_privileges (thd, role, TRUE , buff, sizeof (buff)))
@@ -8746,7 +8747,7 @@ bool mysql_show_grants(THD *thd, LEX_USER *lex_user)
87468747 }
87478748
87488749 /* Show granted roles to acl_user */
8749- if (show_role_grants (thd, username, hostname, acl_user, buff, sizeof (buff)))
8750+ if (show_role_grants (thd, hostname, acl_user, buff, sizeof (buff)))
87508751 goto end;
87518752
87528753 /* Add first global access grants */
@@ -8795,6 +8796,14 @@ bool mysql_show_grants(THD *thd, LEX_USER *lex_user)
87958796 }
87968797 }
87978798
8799+ if (username)
8800+ {
8801+ /* Show default role to acl_user */
8802+ if (show_default_role (thd, acl_user, buff, sizeof (buff)))
8803+ goto end;
8804+ }
8805+
8806+
87988807 error= 0 ;
87998808end:
88008809 mysql_mutex_unlock (&acl_cache->lock );
@@ -8821,15 +8830,44 @@ static ROLE_GRANT_PAIR *find_role_grant_pair(const LEX_STRING *u,
88218830 my_hash_search (&acl_roles_mappings, (uchar*)pair_key.ptr (), key_length);
88228831}
88238832
8824- static bool show_role_grants (THD *thd, const char *username,
8825- const char *hostname, ACL_USER_BASE *acl_entry,
8833+ static bool show_default_role (THD *thd, ACL_USER *acl_entry,
8834+ char *buff, size_t buffsize)
8835+ {
8836+ Protocol *protocol= thd->protocol ;
8837+ LEX_STRING def_rolename= acl_entry->default_rolename ;
8838+
8839+ if (def_rolename.length )
8840+ {
8841+ String def_str (buff, buffsize, system_charset_info);
8842+ def_str.length (0 );
8843+ def_str.append (STRING_WITH_LEN (" SET DEFAULT ROLE " ));
8844+ def_str.append (&def_rolename);
8845+ def_str.append (" FOR '" );
8846+ def_str.append (&acl_entry->user );
8847+ DBUG_ASSERT (!(acl_entry->flags & IS_ROLE));
8848+ def_str.append (STRING_WITH_LEN (" '@'" ));
8849+ def_str.append (acl_entry->host .hostname , acl_entry->hostname_length ,
8850+ system_charset_info);
8851+ def_str.append (' \' ' );
8852+ protocol->prepare_for_resend ();
8853+ protocol->store (def_str.ptr (),def_str.length (),def_str.charset ());
8854+ if (protocol->write ())
8855+ {
8856+ return TRUE ;
8857+ }
8858+ }
8859+ return FALSE ;
8860+ }
8861+
8862+ static bool show_role_grants (THD *thd, const char *hostname,
8863+ ACL_USER_BASE *acl_entry,
88268864 char *buff, size_t buffsize)
88278865{
88288866 uint counter;
88298867 Protocol *protocol= thd->protocol ;
88308868 LEX_STRING host= {const_cast <char *>(hostname), strlen (hostname)};
88318869
8832- String grant (buff,sizeof (buff), system_charset_info);
8870+ String grant (buff, buffsize, system_charset_info);
88338871 for (counter= 0 ; counter < acl_entry->role_grants .elements ; counter++)
88348872 {
88358873 grant.length (0 );
@@ -8873,7 +8911,7 @@ static bool show_global_privileges(THD *thd, ACL_USER_BASE *acl_entry,
88738911 ulong want_access;
88748912 Protocol *protocol= thd->protocol ;
88758913
8876- String global (buff,sizeof (buff), system_charset_info);
8914+ String global (buff, buffsize, system_charset_info);
88778915 global.length (0 );
88788916 global.append (STRING_WITH_LEN (" GRANT " ));
88798917
@@ -8952,7 +8990,7 @@ static bool show_database_privileges(THD *thd, const char *username,
89528990 want_access=acl_db->initial_access ;
89538991 if (want_access)
89548992 {
8955- String db (buff,sizeof (buff), system_charset_info);
8993+ String db (buff, buffsize, system_charset_info);
89568994 db.length (0 );
89578995 db.append (STRING_WITH_LEN (" GRANT " ));
89588996
0 commit comments