| 2802 | |
| 2803 | |
| 2804 | bool sp_process_definer(THD *thd) |
| 2805 | { |
| 2806 | DBUG_ENTER("sp_process_definer"); |
| 2807 | |
| 2808 | LEX *lex= thd->lex; |
| 2809 | |
| 2810 | /* |
| 2811 | If the definer is not specified, this means that CREATE-statement missed |
| 2812 | DEFINER-clause. DEFINER-clause can be missed in two cases: |
| 2813 | |
| 2814 | - The user submitted a statement w/o the clause. This is a normal |
| 2815 | case, we should assign CURRENT_USER as definer. |
| 2816 | |
| 2817 | - Our slave received an updated from the master, that does not |
| 2818 | replicate definer for stored routines. We should also assign |
| 2819 | CURRENT_USER as definer here, but also we should mark this routine |
| 2820 | as NON-SUID. This is essential for the sake of backward |
| 2821 | compatibility. |
| 2822 | |
| 2823 | The problem is the slave thread is running under "special" user (@), |
| 2824 | that actually does not exist. In the older versions we do not fail |
| 2825 | execution of a stored routine if its definer does not exist and |
| 2826 | continue the execution under the authorization of the invoker |
| 2827 | (BUG#13198). And now if we try to switch to slave-current-user (@), |
| 2828 | we will fail. |
| 2829 | |
| 2830 | Actually, this leads to the inconsistent state of master and |
| 2831 | slave (different definers, different SUID behaviour), but it seems, |
| 2832 | this is the best we can do. |
| 2833 | */ |
| 2834 | |
| 2835 | if (!lex->definer) |
| 2836 | { |
| 2837 | Query_arena original_arena; |
| 2838 | Query_arena *ps_arena= thd->activate_stmt_arena_if_needed(&original_arena); |
| 2839 | |
| 2840 | lex->definer= create_default_definer(thd, false); |
| 2841 | |
| 2842 | if (ps_arena) |
| 2843 | thd->restore_active_arena(ps_arena, &original_arena); |
| 2844 | |
| 2845 | /* Error has been already reported. */ |
| 2846 | if (lex->definer == NULL) |
| 2847 | DBUG_RETURN(TRUE); |
| 2848 | |
| 2849 | if (thd->slave_thread && lex->sphead) |
| 2850 | lex->sphead->set_suid(SP_IS_NOT_SUID); |
| 2851 | } |
| 2852 | else |
| 2853 | { |
| 2854 | LEX_USER *d= get_current_user(thd, lex->definer); |
| 2855 | if (!d) |
| 2856 | DBUG_RETURN(TRUE); |
| 2857 | if (d->user.str == public_name.str) |
| 2858 | { |
| 2859 | my_error(ER_INVALID_ROLE, MYF(0), lex->definer->user.str); |
| 2860 | DBUG_RETURN(TRUE); |
| 2861 | } |
no test coverage detected