提交 51004de0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Non-admin users could not open a database using a mode (MODE=xxx) if the…

Non-admin users could not open a database using a mode (MODE=xxx) if the database was already open, even if the mode matched.
上级 d453993d
...@@ -242,12 +242,14 @@ public class Set extends Prepared { ...@@ -242,12 +242,14 @@ public class Set extends Prepared {
break; break;
} }
case SetTypes.MODE: case SetTypes.MODE:
session.getUser().checkAdmin();
Mode mode = Mode.getInstance(stringValue); Mode mode = Mode.getInstance(stringValue);
if (mode == null) { if (mode == null) {
throw DbException.get(ErrorCode.UNKNOWN_MODE_1, stringValue); throw DbException.get(ErrorCode.UNKNOWN_MODE_1, stringValue);
} }
database.setMode(mode); if (database.getMode() != mode) {
session.getUser().checkAdmin();
database.setMode(mode);
}
break; break;
case SetTypes.MULTI_THREADED: { case SetTypes.MULTI_THREADED: {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
......
...@@ -34,6 +34,7 @@ public class TestRights extends TestBase { ...@@ -34,6 +34,7 @@ public class TestRights extends TestBase {
} }
public void test() throws SQLException { public void test() throws SQLException {
testOpenNonAdminWithMode();
testDisallowedTables(); testDisallowedTables();
testDropOwnUser(); testDropOwnUser();
testGetTables(); testGetTables();
...@@ -44,6 +45,26 @@ public class TestRights extends TestBase { ...@@ -44,6 +45,26 @@ public class TestRights extends TestBase {
deleteDb("rights"); deleteDb("rights");
} }
private void testOpenNonAdminWithMode() throws SQLException {
deleteDb("rights");
Connection conn = getConnection("rights");
stat = conn.createStatement();
stat.execute("create user test password 'test'");
Connection conn2 = getConnection("rights", "test", getPassword("test"));
conn2.close();
conn.close();
// if opening alone
conn2 = getConnection("rights;MODE=MYSQL", "test", getPassword("test"));
conn2.close();
// if opening as the second connection
conn = getConnection("rights;MODE=MYSQL");
conn2 = getConnection("rights;MODE=MYSQL", "test", getPassword("test"));
conn2.close();
stat = conn.createStatement();
stat.execute("drop user test");
conn.close();
}
private void testDisallowedTables() throws SQLException { private void testDisallowedTables() throws SQLException {
deleteDb("rights"); deleteDb("rights");
Connection conn = getConnection("rights"); Connection conn = getConnection("rights");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论