summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-11-01 15:23:18 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2019-11-01 15:23:18 +0200
commitec40980ddd921a3a765c23cc430c9c219e48ea85 (patch)
tree6553832d3d3fb4b2cb39aea6a1d69e54275f6eb2 /sql/sql_parse.cc
parent6801f80aface011811d2978f86c03a25ca7b9165 (diff)
parent9c72963d2aef783cae652b5b8ac01f7aa2bcb43a (diff)
downloadmariadb-git-ec40980ddd921a3a765c23cc430c9c219e48ea85.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r--sql/sql_parse.cc51
1 files changed, 24 insertions, 27 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index c0b78ead6d6..516813a0264 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -606,11 +606,12 @@ void init_update_queries(void)
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED |
- CF_SP_BULK_SAFE;
+ CF_SP_BULK_SAFE | CF_DELETES_DATA;
sql_command_flags[SQLCOM_DELETE_MULTI]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
- CF_CAN_BE_EXPLAINED;
+ CF_CAN_BE_EXPLAINED |
+ CF_DELETES_DATA;
sql_command_flags[SQLCOM_REPLACE]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
@@ -3307,6 +3308,10 @@ mysql_execute_command(THD *thd)
#endif
DBUG_ENTER("mysql_execute_command");
+ // check that we correctly marked first table for data insertion
+ DBUG_ASSERT(!(sql_command_flags[lex->sql_command] & CF_INSERTS_DATA) ||
+ first_table->for_insert_data);
+
if (thd->security_ctx->password_expired &&
lex->sql_command != SQLCOM_SET_OPTION)
{
@@ -6751,11 +6756,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
bool check_single_table_access(THD *thd, ulong privilege,
TABLE_LIST *all_tables, bool no_errors)
{
- Security_context * backup_ctx= thd->security_ctx;
-
- /* we need to switch to the saved context (if any) */
- if (all_tables->security_ctx)
- thd->security_ctx= all_tables->security_ctx;
+ Switch_to_definer_security_ctx backup_sctx(thd, all_tables);
const char *db_name;
if ((all_tables->view || all_tables->field_translation) &&
@@ -6768,20 +6769,15 @@ bool check_single_table_access(THD *thd, ulong privilege,
&all_tables->grant.privilege,
&all_tables->grant.m_internal,
0, no_errors))
- goto deny;
+ return 1;
/* Show only 1 table for check_grant */
if (!(all_tables->belong_to_view &&
(thd->lex->sql_command == SQLCOM_SHOW_FIELDS)) &&
check_grant(thd, privilege, all_tables, FALSE, 1, no_errors))
- goto deny;
+ return 1;
- thd->security_ctx= backup_ctx;
return 0;
-
-deny:
- thd->security_ctx= backup_ctx;
- return 1;
}
/**
@@ -6956,7 +6952,6 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
{
TABLE_LIST *org_tables= tables;
TABLE_LIST *first_not_own_table= thd->lex->first_not_own_table();
- Security_context *sctx= thd->security_ctx, *backup_ctx= thd->security_ctx;
uint i= 0;
/*
The check that first_not_own_table is not reached is for the case when
@@ -6968,12 +6963,9 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
{
TABLE_LIST *const table_ref= tables->correspondent_table ?
tables->correspondent_table : tables;
+ Switch_to_definer_security_ctx backup_ctx(thd, table_ref);
ulong want_access= requirements;
- if (table_ref->security_ctx)
- sctx= table_ref->security_ctx;
- else
- sctx= backup_ctx;
/*
Register access for view underlying table.
@@ -6984,7 +6976,7 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
if (table_ref->schema_table_reformed)
{
if (check_show_access(thd, table_ref))
- goto deny;
+ return 1;
continue;
}
@@ -6994,8 +6986,6 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
if (table_ref->is_anonymous_derived_table())
continue;
- thd->security_ctx= sctx;
-
if (table_ref->sequence)
{
/* We want to have either SELECT or INSERT rights to sequences depending
@@ -7009,15 +6999,11 @@ check_table_access(THD *thd, ulong requirements,TABLE_LIST *tables,
&table_ref->grant.privilege,
&table_ref->grant.m_internal,
0, no_errors))
- goto deny;
+ return 1;
}
- thd->security_ctx= backup_ctx;
return check_grant(thd,requirements,org_tables,
any_combination_of_privileges_will_do,
number, no_errors);
-deny:
- thd->security_ctx= backup_ctx;
- return TRUE;
}
@@ -10315,3 +10301,14 @@ CHARSET_INFO *find_bin_collation(CHARSET_INFO *cs)
}
return cs;
}
+
+void LEX::mark_first_table_as_inserting()
+{
+ TABLE_LIST *t= first_select_lex()->table_list.first;
+ DBUG_ENTER("Query_tables_list::mark_tables_with_important_flags");
+ DBUG_ASSERT(sql_command_flags[sql_command] & CF_INSERTS_DATA);
+ t->for_insert_data= TRUE;
+ DBUG_PRINT("info", ("table_list: %p name: %s db: %s command: %u",
+ t, t->table_name.str,t->db.str, sql_command));
+ DBUG_VOID_RETURN;
+}