From 8c35827cecd49de3cb68fb5fe78f6dd018bdac5c Mon Sep 17 00:00:00 2001 From: wd2365151147 <2365151147@qq.com> Date: Thu, 19 Nov 2020 15:20:00 +0800 Subject: [PATCH] cherry pick from inner-692 --- .../dble/config/model/user/ManagerUserConfig.java | 4 ++-- .../dble/services/manager/response/Describe.java | 15 ++++----------- .../services/mysqlauthenticate/util/AuthUtil.java | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/actiontech/dble/config/model/user/ManagerUserConfig.java b/src/main/java/com/actiontech/dble/config/model/user/ManagerUserConfig.java index aedc85bc0..a4c03eea9 100644 --- a/src/main/java/com/actiontech/dble/config/model/user/ManagerUserConfig.java +++ b/src/main/java/com/actiontech/dble/config/model/user/ManagerUserConfig.java @@ -34,8 +34,8 @@ public class ManagerUserConfig extends UserConfig { schemaInfo.setSchema((schemaInfo.getSchema().toLowerCase())); schemaInfo.setTable(schemaInfo.getTable().toLowerCase()); if (!ManagerSchemaInfo.SCHEMA_NAME.equals(schemaInfo.getSchema())) { - String msg = "Access denied for user '" + user + "' to database '" + schemaInfo.getSchema() + "'"; - throw new SQLException(msg, "HY000", ErrorCode.ER_DBACCESS_DENIED_ERROR); + String msg = "Unknown database '" + schemaInfo.getSchema() + "'"; + throw new SQLException(msg, "42000", ErrorCode.ER_BAD_DB_ERROR); } if (!ManagerSchemaInfo.getInstance().getTables().containsKey(schemaInfo.getTable())) { String msg = "Table " + StringUtil.getFullName(schemaInfo.getSchema(), schemaInfo.getTable()) + " doesn't exist"; diff --git a/src/main/java/com/actiontech/dble/services/manager/response/Describe.java b/src/main/java/com/actiontech/dble/services/manager/response/Describe.java index 39dca2f80..38cead9dd 100644 --- a/src/main/java/com/actiontech/dble/services/manager/response/Describe.java +++ b/src/main/java/com/actiontech/dble/services/manager/response/Describe.java @@ -5,7 +5,6 @@ package com.actiontech.dble.services.manager.response; import com.actiontech.dble.backend.mysql.PacketUtil; -import com.actiontech.dble.config.ErrorCode; import com.actiontech.dble.config.Fields; import com.actiontech.dble.meta.ColumnMeta; import com.actiontech.dble.net.mysql.*; @@ -64,21 +63,13 @@ public final class Describe { SQLStatement statement = RouteStrategyFactory.getRouteStrategy().parserSQL(stmt); MySqlExplainStatement describeStatement = (MySqlExplainStatement) statement; SchemaUtil.SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(service.getUser(), service.getSchema(), describeStatement.getTableName(), null); - schemaName = schemaInfo.getSchema().toLowerCase(); + // schemaName = schemaInfo.getSchema().toLowerCase(); tableName = schemaInfo.getTable().toLowerCase(); } catch (SQLException e) { service.writeErrMessage(e.getSQLState(), e.getMessage(), e.getErrorCode()); return; } - if (!ManagerSchemaInfo.SCHEMA_NAME.equals(schemaName)) { - service.writeErrMessage("42000", "Unknown database '" + schemaName + "'", ErrorCode.ER_BAD_DB_ERROR); - return; - } - ManagerBaseTable table = ManagerSchemaInfo.getInstance().getTables().get(tableName); - if (table == null) { - service.writeErrMessage("42S02", " Table '" + ManagerSchemaInfo.SCHEMA_NAME + "." + tableName + "' doesn't exist", ErrorCode.ER_NO_SUCH_TABLE); - return; - } + ByteBuffer buffer = service.allocate(); // write header @@ -94,6 +85,8 @@ public final class Describe { // write rows byte packetId = EOF.getPacketId(); + + ManagerBaseTable table = ManagerSchemaInfo.getInstance().getTables().get(tableName); for (ColumnMeta column : table.getColumnsMeta()) { RowDataPacket row = new RowDataPacket(FIELD_COUNT); row.add(StringUtil.encode(column.getName(), service.getCharset().getResults())); diff --git a/src/main/java/com/actiontech/dble/services/mysqlauthenticate/util/AuthUtil.java b/src/main/java/com/actiontech/dble/services/mysqlauthenticate/util/AuthUtil.java index 9c7deb560..3c721c10c 100644 --- a/src/main/java/com/actiontech/dble/services/mysqlauthenticate/util/AuthUtil.java +++ b/src/main/java/com/actiontech/dble/services/mysqlauthenticate/util/AuthUtil.java @@ -14,6 +14,7 @@ import com.actiontech.dble.config.model.user.UserConfig; import com.actiontech.dble.config.model.user.UserName; import com.actiontech.dble.net.connection.AbstractConnection; import com.actiontech.dble.net.connection.FrontendConnection; +import com.actiontech.dble.services.manager.information.ManagerSchemaInfo; import com.actiontech.dble.services.mysqlauthenticate.PluginName; import com.actiontech.dble.services.mysqlauthenticate.SecurityUtil; import com.actiontech.dble.singleton.CapClientFoundRows; @@ -74,6 +75,13 @@ public final class AuthUtil { if ((Capabilities.CLIENT_FOUND_ROWS == (Capabilities.CLIENT_FOUND_ROWS & clientFlags)) != CapClientFoundRows.getInstance().isEnableCapClientFoundRows()) { return "The client requested CLIENT_FOUND_ROWS capabilities does not match, in the manager use show @@cap_client_found_rows check latest status."; } + } else if (userConfig instanceof ManagerUserConfig) { + switch (checkManagerSchema(schema)) { + case ErrorCode.ER_BAD_DB_ERROR: + return "Unknown database '" + schema + "'"; + default: + break; + } } //check maxconnection @@ -167,4 +175,11 @@ public final class AuthUtil { } } + private static int checkManagerSchema(String schema) { + if (schema != null && !ManagerSchemaInfo.SCHEMA_NAME.equals(schema.toLowerCase())) { + return ErrorCode.ER_BAD_DB_ERROR; + } + return 0; + } + }