Skip to content

Commit

Permalink
Merge pull request #20859 from taosdata/feat/table_level_privilege_wxy
Browse files Browse the repository at this point in the history
fix: table level privilege
  • Loading branch information
xiao-yu-wang committed Apr 11, 2023
2 parents afbc468 + 42a5a87 commit 245e00d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
31 changes: 28 additions & 3 deletions source/dnode/mnode/impl/src/mndUser.c
Expand Up @@ -156,7 +156,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
size_t valueLen = 0;
valueLen = strlen(stb);
size += sizeof(int32_t);
size += keyLen;
size += valueLen;
stb = taosHashIterate(pUser->writeTbs, stb);
}

Expand Down Expand Up @@ -369,7 +369,7 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int32_t valuelen = 0;
SDB_GET_INT32(pRaw, dataPos, &valuelen, _OVER);
char *value = taosMemoryCalloc(valuelen, sizeof(char));
memset(value, 0, keyLen);
memset(value, 0, valuelen);
SDB_GET_BINARY(pRaw, dataPos, value, valuelen, _OVER)

taosHashPut(pUser->writeTbs, key, keyLen, value, valuelen);
Expand Down Expand Up @@ -458,6 +458,31 @@ SHashObj *mndDupTableHash(SHashObj *pOld) {
return pNew;
}

SHashObj *mndDupUseDbHash(SHashObj *pOld) {
SHashObj *pNew =
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pNew == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}

int32_t *db = taosHashIterate(pOld, NULL);
while (db != NULL) {
size_t keyLen = 0;
char *key = taosHashGetKey(db, &keyLen);

if (taosHashPut(pNew, key, keyLen, db, sizeof(*db)) != 0) {
taosHashCancelIterate(pOld, db);
taosHashCleanup(pNew);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
db = taosHashIterate(pOld, db);
}

return pNew;
}

static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
memcpy(pNew, pUser, sizeof(SUserObj));
pNew->authVersion++;
Expand All @@ -469,7 +494,7 @@ static int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew) {
pNew->readTbs = mndDupTableHash(pUser->readTbs);
pNew->writeTbs = mndDupTableHash(pUser->writeTbs);
pNew->topics = mndDupTopicHash(pUser->topics);
pNew->useDbs = mndDupDbHash(pUser->useDbs);
pNew->useDbs = mndDupUseDbHash(pUser->useDbs);
taosRUnLockLatch(&pUser->lock);

if (pNew->readDbs == NULL || pNew->writeDbs == NULL || pNew->topics == NULL) {
Expand Down
3 changes: 2 additions & 1 deletion source/libs/catalog/src/ctgUtil.c
Expand Up @@ -1457,7 +1457,8 @@ int32_t ctgChkSetAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res) {
}
case AUTH_TYPE_READ_OR_WRITE: {
if ((pInfo->readDbs && taosHashGet(pInfo->readDbs, dbFName, strlen(dbFName))) ||
(pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName)))) {
(pInfo->writeDbs && taosHashGet(pInfo->writeDbs, dbFName, strlen(dbFName))) ||
(pInfo->useDbs && taosHashGet(pInfo->useDbs, dbFName, strlen(dbFName)))) {
pRes->pass = true;
return TSDB_CODE_SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion source/libs/parser/src/parInsertSql.c
Expand Up @@ -2022,7 +2022,7 @@ static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray**

SUserAuthInfo userAuth = {.type = AUTH_TYPE_WRITE};
snprintf(userAuth.user, sizeof(userAuth.user), "%s", pUser);
// tNameGetFullDbName(pName, userAuth.dbFName);
memcpy(&userAuth.tbName, pName, sizeof(SName));
taosArrayPush(*pUserAuth, &userAuth);

return TSDB_CODE_SUCCESS;
Expand Down

0 comments on commit 245e00d

Please sign in to comment.