diff options
-rw-r--r-- | mysql-test/suite/galera/r/galera_create_trigger.result | 42 | ||||
-rw-r--r-- | mysql-test/suite/galera/t/galera_create_trigger.test | 43 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 8 |
3 files changed, 91 insertions, 2 deletions
diff --git a/mysql-test/suite/galera/r/galera_create_trigger.result b/mysql-test/suite/galera/r/galera_create_trigger.result new file mode 100644 index 00000000000..7e656081871 --- /dev/null +++ b/mysql-test/suite/galera/r/galera_create_trigger.result @@ -0,0 +1,42 @@ +CREATE TABLE definer_root (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_user (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_current_user (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_default (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE USER 'user1'; +CREATE DEFINER=root@localhost TRIGGER definer_root BEFORE INSERT ON definer_root FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE DEFINER=user1 TRIGGER definer_user BEFORE INSERT ON definer_user FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE DEFINER=current_user TRIGGER definer_current_user BEFORE INSERT ON definer_current_user FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE TRIGGER definer_default BEFORE INSERT ON definer_default FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +INSERT INTO definer_root (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_root'; +DEFINER = 'root@localhost' +1 +SELECT trigger_user = 'root@localhost' FROM definer_root; +trigger_user = 'root@localhost' +1 +INSERT INTO definer_user (f1) VALUES (1); +SELECT DEFINER = 'user1@%' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_user'; +DEFINER = 'user1@%' +1 +SELECT trigger_user = 'user1@%' FROM definer_user; +trigger_user = 'user1@%' +1 +INSERT INTO definer_current_user (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_current_user'; +DEFINER = 'root@localhost' +1 +SELECT trigger_user = 'root@localhost' FROM definer_current_user; +trigger_user = 'root@localhost' +1 +INSERT INTO definer_default (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_default'; +DEFINER = 'root@localhost' +1 +SELECT trigger_user = 'root@localhost' FROM definer_default; +trigger_user = 'root@localhost' +1 +DROP TABLE definer_current_user; +DROP TABLE definer_user; +DROP TABLE definer_root; +DROP TABLE definer_default; +DROP USER 'user1'; diff --git a/mysql-test/suite/galera/t/galera_create_trigger.test b/mysql-test/suite/galera/t/galera_create_trigger.test new file mode 100644 index 00000000000..6708e30bf0f --- /dev/null +++ b/mysql-test/suite/galera/t/galera_create_trigger.test @@ -0,0 +1,43 @@ +--source include/galera_cluster.inc +--source include/have_innodb.inc + +# +# Test CREATE TRIGGER, especially with different DEFINER +# + +CREATE TABLE definer_root (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_user (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_current_user (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; +CREATE TABLE definer_default (f1 INTEGER, trigger_user VARCHAR(100)) ENGINE=InnoDB; + +CREATE USER 'user1'; +CREATE DEFINER=root@localhost TRIGGER definer_root BEFORE INSERT ON definer_root FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE DEFINER=user1 TRIGGER definer_user BEFORE INSERT ON definer_user FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE DEFINER=current_user TRIGGER definer_current_user BEFORE INSERT ON definer_current_user FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); +CREATE TRIGGER definer_default BEFORE INSERT ON definer_default FOR EACH ROW SET NEW.trigger_user = CURRENT_USER(); + +--connection node_2 +INSERT INTO definer_root (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_root'; +SELECT trigger_user = 'root@localhost' FROM definer_root; + +INSERT INTO definer_user (f1) VALUES (1); +SELECT DEFINER = 'user1@%' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_user'; +SELECT trigger_user = 'user1@%' FROM definer_user; + +INSERT INTO definer_current_user (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_current_user'; +SELECT trigger_user = 'root@localhost' FROM definer_current_user; + +INSERT INTO definer_default (f1) VALUES (1); +SELECT DEFINER = 'root@localhost' FROM INFORMATION_SCHEMA.TRIGGERS WHERE TRIGGER_NAME = 'definer_default'; +SELECT trigger_user = 'root@localhost' FROM definer_default; + +--connection node_1 +DROP TABLE definer_current_user; +DROP TABLE definer_user; +DROP TABLE definer_root; +DROP TABLE definer_default; + +DROP USER 'user1'; + diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index cf5b4a39b1f..a2b5f9a68c9 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -2464,9 +2464,13 @@ int wsrep_create_trigger_query(THD *thd, uchar** buf, size_t* buf_len) if (lex->definer) { /* SUID trigger. */ + LEX_USER *d= get_current_user(thd, lex->definer); - definer_user= lex->definer->user; - definer_host= lex->definer->host; + if (!d) + return 1; + + definer_user= d->user; + definer_host= d->host; } else { |