Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f44c2193
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f44c2193
编写于
4月 07, 2023
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: table level privilege
上级
a61279ed
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
133 addition
and
84 deletion
+133
-84
source/libs/catalog/test/CMakeLists.txt
source/libs/catalog/test/CMakeLists.txt
+1
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+9
-3
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+2
-4
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+13
-9
source/libs/parser/src/parAuthenticator.c
source/libs/parser/src/parAuthenticator.c
+55
-27
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+51
-38
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+2
-2
未找到文件。
source/libs/catalog/test/CMakeLists.txt
浏览文件 @
f44c2193
...
...
@@ -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
(
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
f44c2193
...
...
@@ -923,9 +923,15 @@ 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
case
QUERY_NODE_CREATE_FUNCTION_STMT
:
// no pointer field
case
QUERY_NODE_DROP_FUNCTION_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
;
case
QUERY_NODE_CREATE_STREAM_STMT
:
{
SCreateStreamStmt
*
pStmt
=
(
SCreateStreamStmt
*
)
pNode
;
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
f44c2193
...
...
@@ -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
);
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
f44c2193
...
...
@@ -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
;
}
...
...
source/libs/parser/src/parAuthenticator.c
浏览文件 @
f44c2193
...
...
@@ -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
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
bool
pass
=
false
;
SUserAuthInfo
authInfo
=
{
0
};
setUserAuthInfo
(
pCxt
->
pParseCxt
,
pDbName
,
pTabName
,
type
,
&
authInfo
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
SUserAuthRes
authRes
=
{
0
};
if
(
NULL
!=
pCxt
->
pMetaCache
)
{
code
=
getUserAuthFromCache
(
pCxt
->
pMetaCache
,
pParseCxt
->
pUser
,
dbFname
,
type
,
&
pas
s
);
code
=
getUserAuthFromCache
(
pCxt
->
pMetaCache
,
&
authInfo
,
&
authRe
s
);
}
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
(
S
SelectStmt
*
pSelect
,
SNode
*
pTagCond
)
{
static
int32_t
appendStableTagCond
(
S
Node
**
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
;
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
f44c2193
...
...
@@ -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
)
{
...
...
@@ -584,10 +604,12 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) {
}
void
*
p
=
taosHashIterate
(
pUserAuthHash
,
NULL
);
while
(
NULL
!=
p
)
{
size_t
len
=
0
;
char
*
pKey
=
taosHashGetKey
(
p
,
&
len
);
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
(
pK
ey
,
len
,
&
userAuth
);
stringToUserAuth
(
k
ey
,
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
);
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
);
char
key
[
USER_AUTH_KEY_MAX_LEN
]
=
{
0
};
int32_t
len
=
userAuthToStringExt
(
pUser
,
dbFName
,
type
,
key
);
int32_t
len
=
userAuthToString
(
acctId
,
pUser
,
pDb
,
pTable
,
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
getUserAuthFromCache
(
SParseMetaCache
*
pMetaCache
,
SUserAuthInfo
*
pAuthReq
,
SUserAuthRes
*
pAuthRes
)
{
char
key
[
USER_AUTH_KEY_MAX_LEN
]
=
{
0
};
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
;
}
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
f44c2193
...
...
@@ -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
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录