Skip to content

Commit

Permalink
MW-416 Replicating DDL after ACL check, 5.6 version
Browse files Browse the repository at this point in the history
Re-implemented the fix for MW-416 according to 5.7 version
  • Loading branch information
sjaakola authored and Jan Lindström committed Oct 19, 2017
1 parent 38530c8 commit 8822b30
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 11 deletions.
114 changes: 114 additions & 0 deletions mysql-test/suite/galera/r/MW-416.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
CREATE USER 'userMW416'@'localhost';
GRANT SELECT, INSERT, UPDATE ON test.* TO 'userMW416'@'localhost';
SHOW GLOBAL STATUS LIKE 'wsrep_replicated';
Variable_name Value
wsrep_replicated 2
ALTER DATABASE db CHARACTER SET = utf8;
ERROR 42000: Access denied for user 'userMW416'@'localhost' to database 'db'
ALTER EVENT ev1 RENAME TO ev2;
ERROR 42000: Access denied for user 'userMW416'@'localhost' to database 'test'
ALTER FUNCTION fun1 COMMENT 'foo';
ERROR 42000: alter routine command denied to user 'userMW416'@'localhost' for routine 'test.fun1'
ALTER LOGFILE GROUP lfg ADD UNDOFILE 'file' ENGINE=InnoDB;
Got one of the listed errors
ALTER PROCEDURE proc1 COMMENT 'foo';
Got one of the listed errors
ALTER SERVER srv OPTIONS (USER 'sally');
Got one of the listed errors
ALTER TABLE tbl DROP COLUMN col;
Got one of the listed errors
ALTER TABLESPACE tblspc DROP DATAFILE 'file' ENGINE=innodb;
Got one of the listed errors
ALTER VIEW vw AS SELECT 1;
Got one of the listed errors
CREATE DATABASE db;
Got one of the listed errors
CREATE EVENT ev1 ON SCHEDULE AT CURRENT_TIMESTAMP DO SELECT 1;
Got one of the listed errors
CREATE FUNCTION fun1() RETURNS int RETURN(1);
Got one of the listed errors
CREATE FUNCTION fun1 RETURNS STRING SONAME 'funlib.so';
Got one of the listed errors
CREATE PROCEDURE proc1() BEGIN END;
Got one of the listed errors
CREATE INDEX idx ON tbl(id);
Got one of the listed errors
CREATE LOGFILE GROUP lfg ADD UNDOFILE 'undofile' ENGINE innodb;
Got one of the listed errors
CREATE SERVER srv FOREIGN DATA WRAPPER 'fdw' OPTIONS (USER 'user');
Got one of the listed errors
CREATE TABLE t (i int);
Got one of the listed errors
CREATE TABLESPACE tblspc ADD DATAFILE 'file' ENGINE=innodb;
Got one of the listed errors
CREATE TRIGGER trg BEFORE UPDATE ON t FOR EACH ROW BEGIN END;
Got one of the listed errors
CREATE VIEW vw AS SELECT 1;
Got one of the listed errors
DROP DATABASE db;
Got one of the listed errors
DROP EVENT ev;
Got one of the listed errors
DROP FUNCTION fun1;
Got one of the listed errors
DROP INDEX idx ON t0;
Got one of the listed errors
DROP LOGFILE GROUP lfg;
Got one of the listed errors
DROP PROCEDURE proc1;
Got one of the listed errors
DROP SERVEr srv;
Got one of the listed errors
DROP TABLE t0;
Got one of the listed errors
DROP TABLESPACE tblspc;
Got one of the listed errors
DROP TRIGGER trg;
Got one of the listed errors
DROP VIEW vw;
Got one of the listed errors
RENAME TABLE t0 TO t1;
Got one of the listed errors
TRUNCATE TABLE t0;
Got one of the listed errors
ALTER USER myuser PASSWORD EXPIRE;
Got one of the listed errors
CREATE USER myuser IDENTIFIED BY 'pass';
Got one of the listed errors
DROP USER myuser;
Got one of the listed errors
GRANT ALL ON *.* TO 'myuser';
Got one of the listed errors
RENAME USER myuser TO mariauser;
Got one of the listed errors
REVOKE SELECT ON test FROM myuser;
Got one of the listed errors
REVOKE ALL, GRANT OPTION FROM myuser;
Got one of the listed errors
REVOKE PROXY ON myuser FROM myuser;
Got one of the listed errors
ANALYZE TABLE db.tbl;
Got one of the listed errors
CHECK TABLE db.tbl;
Got one of the listed errors
CHECKSUM TABLE db.tbl;
Got one of the listed errors
OPTIMIZE TABLE db.tbl;
Got one of the listed errors
REPAIR TABLE db.tbl;
Got one of the listed errors
INSTALL PLUGIN plg SONAME 'plg.so';
Got one of the listed errors
UNINSTALL PLUGIN plg;
Got one of the listed errors
DROP USER 'userMW416'@'localhost';
SHOW DATABASES;
Database
information_schema
mtr
mysql
performance_schema
test
SHOW GLOBAL STATUS LIKE 'wsrep_replicated';
Variable_name Value
wsrep_replicated 3
132 changes: 132 additions & 0 deletions mysql-test/suite/galera/t/MW-416.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
--source include/galera_cluster.inc
--source include/have_innodb.inc

