fix: remove privilege info on drop db / topic
This commit is contained in:
parent
7b78a15824
commit
5e9a90ef5c
|
@ -34,6 +34,8 @@ SHashObj *mndDupDbHash(SHashObj *pOld);
|
||||||
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
SHashObj *mndDupTopicHash(SHashObj *pOld);
|
||||||
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_t numOfUses, void **ppRsp,
|
||||||
int32_t *pRspLen);
|
int32_t *pRspLen);
|
||||||
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db);
|
||||||
|
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1051,17 +1051,7 @@ static int32_t mndDropDb(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb) {
|
||||||
if (mndDropStreamByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropStreamByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndDropSmasByDb(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||||
|
if (mndUserRemoveDb(pMnode, pTrans, pDb->name) != 0) goto _OVER;
|
||||||
SUserObj *pUser = mndAcquireUser(pMnode, pDb->createUser);
|
|
||||||
if (pUser != NULL) {
|
|
||||||
pUser->authVersion++;
|
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(pUser);
|
|
||||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
|
||||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t rspLen = 0;
|
int32_t rspLen = 0;
|
||||||
void *pRsp = NULL;
|
void *pRsp = NULL;
|
||||||
|
|
|
@ -604,22 +604,19 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndDropTopic(SMnode *pMnode, STrans *pTrans, SRpcMsg *pReq, SMqTopicObj *pTopic) {
|
static int32_t mndDropTopic(SMnode *pMnode, STrans *pTrans, SRpcMsg *pReq, SMqTopicObj *pTopic) {
|
||||||
|
int32_t code = -1;
|
||||||
|
if (mndUserRemoveTopic(pMnode, pTrans, pTopic->name) != 0) goto _OVER;
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic);
|
SSdbRaw *pCommitRaw = mndTopicActionEncode(pTopic);
|
||||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) goto _OVER;
|
||||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
|
||||||
mndTransDrop(pTrans);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
code = 0;
|
||||||
mndTransDrop(pTrans);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
_OVER:
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) {
|
||||||
|
@ -890,6 +887,7 @@ int32_t mndCheckTopicExist(SMnode *pMnode, SDbObj *pDb) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
@ -917,3 +915,4 @@ int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -285,14 +285,35 @@ static int32_t mndUserActionInsert(SSdb *pSdb, SUserObj *pUser) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
|
||||||
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
memcpy(pNew, pUser, sizeof(SUserObj));
|
||||||
|
pNew->authVersion++;
|
||||||
|
pNew->updateTime = taosGetTimestampMs();
|
||||||
|
|
||||||
|
taosRLockLatch(&pUser->lock);
|
||||||
|
pNew->readDbs = mndDupDbHash(pUser->readDbs);
|
||||||
|
pNew->writeDbs = mndDupDbHash(pUser->writeDbs);
|
||||||
|
pNew->topics = mndDupTopicHash(pUser->topics);
|
||||||
|
taosRUnLockLatch(&pUser->lock);
|
||||||
|
|
||||||
|
if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void mndUserFreeObj(SUserObj *pUser) {
|
||||||
taosHashCleanup(pUser->readDbs);
|
taosHashCleanup(pUser->readDbs);
|
||||||
taosHashCleanup(pUser->writeDbs);
|
taosHashCleanup(pUser->writeDbs);
|
||||||
taosHashCleanup(pUser->topics);
|
taosHashCleanup(pUser->topics);
|
||||||
pUser->readDbs = NULL;
|
pUser->readDbs = NULL;
|
||||||
pUser->writeDbs = NULL;
|
pUser->writeDbs = NULL;
|
||||||
pUser->topics = NULL;
|
pUser->topics = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndUserActionDelete(SSdb *pSdb, SUserObj *pUser) {
|
||||||
|
mTrace("user:%s, perform delete action, row:%p", pUser->user, pUser);
|
||||||
|
mndUserFreeObj(pUser);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,19 +537,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
if (mndUserDupObj(pUser, &newUser) != 0) goto _OVER;
|
||||||
newUser.authVersion++;
|
|
||||||
newUser.updateTime = taosGetTimestampMs();
|
|
||||||
|
|
||||||
taosRLockLatch(&pUser->lock);
|
|
||||||
newUser.readDbs = mndDupDbHash(pUser->readDbs);
|
|
||||||
newUser.writeDbs = mndDupDbHash(pUser->writeDbs);
|
|
||||||
newUser.topics = mndDupTopicHash(pUser->topics);
|
|
||||||
taosRUnLockLatch(&pUser->lock);
|
|
||||||
|
|
||||||
if (newUser.readDbs == NULL || newUser.writeDbs == NULL || newUser.topics == NULL) {
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
||||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||||
|
@ -654,9 +663,7 @@ _OVER:
|
||||||
|
|
||||||
mndReleaseUser(pMnode, pOperUser);
|
mndReleaseUser(pMnode, pOperUser);
|
||||||
mndReleaseUser(pMnode, pUser);
|
mndReleaseUser(pMnode, pUser);
|
||||||
taosHashCleanup(newUser.writeDbs);
|
mndUserFreeObj(&newUser);
|
||||||
taosHashCleanup(newUser.readDbs);
|
|
||||||
taosHashCleanup(newUser.topics);
|
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1007,3 +1014,74 @@ _OVER:
|
||||||
tFreeSUserAuthBatchRsp(&batchRsp);
|
tFreeSUserAuthBatchRsp(&batchRsp);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t len = strlen(db) + 1;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
SUserObj newUser = {0};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
code = -1;
|
||||||
|
if (mndUserDupObj(pUser, &newUser) != 0) break;
|
||||||
|
|
||||||
|
bool inRead = (taosHashGet(newUser.readDbs, db, len) != NULL);
|
||||||
|
bool inWrite = (taosHashGet(newUser.writeDbs, db, len) != NULL);
|
||||||
|
if (inRead || inWrite) {
|
||||||
|
(void)taosHashRemove(newUser.readDbs, db, len);
|
||||||
|
(void)taosHashRemove(newUser.writeDbs, db, len);
|
||||||
|
|
||||||
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) break;
|
||||||
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pUser != NULL) sdbRelease(pSdb, pUser);
|
||||||
|
if (pIter != NULL) sdbCancelFetch(pSdb, pIter);
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic) {
|
||||||
|
int32_t code = 0;
|
||||||
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
|
int32_t len = strlen(topic) + 1;
|
||||||
|
void *pIter = NULL;
|
||||||
|
SUserObj *pUser = NULL;
|
||||||
|
SUserObj newUser = {0};
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser);
|
||||||
|
if (pIter == NULL) break;
|
||||||
|
|
||||||
|
code = -1;
|
||||||
|
if (mndUserDupObj(pUser, &newUser) != 0) break;
|
||||||
|
|
||||||
|
bool inTopic = (taosHashGet(newUser.topics, topic, len) != NULL);
|
||||||
|
if (inTopic) {
|
||||||
|
(void)taosHashRemove(newUser.topics, topic, len);
|
||||||
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
|
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) break;
|
||||||
|
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
}
|
||||||
|
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
code = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pUser != NULL) sdbRelease(pSdb, pUser);
|
||||||
|
if (pIter != NULL) sdbCancelFetch(pSdb, pIter);
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue