Skip to content

Commit 4995bcf

Browse files
committed
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().
1 parent b7ad1ba commit 4995bcf

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

storage/connect/ha_connect.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,7 +4054,7 @@ int ha_connect::delete_all_rows()
40544054
} // end of delete_all_rows
40554055

40564056

4057-
bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
4057+
bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn, bool quick)
40584058
{
40594059
const char *db= (dbn && *dbn) ? dbn : NULL;
40604060
TABTYPE type=GetRealType(options);
@@ -4081,6 +4081,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
40814081
case TAB_VEC:
40824082
case TAB_JSON:
40834083
if (options->filename && *options->filename) {
4084+
if (!quick) {
40844085
char *s, path[FN_REFLEN], dbpath[FN_REFLEN];
40854086
#if defined(__WIN__)
40864087
s= "\\";
@@ -4099,7 +4100,7 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
40994100
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--secure-file-priv");
41004101
return true;
41014102
} // endif path
4102-
4103+
}
41034104
} else
41044105
return false;
41054106

@@ -4121,10 +4122,13 @@ bool ha_connect::check_privileges(THD *thd, PTOS options, char *dbn)
41214122
Otherwise it's a DML, the table was normally opened, locked,
41224123
privilege were already checked, and table->grant.privilege is set.
41234124
With SQL SECURITY DEFINER, table->grant.privilege has definer's privileges.
4125+
4126+
Unless we're in prelocking mode, in this case table->grant.privilege
4127+
is only checked in start_stmt(), not in external_lock().
41244128
*/
41254129
if (!table || !table->mdl_ticket || table->mdl_ticket->get_type() == MDL_EXCLUSIVE)
41264130
return check_access(thd, FILE_ACL, db, NULL, NULL, 0, 0);
4127-
if (table->grant.privilege & FILE_ACL)
4131+
if ((!quick && thd->lex->requires_prelocking()) || table->grant.privilege & FILE_ACL)
41284132
return false;
41294133
status_var_increment(thd->status_var.access_denied_errors);
41304134
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)
43084312
PGLOBAL g= GetPlug(thd, xp);
43094313
DBUG_ENTER("ha_connect::start_stmt");
43104314

4315+
if (check_privileges(thd, GetTableOptionStruct(), table->s->db.str, true))
4316+
DBUG_RETURN(HA_ERR_INTERNAL_ERROR);
4317+
43114318
// Action will depend on lock_type
43124319
switch (lock_type) {
43134320
case TL_WRITE_ALLOW_WRITE:

storage/connect/ha_connect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ int index_prev(uchar *buf);
536536
DsMrr_impl ds_mrr;
537537

538538
protected:
539-
bool check_privileges(THD *thd, PTOS options, char *dbn);
539+
bool check_privileges(THD *thd, PTOS options, char *dbn, bool quick=false);
540540
MODE CheckMode(PGLOBAL g, THD *thd, MODE newmode, bool *chk, bool *cras);
541541
char *GetDBfromName(const char *name);
542542

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
create table tcon (i int) engine=Connect table_type=DOS file_name='tcon.dos';
2+
create table tin (i int);
3+
create trigger tr after insert on tin for each row insert into tcon values (new.i);
4+
insert into tin values (1);
5+
drop table tin,tcon;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# MDEV-9610 Trigger on normal table can't insert into CONNECT engine table - Access Denied
3+
#
4+
create table tcon (i int) engine=Connect table_type=DOS file_name='tcon.dos';
5+
create table tin (i int);
6+
create trigger tr after insert on tin for each row insert into tcon values (new.i);
7+
insert into tin values (1);
8+
drop table tin,tcon;
9+
10+
let datadir=`select @@datadir`;
11+
remove_file $datadir/test/tcon.dos;

0 commit comments

Comments
 (0)