CREATE USER 'userMW416'@'localhost';
GRANT SELECT, INSERT, UPDATE ON test.* TO 'userMW416'@'localhost';

SHOW GLOBAL STATUS LIKE 'wsrep_replicated';

--connect userMW416, localhost, userMW416,, test, $NODE_MYPORT_1
--connection userMW416

# DDL

--error 1044
ALTER DATABASE db CHARACTER SET = utf8;
--error 1044
ALTER EVENT ev1 RENAME TO ev2;
--error 1370
ALTER FUNCTION fun1 COMMENT 'foo';
#--error 1044,1227
#ALTER INSTANCE ROTATE INNODB MASTER KEY;
--error 1044,1227
ALTER LOGFILE GROUP lfg ADD UNDOFILE 'file' ENGINE=InnoDB;
--error 1044,1227,1370
ALTER PROCEDURE proc1 COMMENT 'foo';
--error 1044,1227,1370
ALTER SERVER srv OPTIONS (USER 'sally');
--error 1044,1142,1227,1370
ALTER TABLE tbl DROP COLUMN col;
--error 1044,1227,1370
ALTER TABLESPACE tblspc DROP DATAFILE 'file' ENGINE=innodb;
--error 1044,1142,1227,1370
ALTER VIEW vw AS SELECT 1;

--error 1044,1227,1370
CREATE DATABASE db;
--error 1044,1227,1370
CREATE EVENT ev1 ON SCHEDULE AT CURRENT_TIMESTAMP DO SELECT 1;
--error 1044,1227,1370
CREATE FUNCTION fun1() RETURNS int RETURN(1);
--error 1044,1227,1370
CREATE FUNCTION fun1 RETURNS STRING SONAME 'funlib.so';
--error 1044,1227,1370
CREATE PROCEDURE proc1() BEGIN END;
--error 1044,1142,1227,1370
CREATE INDEX idx ON tbl(id);
--error 1044,1142,1227,1370
CREATE LOGFILE GROUP lfg ADD UNDOFILE 'undofile' ENGINE innodb;
--error 1044,1142,1227,1370
CREATE SERVER srv FOREIGN DATA WRAPPER 'fdw' OPTIONS (USER 'user');
--error 1044,1142,1227,1370
CREATE TABLE t (i int);
--error 1044,1142,1227,1370
CREATE TABLESPACE tblspc ADD DATAFILE 'file' ENGINE=innodb;
--error 1044,1142,1227,1370
CREATE TRIGGER trg BEFORE UPDATE ON t FOR EACH ROW BEGIN END;
--error 1044,1142,1227,1370
CREATE VIEW vw AS SELECT 1;



--error 1044,1142,1227,1370
DROP DATABASE db;
--error 1044,1142,1227,1370
DROP EVENT ev;
--error 1044,1142,1227,1370
DROP FUNCTION fun1;
--error 1044,1142,1227,1370
DROP INDEX idx ON t0;
--error 1044,1142,1227,1370
DROP LOGFILE GROUP lfg;
--error 1044,1142,1227,1370
DROP PROCEDURE proc1;
--error 1044,1142,1227,1370
DROP SERVEr srv;
--error 1044,1142,1227,1370
DROP TABLE t0;
--error 1044,1142,1227,1370
DROP TABLESPACE tblspc;
--error 1044,1142,1227,1360,1370
DROP TRIGGER trg;
--error 1044,1142,1227,1370
DROP VIEW vw;

--error 1044,1142,1227,1370
RENAME TABLE t0 TO t1;

--error 1044,1142,1227,1370
TRUNCATE TABLE t0;

# DCL

# account management
--error 1044,1142,1227,1370
ALTER USER myuser PASSWORD EXPIRE;
--error 1044,1142,1227,1370
CREATE USER myuser IDENTIFIED BY 'pass';
--error 1044,1142,1227,1370
DROP USER myuser;
--error 1044,1045,1142,1227,1370
GRANT ALL ON *.* TO 'myuser';
--error 1044,1142,1227,1370
RENAME USER myuser TO mariauser;
--error 1044,1142,1227,1370
REVOKE SELECT ON test FROM myuser;
--error 1044,1142,1227,1370,1698
REVOKE ALL, GRANT OPTION FROM myuser;
--error 1044,1142,1227,1370,1698
REVOKE PROXY ON myuser FROM myuser;

# table maintenance
--error 1044,1142,1227,1370
ANALYZE TABLE db.tbl;
--error 1044,1142,1227,1370
CHECK TABLE db.tbl;
--error 1044,1142,1227,1370
CHECKSUM TABLE db.tbl;
--error 1044,1142,1227,1370
OPTIMIZE TABLE db.tbl;
--error 1044,1142,1227,1370
REPAIR TABLE db.tbl;

