Skip to content

Commit

Permalink
MDEV-9610 Trigger on normal table can't insert into CONNECT engine ta…
Browse files Browse the repository at this point in the history
…ble - Access Denied

in case of prelocking, don't check table->grant.privilege
in handler::external_lock(), do it in
handler::start_stmt().
  • Loading branch information
vuvova committed Apr 26, 2016
1 parent b7ad1ba commit 4995bcf
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
13 changes: 10 additions & 3 deletions storage/connect/ha_connect.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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= "\\";
Expand All @@ -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;

Expand All @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion storage/connect/ha_connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ int index_prev(uchar *buf);
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);

Expand Down
5 changes: 5 additions & 0 deletions storage/connect/mysql-test/connect/r/grant3.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
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;
11 changes: 11 additions & 0 deletions storage/connect/mysql-test/connect/t/grant3.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# 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;

0 comments on commit 4995bcf

Please sign in to comment.