diff --git a/include/client/taos.h b/include/client/taos.h index dac8e61542..6492827b2b 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -125,7 +125,8 @@ typedef enum { typedef enum { TAOS_NOTIFY_PASSVER = 0, - TAOS_NOTIFY_WHITELIST_VER = 1 + TAOS_NOTIFY_WHITELIST_VER = 1, + TAOS_NOTIFY_USER_DROPPED = 2, } TAOS_NOTIFY_TYPE; #define RET_MSG_LENGTH 1024 diff --git a/include/common/tmsg.h b/include/common/tmsg.h index a0af96853e..af44184de6 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -959,7 +959,7 @@ typedef struct { int8_t superAuth; int8_t sysInfo; int8_t enable; - int8_t reserve; + int8_t dropped; SHashObj* createdDbs; SHashObj* readDbs; SHashObj* writeDbs; diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 9448634c5b..bde98052af 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -133,11 +133,13 @@ typedef struct { int32_t ver; void* param; __taos_notify_fn_t fp; -} SPassInfo; +} STscNotifyInfo; + +typedef STscNotifyInfo SPassInfo; typedef struct { - int64_t ver; - void* param; + int64_t ver; + void* param; __taos_notify_fn_t fp; } SWhiteListInfo; @@ -159,6 +161,7 @@ typedef struct STscObj { SHashObj* pRequests; SPassInfo passInfo; SWhiteListInfo whiteListInfo; + STscNotifyInfo userDroppedInfo; } STscObj; typedef struct STscDbg { diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index e64f0d779c..a4fa1e0c41 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -96,6 +96,19 @@ static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *bat } } + if (pRsp->dropped == 1) { + if (pTscObj->userDroppedInfo.fp) { + SPassInfo *dropInfo = &pTscObj->userDroppedInfo; + if (dropInfo->fp) { + (*dropInfo->fp)(dropInfo->param, NULL, TAOS_NOTIFY_USER_DROPPED); + } + } + releaseTscObj(pReq->connKey.tscRid); + // delete the tscObj + releaseTscObj(pReq->connKey.tscRid); + continue; + } + pTscObj->authVer = pRsp->version; if (pTscObj->sysInfo != pRsp->sysInfo) { diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 7902d6029e..293349e2b3 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -147,6 +147,13 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type) taosThreadMutexUnlock(&pObj->mutex); break; } + case TAOS_NOTIFY_USER_DROPPED: { + taosThreadMutexLock(&pObj->mutex); + pObj->userDroppedInfo.fp = fp; + pObj->userDroppedInfo.param = param; + taosThreadMutexUnlock(&pObj->mutex); + break; + } default: { terrno = TSDB_CODE_INVALID_PARA; releaseTscObj(*(int64_t *)taos); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index b4ce55b71d..fd39ae98d9 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1652,7 +1652,7 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp) if (tEncodeI8(pEncoder, pRsp->superAuth) < 0) return -1; if (tEncodeI8(pEncoder, pRsp->sysInfo) < 0) return -1; if (tEncodeI8(pEncoder, pRsp->enable) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->reserve) < 0) return -1; + if (tEncodeI8(pEncoder, pRsp->dropped) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->version) < 0) return -1; int32_t numOfCreatedDbs = taosHashGetSize(pRsp->createdDbs); @@ -1767,7 +1767,7 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs if (tDecodeI8(pDecoder, &pRsp->superAuth) < 0) goto _err; if (tDecodeI8(pDecoder, &pRsp->sysInfo) < 0) goto _err; if (tDecodeI8(pDecoder, &pRsp->enable) < 0) goto _err; - if (tDecodeI8(pDecoder, &pRsp->reserve) < 0) goto _err; + if (tDecodeI8(pDecoder, &pRsp->dropped) < 0) goto _err; if (tDecodeI32(pDecoder, &pRsp->version) < 0) goto _err; int32_t numOfCreatedDbs = 0; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index a82623ae1b..138820a3b8 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -2289,6 +2289,11 @@ int32_t mndValidateUserAuthInfo(SMnode *pMnode, SUserAuthVersion *pUsers, int32_ for (int32_t i = 0; i < numOfUses; ++i) { SUserObj *pUser = mndAcquireUser(pMnode, pUsers[i].user); if (pUser == NULL) { + if (TSDB_CODE_MND_USER_NOT_EXIST == terrno) { + SGetUserAuthRsp rsp = {.dropped = 1}; + memcpy(rsp.user, pUsers[i].user, TSDB_USER_LEN); + taosArrayPush(batchRsp.pArray, &rsp); + } mError("user:%s, failed to auth user since %s", pUsers[i].user, terrstr()); continue; } diff --git a/tests/script/api/passwdTest.c b/tests/script/api/passwdTest.c index 06d2d3455f..4439c93790 100644 --- a/tests/script/api/passwdTest.c +++ b/tests/script/api/passwdTest.c @@ -47,8 +47,10 @@ typedef uint16_t VarDataLenT; void createUsers(TAOS *taos, const char *host, char *qstr); void passVerTestMulti(const char *host, char *qstr); void sysInfoTest(TAOS *taos, const char *host, char *qstr); +void userDroppedTest(TAOS *taos, const char *host, char *qstr); int nPassVerNotified = 0; +int nUserDropped = 0; TAOS *taosu[nRoot] = {0}; char users[nUser][USER_LEN] = {0}; @@ -56,11 +58,16 @@ void __taos_notify_cb(void *param, void *ext, int type) { switch (type) { case TAOS_NOTIFY_PASSVER: { ++nPassVerNotified; - printf("%s:%d type:%d user:%s ver:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext); + printf("%s:%d type:%d user:%s passVer:%d\n", __func__, __LINE__, type, param ? (char *)param : "NULL", *(int *)ext); + break; + } + case TAOS_NOTIFY_USER_DROPPED: { + ++nUserDropped; + printf("%s:%d type:%d user:%s dropped\n", __func__, __LINE__, type, param ? (char *)param : "NULL"); break; } default: - printf("%s:%d unknown type:%d\n", __func__, __LINE__, type); + printf("%s:%d unknown notify type:%d\n", __func__, __LINE__, type); break; } } @@ -201,7 +208,8 @@ int main(int argc, char *argv[]) { } createUsers(taos, argv[1], qstr); passVerTestMulti(argv[1], qstr); - sysInfoTest(taos, argv[1], qstr); + // sysInfoTest(taos, argv[1], qstr); + userDroppedTest(taos, argv[1], qstr); taos_close(taos); taos_cleanup(); @@ -223,9 +231,16 @@ void createUsers(TAOS *taos, const char *host, char *qstr) { int code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_PASSVER); if (code != 0) { - fprintf(stderr, "failed to run: taos_set_notify_cb for user:%s since %d\n", users[i], code); + fprintf(stderr, "failed to run: taos_set_notify_cb(TAOS_NOTIFY_PASSVER) for user:%s since %d\n", users[i], code); } else { - fprintf(stderr, "success to run: taos_set_notify_cb for user:%s\n", users[i]); + fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_PASSVER) for user:%s\n", users[i]); + } + + code = taos_set_notify_cb(taosu[i], __taos_notify_cb, users[i], TAOS_NOTIFY_USER_DROPPED); + if (code != 0) { + fprintf(stderr, "failed to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s since %d\n", users[i], code); + } else { + fprintf(stderr, "success to run: taos_set_notify_cb(TAOS_NOTIFY_USER_DROPPED) for user:%s\n", users[i]); } // alter pass for users @@ -301,6 +316,7 @@ void passVerTestMulti(const char *host, char *qstr) { } void sysInfoTest(TAOS *taosRoot, const char *host, char *qstr) { + fprintf(stderr, "######## %s entry #########\n", __func__); TAOS *taos[nRoot] = {0}; char userName[USER_LEN] = "user0"; @@ -376,4 +392,48 @@ _REP: fprintf(stderr, "######## %s #########\n", __func__); fprintf(stderr, ">>> succeed to run sysInfoTest\n"); fprintf(stderr, "######## %s #########\n", __func__); +} + +void userDroppedTest(TAOS *taos, const char *host, char *qstr) { + // users + int nTestUsers = 1; // nUser + for (int i = 0; i < nTestUsers; ++i) { + // sprintf(users[i], "user%d", i); + taosu[i] = taos_connect(host, users[i], "taos", NULL, 0); + if (taosu[i] == NULL) { + printf("failed to connect to server, user:%s, reason:%s\n", users[i], "null taos" /*taos_errstr(taos)*/); + exit(1); + } + } + + for (int i = 0; i < nTestUsers; ++i) { + // drop user0 ... user${nUser} + sprintf(qstr, "drop user %s", users[i]); + queryDB(taos, qstr); + } + + // calculate the nUserDropped for users + int nConn = nTestUsers; + + for (int i = 0; i < 15; ++i) { + printf("%s:%d [%d] second(s) elasped, passVer notification received:%d, total:%d\n", __func__, __LINE__, i, + nUserDropped, nConn); + if (nUserDropped >= nConn) break; + sleep(1); + } + + for (int i = 0; i < nTestUsers; ++i) { + taos_close(taosu[i]); + printf("%s:%d close taosu[%d]\n", __func__, __LINE__, i); + sleep(1); + } + + fprintf(stderr, "######## %s #########\n", __func__); + if (nUserDropped >= nConn) { + fprintf(stderr, ">>> succeed to get user dropped notification since nNotify %d >= nConn %d\n", nUserDropped, nConn); + } else { + fprintf(stderr, ">>> failed to get user dropped notification since nNotify %d < nConn %d\n", nUserDropped, nConn); + } + fprintf(stderr, "######## %s #########\n", __func__); + sleep(300); } \ No newline at end of file