mirror of
https://github.com/actiontech/dble.git
synced 2026-01-02 02:40:28 -06:00
cherry pick from inner-692
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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()));
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user