# plugin and user defined functions
--error 1044,1142,1227,1370
INSTALL PLUGIN plg SONAME 'plg.so';
--error 1044,1142,1227,1370
UNINSTALL PLUGIN plg;

--connection node_1
DROP USER 'userMW416'@'localhost';
SHOW DATABASES;
SHOW GLOBAL STATUS LIKE 'wsrep_replicated';
15 changes: 15 additions & 0 deletions sql/events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,

if (check_access(thd, EVENT_ACL, parse_data->dbname.str, NULL, NULL, 0, 0))
DBUG_RETURN(TRUE);
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL);

if (check_db_dir_existence(parse_data->dbname.str))
{
Expand Down Expand Up @@ -406,6 +407,10 @@ Events::create_event(THD *thd, Event_parse_data *parse_data,
thd->set_current_stmt_binlog_format_row();

DBUG_RETURN(ret);
#ifdef WITH_WSREP
error:
DBUG_RETURN(TRUE);
#endif /* WITH_WSREP */
}


Expand Down Expand Up @@ -446,6 +451,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,

if (check_access(thd, EVENT_ACL, parse_data->dbname.str, NULL, NULL, 0, 0))
DBUG_RETURN(TRUE);
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL);

if (new_dbname) /* It's a rename */
{
Expand Down Expand Up @@ -521,6 +527,10 @@ Events::update_event(THD *thd, Event_parse_data *parse_data,
thd->set_current_stmt_binlog_format_row();

DBUG_RETURN(ret);
#ifdef WITH_WSREP
error:
DBUG_RETURN(TRUE);
#endif /* WITH_WSREP */
}


Expand Down Expand Up @@ -560,6 +570,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)

if (check_access(thd, EVENT_ACL, dbname.str, NULL, NULL, 0, 0))
DBUG_RETURN(TRUE);
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL);

/*
Turn off row binlogging of this statement and use statement-based so
Expand All @@ -585,6 +596,10 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists)
if (save_binlog_row_based)
thd->set_current_stmt_binlog_format_row();
DBUG_RETURN(ret);
#ifdef WITH_WSREP
error:
DBUG_RETURN(TRUE);
#endif /* WITH_WSREP */
}


Expand Down
1 change: 1 addition & 0 deletions sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -2383,6 +2383,7 @@ class THD :public Statement,
enum wsrep_query_state wsrep_query_state;
enum wsrep_conflict_state wsrep_conflict_state;
mysql_mutex_t LOCK_wsrep_thd;
mysql_cond_t COND_wsrep_thd;
// changed from wsrep_seqno_t to wsrep_trx_meta_t in wsrep API rev 75
// wsrep_seqno_t wsrep_trx_seqno;
wsrep_trx_meta_t wsrep_trx_meta;
Expand Down
7 changes: 0 additions & 7 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3825,7 +3825,6 @@ case SQLCOM_PREPARE:
if (res)
break;

WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
switch (lex->sql_command) {
case SQLCOM_CREATE_EVENT:
{
Expand Down Expand Up @@ -3861,7 +3860,6 @@ case SQLCOM_PREPARE:
lex->spname->m_name);
break;
case SQLCOM_DROP_EVENT:
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
if (!(res= Events::drop_event(thd,
lex->spname->m_db, lex->spname->m_name,
lex->drop_if_exists)))
Expand Down Expand Up @@ -4773,7 +4771,6 @@ case SQLCOM_PREPARE:
Note: SQLCOM_CREATE_VIEW also handles 'ALTER VIEW' commands
as specified through the thd->lex->create_view_mode flag.
*/
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
res= mysql_create_view(thd, first_table, thd->lex->create_view_mode);
break;
}
Expand All @@ -4789,15 +4786,13 @@ case SQLCOM_PREPARE:
case SQLCOM_CREATE_TRIGGER:
{
/* Conditionally writes to binlog. */
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
res= mysql_create_or_drop_trigger(thd, all_tables, 1);

break;
}
case SQLCOM_DROP_TRIGGER:
{
/* Conditionally writes to binlog. */
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
res= mysql_create_or_drop_trigger(thd, all_tables, 0);
break;
}
Expand Down Expand Up @@ -4860,13 +4855,11 @@ case SQLCOM_PREPARE:
my_ok(thd);
break;
case SQLCOM_INSTALL_PLUGIN:
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
if (! (res= mysql_install_plugin(thd, &thd->lex->comment,
&thd->lex->ident)))
my_ok(thd);
break;
case SQLCOM_UNINSTALL_PLUGIN:
WSREP_TO_ISOLATION_BEGIN(WSREP_MYSQL_DB, NULL, NULL)
if (! (res= mysql_uninstall_plugin(thd, &thd->lex->comment,
&thd->lex->ident)))
my_ok(thd);
Expand Down
Loading

0 comments on commit 8822b30

Please sign in to comment.