Commit 7dbea7df authored by unknown's avatar unknown
Browse files

WL#2818 (Add creator to the trigger definition for privilege

checks on trigger activation)


mysql-test/r/information_schema.result:
  Update result file: a new column DEFINER has been added to
  INFORMATION_SCHEMA.TRIGGERS.
mysql-test/r/mysqldump.result:
  Update result file: a new column DEFINER has been added to
  INFORMATION_SCHEMA.TRIGGERS.
mysql-test/r/rpl_ddl.result:
  Update result file: a new column DEFINER has been added to
  INFORMATION_SCHEMA.TRIGGERS.
mysql-test/r/rpl_sp.result:
  Update result file: a new clause DEFINER has been added to
  CREATE TRIGGER statement.
mysql-test/r/rpl_trigger.result:
  Results for new test cases were added.
mysql-test/r/skip_grants.result:
  Error message has been changed.
mysql-test/r/trigger.result:
  Added DEFINER column.
mysql-test/r/view.result:
  Error messages have been changed.
mysql-test/r/view_grant.result:
  Error messages have been changed.
mysql-test/t/mysqldump.test:
  Drop created procedure to not affect further tests.
mysql-test/t/rpl_trigger.test:
  Add tests for new column in information schema.
mysql-test/t/skip_grants.test:
  Error tag has been renamed.
mysql-test/t/view.test:
  Error tag has been renamed.
mysql-test/t/view_grant.test:
  Error tag has been changed.
sql/item_func.cc:
  Fix typo in comments.
sql/mysql_priv.h:
  A try to minimize copy&paste:
    - introduce operations to be used from sql_yacc.yy;
    - introduce an operation to be used from trigger and
      view processing code.
sql/share/errmsg.txt:
  - Rename ER_NO_VIEW_USER to ER_MALFORMED_DEFINER in order to
    be shared for view and trigger implementations;
  - Fix a typo;
  - Add a new error code for trigger warning.
sql/sp.cc:
  set_info() was split into set_info() and set_definer().
sql/sp_head.cc:
  set_info() was split into set_info() and set_definer().
sql/sp_head.h:
  set_info() was split into set_info() and set_definer().
sql/sql_acl.cc:
  Add a new check: exit from the cycle if the table is NULL.
sql/sql_lex.h:
  - Rename create_view_definer to definer, since it is used for views
    and triggers;
  - Change st_lex_user to LEX_USER, since st_lex_user is a structure.
    So, formally, it should be "struct st_lex_user", which is longer
    than just LEX_USER;
  - Add trigger_definition_begin.
sql/sql_parse.cc:
  - Add a new check: exit from the cycle if the table is NULL;
  - Implement definer-related functions.
sql/sql_show.cc:
  Add DEFINER column.
sql/sql_trigger.cc:
  Add DEFINER support for triggers.
sql/sql_trigger.h:
  Add DEFINER support for triggers.
sql/sql_view.cc:
  Rename create_view_definer to definer.
sql/sql_yacc.yy:
  Add support for DEFINER-clause in CREATE TRIGGER statement.
  
  Since CREATE TRIGGER and CREATE VIEW can be similar at the start,
  yacc is unable to distinguish between them. So, had to modify both
  statements in order to make it parsable by yacc.
mysql-test/r/trigger-compat.result:
  Result file for triggers backward compatibility test.
mysql-test/r/trigger-grant.result:
  Result file of the test for WL#2818.
mysql-test/t/trigger-compat.test:
  Triggers backward compatibility test: check that the server
  still can load triggers w/o definer attribute and modify
  tables with such triggers (add a new trigger, etc).
mysql-test/t/trigger-grant.test:
  Test for WL#2818 -- check that DEFINER support in triggers
  works properly
