add rpc update interface

This commit is contained in:
yihaoDeng 2023-09-10 17:02:38 +08:00
parent d121b564c0
commit 9781766009
2 changed files with 45 additions and 4 deletions

View File

@ -260,8 +260,8 @@ bool mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8_t
} }
void mndUpdateIpWhite(char *user, char *fqdn, int8_t type, int8_t lock) { void mndUpdateIpWhite(char *user, char *fqdn, int8_t type, int8_t lock) {
if (lock) taosThreadRwlockWrlock(&ipWhiteMgt.rw); if (lock) taosThreadRwlockWrlock(&ipWhiteMgt.rw);
bool update = mndUpdateIpWhiteImpl(ipWhiteMgt.pIpWhiteTab, user, fqdn, type);
bool update = mndUpdateIpWhiteImpl(ipWhiteMgt.pIpWhiteTab, user, fqdn, type);
if (update) ipWhiteMgt.ver++; if (update) ipWhiteMgt.ver++;
if (lock) taosThreadRwlockUnlock(&ipWhiteMgt.rw); if (lock) taosThreadRwlockUnlock(&ipWhiteMgt.rw);
@ -316,6 +316,7 @@ SHashObj *mndFetchAllIpWhite(SMnode *pMnode) {
void *pIter = NULL; void *pIter = NULL;
SHashObj *pIpWhiteTab = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 1, HASH_ENTRY_LOCK); SHashObj *pIpWhiteTab = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 1, HASH_ENTRY_LOCK);
SArray *pUserNames = taosArrayInit(8, sizeof(void *));
while (1) { while (1) {
SUserObj *pUser = NULL; SUserObj *pUser = NULL;
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser); pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
@ -324,19 +325,47 @@ SHashObj *mndFetchAllIpWhite(SMnode *pMnode) {
SIpWhiteList *pWhiteList = cloneIpWhiteList(pUser->pIpWhiteList); SIpWhiteList *pWhiteList = cloneIpWhiteList(pUser->pIpWhiteList);
taosHashPut(pIpWhiteTab, pUser->user, strlen(pUser->user), &pWhiteList, sizeof(void *)); taosHashPut(pIpWhiteTab, pUser->user, strlen(pUser->user), &pWhiteList, sizeof(void *));
char *name = taosStrdup(pUser->user);
taosArrayPush(pUserNames, &name);
sdbRelease(pSdb, pUser); sdbRelease(pSdb, pUser);
} }
bool found = false;
for (int i = 0; i < taosArrayGetSize(pUserNames); i++) {
char *name = taosArrayGetP(pUserNames, i);
if (strlen(name) == strlen(TSDB_DEFAULT_USER) && strncmp(name, TSDB_DEFAULT_USER, strlen(TSDB_DEFAULT_USER)) == 0) {
found = true;
break;
}
}
if (found == false) {
char *name = taosStrdup(TSDB_DEFAULT_USER);
taosArrayPush(pUserNames, &name);
}
SArray *fqdns = mndGetAllDnodeFqdns(pMnode); SArray *fqdns = mndGetAllDnodeFqdns(pMnode);
for (int i = 0; i < taosArrayGetSize(fqdns); i++) { for (int i = 0; i < taosArrayGetSize(fqdns); i++) {
char *fqdn = taosArrayGetP(fqdns, i); char *fqdn = taosArrayGetP(fqdns, i);
mndUpdateIpWhiteImpl(pIpWhiteTab, TSDB_DEFAULT_USER, fqdn, IP_WHITE_ADD);
for (int j = 0; j < taosArrayGetSize(pUserNames); j++) {
char *name = taosArrayGetP(pUserNames, j);
mndUpdateIpWhiteImpl(pIpWhiteTab, name, fqdn, IP_WHITE_ADD);
}
}
for (int i = 0; i < taosArrayGetSize(fqdns); i++) {
char *fqdn = taosArrayGetP(fqdns, i);
taosMemoryFree(fqdn); taosMemoryFree(fqdn);
} }
taosArrayDestroy(fqdns); taosArrayDestroy(fqdns);
for (int i = 0; i < taosArrayGetSize(pUserNames); i++) {
taosMemoryFree(taosArrayGetP(pUserNames, i));
}
taosArrayDestroy(pUserNames);
return pIpWhiteTab; return pIpWhiteTab;
} }
@ -1544,6 +1573,8 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
} }
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WHITE_LIST) { if (alterReq.alterType == TSDB_ALTER_USER_ADD_WHITE_LIST) {
taosMemoryFree(newUser.pIpWhiteList);
int32_t num = pUser->pIpWhiteList->num + alterReq.numIpRanges; int32_t num = pUser->pIpWhiteList->num + alterReq.numIpRanges;
SIpWhiteList *pNew = taosMemoryCalloc(1, sizeof(SIpWhiteList) + sizeof(SIpV4Range) * num); SIpWhiteList *pNew = taosMemoryCalloc(1, sizeof(SIpWhiteList) + sizeof(SIpV4Range) * num);
@ -1562,6 +1593,8 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
newUser.pIpWhiteList = pNew; newUser.pIpWhiteList = pNew;
} }
if (alterReq.alterType == TSDB_ALTER_USER_DROP_WHITE_LIST) { if (alterReq.alterType == TSDB_ALTER_USER_DROP_WHITE_LIST) {
taosMemoryFree(newUser.pIpWhiteList);
int32_t num = pUser->pIpWhiteList->num; int32_t num = pUser->pIpWhiteList->num;
SIpWhiteList *pNew = taosMemoryCalloc(1, sizeof(SIpWhiteList) + sizeof(SIpV4Range) * num); SIpWhiteList *pNew = taosMemoryCalloc(1, sizeof(SIpWhiteList) + sizeof(SIpV4Range) * num);

View File

@ -292,10 +292,18 @@ void uvWhiteListUpdate(SWhiteList* pWhite, SHashObj* pTable) {
// impl later // impl later
} }
static bool uvWhiteListIsDefaultAddr(uint32_t ip) {
// 127.0.0.1
static SIpV4Range range = {.ip = 16777343, .mask = 0};
return range.ip == ip;
}
bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver) { bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver) {
// impl check // impl check
SHashObj* pWhiteList = pWhite->pList; SHashObj* pWhiteList = pWhite->pList;
bool valid = false; bool valid = false;
if (uvWhiteListIsDefaultAddr(ip)) return true;
SWhiteUserList** ppList = taosHashGet(pWhiteList, user, strlen(user)); SWhiteUserList** ppList = taosHashGet(pWhiteList, user, strlen(user));
if (ppList == NULL || *ppList == NULL) { if (ppList == NULL || *ppList == NULL) {
return false; return false;