Merge branch 'enh/ipWhiteList' of https://github.com/taosdata/TDengine into enh/ipWhiteList
This commit is contained in:
commit
e36dc50828
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1231,25 +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;
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue