Commit 4995bcff authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-9610 Trigger on normal table can't insert into CONNECT engine table - Access Denied

in case of prelocking, don't check table->grant.privilege
in handler::external_lock(), do it in
handler::start_stmt().
parent b7ad1ba5
......@@ -4054,7 +4054,7 @@ int ha_connect::delete_all_rows()
} // end of delete_all_rows
bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick)
{
const char *db= (dbn && *dbn) ? dbn : NULL;
TABTYPE type=GetRealType(options);
......@@ -4081,6 +4081,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
case TAB_VEC:
case TAB_JSON:
if (options->filename && *options->filename) {
if (!quick) {
char *s, path[FN_REFLEN], dbpath[FN_REFLEN];
#if defined(__WIN__)
s= "\\";
......@@ -4099,7 +4100,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
return true;
} // endif path
}
} else
return false;
......@@ -4121,10 +4122,13 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
Otherwise it's a DML, the table was normally opened, locked,
privilege were already checked, and table->grant.privilege is set.
With SQL SECURITY DEFINER, table->grant.privilege has definer's privileges.
Unless we're in prelocking mode, in this case table->grant.privilege
is only checked in start_stmt(), not in external_lock().
*/
if (!table || !table->mdl_ticket || table->mdl_ticket->get_type() == MDL_EXCLUSIVE)
return check_access(thd, FILE_ACL, db, NULL, NULL, 0, 0);
if (table->grant.privilege & FILE_ACL)
if ((!quick && thd->lex->requires_prelocking()) || table->grant.privilege & FILE_ACL)
return false;
status_var_increment(thd->status_var.access_denied_errors);
my_error(access_denied_error_code(thd->password), MYF(0),
......@@ -4308,6 +4312,9 @@ int ha_connect::start_stmt(THD *thd, thr_lock_type lock_type)
PGLOBAL g= GetPlug(thd, xp);
DBUG_ENTER("ha_connect::start_stmt");
if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
// Action will depend on lock_type
switch (lock_type) {
case TL_WRITE_ALLOW_WRITE:
......
......@@ -536,7 +536,7 @@ private:
DsMrr_impl ds_mrr;
protected:
bool check_privileges(THD *thd, PTOS options, char *dbn);
bool check_privileges(THD *thd, PTOS options, char *dbn, bool quick=false);
MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras);
char *GetDBfromName(const char *name);
......
create table tcon (i int) engine=Connect table_type=DOS file_name='tcon.dos';
create table tin (i int);
create trigger tr after insert on tin for each row insert into tcon values (new.i);
insert into tin values (1);
drop table tin,tcon;
#
# MDEV-9610 Trigger on normal table can't insert into CONNECT engine table - Access Denied
#
create table tcon (i int) engine=Connect table_type=DOS file_name='tcon.dos';
create table tin (i int);
create trigger tr after insert on tin for each row insert into tcon values (new.i);
insert into tin values (1);
drop table tin,tcon;
let datadir=`select @@datadir`;
remove_file $datadir/test/tcon.dos;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment