Merge pull request #21158 from taosdata/fix/preventSubtableGrant

fix: subtable grant is not allowed
This commit is contained in:
dapan1121 2023-05-05 15:42:07 +08:00 committed by GitHub
commit 61f13f20eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 7 deletions

View File

@ -6666,22 +6666,40 @@ static int32_t createRealTableForGrantTable(SGrantStmt* pStmt, SRealTableNode**
}
static int32_t translateGrantTagCond(STranslateContext* pCxt, SGrantStmt* pStmt, SAlterUserReq* pReq) {
if (NULL == pStmt->pTagCond) {
return TSDB_CODE_SUCCESS;
}
SRealTableNode* pTable = NULL;
if ('\0' == pStmt->tabName[0] || '*' == pStmt->tabName[0]) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
"The With clause can only be used for table level privilege");
if (pStmt->pTagCond) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
"The With clause can only be used for table level privilege");
} else {
return TSDB_CODE_SUCCESS;
}
}
pCxt->pCurrStmt = (SNode*)pStmt;
SRealTableNode* pTable = NULL;
int32_t code = createRealTableForGrantTable(pStmt, &pTable);
if (TSDB_CODE_SUCCESS == code) {
SName name;
code = getTableMetaImpl(pCxt, toName(pCxt->pParseCxt->acctId, pTable->table.dbName, pTable->table.tableName, &name),
&(pTable->pMeta));
if (code) {
nodesDestroyNode((SNode*)pTable);
return code;
}
if (TSDB_SUPER_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType) {
nodesDestroyNode((SNode*)pTable);
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR,
"Only supertable and normal table can be granted");
}
}
if (TSDB_CODE_SUCCESS == code && NULL == pStmt->pTagCond) {
nodesDestroyNode((SNode*)pTable);
return TSDB_CODE_SUCCESS;
}
pCxt->pCurrStmt = (SNode*)pStmt;
if (TSDB_CODE_SUCCESS == code) {
code = addNamespace(pCxt, pTable);
}