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

Function sp_process_definer

sql/sql_parse.cc:2804–2892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2802
2803
2804bool 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 }

Callers 6

wsrep_TOI_event_bufFunction · 0.85
create_triggerMethod · 0.85
mysql_create_routineFunction · 0.85
sql_parse.ccFile · 0.85
mysql_create_viewFunction · 0.85
mysql_create_userFunction · 0.85

Calls 13

create_default_definerFunction · 0.85
get_current_userFunction · 0.85
my_errorFunction · 0.85
Lex_ident_hostClass · 0.85
Lex_cstring_strlenClass · 0.85
check_global_accessFunction · 0.85
is_acl_userFunction · 0.85
push_warning_printfFunction · 0.85
restore_active_arenaMethod · 0.80
set_suidMethod · 0.80
change_item_treeMethod · 0.80

Tested by

no test coverage detected