Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
689e7f0e
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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,发现更多精彩内容 >>
提交
689e7f0e
编写于
2月 11, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
process get user auth request
上级
fb9b00ef
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
180 addition
and
3 deletion
+180
-3
include/common/tmsg.h
include/common/tmsg.h
+18
-1
include/common/tmsgdef.h
include/common/tmsgdef.h
+1
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+69
-1
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+1
-0
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+63
-1
source/dnode/mnode/impl/test/user/user.cpp
source/dnode/mnode/impl/test/user/user.cpp
+28
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
689e7f0e
...
...
@@ -371,15 +371,32 @@ void* tDeserializeSCreateUserReq(void* buf, SCreateUserReq* pReq);
typedef
struct
{
int8_t
alterType
;
int8_t
superUser
;
char
user
[
TSDB_USER_LEN
];
char
pass
[
TSDB_PASSWORD_LEN
];
char
dbname
[
TSDB_DB_FNAME_LEN
];
int8_t
superUser
;
}
SAlterUserReq
;
int32_t
tSerializeSAlterUserReq
(
void
**
buf
,
SAlterUserReq
*
pReq
);
void
*
tDeserializeSAlterUserReq
(
void
*
buf
,
SAlterUserReq
*
pReq
);
typedef
struct
{
char
user
[
TSDB_USER_LEN
];
}
SGetUserAuthReq
;
int32_t
tSerializeSGetUserAuthReq
(
void
**
buf
,
SGetUserAuthReq
*
pReq
);
void
*
tDeserializeSGetUserAuthReq
(
void
*
buf
,
SGetUserAuthReq
*
pReq
);
typedef
struct
{
char
user
[
TSDB_USER_LEN
];
int8_t
superAuth
;
SHashObj
*
readDbs
;
SHashObj
*
writeDbs
;
}
SGetUserAuthRsp
;
int32_t
tSerializeSGetUserAuthRsp
(
void
**
buf
,
SGetUserAuthRsp
*
pReq
);
void
*
tDeserializeSGetUserAuthRsp
(
void
*
buf
,
SGetUserAuthRsp
*
pReq
);
typedef
struct
{
int16_t
colId
;
// column id
int16_t
colIndex
;
// column index in colList if it is a normal column or index in tagColList if a tag
...
...
include/common/tmsgdef.h
浏览文件 @
689e7f0e
...
...
@@ -97,6 +97,7 @@ enum {
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_USER
,
"mnode-create-user"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_USER
,
"mnode-alter-user"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_DROP_USER
,
"mnode-drop-user"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_GET_USER_AUTH
,
"mnode-get-user-auth"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CREATE_DNODE
,
"mnode-create-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_CONFIG_DNODE
,
"mnode-config-dnode"
,
NULL
,
NULL
)
TD_DEF_MSG_TYPE
(
TDMT_MND_ALTER_DNODE
,
"mnode-alter-dnode"
,
NULL
,
NULL
)
...
...
source/common/src/tmsg.c
浏览文件 @
689e7f0e
...
...
@@ -670,4 +670,72 @@ void *tDeserializeSAlterUserReq(void *buf, SAlterUserReq *pReq) {
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
dbname
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pReq
->
superUser
);
return
buf
;
}
\ No newline at end of file
}
int32_t
tSerializeSGetUserAuthReq
(
void
**
buf
,
SGetUserAuthReq
*
pReq
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pReq
->
user
);
return
tlen
;
}
void
*
tDeserializeSGetUserAuthReq
(
void
*
buf
,
SGetUserAuthReq
*
pReq
)
{
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
user
);
return
buf
;
}
int32_t
tSerializeSGetUserAuthRsp
(
void
**
buf
,
SGetUserAuthRsp
*
pReq
)
{
int32_t
tlen
=
0
;
tlen
+=
taosEncodeString
(
buf
,
pReq
->
user
);
tlen
+=
taosEncodeFixedI8
(
buf
,
pReq
->
superAuth
);
int32_t
numOfReadDbs
=
taosHashGetSize
(
pReq
->
readDbs
);
int32_t
numOfWriteDbs
=
taosHashGetSize
(
pReq
->
writeDbs
);
tlen
+=
taosEncodeFixedI32
(
buf
,
numOfReadDbs
);
tlen
+=
taosEncodeFixedI32
(
buf
,
numOfWriteDbs
);
char
*
db
=
taosHashIterate
(
pReq
->
readDbs
,
NULL
);
while
(
db
!=
NULL
)
{
tlen
+=
taosEncodeString
(
buf
,
db
);
db
=
taosHashIterate
(
pReq
->
readDbs
,
db
);
}
db
=
taosHashIterate
(
pReq
->
writeDbs
,
NULL
);
while
(
db
!=
NULL
)
{
tlen
+=
taosEncodeString
(
buf
,
db
);
db
=
taosHashIterate
(
pReq
->
writeDbs
,
db
);
}
return
tlen
;
}
void
*
tDeserializeSGetUserAuthRsp
(
void
*
buf
,
SGetUserAuthRsp
*
pReq
)
{
buf
=
taosDecodeStringTo
(
buf
,
pReq
->
user
);
buf
=
taosDecodeFixedI8
(
buf
,
&
pReq
->
superAuth
);
pReq
->
readDbs
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
pReq
->
writeDbs
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
if
(
pReq
->
readDbs
==
NULL
||
pReq
->
writeDbs
==
NULL
)
{
return
NULL
;
}
int32_t
numOfReadDbs
=
0
;
int32_t
numOfWriteDbs
=
0
;
buf
=
taosDecodeFixedI32
(
buf
,
&
numOfReadDbs
);
buf
=
taosDecodeFixedI32
(
buf
,
&
numOfWriteDbs
);
for
(
int32_t
i
=
0
;
i
<
numOfReadDbs
;
++
i
)
{
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
buf
=
taosDecodeStringTo
(
buf
,
db
);
int32_t
len
=
strlen
(
db
)
+
1
;
taosHashPut
(
pReq
->
readDbs
,
db
,
len
,
db
,
len
);
}
for
(
int32_t
i
=
0
;
i
<
numOfWriteDbs
;
++
i
)
{
char
db
[
TSDB_DB_FNAME_LEN
]
=
{
0
};
buf
=
taosDecodeStringTo
(
buf
,
db
);
int32_t
len
=
strlen
(
db
)
+
1
;
taosHashPut
(
pReq
->
writeDbs
,
db
,
len
,
db
,
len
);
}
return
buf
;
}
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
689e7f0e
...
...
@@ -73,6 +73,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_USER
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_ALTER_USER
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_USER
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_GET_USER_AUTH
)]
=
dndProcessMnodeReadMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CREATE_DNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_CONFIG_DNODE
)]
=
dndProcessMnodeWriteMsg
;
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_MND_DROP_DNODE
)]
=
dndProcessMnodeWriteMsg
;
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
689e7f0e
...
...
@@ -34,6 +34,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreat
static
int32_t
mndProcessCreateUserReq
(
SMnodeMsg
*
pReq
);
static
int32_t
mndProcessAlterUserReq
(
SMnodeMsg
*
pReq
);
static
int32_t
mndProcessDropUserReq
(
SMnodeMsg
*
pReq
);
static
int32_t
mndProcessGetUserAuthReq
(
SMnodeMsg
*
pReq
);
static
int32_t
mndGetUserMeta
(
SMnodeMsg
*
pReq
,
SShowObj
*
pShow
,
STableMetaRsp
*
pMeta
);
static
int32_t
mndRetrieveUsers
(
SMnodeMsg
*
pReq
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextUser
(
SMnode
*
pMnode
,
void
*
pIter
);
...
...
@@ -51,6 +52,7 @@ int32_t mndInitUser(SMnode *pMnode) {
mndSetMsgHandle
(
pMnode
,
TDMT_MND_CREATE_USER
,
mndProcessCreateUserReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_ALTER_USER
,
mndProcessAlterUserReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_DROP_USER
,
mndProcessDropUserReq
);
mndSetMsgHandle
(
pMnode
,
TDMT_MND_GET_USER_AUTH
,
mndProcessGetUserAuthReq
);
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_USER
,
mndGetUserMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_USER
,
mndRetrieveUsers
);
...
...
@@ -574,6 +576,66 @@ DROP_USER_OVER:
return
code
;
}
static
int32_t
mndProcessGetUserAuthReq
(
SMnodeMsg
*
pReq
)
{
SMnode
*
pMnode
=
pReq
->
pMnode
;
int32_t
code
=
-
1
;
SUserObj
*
pUser
=
NULL
;
SGetUserAuthReq
authReq
=
{
0
};
SGetUserAuthRsp
authRsp
=
{
0
};
if
(
tDeserializeSGetUserAuthReq
(
pReq
->
rpcMsg
.
pCont
,
&
authReq
)
==
NULL
)
goto
GET_AUTH_OVER
;
mTrace
(
"user:%s, start to get auth"
,
authReq
.
user
);
pUser
=
mndAcquireUser
(
pMnode
,
authReq
.
user
);
if
(
pUser
==
NULL
)
{
terrno
=
TSDB_CODE_MND_USER_NOT_EXIST
;
goto
GET_AUTH_OVER
;
}
memcpy
(
authRsp
.
user
,
pUser
->
user
,
TSDB_USER_LEN
);
authRsp
.
superAuth
=
pUser
->
superUser
;
authRsp
.
readDbs
=
mndDupDbHash
(
pUser
->
readDbs
);
authRsp
.
writeDbs
=
mndDupDbHash
(
pUser
->
writeDbs
);
SSdb
*
pSdb
=
pMnode
->
pSdb
;
void
*
pIter
=
NULL
;
while
(
1
)
{
SDbObj
*
pDb
=
NULL
;
pIter
=
sdbFetch
(
pSdb
,
SDB_DB
,
pIter
,
(
void
**
)
&
pDb
);
if
(
pIter
==
NULL
)
break
;
if
(
strcmp
(
pDb
->
createUser
,
pUser
->
user
)
==
0
)
{
int32_t
len
=
strlen
(
pDb
->
name
)
+
1
;
taosHashPut
(
authRsp
.
readDbs
,
pDb
->
name
,
len
,
pDb
->
name
,
len
);
taosHashPut
(
authRsp
.
writeDbs
,
pDb
->
name
,
len
,
pDb
->
name
,
len
);
}
sdbRelease
(
pSdb
,
pDb
);
}
int32_t
contLen
=
tSerializeSGetUserAuthRsp
(
NULL
,
&
authRsp
);
void
*
pRsp
=
rpcMallocCont
(
contLen
);
if
(
pRsp
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
GET_AUTH_OVER
;
}
void
*
pBuf
=
pRsp
;
tSerializeSGetUserAuthRsp
(
&
pBuf
,
&
authRsp
);
pReq
->
pCont
=
pRsp
;
pReq
->
contLen
=
contLen
;
code
=
0
;
GET_AUTH_OVER:
mndReleaseUser
(
pMnode
,
pUser
);
taosHashCleanup
(
authRsp
.
readDbs
);
taosHashCleanup
(
authRsp
.
writeDbs
);
return
code
;
}
static
int32_t
mndGetUserMeta
(
SMnodeMsg
*
pReq
,
SShowObj
*
pShow
,
STableMetaRsp
*
pMeta
)
{
SMnode
*
pMnode
=
pReq
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
...
...
@@ -668,4 +730,4 @@ static int32_t mndRetrieveUsers(SMnodeMsg *pReq, SShowObj *pShow, char *data, in
static
void
mndCancelGetNextUser
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
}
source/dnode/mnode/impl/test/user/user.cpp
浏览文件 @
689e7f0e
...
...
@@ -398,6 +398,34 @@ TEST_F(MndTestUser, 03_Alter_User) {
ASSERT_EQ
(
pRsp
->
code
,
0
);
}
{
SGetUserAuthReq
authReq
=
{
0
};
strcpy
(
authReq
.
user
,
"u3"
);
int32_t
contLen
=
tSerializeSGetUserAuthReq
(
NULL
,
&
authReq
);
void
*
pReq
=
rpcMallocCont
(
contLen
);
void
*
pBuf
=
pReq
;
tSerializeSGetUserAuthReq
(
&
pBuf
,
&
authReq
);
SRpcMsg
*
pRsp
=
test
.
SendReq
(
TDMT_MND_GET_USER_AUTH
,
pReq
,
contLen
);
ASSERT_NE
(
pRsp
,
nullptr
);
ASSERT_EQ
(
pRsp
->
code
,
0
);
SGetUserAuthRsp
authRsp
=
{
0
};
tDeserializeSGetUserAuthRsp
(
pRsp
->
pCont
,
&
authRsp
);
EXPECT_STREQ
(
authRsp
.
user
,
"u3"
);
EXPECT_EQ
(
authRsp
.
superAuth
,
1
);
int32_t
numOfReadDbs
=
taosHashGetSize
(
authRsp
.
readDbs
);
int32_t
numOfWriteDbs
=
taosHashGetSize
(
authRsp
.
writeDbs
);
EXPECT_EQ
(
numOfReadDbs
,
1
);
EXPECT_EQ
(
numOfWriteDbs
,
0
);
char
*
dbname
=
(
char
*
)
taosHashGet
(
authRsp
.
readDbs
,
"1.d2"
,
5
);
EXPECT_STREQ
(
dbname
,
"1.d2"
);
taosHashCleanup
(
authRsp
.
readDbs
);
taosHashCleanup
(
authRsp
.
writeDbs
);
}
{
SAlterUserReq
alterReq
=
{
0
};
alterReq
.
alterType
=
TSDB_ALTER_USER_REMOVE_READ_DB
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录