mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
small post-merge fixes for bug#16406
(pre-push) mysql-test/r/events.result: update result mysql-test/t/events.test: few more tests sql/event.cc: fix compilation failure after big merge sql/event.h: initialize s_ctx to be the context to be used. don't use sphead->m_security_ctx but we will copy the initted ctx to there sql/event_timed.cc: -initialize s_ctx to be the context to be used. don't use sphead->m_security_ctx but we will copy the initted ctx to there - first init the context - then compile the event - and then copy the context - don't use mysql_change_db() for now change_security_context() gets the right context info
This commit is contained in:
@@ -23,6 +23,7 @@ DROP EVENT e_x2;
|
|||||||
DROP DATABASE db_x;
|
DROP DATABASE db_x;
|
||||||
DROP USER pauline@localhost;
|
DROP USER pauline@localhost;
|
||||||
USE events_test;
|
USE events_test;
|
||||||
|
SET GLOBAL event_scheduler=0;
|
||||||
drop event if exists event1;
|
drop event if exists event1;
|
||||||
Warnings:
|
Warnings:
|
||||||
Note 1305 Event event1 does not exist
|
Note 1305 Event event1 does not exist
|
||||||
@@ -43,6 +44,14 @@ select db, name, body, status, interval_field, interval_value from mysql.event;
|
|||||||
db name body status interval_field interval_value
|
db name body status interval_field interval_value
|
||||||
events_test e_43 set @a = 4 ENABLED SECOND 1
|
events_test e_43 set @a = 4 ENABLED SECOND 1
|
||||||
drop event e_43;
|
drop event e_43;
|
||||||
|
"Let's check whether we can use non-qualified names"
|
||||||
|
create table non_qualif(a int);
|
||||||
|
create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219);
|
||||||
|
select * from non_qualif;
|
||||||
|
a
|
||||||
|
800219
|
||||||
|
drop event non_qualif_ev;
|
||||||
|
drop table non_qualif;
|
||||||
set global event_scheduler = 0;
|
set global event_scheduler = 0;
|
||||||
create table t_event3 (a int, b float);
|
create table t_event3 (a int, b float);
|
||||||
drop event if exists event3;
|
drop event if exists event3;
|
||||||
@@ -374,7 +383,6 @@ show processlist;
|
|||||||
Id User Host db Command Time State Info
|
Id User Host db Command Time State Info
|
||||||
# root localhost events_test Query # NULL show processlist
|
# root localhost events_test Query # NULL show processlist
|
||||||
# event_scheduler connecting host NULL Connect # Sleeping NULL
|
# event_scheduler connecting host NULL Connect # Sleeping NULL
|
||||||
# root localhost events_test Connect # User lock select get_lock("test_lock2_1", 20)
|
|
||||||
"Release the lock so the child process should finish. Hence the scheduler also"
|
"Release the lock so the child process should finish. Hence the scheduler also"
|
||||||
select release_lock("test_lock2_1");
|
select release_lock("test_lock2_1");
|
||||||
release_lock("test_lock2_1")
|
release_lock("test_lock2_1")
|
||||||
|
@@ -28,11 +28,11 @@ connection default;
|
|||||||
DROP DATABASE db_x;
|
DROP DATABASE db_x;
|
||||||
DROP USER pauline@localhost;
|
DROP USER pauline@localhost;
|
||||||
USE events_test;
|
USE events_test;
|
||||||
--sleep 1
|
|
||||||
#
|
#
|
||||||
# END: BUG #17289 Events: missing privilege check for drop database
|
# END: BUG #17289 Events: missing privilege check for drop database
|
||||||
#
|
#
|
||||||
|
SET GLOBAL event_scheduler=0;
|
||||||
|
--sleep 1
|
||||||
drop event if exists event1;
|
drop event if exists event1;
|
||||||
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
|
create event event1 on schedule every 15 minute starts now() ends date_add(now(), interval 5 hour) DO begin end;
|
||||||
alter event event1 rename to event2 enable;
|
alter event event1 rename to event2 enable;
|
||||||
@@ -56,6 +56,14 @@ alter event e_43 do alter event e_43 do set @a = 4;
|
|||||||
select db, name, body, status, interval_field, interval_value from mysql.event;
|
select db, name, body, status, interval_field, interval_value from mysql.event;
|
||||||
drop event e_43;
|
drop event e_43;
|
||||||
--sleep 1
|
--sleep 1
|
||||||
|
|
||||||
|
--echo "Let's check whether we can use non-qualified names"
|
||||||
|
create table non_qualif(a int);
|
||||||
|
create event non_qualif_ev on schedule every 10 minute do insert into non_qualif values (800219);
|
||||||
|
--sleep 2
|
||||||
|
select * from non_qualif;
|
||||||
|
drop event non_qualif_ev;
|
||||||
|
drop table non_qualif;
|
||||||
set global event_scheduler = 0;
|
set global event_scheduler = 0;
|
||||||
|
|
||||||
create table t_event3 (a int, b float);
|
create table t_event3 (a int, b float);
|
||||||
|
@@ -1272,7 +1272,7 @@ int db_drop_event(THD *thd, event_timed *et, bool drop_if_exists,
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ret= evex_db_find_event_aux(thd, et->dbname,et->name,et->definer,table)))
|
if (!(ret= evex_db_find_event_aux(thd, et, table)))
|
||||||
{
|
{
|
||||||
if ((ret= table->file->ha_delete_row(table->record[0])))
|
if ((ret= table->file->ha_delete_row(table->record[0])))
|
||||||
{
|
{
|
||||||
@@ -1452,7 +1452,7 @@ evex_drop_db_events(THD *thd, char *db)
|
|||||||
READ_RECORD read_record_info;
|
READ_RECORD read_record_info;
|
||||||
MYSQL_LOCK *lock;
|
MYSQL_LOCK *lock;
|
||||||
int ret= 0;
|
int ret= 0;
|
||||||
int i;
|
uint i;
|
||||||
LEX_STRING db_lex= {db, strlen(db)};
|
LEX_STRING db_lex= {db, strlen(db)};
|
||||||
|
|
||||||
DBUG_ENTER("evex_drop_db_events");
|
DBUG_ENTER("evex_drop_db_events");
|
||||||
|
@@ -247,7 +247,8 @@ public:
|
|||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
bool
|
bool
|
||||||
change_security_context(THD *thd, Security_context **backup);
|
change_security_context(THD *thd, Security_context *s_ctx,
|
||||||
|
Security_context **backup);
|
||||||
|
|
||||||
void
|
void
|
||||||
restore_security_context(THD *thd, Security_context *backup);
|
restore_security_context(THD *thd, Security_context *backup);
|
||||||
|
@@ -412,21 +412,30 @@ event_timed::init_definer(THD *thd)
|
|||||||
{
|
{
|
||||||
DBUG_ENTER("event_timed::init_definer");
|
DBUG_ENTER("event_timed::init_definer");
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("init definer_user thd->mem_root=0x%lx "
|
||||||
|
"thd->sec_ctx->priv_user=0x%lx", thd->mem_root,
|
||||||
|
thd->security_ctx->priv_user));
|
||||||
definer_user.str= strdup_root(thd->mem_root, thd->security_ctx->priv_user);
|
definer_user.str= strdup_root(thd->mem_root, thd->security_ctx->priv_user);
|
||||||
definer_user.length= strlen(thd->security_ctx->priv_user);
|
definer_user.length= strlen(thd->security_ctx->priv_user);
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("init definer_host thd->s_c->priv_host=0x%lx",
|
||||||
|
thd->security_ctx->priv_host));
|
||||||
definer_host.str= strdup_root(thd->mem_root, thd->security_ctx->priv_host);
|
definer_host.str= strdup_root(thd->mem_root, thd->security_ctx->priv_host);
|
||||||
definer_host.length= strlen(thd->security_ctx->priv_host);
|
definer_host.length= strlen(thd->security_ctx->priv_host);
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("init definer as whole"));
|
||||||
definer.length= definer_user.length + definer_host.length + 1;
|
definer.length= definer_user.length + definer_host.length + 1;
|
||||||
definer.str= alloc_root(thd->mem_root, definer.length + 1);
|
definer.str= alloc_root(thd->mem_root, definer.length + 1);
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("copy the user"));
|
||||||
memcpy(definer.str, definer_user.str, definer_user.length);
|
memcpy(definer.str, definer_user.str, definer_user.length);
|
||||||
definer.str[definer_user.length]= '@';
|
definer.str[definer_user.length]= '@';
|
||||||
|
|
||||||
|
DBUG_PRINT("info",("copy the host"));
|
||||||
memcpy(definer.str + definer_user.length + 1, definer_host.str,
|
memcpy(definer.str + definer_user.length + 1, definer_host.str,
|
||||||
definer_host.length);
|
definer_host.length);
|
||||||
definer.str[definer.length]= '\0';
|
definer.str[definer.length]= '\0';
|
||||||
|
DBUG_PRINT("info",("definer initted"));
|
||||||
|
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
}
|
}
|
||||||
@@ -1070,6 +1079,8 @@ int
|
|||||||
event_timed::execute(THD *thd, MEM_ROOT *mem_root)
|
event_timed::execute(THD *thd, MEM_ROOT *mem_root)
|
||||||
{
|
{
|
||||||
Security_context *save_ctx;
|
Security_context *save_ctx;
|
||||||
|
/* this one is local and not needed after exec */
|
||||||
|
Security_context security_ctx;
|
||||||
int ret= 0;
|
int ret= 0;
|
||||||
|
|
||||||
DBUG_ENTER("event_timed::execute");
|
DBUG_ENTER("event_timed::execute");
|
||||||
@@ -1085,18 +1096,19 @@ event_timed::execute(THD *thd, MEM_ROOT *mem_root)
|
|||||||
running= true;
|
running= true;
|
||||||
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
||||||
|
|
||||||
// TODO Andrey : make this as member variable and delete in destructor
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
||||||
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
||||||
|
change_security_context(thd, &security_ctx, &save_ctx);
|
||||||
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
||||||
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
||||||
|
|
||||||
if (!sphead && (ret= compile(thd, mem_root)))
|
if (!sphead && (ret= compile(thd, mem_root)))
|
||||||
goto done;
|
goto done;
|
||||||
|
/* Now we are sure we have valid this->sphead so we can copy the context */
|
||||||
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
sphead->m_security_ctx= security_ctx;
|
||||||
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
thd->db= dbname.str;
|
||||||
change_security_context(thd, &save_ctx);
|
thd->db_length= dbname.length;
|
||||||
|
if (!check_access(thd, EVENT_ACL,dbname.str, 0, 0, 0,is_schema_db(dbname.str)))
|
||||||
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
|
||||||
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
|
||||||
if (mysql_change_db(thd, dbname.str, 0))
|
|
||||||
{
|
{
|
||||||
List<Item> empty_item_list;
|
List<Item> empty_item_list;
|
||||||
empty_item_list.empty();
|
empty_item_list.empty();
|
||||||
@@ -1109,16 +1121,20 @@ event_timed::execute(THD *thd, MEM_ROOT *mem_root)
|
|||||||
ret= -99;
|
ret= -99;
|
||||||
}
|
}
|
||||||
restore_security_context(thd, save_ctx);
|
restore_security_context(thd, save_ctx);
|
||||||
|
|
||||||
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
DBUG_PRINT("info", ("master_access=%d db_access=%d",
|
||||||
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
thd->security_ctx->master_access, thd->security_ctx->db_access));
|
||||||
|
thd->db= 0;
|
||||||
|
|
||||||
VOID(pthread_mutex_lock(&this->LOCK_running));
|
VOID(pthread_mutex_lock(&this->LOCK_running));
|
||||||
running= false;
|
running= false;
|
||||||
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
VOID(pthread_mutex_unlock(&this->LOCK_running));
|
||||||
|
|
||||||
done:
|
done:
|
||||||
// Don't cache sphead if allocated on another mem_root
|
/*
|
||||||
|
1. Don't cache sphead if allocated on another mem_root
|
||||||
|
2. Don't call security_ctx.destroy() because this will free our dbname.str
|
||||||
|
name.str and definer.str
|
||||||
|
*/
|
||||||
if (mem_root && sphead)
|
if (mem_root && sphead)
|
||||||
{
|
{
|
||||||
delete sphead;
|
delete sphead;
|
||||||
@@ -1143,20 +1159,22 @@ done:
|
|||||||
1 - Error (generates error too)
|
1 - Error (generates error too)
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
event_timed::change_security_context(THD *thd, Security_context **backup)
|
event_timed::change_security_context(THD *thd, Security_context *s_ctx,
|
||||||
|
Security_context **backup)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("event_timed::change_security_context");
|
DBUG_ENTER("event_timed::change_security_context");
|
||||||
DBUG_PRINT("info",("%s@%s@%s",definer_user.str,definer_host.str, dbname.str));
|
DBUG_PRINT("info",("%s@%s@%s",definer_user.str,definer_host.str, dbname.str));
|
||||||
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
#ifndef NO_EMBEDDED_ACCESS_CHECKS
|
||||||
|
s_ctx->init();
|
||||||
*backup= 0;
|
*backup= 0;
|
||||||
if (acl_getroot_no_password(&sphead->m_security_ctx, definer_user.str,
|
if (acl_getroot_no_password(s_ctx, definer_user.str, definer_host.str,
|
||||||
definer_host.str, definer_host.str, dbname.str))
|
definer_host.str, dbname.str))
|
||||||
{
|
{
|
||||||
my_error(ER_NO_SUCH_USER, MYF(0), definer_user.str, definer_host.str);
|
my_error(ER_NO_SUCH_USER, MYF(0), definer_user.str, definer_host.str);
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
}
|
}
|
||||||
*backup= thd->security_ctx;
|
*backup= thd->security_ctx;
|
||||||
thd->security_ctx= &sphead->m_security_ctx;
|
thd->security_ctx= s_ctx;
|
||||||
#endif
|
#endif
|
||||||
DBUG_RETURN(FALSE);
|
DBUG_RETURN(FALSE);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user