From bfaceda030b09cfb5326b12659f079cc3f9ee81b Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Sat, 7 May 2022 18:25:52 +0800 Subject: [PATCH] feat: sql command 'grant', 'revoke', 'kill transaction' and 'show transactions' --- source/dnode/mnode/impl/src/mndUser.c | 5 +++++ source/libs/parser/src/parAuthenticator.c | 9 +++++++++ source/libs/parser/test/mockCatalog.cpp | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index a0ef047ddc..d0af17ff5c 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -412,6 +412,11 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) { goto _OVER; } + if (TSDB_ALTER_USER_PASSWD == alterReq.alterType && alterReq.pass[0] == 0) { + terrno = TSDB_CODE_MND_INVALID_PASS_FORMAT; + goto _OVER; + } + pUser = mndAcquireUser(pMnode, alterReq.user); if (pUser == NULL) { terrno = TSDB_CODE_MND_USER_NOT_EXIST; diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 08141cbe60..c343c934ea 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -52,9 +52,18 @@ static int32_t authSelect(SAuthCxt* pCxt, SSelectStmt* pSelect) { return pCxt->errCode; } +static int32_t authSetOperator(SAuthCxt* pCxt, SSetOperator* pSetOper) { + int32_t code = authQuery(pCxt, pSetOper->pLeft); + if (TSDB_CODE_SUCCESS == code) { + code = authQuery(pCxt, pSetOper->pRight); + } + return code; +} + static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt) { switch (nodeType(pStmt)) { case QUERY_NODE_SET_OPERATOR: + return authSetOperator(pCxt, (SSetOperator*)pStmt); case QUERY_NODE_SELECT_STMT: return authSelect(pCxt, (SSelectStmt*)pStmt); case QUERY_NODE_VNODE_MODIF_STMT: diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 2d9a907d9b..a82fbfce26 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -181,6 +181,12 @@ int32_t __catalogGetDBCfg(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, co return 0; } +int32_t __catalogChkAuth(SCatalog* pCtg, void* pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName, + AUTH_TYPE type, bool* pass) { + *pass = true; + return 0; +} + void initMetaDataEnv() { mockCatalogService.reset(new MockCatalogService()); @@ -193,6 +199,7 @@ void initMetaDataEnv() { stub.set(catalogGetDBVgVersion, __catalogGetDBVgVersion); stub.set(catalogGetDBVgInfo, __catalogGetDBVgInfo); stub.set(catalogGetDBCfg, __catalogGetDBCfg); + stub.set(catalogChkAuth, __catalogChkAuth); // { // AddrAny any("libcatalog.so"); // std::map result;