Commit dc5b10d3 authored by unknown's avatar unknown

Merge tulin@bk-internal.mysql.com:/home/bk/mysql-5.1-new

into  poseidon.ndb.mysql.com:/home/tomas/mysql-5.1-new

parents 5bcd374c 642e222c
...@@ -110,109 +110,6 @@ user_str ...@@ -110,109 +110,6 @@ user_str
mysqltest_dfn@localhost mysqltest_dfn@localhost
mysqltest_dfn@localhost mysqltest_dfn@localhost
---> connection: default
use mysqltest_db1;
REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost;
---> connection: wl2818_definer_con
use mysqltest_db1;
DROP TRIGGER trg1;
SET @new_sum = 0;
SET @old_sum = 0;
---> INSERT INTO statement; BEFORE timing
CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
INSERT INTO t1 VALUES(4);
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> INSERT INTO statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER INSERT ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
INSERT INTO t1 VALUES(5);
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> UPDATE statement; BEFORE timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 BEFORE UPDATE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
UPDATE t1 SET num_value = 10;
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> UPDATE statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER UPDATE ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
UPDATE t1 SET num_value = 20;
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> DELETE statement; BEFORE timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 BEFORE DELETE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
DELETE FROM t1;
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> DELETE statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER DELETE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
DELETE FROM t1;
ERROR 42000: SELECT command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> connection: default
use mysqltest_db1;
GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_dfn@localhost;
REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost;
---> connection: wl2818_definer_con
use mysqltest_db1;
DROP TRIGGER trg1;
SET @new_sum = 0;
SET @old_sum = 0;
---> INSERT INTO statement; BEFORE timing
CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
INSERT INTO t1 VALUES(4);
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> INSERT INTO statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER INSERT ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
INSERT INTO t1 VALUES(5);
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> UPDATE statement; BEFORE timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 BEFORE UPDATE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
UPDATE t1 SET num_value = 10;
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> UPDATE statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER UPDATE ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
UPDATE t1 SET num_value = 20;
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> DELETE statement; BEFORE timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 BEFORE DELETE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
DELETE FROM t1;
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> DELETE statement; AFTER timing
DROP TRIGGER trg1;
CREATE TRIGGER trg1 AFTER DELETE ON t1
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
DELETE FROM t1;
ERROR 42000: UPDATE command denied to user 'mysqltest_dfn'@'localhost' for table 't1'
---> connection: wl2818_definer_con ---> connection: wl2818_definer_con
use mysqltest_db1; use mysqltest_db1;
DROP TRIGGER trg1; DROP TRIGGER trg1;
...@@ -284,3 +181,185 @@ DROP USER mysqltest_inv@localhost; ...@@ -284,3 +181,185 @@ DROP USER mysqltest_inv@localhost;
DROP DATABASE mysqltest_db1; DROP DATABASE mysqltest_db1;
Warnings: Warnings:
Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger. Warning 1454 No definer attribute for trigger 'mysqltest_db1'.'trg1'. The trigger will be activated under the authorization of the invoker, which may have insufficient privileges. Please recreate the trigger.
DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
FLUSH PRIVILEGES;
DROP DATABASE IF EXISTS mysqltest_db1;
CREATE DATABASE mysqltest_db1;
use mysqltest_db1;
CREATE TABLE t1(col CHAR(20));
CREATE TABLE t2(col CHAR(20));
CREATE TABLE t3(col CHAR(20));
CREATE TABLE t4(col CHAR(20));
CREATE USER mysqltest_u1@localhost;
REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
GRANT TRIGGER ON mysqltest_db1.* TO mysqltest_u1@localhost;
SET @mysqltest_var = NULL;
---> connection: default
use mysqltest_db1;
GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost;
SHOW GRANTS FOR mysqltest_u1@localhost;
Grants for mysqltest_u1@localhost
GRANT USAGE ON *.* TO 'mysqltest_u1'@'localhost'
GRANT DELETE, TRIGGER ON `mysqltest_db1`.* TO 'mysqltest_u1'@'localhost'
---> connection: bug15166_u1_con
use mysqltest_db1;
CREATE TRIGGER t1_trg_after_delete AFTER DELETE ON t1
FOR EACH ROW
SET @mysqltest_var = 'Hello, world!';
---> connection: default
use mysqltest_db1;
GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
---> connection: bug15166_u1_con
use mysqltest_db1;
CREATE TRIGGER t1_trg_err_1 BEFORE INSERT ON t1
FOR EACH ROW
SET @mysqltest_var = NEW.col;
DROP TRIGGER t1_trg_err_1;
CREATE TRIGGER t1_trg_err_2 BEFORE DELETE ON t1
FOR EACH ROW
SET @mysqltest_var = OLD.col;
DROP TRIGGER t1_trg_err_2;
CREATE TRIGGER t2_trg_before_insert BEFORE INSERT ON t2
FOR EACH ROW
SET NEW.col = 't2_trg_before_insert';
CREATE TRIGGER t3_trg_err_1 BEFORE INSERT ON t3
FOR EACH ROW
SET @mysqltest_var = NEW.col;
DROP TRIGGER t3_trg_err_1;
CREATE TRIGGER t3_trg_err_2 BEFORE DELETE ON t3
FOR EACH ROW
SET @mysqltest_var = OLD.col;
DROP TRIGGER t3_trg_err_2;
CREATE TRIGGER t4_trg_before_insert BEFORE INSERT ON t4
FOR EACH ROW
SET NEW.col = 't4_trg_before_insert';
---> connection: default
use mysqltest_db1;
REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
GRANT SELECT(col) on mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT SELECT(col) on mysqltest_db1.t4 TO mysqltest_u1@localhost;
---> connection: bug15166_u1_con
use mysqltest_db1;
CREATE TRIGGER t1_trg_after_insert AFTER INSERT ON t1
FOR EACH ROW
SET @mysqltest_var = NEW.col;
CREATE TRIGGER t1_trg_after_update AFTER UPDATE ON t1
FOR EACH ROW
SET @mysqltest_var = OLD.col;
CREATE TRIGGER t2_trg_err_1 BEFORE UPDATE ON t2
FOR EACH ROW
SET NEW.col = 't2_trg_err_1';
DROP TRIGGER t2_trg_err_1;
CREATE TRIGGER t2_trg_err_2 BEFORE UPDATE ON t2
FOR EACH ROW
SET NEW.col = CONCAT(OLD.col, '(updated)');
DROP TRIGGER t2_trg_err_2;
CREATE TRIGGER t3_trg_after_insert AFTER INSERT ON t3
FOR EACH ROW
SET @mysqltest_var = NEW.col;
CREATE TRIGGER t3_trg_after_update AFTER UPDATE ON t3
FOR EACH ROW
SET @mysqltest_var = OLD.col;
CREATE TRIGGER t4_trg_err_1 BEFORE UPDATE ON t4
FOR EACH ROW
SET NEW.col = 't4_trg_err_1';
DROP TRIGGER t4_trg_err_1;
CREATE TRIGGER t4_trg_err_2 BEFORE UPDATE ON t4
FOR EACH ROW
SET NEW.col = CONCAT(OLD.col, '(updated)');
DROP TRIGGER t4_trg_err_2;
---> connection: default
use mysqltest_db1;
REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
REVOKE SELECT ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
REVOKE SELECT(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
REVOKE SELECT(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
INSERT INTO t1 VALUES('line1');
ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for column 'col' in table 't1'
SELECT * FROM t1;
col
line1
SELECT @mysqltest_var;
@mysqltest_var
NULL
INSERT INTO t2 VALUES('line2');
SELECT * FROM t2;
col
t2_trg_before_insert
INSERT INTO t3 VALUES('t3_line1');
ERROR 42000: SELECT command denied to user 'mysqltest_u1'@'localhost' for column 'col' in table 't3'
SELECT * FROM t3;
col
t3_line1
SELECT @mysqltest_var;
@mysqltest_var
NULL
INSERT INTO t4 VALUES('t4_line2');
SELECT * FROM t4;
col
t4_trg_before_insert
---> connection: default
use mysqltest_db1;
REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
GRANT SELECT(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT SELECT(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
INSERT INTO t1 VALUES('line3');
SELECT * FROM t1;
col
line1
line3
SELECT @mysqltest_var;
@mysqltest_var
line3
INSERT INTO t2 VALUES('line4');
ERROR 42000: UPDATE command denied to user 'mysqltest_u1'@'localhost' for column 'col' in table 't2'
SELECT * FROM t2;
col
t2_trg_before_insert
INSERT INTO t3 VALUES('t3_line2');
SELECT * FROM t3;
col
t3_line1
t3_line2
SELECT @mysqltest_var;
@mysqltest_var
t3_line2
INSERT INTO t4 VALUES('t4_line2');
ERROR 42000: UPDATE command denied to user 'mysqltest_u1'@'localhost' for column 'col' in table 't4'
SELECT * FROM t4;
col
t4_trg_before_insert
DELETE FROM t1;
SELECT @mysqltest_var;
@mysqltest_var
Hello, world!
DROP USER mysqltest_u1@localhost;
DROP DATABASE mysqltest_db1;
...@@ -8,8 +8,6 @@ ...@@ -8,8 +8,6 @@
# #
# Tests for WL#2818: # Tests for WL#2818:
# - Check that triggers are executed under the authorization of the definer. # - Check that triggers are executed under the authorization of the definer.
# - Check that if trigger contains NEW/OLD variables, the definer must have
# SELECT privilege on the subject table.
# - Check DEFINER clause of CREATE TRIGGER statement; # - Check DEFINER clause of CREATE TRIGGER statement;
# - Check that SUPER privilege required to create a trigger with different # - Check that SUPER privilege required to create a trigger with different
# definer. # definer.
...@@ -18,6 +16,8 @@ ...@@ -18,6 +16,8 @@
# - Check that the definer of a trigger does not exist, the trigger will # - Check that the definer of a trigger does not exist, the trigger will
# not be activated. # not be activated.
# - Check that SHOW TRIGGERS statement provides "Definer" column. # - Check that SHOW TRIGGERS statement provides "Definer" column.
# - Check that if trigger contains NEW/OLD variables, the definer must have
# SELECT privilege on the subject table (aka BUG#15166/BUG#15196).
# #
# Let's also check that user name part of definer can contain '@' symbol (to # Let's also check that user name part of definer can contain '@' symbol (to
# check that triggers are not affected by BUG#13310 "incorrect user parsing # check that triggers are not affected by BUG#13310 "incorrect user parsing
...@@ -255,19 +255,39 @@ SELECT * FROM t1; ...@@ -255,19 +255,39 @@ SELECT * FROM t1;
SELECT * FROM t2; SELECT * FROM t2;
# #
# Check that if trigger contains NEW/OLD variables, the definer must have # Check DEFINER clause of CREATE TRIGGER statement.
# SELECT/UPDATE privilege on the subject table: #
# - drop the trigger; # - Check that SUPER privilege required to create a trigger with different
# - create a new trigger, which will use NEW variable; # definer:
# - create another new trigger, which will use OLD variable; # - try to create a trigger with DEFINER="definer@localhost" under
# - revoke SELECT/UPDATE privilege on the first table from "definer"; # "invoker";
# - insert a row into the first table;
# - analyze error code; # - analyze error code;
# - Check that if the user specified as DEFINER does not exist, a warning is
# emitted:
# - create a trigger with DEFINER="non_existent_user@localhost" from
# "definer";
# - check that a warning emitted;
# - Check that the definer of a trigger does not exist, the trigger will not
# be activated:
# - activate just created trigger;
# - check error code;
# #
# --connection wl2818_definer_con
# SELECT privilege. --echo
# --echo ---> connection: wl2818_definer_con
use mysqltest_db1;
DROP TRIGGER trg1;
# Check that SUPER is required to specify different DEFINER.
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
CREATE DEFINER='mysqltest_inv'@'localhost'
TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = 0;
--connection default --connection default
--echo --echo
...@@ -275,105 +295,145 @@ SELECT * FROM t2; ...@@ -275,105 +295,145 @@ SELECT * FROM t2;
use mysqltest_db1; use mysqltest_db1;
REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost; GRANT SUPER ON *.* TO mysqltest_dfn@localhost;
--disconnect wl2818_definer_con
--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1)
--connection wl2818_definer_con --connection wl2818_definer_con
--echo --echo
--echo ---> connection: wl2818_definer_con --echo ---> connection: wl2818_definer_con
use mysqltest_db1; CREATE DEFINER='mysqltest_inv'@'localhost'
TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = 0;
DROP TRIGGER trg1; # Create with non-existent user.
SET @new_sum = 0; CREATE DEFINER='mysqltest_nonexs'@'localhost'
SET @old_sum = 0; TRIGGER trg2 AFTER INSERT ON t1
FOR EACH ROW
SET @new_sum = 0;
# INSERT INTO statement; BEFORE timing # Check that trg2 will not be activated.
--echo ---> INSERT INTO statement; BEFORE timing # --error ER_SPECIFIC_ACCESS_DENIED_ERROR
#
# TODO: Due to the BUG#13198(SP executes if definer does not exist) the
# following statement does not fail as it should.
INSERT INTO t1 VALUES(6);
#
# Check that SHOW TRIGGERS statement provides "Definer" column.
#
SHOW TRIGGERS;
#
# Check that weird definer values do not break functionality. I.e. check the
# following definer values:
# - '';
# - '@';
# - '@abc@def@@';
# - '@hostname';
# - '@abc@def@@@hostname';
#
DROP TRIGGER trg1;
DROP TRIGGER trg2;
CREATE TRIGGER trg1 BEFORE INSERT ON t1 CREATE TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value; SET @a = 1;
--error ER_TABLEACCESS_DENIED_ERROR
INSERT INTO t1 VALUES(4);
# INSERT INTO statement; AFTER timing CREATE TRIGGER trg2 AFTER INSERT ON t1
FOR EACH ROW
SET @a = 2;
--echo ---> INSERT INTO statement; AFTER timing CREATE TRIGGER trg3 BEFORE UPDATE ON t1
FOR EACH ROW
SET @a = 3;
DROP TRIGGER trg1; CREATE TRIGGER trg4 AFTER UPDATE ON t1
FOR EACH ROW
SET @a = 4;
CREATE TRIGGER trg1 AFTER INSERT ON t1 CREATE TRIGGER trg5 BEFORE DELETE ON t1
FOR EACH ROW FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value; SET @a = 5;
--error ER_TABLEACCESS_DENIED_ERROR --exec egrep -v '^definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
INSERT INTO t1 VALUES(5); --exec echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQL_TEST_DIR/var/tmp/t1.TRG
--exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG
# UPDATE statement; BEFORE timing --echo
--echo ---> UPDATE statement; BEFORE timing SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
DROP TRIGGER trg1; --echo
CREATE TRIGGER trg1 BEFORE UPDATE ON t1 SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name;
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
--error ER_TABLEACCESS_DENIED_ERROR #
UPDATE t1 SET num_value = 10; # Cleanup
#
# UPDATE statement; AFTER timing --connection default
--echo
--echo ---> connection: default
--echo ---> UPDATE statement; AFTER timing DROP USER mysqltest_dfn@localhost;
DROP USER mysqltest_inv@localhost;
DROP TRIGGER trg1; DROP DATABASE mysqltest_db1;
CREATE TRIGGER trg1 AFTER UPDATE ON t1
FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value;
--error ER_TABLEACCESS_DENIED_ERROR ###########################################################################
UPDATE t1 SET num_value = 20; #
# BUG#15166: Wrong update [was: select/update] permissions required to execute
# triggers.
#
# BUG#15196: Wrong select permission required to execute triggers.
#
###########################################################################
# DELETE statement; BEFORE timing #
# Prepare environment.
#
--echo ---> DELETE statement; BEFORE timing DELETE FROM mysql.user WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.db WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.tables_priv WHERE User LIKE 'mysqltest_%';
DELETE FROM mysql.columns_priv WHERE User LIKE 'mysqltest_%';
FLUSH PRIVILEGES;
DROP TRIGGER trg1; --disable_warnings
DROP DATABASE IF EXISTS mysqltest_db1;
--enable_warnings
CREATE TRIGGER trg1 BEFORE DELETE ON t1 CREATE DATABASE mysqltest_db1;
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
--error ER_TABLEACCESS_DENIED_ERROR use mysqltest_db1;
DELETE FROM t1;
# DELETE statement; AFTER timing # Tables for tesing table-level privileges:
CREATE TABLE t1(col CHAR(20)); # table for "read-value" trigger
CREATE TABLE t2(col CHAR(20)); # table for "write-value" trigger
--echo ---> DELETE statement; AFTER timing # Tables for tesing column-level privileges:
CREATE TABLE t3(col CHAR(20)); # table for "read-value" trigger
CREATE TABLE t4(col CHAR(20)); # table for "write-value" trigger
DROP TRIGGER trg1; CREATE USER mysqltest_u1@localhost;
REVOKE ALL PRIVILEGES, GRANT OPTION FROM mysqltest_u1@localhost;
GRANT TRIGGER ON mysqltest_db1.* TO mysqltest_u1@localhost;
CREATE TRIGGER trg1 AFTER DELETE ON t1 SET @mysqltest_var = NULL;
FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value;
--error ER_TABLEACCESS_DENIED_ERROR --connect (bug15166_u1_con,localhost,mysqltest_u1,,mysqltest_db1)
DELETE FROM t1;
# # parsing (CREATE TRIGGER) time:
# UPDATE privilege # - check that nor SELECT either UPDATE is required to execute triggger w/o
# # NEW/OLD variables.
# NOTE: At the moment, UPDATE privilege is required if the trigger contains
# NEW/OLD variables, whenever the trigger modifies them or not. Moreover,
# UPDATE privilege is checked for whole table, not for individual columns.
#
# The following test cases should be changed when full support of UPDATE
# privilege will be done.
#
--connection default --connection default
--echo --echo
...@@ -381,225 +441,255 @@ DELETE FROM t1; ...@@ -381,225 +441,255 @@ DELETE FROM t1;
use mysqltest_db1; use mysqltest_db1;
GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_dfn@localhost; GRANT DELETE ON mysqltest_db1.* TO mysqltest_u1@localhost;
REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_dfn@localhost; SHOW GRANTS FOR mysqltest_u1@localhost;
--connection wl2818_definer_con --connection bug15166_u1_con
--echo --echo
--echo ---> connection: wl2818_definer_con --echo ---> connection: bug15166_u1_con
use mysqltest_db1; use mysqltest_db1;
DROP TRIGGER trg1; CREATE TRIGGER t1_trg_after_delete AFTER DELETE ON t1
FOR EACH ROW
SET @mysqltest_var = 'Hello, world!';
SET @new_sum = 0; # parsing (CREATE TRIGGER) time:
SET @old_sum = 0; # - check that UPDATE is not enough to read the value;
# - check that UPDATE is required to modify the value;
# INSERT INTO statement; BEFORE timing --connection default
--echo
--echo ---> connection: default
--echo ---> INSERT INTO statement; BEFORE timing use mysqltest_db1;
CREATE TRIGGER trg1 BEFORE INSERT ON t1 GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
FOR EACH ROW GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
SET @new_sum = @new_sum + NEW.num_value;
--error ER_TABLEACCESS_DENIED_ERROR GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
INSERT INTO t1 VALUES(4); GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
# INSERT INTO statement; AFTER timing --connection bug15166_u1_con
--echo
--echo ---> connection: bug15166_u1_con
--echo ---> INSERT INTO statement; AFTER timing use mysqltest_db1;
DROP TRIGGER trg1; # - table-level privileges
CREATE TRIGGER trg1 AFTER INSERT ON t1 # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t1_trg_err_1 BEFORE INSERT ON t1
FOR EACH ROW FOR EACH ROW
SET @new_sum = @new_sum + NEW.num_value; SET @mysqltest_var = NEW.col;
DROP TRIGGER t1_trg_err_1;
--error ER_TABLEACCESS_DENIED_ERROR # TODO: check privileges at CREATE TRIGGER time.
INSERT INTO t1 VALUES(5); # --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t1_trg_err_2 BEFORE DELETE ON t1
FOR EACH ROW
SET @mysqltest_var = OLD.col;
DROP TRIGGER t1_trg_err_2;
# UPDATE statement; BEFORE timing CREATE TRIGGER t2_trg_before_insert BEFORE INSERT ON t2
FOR EACH ROW
SET NEW.col = 't2_trg_before_insert';
--echo ---> UPDATE statement; BEFORE timing # - column-level privileges
DROP TRIGGER trg1; # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t3_trg_err_1 BEFORE INSERT ON t3
FOR EACH ROW
SET @mysqltest_var = NEW.col;
DROP TRIGGER t3_trg_err_1;
CREATE TRIGGER trg1 BEFORE UPDATE ON t1 # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t3_trg_err_2 BEFORE DELETE ON t3
FOR EACH ROW FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value; SET @mysqltest_var = OLD.col;
DROP TRIGGER t3_trg_err_2;
--error ER_TABLEACCESS_DENIED_ERROR CREATE TRIGGER t4_trg_before_insert BEFORE INSERT ON t4
UPDATE t1 SET num_value = 10; FOR EACH ROW
SET NEW.col = 't4_trg_before_insert';
# UPDATE statement; AFTER timing # parsing (CREATE TRIGGER) time:
# - check that SELECT is required to read the value;
# - check that SELECT is not enough to modify the value;
--echo ---> UPDATE statement; AFTER timing --connection default
--echo
--echo ---> connection: default
DROP TRIGGER trg1; use mysqltest_db1;
CREATE TRIGGER trg1 AFTER UPDATE ON t1 REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
FOR EACH ROW REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
SET @new_sum = @new_sum + NEW.num_value; GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
--error ER_TABLEACCESS_DENIED_ERROR REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
UPDATE t1 SET num_value = 20; REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
GRANT SELECT(col) on mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT SELECT(col) on mysqltest_db1.t4 TO mysqltest_u1@localhost;
# DELETE statement; BEFORE timing --connection bug15166_u1_con
--echo
--echo ---> connection: bug15166_u1_con
--echo ---> DELETE statement; BEFORE timing use mysqltest_db1;
DROP TRIGGER trg1; # - table-level privileges
CREATE TRIGGER trg1 BEFORE DELETE ON t1 CREATE TRIGGER t1_trg_after_insert AFTER INSERT ON t1
FOR EACH ROW FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value; SET @mysqltest_var = NEW.col;
--error ER_TABLEACCESS_DENIED_ERROR CREATE TRIGGER t1_trg_after_update AFTER UPDATE ON t1
DELETE FROM t1; FOR EACH ROW
SET @mysqltest_var = OLD.col;
# DELETE statement; AFTER timing # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t2_trg_err_1 BEFORE UPDATE ON t2
FOR EACH ROW
SET NEW.col = 't2_trg_err_1';
DROP TRIGGER t2_trg_err_1;
--echo ---> DELETE statement; AFTER timing # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t2_trg_err_2 BEFORE UPDATE ON t2
FOR EACH ROW
SET NEW.col = CONCAT(OLD.col, '(updated)');
DROP TRIGGER t2_trg_err_2;
DROP TRIGGER trg1; # - column-level privileges
CREATE TRIGGER trg1 AFTER DELETE ON t1 CREATE TRIGGER t3_trg_after_insert AFTER INSERT ON t3
FOR EACH ROW FOR EACH ROW
SET @old_sum = @old_sum + OLD.num_value; SET @mysqltest_var = NEW.col;
--error ER_TABLEACCESS_DENIED_ERROR CREATE TRIGGER t3_trg_after_update AFTER UPDATE ON t3
DELETE FROM t1; FOR EACH ROW
SET @mysqltest_var = OLD.col;
# # TODO: check privileges at CREATE TRIGGER time.
# Check DEFINER clause of CREATE TRIGGER statement. # --error ER_COLUMNACCESS_DENIED_ERROR
# CREATE TRIGGER t4_trg_err_1 BEFORE UPDATE ON t4
# - Check that SUPER privilege required to create a trigger with different FOR EACH ROW
# definer: SET NEW.col = 't4_trg_err_1';
# - try to create a trigger with DEFINER="definer@localhost" under DROP TRIGGER t4_trg_err_1;
# "invoker";
# - analyze error code;
# - Check that if the user specified as DEFINER does not exist, a warning is
# emitted:
# - create a trigger with DEFINER="non_existent_user@localhost" from
# "definer";
# - check that a warning emitted;
# - Check that the definer of a trigger does not exist, the trigger will not
# be activated:
# - activate just created trigger;
# - check error code;
#
--connection wl2818_definer_con # TODO: check privileges at CREATE TRIGGER time.
# --error ER_COLUMNACCESS_DENIED_ERROR
CREATE TRIGGER t4_trg_err_2 BEFORE UPDATE ON t4
FOR EACH ROW
SET NEW.col = CONCAT(OLD.col, '(updated)');
DROP TRIGGER t4_trg_err_2;
# execution time:
# - check that UPDATE is not enough to read the value;
# - check that UPDATE is required to modify the value;
--connection default
--echo --echo
--echo ---> connection: wl2818_definer_con --echo ---> connection: default
use mysqltest_db1; use mysqltest_db1;
DROP TRIGGER trg1; REVOKE SELECT ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
REVOKE SELECT ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
GRANT UPDATE ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT UPDATE ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
# Check that SUPER is required to specify different DEFINER. REVOKE SELECT(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
REVOKE SELECT(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT UPDATE(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
--error ER_SPECIFIC_ACCESS_DENIED_ERROR # - table-level privileges
CREATE DEFINER='mysqltest_inv'@'localhost'
TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = 0;
--connection default --error ER_COLUMNACCESS_DENIED_ERROR
--echo INSERT INTO t1 VALUES('line1');
--echo ---> connection: default
use mysqltest_db1; SELECT * FROM t1;
SELECT @mysqltest_var;
GRANT SUPER ON *.* TO mysqltest_dfn@localhost; INSERT INTO t2 VALUES('line2');
--disconnect wl2818_definer_con SELECT * FROM t2;
--connect (wl2818_definer_con,localhost,mysqltest_dfn,,mysqltest_db1)
--connection wl2818_definer_con
--echo
--echo ---> connection: wl2818_definer_con
CREATE DEFINER='mysqltest_inv'@'localhost' # - column-level privileges
TRIGGER trg1 BEFORE INSERT ON t1
FOR EACH ROW
SET @new_sum = 0;
# Create with non-existent user. --error ER_COLUMNACCESS_DENIED_ERROR
INSERT INTO t3 VALUES('t3_line1');
CREATE DEFINER='mysqltest_nonexs'@'localhost' SELECT * FROM t3;
TRIGGER trg2 AFTER INSERT ON t1 SELECT @mysqltest_var;
FOR EACH ROW
SET @new_sum = 0;
# Check that trg2 will not be activated. INSERT INTO t4 VALUES('t4_line2');
# --error ER_SPECIFIC_ACCESS_DENIED_ERROR SELECT * FROM t4;
#
# TODO: Due to the BUG#13198(SP executes if definer does not exist) the
# following statement does not fail as it should.
INSERT INTO t1 VALUES(6);
# # execution time:
# Check that SHOW TRIGGERS statement provides "Definer" column. # - check that SELECT is required to read the value;
# # - check that SELECT is not enough to modify the value;
SHOW TRIGGERS; --connection default
--echo
--echo ---> connection: default
# use mysqltest_db1;
# Check that weird definer values do not break functionality. I.e. check the
# following definer values:
# - '';
# - '@';
# - '@abc@def@@';
# - '@hostname';
# - '@abc@def@@@hostname';
#
DROP TRIGGER trg1; REVOKE UPDATE ON mysqltest_db1.t1 FROM mysqltest_u1@localhost;
DROP TRIGGER trg2; REVOKE UPDATE ON mysqltest_db1.t2 FROM mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t1 TO mysqltest_u1@localhost;
GRANT SELECT ON mysqltest_db1.t2 TO mysqltest_u1@localhost;
CREATE TRIGGER trg1 BEFORE INSERT ON t1 REVOKE UPDATE(col) ON mysqltest_db1.t3 FROM mysqltest_u1@localhost;
FOR EACH ROW REVOKE UPDATE(col) ON mysqltest_db1.t4 FROM mysqltest_u1@localhost;
SET @a = 1; GRANT SELECT(col) ON mysqltest_db1.t3 TO mysqltest_u1@localhost;
GRANT SELECT(col) ON mysqltest_db1.t4 TO mysqltest_u1@localhost;
CREATE TRIGGER trg2 AFTER INSERT ON t1 # - table-level privileges
FOR EACH ROW
SET @a = 2;
CREATE TRIGGER trg3 BEFORE UPDATE ON t1 INSERT INTO t1 VALUES('line3');
FOR EACH ROW
SET @a = 3;
CREATE TRIGGER trg4 AFTER UPDATE ON t1 SELECT * FROM t1;
FOR EACH ROW SELECT @mysqltest_var;
SET @a = 4;
CREATE TRIGGER trg5 BEFORE DELETE ON t1 --error ER_COLUMNACCESS_DENIED_ERROR
FOR EACH ROW INSERT INTO t2 VALUES('line4');
SET @a = 5;
--exec egrep -v '^definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG SELECT * FROM t2;
--exec echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQL_TEST_DIR/var/tmp/t1.TRG
--exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG
--echo # - column-level privileges
SELECT trigger_name, definer FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; INSERT INTO t3 VALUES('t3_line2');
--echo SELECT * FROM t3;
SELECT @mysqltest_var;
SELECT * FROM INFORMATION_SCHEMA.TRIGGERS ORDER BY trigger_name; --error ER_COLUMNACCESS_DENIED_ERROR
INSERT INTO t4 VALUES('t4_line2');
SELECT * FROM t4;
# execution time:
# - check that nor SELECT either UPDATE is required to execute triggger w/o
# NEW/OLD variables.
DELETE FROM t1;
SELECT @mysqltest_var;
# #
# Cleanup # Cleanup.
# #
--connection default DROP USER mysqltest_u1@localhost;
--echo
--echo ---> connection: default
DROP USER mysqltest_dfn@localhost;
DROP USER mysqltest_inv@localhost;
DROP DATABASE mysqltest_db1; DROP DATABASE mysqltest_db1;
...@@ -5257,6 +5257,7 @@ void Item_insert_value::print(String *str) ...@@ -5257,6 +5257,7 @@ void Item_insert_value::print(String *str)
setup_field() setup_field()
thd - current thread context thd - current thread context
table - table of trigger (and where we looking for fields) table - table of trigger (and where we looking for fields)
table_grant_info - GRANT_INFO of the subject table
NOTE NOTE
This function does almost the same as fix_fields() for Item_field This function does almost the same as fix_fields() for Item_field
...@@ -5270,7 +5271,8 @@ void Item_insert_value::print(String *str) ...@@ -5270,7 +5271,8 @@ void Item_insert_value::print(String *str)
table of trigger which uses this item. table of trigger which uses this item.
*/ */
void Item_trigger_field::setup_field(THD *thd, TABLE *table) void Item_trigger_field::setup_field(THD *thd, TABLE *table,
GRANT_INFO *table_grant_info)
{ {
bool save_set_query_id= thd->set_query_id; bool save_set_query_id= thd->set_query_id;
...@@ -5284,6 +5286,7 @@ void Item_trigger_field::setup_field(THD *thd, TABLE *table) ...@@ -5284,6 +5286,7 @@ void Item_trigger_field::setup_field(THD *thd, TABLE *table)
0, &field_idx); 0, &field_idx);
thd->set_query_id= save_set_query_id; thd->set_query_id= save_set_query_id;
triggers= table->triggers; triggers= table->triggers;
table_grants= table_grant_info;
} }
...@@ -5302,22 +5305,42 @@ bool Item_trigger_field::fix_fields(THD *thd, Item **items) ...@@ -5302,22 +5305,42 @@ bool Item_trigger_field::fix_fields(THD *thd, Item **items)
Since trigger is object tightly associated with TABLE object most Since trigger is object tightly associated with TABLE object most
of its set up can be performed during trigger loading i.e. trigger of its set up can be performed during trigger loading i.e. trigger
parsing! So we have little to do in fix_fields. :) parsing! So we have little to do in fix_fields. :)
FIXME may be we still should bother about permissions here.
*/ */
DBUG_ASSERT(fixed == 0); DBUG_ASSERT(fixed == 0);
/* Set field. */
if (field_idx != (uint)-1) if (field_idx != (uint)-1)
{ {
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/*
Check access privileges for the subject table. We check privileges only
in runtime.
*/
if (table_grants)
{
table_grants->want_privilege=
access_type == AT_READ ? SELECT_ACL : UPDATE_ACL;
if (check_grant_column(thd, table_grants, triggers->table->s->db.str,
triggers->table->s->table_name.str, field_name,
strlen(field_name), thd->security_ctx))
return TRUE;
}
#endif // NO_EMBEDDED_ACCESS_CHECKS
field= (row_version == OLD_ROW) ? triggers->old_field[field_idx] : field= (row_version == OLD_ROW) ? triggers->old_field[field_idx] :
triggers->new_field[field_idx]; triggers->new_field[field_idx];
set_field(field); set_field(field);
fixed= 1; fixed= 1;
return 0; return FALSE;
} }
my_error(ER_BAD_FIELD_ERROR, MYF(0), field_name, my_error(ER_BAD_FIELD_ERROR, MYF(0), field_name,
(row_version == NEW_ROW) ? "NEW" : "OLD"); (row_version == NEW_ROW) ? "NEW" : "OLD");
return 1; return TRUE;
} }
......
...@@ -2172,6 +2172,8 @@ public: ...@@ -2172,6 +2172,8 @@ public:
/* Is this item represents row from NEW or OLD row ? */ /* Is this item represents row from NEW or OLD row ? */
enum row_version_type {OLD_ROW, NEW_ROW}; enum row_version_type {OLD_ROW, NEW_ROW};
row_version_type row_version; row_version_type row_version;
/* Is this item used for reading or updating the value? */
enum access_types { AT_READ = 0x1, AT_UPDATE = 0x2 };
/* Next in list of all Item_trigger_field's in trigger */ /* Next in list of all Item_trigger_field's in trigger */
Item_trigger_field *next_trg_field; Item_trigger_field *next_trg_field;
/* Index of the field in the TABLE::field array */ /* Index of the field in the TABLE::field array */
...@@ -2181,18 +2183,24 @@ public: ...@@ -2181,18 +2183,24 @@ public:
Item_trigger_field(Name_resolution_context *context_arg, Item_trigger_field(Name_resolution_context *context_arg,
row_version_type row_ver_arg, row_version_type row_ver_arg,
const char *field_name_arg) const char *field_name_arg,
access_types access_type_arg)
:Item_field(context_arg, :Item_field(context_arg,
(const char *)NULL, (const char *)NULL, field_name_arg), (const char *)NULL, (const char *)NULL, field_name_arg),
row_version(row_ver_arg), field_idx((uint)-1) row_version(row_ver_arg), field_idx((uint)-1),
access_type(access_type_arg), table_grants(NULL)
{} {}
void setup_field(THD *thd, TABLE *table); void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info);
enum Type type() const { return TRIGGER_FIELD_ITEM; } enum Type type() const { return TRIGGER_FIELD_ITEM; }
bool eq(const Item *item, bool binary_cmp) const; bool eq(const Item *item, bool binary_cmp) const;
bool fix_fields(THD *, Item **); bool fix_fields(THD *, Item **);
void print(String *str); void print(String *str);
table_map used_tables() const { return (table_map)0L; } table_map used_tables() const { return (table_map)0L; }
void cleanup(); void cleanup();
private:
access_types access_type;
GRANT_INFO *table_grants;
}; };
......
...@@ -390,7 +390,12 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables, ...@@ -390,7 +390,12 @@ bool Table_triggers_list::create_trigger(THD *thd, TABLE_LIST *tables,
for (trg_field= (Item_trigger_field *)(lex->trg_table_fields.first); for (trg_field= (Item_trigger_field *)(lex->trg_table_fields.first);
trg_field; trg_field= trg_field->next_trg_field) trg_field; trg_field= trg_field->next_trg_field)
{ {
trg_field->setup_field(thd, table); /*
NOTE: now we do not check privileges at CREATE TRIGGER time. This will
be changed in the future.
*/
trg_field->setup_field(thd, table, NULL);
if (!trg_field->fixed && if (!trg_field->fixed &&
trg_field->fix_fields(thd, (Item **)0)) trg_field->fix_fields(thd, (Item **)0))
return 1; return 1;
...@@ -826,8 +831,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, ...@@ -826,8 +831,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
char *trg_name_buff; char *trg_name_buff;
List_iterator_fast<ulonglong> itm(triggers->definition_modes_list); List_iterator_fast<ulonglong> itm(triggers->definition_modes_list);
List_iterator_fast<LEX_STRING> it_definer(triggers-> List_iterator_fast<LEX_STRING> it_definer(triggers->definers_list);
definers_list);
LEX *old_lex= thd->lex, lex; LEX *old_lex= thd->lex, lex;
sp_rcontext *save_spcont= thd->spcont; sp_rcontext *save_spcont= thd->spcont;
ulong save_sql_mode= thd->variables.sql_mode; ulong save_sql_mode= thd->variables.sql_mode;
...@@ -842,6 +846,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, ...@@ -842,6 +846,7 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
{ {
trg_sql_mode= itm++; trg_sql_mode= itm++;
LEX_STRING *trg_definer= it_definer++; LEX_STRING *trg_definer= it_definer++;
thd->variables.sql_mode= (ulong)*trg_sql_mode; thd->variables.sql_mode= (ulong)*trg_sql_mode;
lex_start(thd, (uchar*)trg_create_str->str, trg_create_str->length); lex_start(thd, (uchar*)trg_create_str->str, trg_create_str->length);
...@@ -915,11 +920,11 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db, ...@@ -915,11 +920,11 @@ bool Table_triggers_list::check_n_load(THD *thd, const char *db,
(Item_trigger_field *)(lex.trg_table_fields.first); (Item_trigger_field *)(lex.trg_table_fields.first);
trg_field; trg_field;
trg_field= trg_field->next_trg_field) trg_field= trg_field->next_trg_field)
trg_field->setup_field(thd, table); {
trg_field->setup_field(thd, table,
triggers->m_spec_var_used[lex.trg_chistics.event] &triggers->subject_table_grants[lex.trg_chistics.event]
[lex.trg_chistics.action_time]= [lex.trg_chistics.action_time]);
lex.trg_table_fields.first ? TRUE : FALSE; }
lex_end(&lex); lex_end(&lex);
} }
...@@ -1159,38 +1164,30 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event, ...@@ -1159,38 +1164,30 @@ bool Table_triggers_list::process_triggers(THD *thd, trg_event_type event,
if (sp_change_security_context(thd, sp_trigger, &save_ctx)) if (sp_change_security_context(thd, sp_trigger, &save_ctx))
return TRUE; return TRUE;
{
TABLE_LIST table_list, **save_query_tables_own_last;
ulong wanted_access = TRIGGER_ACL;
bzero((char *) &table_list, sizeof (table_list));
table_list.db= (char *) table->s->db.str;
table_list.db_length= table->s->db.length;
table_list.table_name= table->s->table_name.str;
table_list.table_name_length= table->s->table_name.length;
table_list.alias= (char *) table->alias;
table_list.table= table;
save_query_tables_own_last= thd->lex->query_tables_own_last;
thd->lex->query_tables_own_last= 0;
/* /*
If the trigger uses special variables (NEW/OLD), check that we have Fetch information about table-level privileges to GRANT_INFO structure for
SELECT and UPDATE privileges on the subject table. subject table. Check of privileges that will use it and information about
column-level privileges will happen in Item_trigger_field::fix_fields().
*/ */
if (is_special_var_used(event, time_type)) fill_effective_table_privileges(thd,
wanted_access|= SELECT_ACL | UPDATE_ACL; &subject_table_grants[event][time_type],
table->s->db.str, table->s->table_name.str);
err_status= check_table_access(thd, wanted_access, &table_list, 0); /* Check that the definer has TRIGGER privilege on the subject table. */
thd->lex->query_tables_own_last= save_query_tables_own_last; if (!(subject_table_grants[event][time_type].privilege & TRIGGER_ACL))
if (err_status)
{ {
char priv_desc[128];
get_privilege_desc(priv_desc, sizeof(priv_desc), TRIGGER_ACL);
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), priv_desc,
thd->security_ctx->priv_user, thd->security_ctx->host_or_ip,
table->s->table_name);
sp_restore_security_context(thd, save_ctx); sp_restore_security_context(thd, save_ctx);
return TRUE; return TRUE;
} }
}
#endif // NO_EMBEDDED_ACCESS_CHECKS #endif // NO_EMBEDDED_ACCESS_CHECKS
thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER); thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER);
......
...@@ -56,10 +56,9 @@ class Table_triggers_list: public Sql_alloc ...@@ -56,10 +56,9 @@ class Table_triggers_list: public Sql_alloc
LEX_STRING sroutines_key; LEX_STRING sroutines_key;
/* /*
is_special_var_used specifies whether trigger body contains special Grant information for each trigger (pair: subject table, trigger definer).
variables (NEW/OLD).
*/ */
bool m_spec_var_used[TRG_EVENT_MAX][TRG_ACTION_MAX]; GRANT_INFO subject_table_grants[TRG_EVENT_MAX][TRG_ACTION_MAX];
public: public:
/* /*
...@@ -78,6 +77,7 @@ public: ...@@ -78,6 +77,7 @@ public:
record1_field(0), table(table_arg) record1_field(0), table(table_arg)
{ {
bzero((char *)bodies, sizeof(bodies)); bzero((char *)bodies, sizeof(bodies));
bzero((char *)&subject_table_grants, sizeof(subject_table_grants));
} }
~Table_triggers_list(); ~Table_triggers_list();
...@@ -109,11 +109,6 @@ public: ...@@ -109,11 +109,6 @@ public:
return test(bodies[TRG_EVENT_UPDATE][TRG_ACTION_BEFORE]); return test(bodies[TRG_EVENT_UPDATE][TRG_ACTION_BEFORE]);
} }
inline bool is_special_var_used(int event, int action_time) const
{
return m_spec_var_used[event][action_time];
}
void set_table(TABLE *new_table); void set_table(TABLE *new_table);
friend class Item_trigger_field; friend class Item_trigger_field;
......
...@@ -9043,7 +9043,8 @@ simple_ident_q: ...@@ -9043,7 +9043,8 @@ simple_ident_q:
new_row ? new_row ?
Item_trigger_field::NEW_ROW: Item_trigger_field::NEW_ROW:
Item_trigger_field::OLD_ROW, Item_trigger_field::OLD_ROW,
$3.str))) $3.str,
Item_trigger_field::AT_READ)))
YYABORT; YYABORT;
/* /*
...@@ -9727,7 +9728,9 @@ sys_option_value: ...@@ -9727,7 +9728,9 @@ sys_option_value:
if (!(trg_fld= new Item_trigger_field(Lex->current_context(), if (!(trg_fld= new Item_trigger_field(Lex->current_context(),
Item_trigger_field::NEW_ROW, Item_trigger_field::NEW_ROW,
$2.base_name.str)) || $2.base_name.str,
Item_trigger_field::AT_UPDATE)
) ||
!(sp_fld= new sp_instr_set_trigger_field(lex->sphead-> !(sp_fld= new sp_instr_set_trigger_field(lex->sphead->
instructions(), instructions(),
lex->spcont, lex->spcont,
......
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