Merge pull request #20804 from taosdata/feat/table_level_privilege_wxy
feat: table level privilege
This commit is contained in:
commit
d96f9c7f40
|
@ -9,7 +9,7 @@ IF(NOT TD_DARWIN)
|
|||
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
catalogTest
|
||||
PUBLIC os util common catalog transport gtest qcom taos_static
|
||||
PUBLIC os util common nodes catalog transport gtest qcom taos_static
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -923,7 +923,13 @@ void nodesDestroyNode(SNode* pNode) {
|
|||
taosMemoryFree(((SDescribeStmt*)pNode)->pMeta);
|
||||
break;
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT: // no pointer field
|
||||
case QUERY_NODE_COMPACT_DATABASE_STMT: // no pointer field
|
||||
break;
|
||||
case QUERY_NODE_COMPACT_DATABASE_STMT: {
|
||||
SCompactDatabaseStmt* pStmt = (SCompactDatabaseStmt*)pNode;
|
||||
nodesDestroyNode(pStmt->pStart);
|
||||
nodesDestroyNode(pStmt->pEnd);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_CREATE_FUNCTION_STMT: // no pointer field
|
||||
case QUERY_NODE_DROP_FUNCTION_STMT: // no pointer field
|
||||
break;
|
||||
|
|
|
@ -97,9 +97,8 @@ int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* p
|
|||
int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type,
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
|
||||
|
@ -110,8 +109,7 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName,
|
|||
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
|
||||
int32_t* pTableNum, int64_t* pStateTs);
|
||||
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
|
||||
bool* pPass);
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes);
|
||||
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo);
|
||||
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes);
|
||||
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput);
|
||||
|
|
|
@ -154,7 +154,8 @@ static int32_t collectMetaKeyFromRealTableImpl(SCollectMetaKeyCxt* pCxt, const c
|
|||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pDb, pTable, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, authType, pCxt->pMetaCache);
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pDb, pTable, authType,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pDb, pCxt->pMetaCache);
|
||||
|
@ -247,7 +248,7 @@ static int32_t collectMetaKeyFromCreateTable(SCollectMetaKeyCxt* pCxt, SCreateTa
|
|||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, AUTH_TYPE_WRITE,
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_WRITE,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
|
@ -267,8 +268,8 @@ static int32_t collectMetaKeyFromCreateMultiTable(SCollectMetaKeyCxt* pCxt, SCre
|
|||
code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, AUTH_TYPE_WRITE,
|
||||
pCxt->pMetaCache);
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, NULL,
|
||||
AUTH_TYPE_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
|
@ -439,8 +440,9 @@ static int32_t collectMetaKeyFromShowStables(SCollectMetaKeyCxt* pCxt, SShowStmt
|
|||
int32_t code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, TSDB_INFORMATION_SCHEMA_DB, TSDB_INS_TABLE_STABLES,
|
||||
pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
|
||||
((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||
code =
|
||||
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -457,8 +459,9 @@ static int32_t collectMetaKeyFromShowTables(SCollectMetaKeyCxt* pCxt, SShowStmt*
|
|||
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, ((SValueNode*)pStmt->pDbName)->literal, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser,
|
||||
((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||
code =
|
||||
reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, ((SValueNode*)pStmt->pDbName)->literal,
|
||||
NULL, AUTH_TYPE_READ_OR_WRITE, pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -561,7 +564,8 @@ static int32_t collectMetaKeyFromShowCreateTable(SCollectMetaKeyCxt* pCxt, SShow
|
|||
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pCxt->pMetaCache);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = reserveUserAuthInCacheExt(pCxt->pParseCxt->pUser, &name, AUTH_TYPE_READ, pCxt->pMetaCache);
|
||||
code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, NULL, AUTH_TYPE_READ,
|
||||
pCxt->pMetaCache);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -30,31 +30,40 @@ typedef struct SSelectAuthCxt {
|
|||
|
||||
static int32_t authQuery(SAuthCxt* pCxt, SNode* pStmt);
|
||||
|
||||
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, AUTH_TYPE type) {
|
||||
static void setUserAuthInfo(SParseContext* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type,
|
||||
SUserAuthInfo* pAuth) {
|
||||
snprintf(pAuth->user, sizeof(pAuth->user), "%s", pCxt->pUser);
|
||||
if (NULL == pTabName) {
|
||||
tNameSetDbName(&pAuth->tbName, pCxt->acctId, pDbName, strlen(pDbName));
|
||||
} else {
|
||||
toName(pCxt->acctId, pDbName, pTabName, &pAuth->tbName);
|
||||
}
|
||||
pAuth->type = type;
|
||||
}
|
||||
|
||||
static int32_t checkAuth(SAuthCxt* pCxt, const char* pDbName, const char* pTabName, AUTH_TYPE type, SNode** pCond) {
|
||||
SParseContext* pParseCxt = pCxt->pParseCxt;
|
||||
if (pParseCxt->isSuperUser) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SName name;
|
||||
tNameSetDbName(&name, pParseCxt->acctId, pDbName, strlen(pDbName));
|
||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFname);
|
||||
|
||||
SUserAuthInfo authInfo = {0};
|
||||
setUserAuthInfo(pCxt->pParseCxt, pDbName, pTabName, type, &authInfo);
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
bool pass = false;
|
||||
SUserAuthRes authRes = {0};
|
||||
if (NULL != pCxt->pMetaCache) {
|
||||
code = getUserAuthFromCache(pCxt->pMetaCache, pParseCxt->pUser, dbFname, type, &pass);
|
||||
code = getUserAuthFromCache(pCxt->pMetaCache, &authInfo, &authRes);
|
||||
} else {
|
||||
SRequestConnInfo conn = {.pTrans = pParseCxt->pTransporter,
|
||||
.requestId = pParseCxt->requestId,
|
||||
.requestObjRefId = pParseCxt->requestRid,
|
||||
.mgmtEps = pParseCxt->mgmtEpSet};
|
||||
|
||||
SUserAuthInfo authInfo = {0};
|
||||
SUserAuthRes authRes = {0};
|
||||
//code = catalogChkAuth(pParseCxt->pCatalog, &conn, pParseCxt->pUser, dbFname, type, &pass);
|
||||
code = catalogChkAuth(pParseCxt->pCatalog, &conn, &authInfo, &authRes);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == code ? (pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCond) {
|
||||
*pCond = authRes.pCond;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == code ? (authRes.pass ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED) : code;
|
||||
}
|
||||
|
||||
static EDealRes authSubquery(SAuthCxt* pCxt, SNode* pStmt) {
|
||||
|
@ -81,30 +90,35 @@ static int32_t mergeStableTagCond(SNode** pWhere, SNode** pTagCond) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t appendStableTagCond(SSelectStmt* pSelect, SNode* pTagCond) {
|
||||
static int32_t appendStableTagCond(SNode** pWhere, SNode* pTagCond) {
|
||||
SNode* pTagCondCopy = nodesCloneNode(pTagCond);
|
||||
if (NULL == pTagCondCopy) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NULL == pSelect->pWhere) {
|
||||
pSelect->pWhere = pTagCondCopy;
|
||||
if (NULL == *pWhere) {
|
||||
*pWhere = pTagCondCopy;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(pSelect->pWhere) &&
|
||||
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)pSelect->pWhere)->condType) {
|
||||
return nodesListStrictAppend(((SLogicConditionNode*)pSelect->pWhere)->pParameterList, pTagCondCopy);
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pWhere) &&
|
||||
LOGIC_COND_TYPE_AND == ((SLogicConditionNode*)*pWhere)->condType) {
|
||||
return nodesListStrictAppend(((SLogicConditionNode*)*pWhere)->pParameterList, pTagCondCopy);
|
||||
}
|
||||
|
||||
return mergeStableTagCond(&pSelect->pWhere, &pTagCondCopy);
|
||||
return mergeStableTagCond(pWhere, &pTagCondCopy);
|
||||
}
|
||||
|
||||
static EDealRes authSelectImpl(SNode* pNode, void* pContext) {
|
||||
SSelectAuthCxt* pCxt = pContext;
|
||||
SAuthCxt* pAuthCxt = pCxt->pAuthCxt;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pNode)) {
|
||||
pAuthCxt->errCode = checkAuth(pAuthCxt, ((SRealTableNode*)pNode)->table.dbName, AUTH_TYPE_READ);
|
||||
SNode* pTagCond = NULL;
|
||||
STableNode* pTable = (STableNode*)pNode;
|
||||
pAuthCxt->errCode = checkAuth(pAuthCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_READ, &pTagCond);
|
||||
if (TSDB_CODE_SUCCESS == pAuthCxt->errCode && NULL != pTagCond) {
|
||||
pAuthCxt->errCode = appendStableTagCond(&pCxt->pSelect->pWhere, pTagCond);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pAuthCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
} else if (QUERY_NODE_TEMP_TABLE == nodeType(pNode)) {
|
||||
return authSubquery(pAuthCxt, ((STempTableNode*)pNode)->pSubquery);
|
||||
|
@ -134,11 +148,20 @@ static int32_t authDropUser(SAuthCxt* pCxt, SDropUserStmt* pStmt) {
|
|||
}
|
||||
|
||||
static int32_t authDelete(SAuthCxt* pCxt, SDeleteStmt* pDelete) {
|
||||
return checkAuth(pCxt, ((SRealTableNode*)pDelete->pFromTable)->table.dbName, AUTH_TYPE_WRITE);
|
||||
SNode* pTagCond = NULL;
|
||||
STableNode* pTable = (STableNode*)pDelete->pFromTable;
|
||||
int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pTagCond) {
|
||||
code = appendStableTagCond(&pDelete->pWhere, pTagCond);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
|
||||
int32_t code = checkAuth(pCxt, ((SRealTableNode*)pInsert->pTable)->table.dbName, AUTH_TYPE_WRITE);
|
||||
SNode* pTagCond = NULL;
|
||||
STableNode* pTable = (STableNode*)pInsert->pTable;
|
||||
// todo check tag condition for subtable
|
||||
int32_t code = checkAuth(pCxt, pTable->dbName, pTable->tableName, AUTH_TYPE_WRITE, &pTagCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = authQuery(pCxt, pInsert->pQuery);
|
||||
}
|
||||
|
@ -146,22 +169,27 @@ static int32_t authInsert(SAuthCxt* pCxt, SInsertStmt* pInsert) {
|
|||
}
|
||||
|
||||
static int32_t authShowTables(SAuthCxt* pCxt, SShowStmt* pStmt) {
|
||||
return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, AUTH_TYPE_READ_OR_WRITE);
|
||||
return checkAuth(pCxt, ((SValueNode*)pStmt->pDbName)->literal, NULL, AUTH_TYPE_READ_OR_WRITE, NULL);
|
||||
}
|
||||
|
||||
static int32_t authShowCreateTable(SAuthCxt* pCxt, SShowCreateTableStmt* pStmt) {
|
||||
return checkAuth(pCxt, pStmt->dbName, AUTH_TYPE_READ);
|
||||
SNode* pTagCond = NULL;
|
||||
// todo check tag condition for subtable
|
||||
return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_READ, &pTagCond);
|
||||
}
|
||||
|
||||
static int32_t authCreateTable(SAuthCxt* pCxt, SCreateTableStmt* pStmt) {
|
||||
return checkAuth(pCxt, pStmt->dbName, AUTH_TYPE_WRITE);
|
||||
SNode* pTagCond = NULL;
|
||||
// todo check tag condition for subtable
|
||||
return checkAuth(pCxt, pStmt->dbName, NULL, AUTH_TYPE_WRITE, &pTagCond);
|
||||
}
|
||||
|
||||
static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStmt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pStmt->pSubTables) {
|
||||
code = checkAuth(pCxt, ((SCreateSubTableClause*)pNode)->dbName, AUTH_TYPE_WRITE);
|
||||
SCreateSubTableClause* pClause = (SCreateSubTableClause*)pNode;
|
||||
code = checkAuth(pCxt, pClause->dbName, NULL, AUTH_TYPE_WRITE, NULL);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "cJSON.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_DB_FNAME_LEN + 2
|
||||
#define USER_AUTH_KEY_MAX_LEN TSDB_USER_LEN + TSDB_TABLE_FNAME_LEN + 2
|
||||
|
||||
const void* nullPointer = NULL;
|
||||
|
||||
|
@ -496,24 +496,44 @@ int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type, char* pStr) {
|
||||
return sprintf(pStr, "%s*%d.%s*%d", pUser, acctId, pDb, type);
|
||||
static int32_t userAuthToString(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
char* pStr) {
|
||||
return sprintf(pStr, "%s*%d*%s*%s*%d", pUser, acctId, pDb, (NULL != pTable && '\0' == pTable[0]) ? NULL : pTable,
|
||||
type);
|
||||
}
|
||||
|
||||
static int32_t userAuthToStringExt(const char* pUser, const char* pDbFName, AUTH_TYPE type, char* pStr) {
|
||||
return sprintf(pStr, "%s*%s*%d", pUser, pDbFName, type);
|
||||
static int32_t getIntegerFromAuthStr(const char* pStart, char** pNext) {
|
||||
char* p = strchr(pStart, '*');
|
||||
char buf[10] = {0};
|
||||
if (NULL == p) {
|
||||
strcpy(buf, pStart);
|
||||
*pNext = NULL;
|
||||
} else {
|
||||
strncpy(buf, pStart, p - pStart);
|
||||
*pNext = ++p;
|
||||
}
|
||||
return taosStr2Int32(buf, NULL, 10);
|
||||
}
|
||||
|
||||
static void getStringFromAuthStr(const char* pStart, char* pStr, char** pNext) {
|
||||
char* p = strchr(pStart, '*');
|
||||
if (NULL == p) {
|
||||
strcpy(pStr, pStart);
|
||||
*pNext = NULL;
|
||||
} else {
|
||||
strncpy(pStr, pStart, p - pStart);
|
||||
*pNext = ++p;
|
||||
}
|
||||
}
|
||||
|
||||
static void stringToUserAuth(const char* pStr, int32_t len, SUserAuthInfo* pUserAuth) {
|
||||
char* p1 = strchr(pStr, '*');
|
||||
strncpy(pUserAuth->user, pStr, p1 - pStr);
|
||||
++p1;
|
||||
char* p2 = strchr(p1, '*');
|
||||
//strncpy(pUserAuth->dbFName, p1, p2 - p1);
|
||||
++p2;
|
||||
char buf[10] = {0};
|
||||
strncpy(buf, p2, len - (p2 - pStr));
|
||||
pUserAuth->type = taosStr2Int32(buf, NULL, 10);
|
||||
char* p = NULL;
|
||||
getStringFromAuthStr(pStr, pUserAuth->user, &p);
|
||||
pUserAuth->tbName.acctId = getIntegerFromAuthStr(p, &p);
|
||||
getStringFromAuthStr(p, pUserAuth->tbName.dbname, &p);
|
||||
getStringFromAuthStr(p, pUserAuth->tbName.tname, &p);
|
||||
pUserAuth->tbName.type = TSDB_TABLE_NAME_T;
|
||||
pUserAuth->type = getIntegerFromAuthStr(p, &p);
|
||||
}
|
||||
|
||||
static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) {
|
||||
|
@ -586,8 +606,10 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) {
|
|||
while (NULL != p) {
|
||||
size_t len = 0;
|
||||
char* pKey = taosHashGetKey(p, &len);
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
strncpy(key, pKey, len);
|
||||
SUserAuthInfo userAuth = {0};
|
||||
stringToUserAuth(pKey, len, &userAuth);
|
||||
stringToUserAuth(key, len, &userAuth);
|
||||
taosArrayPush(*pUserAuth, &userAuth);
|
||||
p = taosHashIterate(pUserAuthHash, p);
|
||||
}
|
||||
|
@ -712,8 +734,8 @@ static int32_t putUserAuthToCache(const SArray* pUserAuthReq, const SArray* pUse
|
|||
for (int32_t i = 0; i < nvgs; ++i) {
|
||||
SUserAuthInfo* pUser = taosArrayGet(pUserAuthReq, i);
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
//int32_t len = userAuthToStringExt(pUser->user, pUser->dbFName, pUser->type, key);
|
||||
int32_t len = 0;
|
||||
int32_t len = userAuthToString(pUser->tbName.acctId, pUser->user, pUser->tbName.dbname, pUser->tbName.tname,
|
||||
pUser->type, key);
|
||||
if (TSDB_CODE_SUCCESS != putMetaDataToHash(key, len, pUserAuthData, i, pUserAuth)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -911,33 +933,24 @@ static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseM
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
bool pass = false;
|
||||
return taosHashPut(pMetaCache->pUserAuth, pKey, len, &pass, sizeof(pass));
|
||||
return taosHashPut(pMetaCache->pUserAuth, pKey, len, &nullPointer, POINTER_BYTES);
|
||||
}
|
||||
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type,
|
||||
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type,
|
||||
SParseMetaCache* pMetaCache) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToString(acctId, pUser, pDb, type, key);
|
||||
int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key);
|
||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
||||
}
|
||||
|
||||
int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(pName, dbFName);
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToStringExt(pUser, dbFName, type, key);
|
||||
return reserveUserAuthInCacheImpl(key, len, pMetaCache);
|
||||
}
|
||||
|
||||
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
|
||||
bool* pPass) {
|
||||
char key[USER_AUTH_KEY_MAX_LEN] = {0};
|
||||
int32_t len = userAuthToStringExt(pUser, pDbFName, type, key);
|
||||
bool* pRes = NULL;
|
||||
int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pRes);
|
||||
int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname,
|
||||
pAuthReq->tbName.tname, pAuthReq->type, key);
|
||||
SUserAuthRes* pAuth = NULL;
|
||||
int32_t code = getMetaDataFromHash(key, len, pMetaCache->pUserAuth, (void**)&pAuth);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPass = *pRes;
|
||||
memcpy(pAuthRes, pAuth, sizeof(SUserAuthRes));
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -589,8 +589,8 @@ class MockCatalogServiceImpl {
|
|||
*pUserAuthData = taosArrayInit(num, sizeof(SMetaRes));
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SMetaRes res = {0};
|
||||
res.pRes = taosMemoryCalloc(1, sizeof(bool));
|
||||
*(bool*)(res.pRes) = true;
|
||||
res.pRes = taosMemoryCalloc(1, sizeof(SUserAuthRes));
|
||||
((SUserAuthRes*)res.pRes)->pass = true;
|
||||
taosArrayPush(*pUserAuthData, &res);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue