MCPcopy Create free account
hub / github.com/MariaDB/server / acl_setauthorization

Function acl_setauthorization

sql/sql_acl.cc:12749–12828  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12747
12748
12749int acl_setauthorization(THD *thd, const LEX_USER *user)
12750{
12751 if (!initialized)
12752 {
12753 my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables");
12754 return 1;
12755 }
12756
12757 Security_context *sctx= thd->security_ctx, save_security_ctx= *sctx;
12758
12759 DBUG_ASSERT(*user->host.str); // guaranteed by the parser
12760
12761 if (user->host.str == host_not_specified.str)
12762 {
12763 my_error(ER_NO_SUCH_USER, MYF(0), user->user.str, "");
12764 return 1;
12765 }
12766
12767 if (!user->user.length)
12768 {
12769 my_error(ER_NO_SUCH_USER, MYF(0), "", user->host.str);
12770 return 1;
12771 }
12772
12773 mysql_mutex_lock(&acl_cache->lock);
12774 ACL_USER *acl_user= find_user_or_anon(user->host.str, user->user.str, user->host.str);
12775 if (acl_user)
12776 acl_user= acl_user->copy(thd->mem_root);
12777 mysql_mutex_unlock(&acl_cache->lock);
12778
12779 if (!acl_user)
12780 {
12781 if (!(sctx->master_access & PRIV_SUDO_CHANGE_USER))
12782 goto access_denied;
12783 my_error(ER_NO_SUCH_USER, MYF(0), user->user.str, user->host.str);
12784 return 1;
12785 }
12786
12787 if (!(sctx->master_access & PRIV_SUDO_CHANGE_USER) &&
12788 (strcmp(user->user.str, sctx->user) ||
12789 strcmp(user->host.str, sctx->host_or_ip) ||
12790 strcmp(acl_user->user.str, sctx->priv_user) ||
12791 strcmp(acl_user->host.hostname, sctx->priv_host)))
12792 goto access_denied;
12793
12794 thd->change_user();
12795 thd->clear_error(); // if errors from rollback
12796 my_free(const_cast<char*>(thd->db.str));
12797 thd->reset_db(&null_clex_str);
12798
12799 sctx->init();
12800 sctx->user= *user->user.str
12801 ? my_strndup(key_memory_MPVIO_EXT_auth_info, user->user.str,
12802 user->user.length, MYF(MY_WME))
12803 : NULL;
12804 if (strcmp(user->host.str, my_localhost) == 0)
12805 sctx->host= my_localhost;
12806 else

Callers 1

updateMethod · 0.85

Calls 12

my_errorFunction · 0.85
find_user_or_anonFunction · 0.85
my_freeFunction · 0.85
my_strndupFunction · 0.85
set_privs_on_loginFunction · 0.85
change_userMethod · 0.80
reset_dbMethod · 0.80
copyMethod · 0.45
clear_errorMethod · 0.45
initMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected