diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 52d070aaef..2a18e800b8 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -240,7 +240,7 @@ typedef struct SDropTableStmt { ENodeType type; SNodeList* pTables; bool withTsma; - bool withUid; + bool withOpt; } SDropTableStmt; typedef struct SDropSuperTableStmt { @@ -248,7 +248,7 @@ typedef struct SDropSuperTableStmt { char dbName[TSDB_DB_NAME_LEN]; char tableName[TSDB_TABLE_NAME_LEN]; bool ignoreNotExists; - bool withUid; + bool withOpt; } SDropSuperTableStmt; typedef struct SAlterTableStmt { diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 9b63d938f9..0217ec834a 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -6038,7 +6038,7 @@ static int32_t jsonToDropTableStmt(const SJson* pJson, void* pObj) { static const char* jkDropSuperTableStmtDbName = "DbName"; static const char* jkDropSuperTableStmtTableName = "TableName"; static const char* jkDropSuperTableStmtIgnoreNotExists = "IgnoreNotExists"; -static const char* jkDropSuperTableStmtWithUid = "WithUid"; +static const char* jkDropSuperTableStmtwithOpt = "withOpt"; static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) { const SDropSuperTableStmt* pNode = (const SDropSuperTableStmt*)pObj; @@ -6051,7 +6051,7 @@ static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) { code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtIgnoreNotExists, pNode->ignoreNotExists); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtWithUid, pNode->withUid); + code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtwithOpt, pNode->withOpt); } return code; @@ -6068,7 +6068,7 @@ static int32_t jsonToDropStableStmt(const SJson* pJson, void* pObj) { code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtIgnoreNotExists, &pNode->ignoreNotExists); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtWithUid, &pNode->withUid); + code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtwithOpt, &pNode->withOpt); } return code; diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index db39ddb47b..18ebf3bd21 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -2360,7 +2360,7 @@ SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTa pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, (SNode**)&pStmt); CHECK_MAKE_NODE(pStmt); pStmt->pTables = pTables; - pStmt->withUid = withOpt; + pStmt->withOpt = withOpt; return (SNode*)pStmt; _err: nodesDestroyList(pTables); @@ -2375,7 +2375,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool igno strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); pStmt->ignoreNotExists = ignoreNotExists; - pStmt->withUid = withOpt; + pStmt->withOpt = withOpt; nodesDestroyNode(pRealTable); return (SNode*)pStmt; _err: diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index ffe4569cc5..eae9ea90f1 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -377,27 +377,19 @@ static int32_t collectMetaKeyFromCreateSubTableFromFile(SCollectMetaKeyCxt* static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableStmt* pStmt) { int32_t code = TSDB_CODE_SUCCESS; SNode* pNode = NULL; - char tableName[50] = "aa\u00bf\u200bstb0"; + // char tableName[50] = "aa\u00bf\u200bstb0"; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); - if (TSDB_CODE_SUCCESS == code) { - code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache); - } + if (TSDB_CODE_SUCCESS == code) { code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); } - if (TSDB_CODE_SUCCESS == code) { - code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, tableName, pCxt->pMetaCache); - } + if (TSDB_CODE_SUCCESS == code) { code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); } - if (TSDB_CODE_SUCCESS == code) { - code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, - tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); - } if (TSDB_CODE_SUCCESS != code) { break; } diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 9f738b32e8..0eb07d8143 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -290,7 +290,10 @@ static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStm static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) { int32_t code = TSDB_CODE_SUCCESS; - SNode* pNode = NULL; + if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } + SNode* pNode = NULL; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL); @@ -302,6 +305,9 @@ static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) { } static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) { + if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 4a80bc6b26..eb6eb679ff 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -14449,22 +14449,22 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut) return code; } -static int32_t rewriteDropTableWithUid(STranslateContext* pCxt, SDropTableStmt* pStmt) { - if (!pStmt->withUid) return TSDB_CODE_SUCCESS; +// static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) { +// if (!pStmt->withOpt) return TSDB_CODE_SUCCESS; - SNode* pNode = NULL; - const char* pTableName = NULL; - FOREACH(pNode, pStmt->pTables) { - SDropTableClause* pClause = (SDropTableClause*)pNode; - pTableName = "aa\u00bf\u200bstb0"; - if (!pTableName) { - return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'", - pClause->tableName); - } - tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN); - } - return TSDB_CODE_SUCCESS; -} +// SNode* pNode = NULL; +// const char* pTableName = NULL; +// FOREACH(pNode, pStmt->pTables) { +// SDropTableClause* pClause = (SDropTableClause*)pNode; +// pTableName = "aa\u00bf\u200bstb0"; +// if (!pTableName) { +// return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'", +// pClause->tableName); +// } +// tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN); +// } +// return TSDB_CODE_SUCCESS; +// } static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot; @@ -14472,7 +14472,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { SNode* pNode; SArray* pTsmas = NULL; - TAOS_CHECK_RETURN(rewriteDropTableWithUid(pCxt, pStmt)); + // TAOS_CHECK_RETURN(rewriteDropTablewithOpt(pCxt, pStmt)); SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pVgroupHashmap) {