Skip to content

Commit d39addc

Browse files
committed
MDEV-6733: Implement ALTER PROCEDURE/FUNCTION DEFINER
1 parent 96b3dd0 commit d39addc

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

sql/sp.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,9 +1765,19 @@ Sp_handler::sp_update_routine(THD *thd, const Database_qualified_name *name,
17651765
if (chistics->comment.str)
17661766
table->field[MYSQL_PROC_FIELD_COMMENT]->store(chistics->comment,
17671767
system_charset_info);
1768+
if (thd->lex->definer)
1769+
{
1770+
char definer_str[USER_HOST_BUFF_SIZE];
1771+
uint definer_len= strxnmov(definer_str, sizeof(definer_str)-1,
1772+
thd->lex->definer->user.str, "@",
1773+
thd->lex->definer->host.str, NullS) - definer_str;
1774+
1775+
table->field[MYSQL_PROC_FIELD_DEFINER]->store(definer_str, definer_len, system_charset_info);
1776+
}
17681777
if (chistics->agg_type != DEFAULT_AGGREGATE)
17691778
table->field[MYSQL_PROC_FIELD_AGGREGATE]->
17701779
store((longlong)chistics->agg_type, TRUE);
1780+
17711781
if ((ret= table->file->ha_update_row(table->record[1],table->record[0])) &&
17721782
ret != HA_ERR_RECORD_IS_THE_SAME)
17731783
ret= SP_WRITE_ROW_FAILED;

sql/sql_parse.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6448,7 +6448,16 @@ alter_routine(THD *thd, LEX *lex)
64486448
if (check_routine_access(thd, ALTER_PROC_ACL, &lex->spname->m_db,
64496449
&lex->spname->m_name, sph, 0))
64506450
return 1;
6451+
if (lex->definer &&
6452+
(my_strcasecmp(system_charset_info, lex->definer->user.str, thd->security_ctx->priv_user) ||
6453+
my_strcasecmp(system_charset_info, lex->definer->host.str, thd->security_ctx->priv_host)) &&
6454+
check_global_access(thd, SUPER_ACL))
6455+
{
6456+
return 1;
6457+
}
6458+
64516459
/*
6460+
64526461
Note that if you implement the capability of ALTER FUNCTION to
64536462
alter the body of the function, this command should be made to
64546463
follow the restrictions that log-bin-trust-function-creators=0

0 commit comments

Comments
 (0)