parent 96ae0b92
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -722,6 +722,7 @@ information_schema ROUTINES SQL_MODE
information_schema	TRIGGERS	ACTION_CONDITION
information_schema	TRIGGERS	ACTION_STATEMENT
information_schema	TRIGGERS	SQL_MODE
information_schema	TRIGGERS	DEFINER
information_schema	VIEWS	VIEW_DEFINITION
select table_name, column_name, data_type from information_schema.columns
where data_type = 'datetime';
@@ -800,45 +801,45 @@ set @fired:= "Yes";
end if;
end|
show triggers;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
trg1	INSERT	t1	
begin
if new.j > 10 then
set new.j := 10;
end if;
end	BEFORE	NULL	
end	BEFORE	NULL		root@localhost
trg2	UPDATE	t1	
begin
if old.i % 2 = 0 then
set new.j := -1;
end if;
end	BEFORE	NULL	
end	BEFORE	NULL		root@localhost
trg3	UPDATE	t1	
begin
if new.j = -1 then
set @fired:= "Yes";
end if;
end	AFTER	NULL	
end	AFTER	NULL		root@localhost
select * from information_schema.triggers;
TRIGGER_CATALOG	TRIGGER_SCHEMA	TRIGGER_NAME	EVENT_MANIPULATION	EVENT_OBJECT_CATALOG	EVENT_OBJECT_SCHEMA	EVENT_OBJECT_TABLE	ACTION_ORDER	ACTION_CONDITION	ACTION_STATEMENT	ACTION_ORIENTATION	ACTION_TIMING	ACTION_REFERENCE_OLD_TABLE	ACTION_REFERENCE_NEW_TABLE	ACTION_REFERENCE_OLD_ROW	ACTION_REFERENCE_NEW_ROW	CREATED	SQL_MODE
TRIGGER_CATALOG	TRIGGER_SCHEMA	TRIGGER_NAME	EVENT_MANIPULATION	EVENT_OBJECT_CATALOG	EVENT_OBJECT_SCHEMA	EVENT_OBJECT_TABLE	ACTION_ORDER	ACTION_CONDITION	ACTION_STATEMENT	ACTION_ORIENTATION	ACTION_TIMING	ACTION_REFERENCE_OLD_TABLE	ACTION_REFERENCE_NEW_TABLE	ACTION_REFERENCE_OLD_ROW	ACTION_REFERENCE_NEW_ROW	CREATED	SQL_MODE	DEFINER
NULL	test	trg1	INSERT	NULL	test	t1	0	NULL	
begin
if new.j > 10 then
set new.j := 10;
end if;
end	ROW	BEFORE	NULL	NULL	OLD	NEW	NULL	
end	ROW	BEFORE	NULL	NULL	OLD	NEW	NULL		root@localhost
NULL	test	trg2	UPDATE	NULL	test	t1	0	NULL	
begin
if old.i % 2 = 0 then
set new.j := -1;
end if;
end	ROW	BEFORE	NULL	NULL	OLD	NEW	NULL	
end	ROW	BEFORE	NULL	NULL	OLD	NEW	NULL		root@localhost
NULL	test	trg3	UPDATE	NULL	test	t1	0	NULL	
begin
if new.j = -1 then
set @fired:= "Yes";
end if;
end	ROW	AFTER	NULL	NULL	OLD	NEW	NULL	
end	ROW	AFTER	NULL	NULL	OLD	NEW	NULL		root@localhost
drop trigger trg1;
drop trigger trg2;
drop trigger trg3;
+12 −11
Original line number Diff line number Diff line
@@ -1926,23 +1926,23 @@ end if;
end|
set sql_mode=default|
show triggers like "t1";
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
trg1	INSERT	t1	
begin
if new.a > 10 then
set new.a := 10;
set new.a := 11;
end if;
end	BEFORE	0000-00-00 00:00:00	
end	BEFORE	0000-00-00 00:00:00		root@localhost
trg2	UPDATE	t1	 begin
if old.a % 2 = 0 then set new.b := 12; end if;
end	BEFORE	0000-00-00 00:00:00	
end	BEFORE	0000-00-00 00:00:00		root@localhost
trg3	UPDATE	t1	
begin
if new.a = -1 then
set @fired:= "Yes";
end if;
end	AFTER	0000-00-00 00:00:00	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
end	AFTER	0000-00-00 00:00:00	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER	root@localhost
INSERT INTO t1 (a) VALUES (1),(2),(3),(22);
update t1 set a = 4 where a=3;

