From 0537ce4e9fab393c5941ddfc636b9022f106e36e Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 24 Sep 2022 23:12:00 +0200 Subject: [PATCH] remove LEX_USER->is_public it's now redundant --- sql/sql_acl.cc | 32 +++++++++++++++----------------- sql/sql_class.cc | 1 - sql/sql_parse.cc | 3 +-- sql/sql_yacc.yy | 3 --- sql/structs.h | 1 - 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 65cdd63f2ef..f6f7fb387a8 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -108,6 +108,9 @@ LEX_CSTRING current_user_and_current_role= LEX_CSTRING none= {STRING_WITH_LEN("NONE") }; LEX_CSTRING public_name= {STRING_WITH_LEN("PUBLIC") }; +static inline bool is_public(const char *l) { return l == public_name.str; } +static inline bool is_public(const LEX_CSTRING *l) { return is_public(l->str); } +static inline bool is_public(const LEX_USER *l) { return is_public(&l->user); } static plugin_ref old_password_plugin; static plugin_ref native_password_plugin; @@ -2199,7 +2202,7 @@ ACL_ROLE::ACL_ROLE(const char *rolename, privilege_t privileges, MEM_ROOT *root) : initial_role_access(privileges), counter(0) { this->access= initial_role_access; - if (rolename == public_name.str) + if (is_public(rolename)) this->user= public_name; else { @@ -3597,8 +3600,8 @@ static void acl_insert_role(const char *rolename, privilege_t privileges) sizeof(ACL_ROLE *), 0, 8, MYF(0)); my_hash_insert(&acl_roles, (uchar *)entry); - DBUG_ASSERT(strcasecmp(rolename, public_name.str) || rolename == public_name.str); - if (rolename == public_name.str) + DBUG_ASSERT(strcasecmp(rolename, public_name.str) || is_public(rolename)); + if (is_public(rolename)) acl_public= entry; DBUG_VOID_RETURN; @@ -7275,7 +7278,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, error= copy_and_check_auth(Str, Str, thd) || replace_user_table(thd, tables.user_table(), Str, NO_ACL, revoke_grant, create_new_users, - MY_TEST(!Str->is_public && + MY_TEST(!is_public(Str) && (thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER))); if (unlikely(error)) @@ -7461,7 +7464,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, if (copy_and_check_auth(Str, tmp_Str, thd) || replace_user_table(thd, tables.user_table(), Str, NO_ACL, revoke_grant, create_new_users, - !Str->is_public && (thd->variables.sql_mode & + !is_public(Str) && (thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER))) { result= TRUE; @@ -7707,7 +7710,6 @@ bool mysql_grant_role(THD *thd, List &list, bool revoke) continue; case ROLE_NAME_PUBLIC: user->host= hostname= empty_clex_str; - user->is_public= true; role_as_user= acl_public; break; case ROLE_NAME_OK: @@ -7726,7 +7728,7 @@ bool mysql_grant_role(THD *thd, List &list, bool revoke) if (has_auth(user, thd->lex)) DBUG_ASSERT(!grantee); - else if (!grantee && !user->is_public) + else if (!grantee && !is_public(user)) grantee= find_user_exact(hostname.str, username.str); if (!grantee && !revoke) @@ -7738,13 +7740,13 @@ bool mysql_grant_role(THD *thd, List &list, bool revoke) if (copy_and_check_auth(&user_combo, &user_combo, thd) || replace_user_table(thd, tables.user_table(), &user_combo, NO_ACL, false, create_new_user, - (!user_combo.is_public && no_auto_create_user))) + (!is_public(&user_combo) && no_auto_create_user))) { append_user(thd, &wrong_users, &username, &hostname); result= 1; continue; } - if (!user_combo.is_public) + if (!is_public(&user_combo)) grantee= find_user_exact(hostname.str, username.str); else grantee= role_as_user= acl_public; @@ -7913,7 +7915,7 @@ bool mysql_grant(THD *thd, const char *db, List &list, replace_user_table(thd, tables.user_table(), Str, (!db ? rights : NO_ACL), revoke_grant, create_new_users, - MY_TEST(!Str->is_public && + MY_TEST(!is_public(Str) && (thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER)))) result= true; @@ -9464,7 +9466,7 @@ bool get_show_user(THD *thd, LEX_USER *lex_user, const char **username, if (lex_user->is_role()) { *rolename= lex_user->user.str; - do_check_access= !lex_user->is_public && strcmp(*rolename, sctx->priv_role); + do_check_access= !is_public(lex_user) && strcmp(*rolename, sctx->priv_role); } else { @@ -9772,7 +9774,7 @@ static void add_to_user(THD *thd, String *result, const char *user, bool is_user, const char *host) { result->append(STRING_WITH_LEN(" TO ")); - if (user == public_name.str) + if (is_public(user)) result->append(public_name); else append_identifier(thd, result, user, strlen(user)); @@ -11217,7 +11219,7 @@ bool mysql_drop_user(THD *thd, List &list, bool handle_as_role) { int rc; user_name= get_current_user(thd, tmp_user_name, false); - if (!user_name || (handle_as_role && user_name->is_public)) + if (!user_name || (handle_as_role && is_public(user_name))) { thd->clear_error(); if (!user_name) @@ -11909,7 +11911,6 @@ bool sp_grant_privileges(THD *thd, const char *sp_db, const char *sp_name, thd->make_lex_string(&combo->host, combo->host.str, strlen(combo->host.str)); combo->auth= NULL; - combo->is_public= false; if (user_list.push_back(combo, thd->mem_root)) DBUG_RETURN(TRUE); @@ -13006,8 +13007,6 @@ LEX_USER *get_current_user(THD *thd, LEX_USER *user, bool lock) if (!dup) return 0; - dup->is_public= false; - #ifndef NO_EMBEDDED_ACCESS_CHECKS if (has_auth(user, thd->lex)) { @@ -13020,7 +13019,6 @@ LEX_USER *get_current_user(THD *thd, LEX_USER *user, bool lock) return 0; if (result == ROLE_NAME_PUBLIC) { - dup->is_public= true; dup->host= empty_clex_str; return dup; } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 5d51ed00ebc..0c2ed1bf302 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -6029,7 +6029,6 @@ void THD::get_definer(LEX_USER *definer, bool role) definer->user= invoker.user; definer->host= invoker.host; definer->auth= NULL; - definer->is_public= false; } else #endif diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d3101bf0c13..7851e775c35 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2801,7 +2801,7 @@ bool sp_process_definer(THD *thd) LEX_USER *d= get_current_user(thd, lex->definer); if (!d) DBUG_RETURN(TRUE); - if (d->is_public) + if (d->user.str == public_name.str) { my_error(ER_INVALID_ROLE, MYF(0), lex->definer->user.str); DBUG_RETURN(TRUE); @@ -10064,7 +10064,6 @@ void get_default_definer(THD *thd, LEX_USER *definer, bool role) } definer->user.length= strlen(definer->user.str); definer->auth= NULL; - definer->is_public= false; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e789df01bf1..0b09d52e217 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -17155,10 +17155,7 @@ role_name: ident_or_text if (lex_string_eq(&$1, &none)) $$->user= none; else if (lex_string_eq(&$1, &public_name)) - { $$->user= public_name; - $$->is_public= true; - } else if (check_string_char_length(&($$->user= $1), ER_USERNAME, username_char_length, cs, 0)) MYSQL_YYABORT; diff --git a/sql/structs.h b/sql/structs.h index edecbf0888b..b36f8e6a1a0 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -254,7 +254,6 @@ struct AUTHID struct LEX_USER: public AUTHID { USER_AUTH *auth; - bool is_public; bool has_auth() { return auth && (auth->plugin.length || auth->auth_str.length || auth->pwtext.length);