| 12747 | |
| 12748 | |
| 12749 | int 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 |
no test coverage detected