@@ -2085,29 +2085,29 @@ Tables_in_test
t1
t2
show triggers;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
trg1	INSERT	t1	
begin
if new.a > 10 then
set new.a := 10;
set new.a := 11;
end if;
end	BEFORE	#	
end	BEFORE	#		root@localhost
trg2	UPDATE	t1	 begin
if old.a % 2 = 0 then set new.b := 12; end if;
end	BEFORE	#	
end	BEFORE	#		root@localhost
trg3	UPDATE	t1	
begin
if new.a = -1 then
set @fired:= "Yes";
end if;
end	AFTER	#	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
end	AFTER	#	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER	root@localhost
trg4	INSERT	t2	
begin
if new.a > 10 then
set @fired:= "No";
end if;
end	BEFORE	#	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER
end	BEFORE	#	STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER	root@localhost
DROP TABLE t1, t2;
--port=1234
--port=1234
@@ -2130,9 +2130,9 @@ SELECT * FROM `test2`;
a2
1
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
testref	INSERT	test1	 BEGIN
INSERT INTO test2 SET a2 = NEW.a1; END	BEFORE	NULL	
INSERT INTO test2 SET a2 = NEW.a1; END	BEFORE	NULL		root@localhost
SELECT * FROM `test1`;
a1
1
@@ -2147,6 +2147,7 @@ DROP FUNCTION IF EXISTS bug9056_func1;
DROP FUNCTION IF EXISTS bug9056_func2;
DROP PROCEDURE IF EXISTS bug9056_proc1;
DROP PROCEDURE IF EXISTS bug9056_proc2;
DROP PROCEDURE IF EXISTS `a'b`;
CREATE TABLE t1 (id int);
INSERT INTO t1 VALUES(1), (2), (3), (4), (5);
CREATE FUNCTION `bug9056_func1`(a INT, b INT) RETURNS int(11) RETURN a+b //
+6 −6
Original line number Diff line number Diff line
@@ -1465,13 +1465,13 @@ flush logs;

-------- switch to master -------
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
trg1	INSERT	t1	 SET @a:=1	BEFORE	NULL	
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
trg1	INSERT	t1	 SET @a:=1	BEFORE	NULL		root@localhost

-------- switch to slave -------
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
trg1	INSERT	t1	 SET @a:=1	BEFORE	NULL	
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer
trg1	INSERT	t1	 SET @a:=1	BEFORE	NULL		root@localhost

######## DROP TRIGGER trg1  ########

@@ -1520,11 +1520,11 @@ flush logs;

-------- switch to master -------
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer

-------- switch to slave -------
SHOW TRIGGERS;
Trigger	Event	Table	Statement	Timing	Created	sql_mode
Trigger	Event	Table	Statement	Timing	Created	sql_mode	Definer

######## CREATE USER user1@localhost  ########

+1 −1
Original line number Diff line number Diff line
@@ -256,7 +256,7 @@ a
show binlog events in 'master-bin.000002' from 98;
Log_name	Pos	Event_type	Server_id	End_log_pos	Info
master-bin.000002	#	Query	1	#	use `mysqltest1`; delete from t1
master-bin.000002	#	Query	1	#	use `mysqltest1`; create trigger trg before insert on t1 for each row set new.a= 10
master-bin.000002	#	Query	1	#	use `mysqltest1`; CREATE DEFINER=`root`@`localhost` trigger trg before insert on t1 for each row set new.a= 10
master-bin.000002	#	Query	1	#	use `mysqltest1`; insert into t1 values (1)
master-bin.000002	#	Query	1	#	use `mysqltest1`; delete from t1
master-bin.000002	#	Query	1	#	use `mysqltest1`; drop trigger trg
+16 −0
Original line number Diff line number Diff line
@@ -89,8 +89,24 @@ insert into t1 set a = now();
select a=b && a=c from t1;
a=b && a=c
1
SELECT routine_name, definer
FROM information_schema.routines;
routine_name	definer
bug12480	root@localhost
SELECT trigger_name, definer
FROM information_schema.triggers;
trigger_name	definer
t1_first	root@localhost

--- On slave --
SELECT routine_name, definer
FROM information_schema.routines;
routine_name	definer
bug12480	@
SELECT trigger_name, definer
FROM information_schema.triggers;
trigger_name	definer
t1_first	root@localhost
select a=b && a=c from t1;
a=b && a=c
1
Loading