From 65913f6ad95c045e41f0cb9186d69ae90c41cd60 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 20 Dec 2022 17:14:10 +0800 Subject: [PATCH] enh: support auth read or write --- include/libs/catalog/catalog.h | 1 + source/libs/catalog/inc/catalogInt.h | 3 +++ source/libs/catalog/src/catalog.c | 4 ++-- source/libs/catalog/src/ctgAsync.c | 4 ++-- source/libs/catalog/src/ctgCache.c | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index a95db86d3f..0e2d043174 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -44,6 +44,7 @@ typedef enum { AUTH_TYPE_READ = 1, AUTH_TYPE_WRITE, AUTH_TYPE_OTHER, + AUTH_TYPE_READ_OR_WRITE, } AUTH_TYPE; typedef struct SUserAuthInfo { diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 6e072a9630..a6ce613882 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -485,6 +485,9 @@ typedef struct SCtgOperation { ctgOpFunc func; } SCtgOperation; +#define CTG_AUTH_READ(_t) ((_t) == AUTH_TYPE_READ || (_t) == AUTH_TYPE_READ_OR_WRITE) +#define CTG_AUTH_WRITE(_t) ((_t) == AUTH_TYPE_WRITE || (_t) == AUTH_TYPE_READ_OR_WRITE) + #define CTG_QUEUE_INC() atomic_add_fetch_64(&gCtgMgmt.queue.qRemainNum, 1) #define CTG_QUEUE_DEC() atomic_sub_fetch_64(&gCtgMgmt.queue.qRemainNum, 1) diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index e9e0bae8d7..acd0fb9d8c 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -352,9 +352,9 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, co goto _return; } - if (type == AUTH_TYPE_READ && authRsp.readDbs && taosHashGet(authRsp.readDbs, dbFName, strlen(dbFName))) { + if (CTG_AUTH_READ(type) && authRsp.readDbs && taosHashGet(authRsp.readDbs, dbFName, strlen(dbFName))) { *pass = true; - } else if (type == AUTH_TYPE_WRITE && authRsp.writeDbs && taosHashGet(authRsp.writeDbs, dbFName, strlen(dbFName))) { + } else if (CTG_AUTH_WRITE(type) && authRsp.writeDbs && taosHashGet(authRsp.writeDbs, dbFName, strlen(dbFName))) { *pass = true; } diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 5b01ac1fb9..acd18fcca5 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -1549,10 +1549,10 @@ int32_t ctgHandleGetUserRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* goto _return; } - if (ctx->user.type == AUTH_TYPE_READ && pOut->readDbs && + if (CTG_AUTH_READ(ctx->user.type) && pOut->readDbs && taosHashGet(pOut->readDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) { pass = true; - } else if (ctx->user.type == AUTH_TYPE_WRITE && pOut->writeDbs && + } else if (CTG_AUTH_WRITE(ctx->user.type) && pOut->writeDbs && taosHashGet(pOut->writeDbs, ctx->user.dbFName, strlen(ctx->user.dbFName))) { pass = true; } diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 94ee295fe4..fe83854a91 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -718,11 +718,11 @@ int32_t ctgChkAuthFromCache(SCatalog *pCtg, char *user, char *dbFName, AUTH_TYPE return TSDB_CODE_SUCCESS; } - if (pUser->readDbs && taosHashGet(pUser->readDbs, dbFName, strlen(dbFName)) && type == AUTH_TYPE_READ) { + if (pUser->readDbs && taosHashGet(pUser->readDbs, dbFName, strlen(dbFName)) && CTG_AUTH_READ(type)) { *pass = true; } - if (pUser->writeDbs && taosHashGet(pUser->writeDbs, dbFName, strlen(dbFName)) && type == AUTH_TYPE_WRITE) { + if (pUser->writeDbs && taosHashGet(pUser->writeDbs, dbFName, strlen(dbFName)) && CTG_AUTH_WRITE(type)) { *pass = true; } -- GitLab