From 6dfb939f22b0c04e169e331711c705444b708cb0 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 14 Sep 2023 14:11:50 +0800 Subject: [PATCH 1/2] enhance: enhance test case --- include/common/tmsg.h | 7 +------ source/client/src/clientMain.c | 15 ++++++++++++++- tests/script/api/whiteListTest.c | 10 +++++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 2dd4af3441..9d1a8a9189 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -876,14 +876,9 @@ typedef struct { int32_t tSerializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq); int32_t tDeserializeSDropUserReq(void* buf, int32_t bufLen, SDropUserReq* pReq); -typedef union { - struct { - uint64_t ip_mask; - }; - struct { +typedef struct SIpV4Range{ uint32_t ip; uint32_t mask; - }; } SIpV4Range; typedef struct { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index fd7a57d847..7902d6029e 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -178,8 +178,21 @@ int32_t fetchWhiteListCallbackFn(void* param, SDataBuf* pMsg, int32_t code) { SGetUserWhiteListRsp wlRsp; tDeserializeSGetUserWhiteListRsp(pMsg->pData, pMsg->len, &wlRsp); - pInfo->userCbFn(pInfo->userParam, code, taos, wlRsp.numWhiteLists, &wlRsp.pWhiteLists->ip_mask); + uint64_t* pWhiteLists = taosMemoryMalloc(wlRsp.numWhiteLists * sizeof(uint64_t)); + if (pWhiteLists == NULL) { + taosMemoryFree(pMsg->pData); + taosMemoryFree(pMsg->pEpSet); + taosMemoryFree(pInfo); + tFreeSGetUserWhiteListRsp(&wlRsp); + } + for (int i = 0; i < wlRsp.numWhiteLists; ++i) { + pWhiteLists[i] = ((uint64_t)wlRsp.pWhiteLists[i].mask << 32) | wlRsp.pWhiteLists[i].ip; + } + + pInfo->userCbFn(pInfo->userParam, code, taos, wlRsp.numWhiteLists, pWhiteLists); + + taosMemoryFree(pWhiteLists); taosMemoryFree(pMsg->pData); taosMemoryFree(pMsg->pEpSet); taosMemoryFree(pInfo); diff --git a/tests/script/api/whiteListTest.c b/tests/script/api/whiteListTest.c index 9e5eec2ef6..1fe377f0f5 100644 --- a/tests/script/api/whiteListTest.c +++ b/tests/script/api/whiteListTest.c @@ -64,7 +64,7 @@ void __taos_async_whitelist_cb(void *param, int code, TAOS *taos, int numOfWhite if (code == 0) { printf("fetch whitelist cb. user: %s numofWhitelist: %d\n", param ? (char*)param : NULL, numOfWhiteLists); for (int i = 0; i < numOfWhiteLists; ++i) { - printf(" %d: %16x\n", i, pWhiteList[i]); + printf(" %d: 0x%llx\n", i, pWhiteList[i]); } } else { printf("fetch whitelist cb error %d\n", code); @@ -118,8 +118,11 @@ int main(int argc, char *argv[]) { } createUsers(taos, argv[1]); - sleep(1); - + while (nWhiteListVerNotified < 10) { + printf("white list update notified %d times\n", nWhiteListVerNotified); + sleep(1); + } + printf("succeed in getting white list nofication. %d times\n", nWhiteListVerNotified); dropUsers(taos); taos_close(taos); taos_cleanup(); @@ -163,4 +166,5 @@ void createUsers(TAOS *taos, const char *host) { taos_fetch_whitelist_a(taosu[i], __taos_async_whitelist_cb, users[i]); } + } From 2a40113f131cbec6b92006dda1f05385470105b2 Mon Sep 17 00:00:00 2001 From: slzhou Date: Thu, 14 Sep 2023 14:44:09 +0800 Subject: [PATCH 2/2] fix: entprise version compilation --- source/dnode/mnode/impl/src/mndPrivilege.c | 22 ++++++++++++++++++++++ source/dnode/mnode/impl/src/mndUser.c | 20 -------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index fccdd4afd8..0ecaee2168 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -33,6 +33,28 @@ int32_t mndCheckTopicPrivilege(SMnode *pMnode, const char *user, EOperType operT int32_t mndCheckTopicPrivilegeByName(SMnode *pMnode, const char *user, EOperType operType, const char *topicName) { return 0; } + + +// TODO: for community version use the commented version +int32_t mndSetUserWhiteListRsp(SMnode *pMnode, SUserObj *pUser, SGetUserWhiteListRsp *pWhiteListRsp) { + memcpy(pWhiteListRsp->user, pUser->user, TSDB_USER_LEN); + // pWhiteListRsp->numWhiteLists = 1; + // pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + // if (pWhiteListRsp->pWhiteLists == NULL) { + // return TSDB_CODE_OUT_OF_MEMORY; + // } + // memset(pUser->pIpWhiteList->pIpRange, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + pWhiteListRsp->numWhiteLists = pUser->pIpWhiteList->num; + pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + if (pWhiteListRsp->pWhiteLists == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + memcpy(pWhiteListRsp->pWhiteLists, pUser->pIpWhiteList->pIpRange, + pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); + + return 0; +} + int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp) { memcpy(pRsp->user, pUser->user, TSDB_USER_LEN); pRsp->superAuth = 1; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index d8ec075f45..4943328b43 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -1231,26 +1231,6 @@ _OVER: return code; } -// TODO: for community version use the commented version -int32_t mndSetUserWhiteListRsp(SMnode *pMnode, SUserObj *pUser, SGetUserWhiteListRsp *pWhiteListRsp) { - memcpy(pWhiteListRsp->user, pUser->user, TSDB_USER_LEN); - // pWhiteListRsp->numWhiteLists = 1; - // pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - // if (pWhiteListRsp->pWhiteLists == NULL) { - // return TSDB_CODE_OUT_OF_MEMORY; - // } - // memset(pUser->pIpWhiteList->pIpRange, 0, pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - pWhiteListRsp->numWhiteLists = pUser->pIpWhiteList->num; - pWhiteListRsp->pWhiteLists = taosMemoryMalloc(pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - if (pWhiteListRsp->pWhiteLists == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - memcpy(pWhiteListRsp->pWhiteLists, pUser->pIpWhiteList->pIpRange, - pWhiteListRsp->numWhiteLists * sizeof(SIpV4Range)); - - return 0; -} - int32_t mndProcessGetUserWhiteListReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1;