Skip to content

Commit

Permalink
[fix](auth)fix create table like need create_priv of existed table (#…
Browse files Browse the repository at this point in the history
…37879)

create table like only need create_priv of newTable, and select_priv of
existedTable

not need create_priv of existed table

ps: have already added cases in other PRs
  • Loading branch information
zddr authored Jul 31, 2024
1 parent c60e60a commit 47e1cae
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -1226,6 +1227,8 @@ public boolean createTable(CreateTableStmt stmt) throws UserException {
}

public void createTableLike(CreateTableLikeStmt stmt) throws DdlException {
ConnectContext ctx = ConnectContext.get();
Objects.requireNonNull(ctx, "ConnectContext.get() can not be null.");
try {
DatabaseIf db = getDbOrDdlException(stmt.getExistedDbName());
TableIf table = db.getTableOrDdlException(stmt.getExistedTableName());
Expand Down Expand Up @@ -1259,14 +1262,23 @@ public void createTableLike(CreateTableLikeStmt stmt) throws DdlException {
} finally {
table.readUnlock();
}
CreateTableStmt parsedCreateTableStmt = (CreateTableStmt) SqlParserUtils.parseAndAnalyzeStmt(
createTableStmt.get(0), ConnectContext.get());
parsedCreateTableStmt.setTableName(stmt.getTableName());
parsedCreateTableStmt.setIfNotExists(stmt.isIfNotExists());
createTable(parsedCreateTableStmt);

try {
// analyze CreateTableStmt will check create_priv of existedTable, create table like only need
// create_priv of newTable, and select_priv of existedTable, and priv check has done in
// CreateTableStmt/CreateTableCommand, so we skip it
ctx.setSkipAuth(true);
CreateTableStmt parsedCreateTableStmt = (CreateTableStmt) SqlParserUtils.parseAndAnalyzeStmt(
createTableStmt.get(0), ctx);
parsedCreateTableStmt.setTableName(stmt.getTableName());
parsedCreateTableStmt.setIfNotExists(stmt.isIfNotExists());
createTable(parsedCreateTableStmt);
} finally {
ctx.setSkipAuth(false);
}
} catch (UserException e) {
throw new DdlException("Failed to execute CREATE TABLE LIKE " + stmt.getExistedTableName() + ". Reason: "
+ e.getMessage());
+ e.getMessage(), e);
}
}

Expand Down

0 comments on commit 47e1cae

Please sign in to comment.