Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
387d6111
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
387d6111
编写于
6月 30, 2023
作者:
K
kailixu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore: passVer and authVer refact
上级
1e9b8554
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
96 addition
and
330 deletion
+96
-330
include/common/tmsg.h
include/common/tmsg.h
+1
-17
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+4
-2
source/client/src/clientHb.c
source/client/src/clientHb.c
+71
-169
source/client/src/clientMain.c
source/client/src/clientMain.c
+0
-5
source/common/src/tmsg.c
source/common/src/tmsg.c
+14
-58
source/dnode/mnode/impl/inc/mndUser.h
source/dnode/mnode/impl/inc/mndUser.h
+0
-2
source/dnode/mnode/impl/src/mndPrivilege.c
source/dnode/mnode/impl/src/mndPrivilege.c
+1
-0
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+0
-10
source/dnode/mnode/impl/src/mndUser.c
source/dnode/mnode/impl/src/mndUser.c
+0
-64
tests/script/api/passwdTest.c
tests/script/api/passwdTest.c
+5
-3
未找到文件。
include/common/tmsg.h
浏览文件 @
387d6111
...
...
@@ -106,7 +106,6 @@ enum {
HEARTBEAT_KEY_DBINFO
,
HEARTBEAT_KEY_STBINFO
,
HEARTBEAT_KEY_TMQ
,
HEARTBEAT_KEY_USER_PASSINFO
,
};
typedef
enum
_mgmt_table
{
...
...
@@ -704,6 +703,7 @@ int32_t tDeserializeSGetUserAuthReq(void* buf, int32_t bufLen, SGetUserAuthReq*
typedef
struct
{
char
user
[
TSDB_USER_LEN
];
int32_t
version
;
int32_t
passVer
;
int8_t
superAuth
;
int8_t
sysInfo
;
int8_t
enable
;
...
...
@@ -720,14 +720,6 @@ int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pR
int32_t
tDeserializeSGetUserAuthRsp
(
void
*
buf
,
int32_t
bufLen
,
SGetUserAuthRsp
*
pRsp
);
void
tFreeSGetUserAuthRsp
(
SGetUserAuthRsp
*
pRsp
);
typedef
struct
SUserPassVersion
{
char
user
[
TSDB_USER_LEN
];
int32_t
version
;
}
SUserPassVersion
;
typedef
SGetUserAuthReq
SGetUserPassReq
;
typedef
SUserPassVersion
SGetUserPassRsp
;
/*
* for client side struct, only column id, type, bytes are necessary
* But for data in vnode side, we need all the following information.
...
...
@@ -1071,14 +1063,6 @@ int32_t tSerializeSUserAuthBatchRsp(void* buf, int32_t bufLen, SUserAuthBatchRsp
int32_t
tDeserializeSUserAuthBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
SUserAuthBatchRsp
*
pRsp
);
void
tFreeSUserAuthBatchRsp
(
SUserAuthBatchRsp
*
pRsp
);
typedef
struct
{
SArray
*
pArray
;
// Array of SGetUserPassRsp
}
SUserPassBatchRsp
;
int32_t
tSerializeSUserPassBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
SUserPassBatchRsp
*
pRsp
);
int32_t
tDeserializeSUserPassBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
SUserPassBatchRsp
*
pRsp
);
void
tFreeSUserPassBatchRsp
(
SUserPassBatchRsp
*
pRsp
);
typedef
struct
{
char
db
[
TSDB_DB_FNAME_LEN
];
STimeWindow
timeRange
;
...
...
source/client/inc/clientInt.h
浏览文件 @
387d6111
...
...
@@ -33,6 +33,7 @@ extern "C" {
#include "tmsg.h"
#include "tmsgtype.h"
#include "trpc.h"
#include "tsimplehash.h"
#include "tconfig.h"
...
...
@@ -63,7 +64,7 @@ typedef struct {
// statistics
int32_t
reportCnt
;
int32_t
connKeyCnt
;
int
32_t
passKeyCnt
;
// with passVer call back
int
8_t
connHbFlag
;
int64_t
reportBytes
;
// not implemented
int64_t
startTime
;
// ctl
...
...
@@ -83,8 +84,9 @@ typedef struct {
int8_t
threadStop
;
int8_t
quitByKill
;
TdThread
thread
;
TdThreadMutex
lock
;
// used when app init and cleanup
TdThreadMutex
lock
;
// used when app init and cleanup
SHashObj
*
appSummary
;
SSHashObj
*
appHbHash
;
// key: clusterId
SArray
*
appHbMgrs
;
// SArray<SAppHbMgr*> one for each cluster
FHbReqHandle
reqHandle
[
CONN_TYPE__MAX
];
FHbRspHandle
rspHandle
[
CONN_TYPE__MAX
];
...
...
source/client/src/clientHb.c
浏览文件 @
387d6111
...
...
@@ -18,15 +18,16 @@
#include "clientLog.h"
#include "scheduler.h"
#include "trpc.h"
#include "tsimplehash.h"
typedef
struct
{
SAppHbMgr
*
pAppHbMgr
;
union
{
struct
{
int64_t
clusterId
;
int32_t
passKeyCnt
;
int32_t
passVer
;
int32_t
authVer
;
// int32_t authVer;
int32_t
reqCnt
;
int8_t
connHbFlag
;
};
};
}
SHbParam
;
...
...
@@ -50,14 +51,16 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
return
-
1
;
}
int32_t
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
atomic_val_compare_exchange_8
(
&
pAppHbMgr
->
connHbFlag
,
2
,
0
);
int32_t
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
tscDebug
(
"hb user auth rsp, user:%s, version:%d"
,
rsp
->
user
,
rsp
->
version
);
catalogUpdateUserAuthInfo
(
pCatalog
,
rsp
);
}
#if 1
SClientHbReq
*
pReq
=
NULL
;
while
((
pReq
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pReq
)))
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
pReq
->
connKey
.
tscRid
);
...
...
@@ -68,6 +71,7 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserAuthRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
pTscObj
->
authVer
=
rsp
->
version
;
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
if
(
pTscObj
->
sysInfo
!=
rsp
->
sysInfo
)
{
printf
(
"update sysInfo of user %s from %"
PRIi8
" to %"
PRIi8
", tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
...
...
@@ -77,51 +81,23 @@ static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SC
printf
(
"not update sysInfo of user %s since not change: %"
PRIi8
", tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
pTscObj
->
sysInfo
,
pTscObj
->
id
);
}
break
;
}
}
releaseTscObj
(
pReq
->
connKey
.
tscRid
);
}
#endif
taosArrayDestroy
(
batchRsp
.
pArray
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
hbProcessUserPassInfoRsp
(
void
*
value
,
int32_t
valueLen
,
SClientHbKey
*
connKey
,
SAppHbMgr
*
pAppHbMgr
)
{
int32_t
code
=
0
;
int32_t
numOfBatchs
=
0
;
SUserPassBatchRsp
batchRsp
=
{
0
};
if
(
tDeserializeSUserPassBatchRsp
(
value
,
valueLen
,
&
batchRsp
)
!=
0
)
{
code
=
TSDB_CODE_INVALID_MSG
;
return
code
;
}
numOfBatchs
=
taosArrayGetSize
(
batchRsp
.
pArray
);
SClientHbReq
*
pReq
=
NULL
;
while
((
pReq
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pReq
)))
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
pReq
->
connKey
.
tscRid
);
if
(
!
pTscObj
)
{
continue
;
}
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
if
(
!
passInfo
->
fp
)
{
releaseTscObj
(
pReq
->
connKey
.
tscRid
);
continue
;
}
for
(
int32_t
i
=
0
;
i
<
numOfBatchs
;
++
i
)
{
SGetUserPassRsp
*
rsp
=
taosArrayGet
(
batchRsp
.
pArray
,
i
);
if
(
0
==
strncmp
(
rsp
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
))
{
int32_t
oldVer
=
atomic_load_32
(
&
passInfo
->
ver
);
if
(
oldVer
<
rsp
->
version
)
{
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
version
);
if
(
passInfo
->
fp
)
{
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
passInfo
->
ver
,
TAOS_NOTIFY_PASSVER
);
}
tscDebug
(
"update passVer of user %s from %d to %d, tscRid:%"
PRIi64
,
rsp
->
user
,
oldVer
,
SPassInfo
*
passInfo
=
&
pTscObj
->
passInfo
;
if
(
passInfo
->
fp
)
{
int32_t
oldVer
=
atomic_load_32
(
&
passInfo
->
ver
);
if
(
oldVer
<
rsp
->
passVer
)
{
atomic_store_32
(
&
passInfo
->
ver
,
rsp
->
passVer
);
if
(
passInfo
->
fp
)
{
(
*
passInfo
->
fp
)(
passInfo
->
param
,
&
passInfo
->
ver
,
TAOS_NOTIFY_PASSVER
);
}
printf
(
"update passVer of user %s from %d to %d, tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
oldVer
,
atomic_load_32
(
&
passInfo
->
ver
),
pTscObj
->
id
);
}
else
{
printf
(
"not update passVer of user %s since not changed: %d, tscRid:%"
PRIi64
"
\n
"
,
rsp
->
user
,
oldVer
,
pTscObj
->
id
);
}
}
break
;
}
}
...
...
@@ -129,8 +105,7 @@ static int32_t hbProcessUserPassInfoRsp(void *value, int32_t valueLen, SClientHb
}
taosArrayDestroy
(
batchRsp
.
pArray
);
return
code
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
hbGenerateVgInfoFromRsp
(
SDBVgInfo
**
pInfo
,
SUseDbRsp
*
rsp
)
{
...
...
@@ -380,15 +355,6 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
hbProcessStbInfoRsp
(
kv
->
value
,
kv
->
valueLen
,
pCatalog
);
break
;
}
case
HEARTBEAT_KEY_USER_PASSINFO
:
{
if
(
kv
->
valueLen
<=
0
||
NULL
==
kv
->
value
)
{
tscError
(
"invalid hb user pass info, len:%d, value:%p"
,
kv
->
valueLen
,
kv
->
value
);
break
;
}
hbProcessUserPassInfoRsp
(
kv
->
value
,
kv
->
valueLen
,
&
pRsp
->
connKey
,
pAppHbMgr
);
break
;
}
default:
tscError
(
"invalid hb key type:%d"
,
kv
->
key
);
break
;
...
...
@@ -569,69 +535,6 @@ int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
hbGetUserBasicInfo
(
SClientHbKey
*
connKey
,
SHbParam
*
param
,
SClientHbReq
*
req
)
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
connKey
->
tscRid
);
if
(
!
pTscObj
)
{
tscWarn
(
"tscObj rid %"
PRIx64
" not exist"
,
connKey
->
tscRid
);
return
TSDB_CODE_APP_ERROR
;
}
int32_t
code
=
0
;
if
(
param
&&
(
param
->
passVer
!=
INT32_MIN
)
&&
(
param
->
passVer
<=
pTscObj
->
passInfo
.
ver
))
{
tscDebug
(
"hb got user basic info, no need since passVer %d <= %d"
,
param
->
passVer
,
pTscObj
->
passInfo
.
ver
);
goto
_return
;
}
SKv
kv
=
{.
key
=
HEARTBEAT_KEY_USER_PASSINFO
};
SKv
*
pKv
=
NULL
;
if
((
pKv
=
taosHashGet
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
))))
{
SUserPassVersion
*
pPassVer
=
(
SUserPassVersion
*
)
pKv
->
value
;
tscDebug
(
"hb got user basic info, already exists:%s, update passVer from %d to %d"
,
pTscObj
->
user
,
htonl
(
pPassVer
->
version
),
pTscObj
->
passInfo
.
ver
);
pPassVer
->
version
=
htonl
(
pTscObj
->
passInfo
.
ver
);
if
(
param
)
param
->
passVer
=
pTscObj
->
passInfo
.
ver
;
goto
_return
;
}
SUserPassVersion
*
user
=
taosMemoryMalloc
(
sizeof
(
SUserPassVersion
));
if
(
!
user
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_return
;
}
strncpy
(
user
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
);
user
->
version
=
htonl
(
pTscObj
->
passInfo
.
ver
);
kv
.
valueLen
=
sizeof
(
SUserPassVersion
);
kv
.
value
=
user
;
tscDebug
(
"hb got user basic info, valueLen:%d, user:%s, passVer:%d, tscRid:%"
PRIi64
,
kv
.
valueLen
,
user
->
user
,
pTscObj
->
passInfo
.
ver
,
connKey
->
tscRid
);
if
(
!
req
->
info
)
{
req
->
info
=
taosHashInit
(
64
,
hbKeyHashFunc
,
1
,
HASH_ENTRY_LOCK
);
}
if
(
taosHashPut
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
),
&
kv
,
sizeof
(
kv
))
<
0
)
{
taosMemoryFreeClear
(
user
);
code
=
terrno
?
terrno
:
TSDB_CODE_APP_ERROR
;
goto
_return
;
}
// assign the passVer
if
(
param
)
{
param
->
passVer
=
pTscObj
->
passInfo
.
ver
;
}
_return:
releaseTscObj
(
connKey
->
tscRid
);
if
(
code
)
{
tscError
(
"hb got user basic info failed since %s"
,
terrstr
(
code
));
}
return
code
;
}
static
int32_t
hbGetUserAuthInfo
(
SClientHbKey
*
connKey
,
SHbParam
*
param
,
SClientHbReq
*
req
)
{
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
connKey
->
tscRid
);
if
(
!
pTscObj
)
{
...
...
@@ -641,11 +544,6 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
int32_t
code
=
0
;
if
(
param
&&
(
param
->
authVer
!=
INT32_MIN
)
&&
(
param
->
authVer
<=
pTscObj
->
authVer
))
{
tscDebug
(
"hb got user auth info, no need since authVer %d <= %d"
,
param
->
authVer
,
pTscObj
->
authVer
);
goto
_return
;
}
SKv
kv
=
{.
key
=
HEARTBEAT_KEY_USER_AUTHINFO
};
SKv
*
pKv
=
NULL
;
if
((
pKv
=
taosHashGet
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
))))
{
...
...
@@ -653,24 +551,20 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
SUserAuthVersion
*
pUserAuths
=
(
SUserAuthVersion
*
)
pKv
->
value
;
for
(
int32_t
i
=
0
;
i
<
userNum
;
++
i
)
{
SUserAuthVersion
*
pUserAuth
=
pUserAuths
+
i
;
// user exist
//
both key and
user exist
if
(
strncmp
(
pUserAuth
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
)
==
0
)
{
if
(
htonl
(
pUserAuth
->
version
)
>
pTscObj
->
authVer
)
{
pUserAuth
->
version
=
htonl
(
pTscObj
->
authVer
);
}
if
(
param
)
param
->
authVer
=
htonl
(
pUserAuth
->
version
);
pUserAuth
->
version
=
htonl
(
-
1
);
// force get userAuthInfo
goto
_return
;
}
}
// key exists,
but
user not exist
// key exists, user not exist
SUserAuthVersion
*
qUserAuth
=
(
SUserAuthVersion
*
)
taosMemoryRealloc
(
pKv
->
value
,
(
userNum
+
1
)
*
sizeof
(
SUserAuthVersion
));
if
(
qUserAuth
)
{
strncpy
((
qUserAuth
+
userNum
)
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
);
(
qUserAuth
+
userNum
)
->
version
=
htonl
(
pTscObj
->
authVer
);
(
qUserAuth
+
userNum
)
->
version
=
htonl
(
-
1
);
// force get userAuthInfo
pKv
->
value
=
qUserAuth
;
pKv
->
valueLen
+=
sizeof
(
SUserAuthVersion
);
if
(
param
)
param
->
authVer
=
pTscObj
->
authVer
;
}
else
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -683,7 +577,7 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
goto
_return
;
}
strncpy
(
user
->
user
,
pTscObj
->
user
,
TSDB_USER_LEN
);
user
->
version
=
htonl
(
pTscObj
->
authVer
);
user
->
version
=
htonl
(
-
1
);
// force get userAuthInfo
kv
.
valueLen
=
sizeof
(
SUserAuthVersion
);
kv
.
value
=
user
;
...
...
@@ -695,15 +589,11 @@ static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClient
}
if
(
taosHashPut
(
req
->
info
,
&
kv
.
key
,
sizeof
(
kv
.
key
),
&
kv
,
sizeof
(
kv
))
<
0
)
{
taosMemoryFree
Clear
(
user
);
taosMemoryFree
(
user
);
code
=
terrno
?
terrno
:
TSDB_CODE_APP_ERROR
;
goto
_return
;
}
if
(
param
)
{
param
->
authVer
=
pTscObj
->
authVer
;
}
_return:
releaseTscObj
(
connKey
->
tscRid
);
if
(
code
)
{
...
...
@@ -713,8 +603,6 @@ _return:
return
code
;
}
int32_t
hbGetExpiredUserInfo
(
SClientHbKey
*
connKey
,
struct
SCatalog
*
pCatalog
,
SClientHbReq
*
req
)
{
SUserAuthVersion
*
users
=
NULL
;
uint32_t
userNum
=
0
;
...
...
@@ -724,11 +612,21 @@ int32_t hbGetExpiredUserInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, S
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
STscObj
*
pTscObj
=
(
STscObj
*
)
acquireTscObj
(
connKey
->
tscRid
);
if
(
NULL
==
pTscObj
)
{
tscWarn
(
"tscObj rid %"
PRIx64
" not exist"
,
connKey
->
tscRid
);
return
TSDB_CODE_APP_ERROR
;
}
if
(
userNum
<=
0
)
{
// printf("%s:%d hb get expired: [User:%s] NNNNo user since user num: %d, second:%d\n", __func__, __LINE__, pTscObj->user, userNum,
// taosGetTimestampSec());
taosMemoryFree
(
users
);
releaseTscObj
(
connKey
->
tscRid
);
return
TSDB_CODE_SUCCESS
;
}
}
releaseTscObj
(
connKey
->
tscRid
);
for
(
int32_t
i
=
0
;
i
<
userNum
;
++
i
)
{
SUserAuthVersion
*
user
=
&
users
[
i
];
...
...
@@ -867,14 +765,21 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
hbGetQueryBasicInfo
(
connKey
,
req
);
if
(
hbParam
->
passKeyCnt
>
0
)
{
hbGetUserBasicInfo
(
connKey
,
hbParam
,
req
);
}
if
(
hbParam
->
reqCnt
==
0
)
{
if
(
!
tSimpleHashGet
(
clientHbMgr
.
appHbHash
,
&
hbParam
->
clusterId
,
sizeof
(
hbParam
->
clusterId
)))
{
code
=
hbGetExpiredUserInfo
(
connKey
,
pCatalog
,
req
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
}
if
(
hbParam
->
reqCnt
==
0
)
{
code
=
hbGetExpiredUserInfo
(
connKey
,
pCatalog
,
req
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
// invoke after hbGetExpiredUserInfo
if
(
atomic_load_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
))
{
code
=
hbGetUserAuthInfo
(
connKey
,
hbParam
,
req
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
atomic_store_8
(
&
hbParam
->
pAppHbMgr
->
connHbFlag
,
2
);
}
code
=
hbGetExpiredDBInfo
(
connKey
,
pCatalog
,
req
);
...
...
@@ -887,10 +792,7 @@ int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req
return
code
;
}
}
++
hbParam
->
reqCnt
;
// success to get catalog info
// N.B. put after hbGetExpiredUserInfo
hbGetUserAuthInfo
(
connKey
,
hbParam
,
req
);
++
hbParam
->
reqCnt
;
// success to get catalog info
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -918,7 +820,7 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
}
void
*
pIter
=
NULL
;
SHbParam
param
=
{
0
};
SHbParam
param
=
{
.
pAppHbMgr
=
pAppHbMgr
};
while
((
pIter
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pIter
)))
{
SClientHbReq
*
pOneReq
=
pIter
;
SClientHbKey
*
connKey
=
&
pOneReq
->
connKey
;
...
...
@@ -935,10 +837,8 @@ SClientHbBatchReq *hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
if
(
param
.
clusterId
==
0
)
{
// init
param
.
clusterId
=
pOneReq
->
clusterId
;
param
.
passVer
=
INT32_MIN
;
param
.
authVer
=
INT32_MIN
;
param
.
connHbFlag
=
atomic_load_8
(
&
pAppHbMgr
->
connHbFlag
);
}
param
.
passKeyCnt
=
atomic_load_32
(
&
pAppHbMgr
->
passKeyCnt
);
break
;
}
default:
...
...
@@ -1022,8 +922,13 @@ static void *hbThreadFunc(void *param) {
int
sz
=
taosArrayGetSize
(
clientHbMgr
.
appHbMgrs
);
if
(
sz
>
0
)
{
hbGatherAppInfo
();
if
(
sz
>
1
&&
!
clientHbMgr
.
appHbHash
)
{
clientHbMgr
.
appHbHash
=
tSimpleHashInit
(
0
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
));
}
}
tSimpleHashClear
(
clientHbMgr
.
appHbHash
);
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SAppHbMgr
*
pAppHbMgr
=
taosArrayGetP
(
clientHbMgr
.
appHbMgrs
,
i
);
if
(
pAppHbMgr
==
NULL
)
{
...
...
@@ -1074,7 +979,7 @@ static void *hbThreadFunc(void *param) {
asyncSendMsgToServer
(
pAppInstInfo
->
pTransporter
,
&
epSet
,
&
transporterId
,
pInfo
);
tFreeClientHbBatchReq
(
pReq
);
// hbClearReqInfo(pAppHbMgr);
tSimpleHashPut
(
clientHbMgr
.
appHbHash
,
&
pAppHbMgr
->
pAppInstInfo
->
clusterId
,
sizeof
(
int64_t
),
NULL
,
0
);
atomic_add_fetch_32
(
&
pAppHbMgr
->
reportCnt
,
1
);
}
...
...
@@ -1082,6 +987,7 @@ static void *hbThreadFunc(void *param) {
taosMsleep
(
HEARTBEAT_INTERVAL
);
}
return
NULL
;
}
...
...
@@ -1130,7 +1036,7 @@ SAppHbMgr *appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key) {
// init stat
pAppHbMgr
->
startTime
=
taosGetTimestampMs
();
pAppHbMgr
->
connKeyCnt
=
0
;
pAppHbMgr
->
passKeyCnt
=
0
;
pAppHbMgr
->
connHbFlag
=
1
;
pAppHbMgr
->
reportCnt
=
0
;
pAppHbMgr
->
reportBytes
=
0
;
pAppHbMgr
->
key
=
taosStrdup
(
key
);
...
...
@@ -1193,6 +1099,11 @@ void appHbMgrCleanup(void) {
if
(
pTarget
==
NULL
)
continue
;
hbFreeAppHbMgr
(
pTarget
);
}
clientHbMgr
.
appHbMgrs
=
taosArrayDestroy
(
clientHbMgr
.
appHbMgrs
);
tSimpleHashCleanup
(
clientHbMgr
.
appHbHash
);
clientHbMgr
.
appHbHash
=
NULL
;
taosHashCleanup
(
clientHbMgr
.
appSummary
);
clientHbMgr
.
appSummary
=
NULL
;
}
int
hbMgrInit
()
{
...
...
@@ -1246,10 +1157,7 @@ void hbMgrCleanUp() {
taosThreadMutexLock
(
&
clientHbMgr
.
lock
);
appHbMgrCleanup
();
taosArrayDestroy
(
clientHbMgr
.
appHbMgrs
);
taosThreadMutexUnlock
(
&
clientHbMgr
.
lock
);
clientHbMgr
.
appHbMgrs
=
NULL
;
}
int
hbRegisterConnImpl
(
SAppHbMgr
*
pAppHbMgr
,
SClientHbKey
connKey
,
int64_t
clusterId
)
{
...
...
@@ -1301,12 +1209,6 @@ void hbDeregisterConn(STscObj *pTscObj, SClientHbKey connKey) {
}
atomic_sub_fetch_32
(
&
pAppHbMgr
->
connKeyCnt
,
1
);
taosThreadMutexLock
(
&
pTscObj
->
mutex
);
if
(
pTscObj
->
passInfo
.
fp
)
{
atomic_sub_fetch_32
(
&
pAppHbMgr
->
passKeyCnt
,
1
);
}
taosThreadMutexUnlock
(
&
pTscObj
->
mutex
);
}
// set heart beat thread quit mode , if quicByKill 1 then kill thread else quit from inner
...
...
source/client/src/clientMain.c
浏览文件 @
387d6111
...
...
@@ -135,11 +135,6 @@ int taos_set_notify_cb(TAOS *taos, __taos_notify_fn_t fp, void *param, int type)
switch
(
type
)
{
case
TAOS_NOTIFY_PASSVER
:
{
taosThreadMutexLock
(
&
pObj
->
mutex
);
if
(
fp
&&
!
pObj
->
passInfo
.
fp
)
{
atomic_add_fetch_32
(
&
pObj
->
pAppInfo
->
pAppHbMgr
->
passKeyCnt
,
1
);
}
else
if
(
!
fp
&&
pObj
->
passInfo
.
fp
)
{
atomic_sub_fetch_32
(
&
pObj
->
pAppInfo
->
pAppHbMgr
->
passKeyCnt
,
1
);
}
pObj
->
passInfo
.
fp
=
fp
;
pObj
->
passInfo
.
param
=
param
;
taosThreadMutexUnlock
(
&
pObj
->
mutex
);
...
...
source/common/src/tmsg.c
浏览文件 @
387d6111
...
...
@@ -1518,6 +1518,9 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp)
useDb
=
taosHashIterate
(
pRsp
->
useDbs
,
useDb
);
}
// since 3.0.7.0
if
(
tEncodeI32
(
pEncoder
,
pRsp
->
passVer
)
<
0
)
return
-
1
;
return
0
;
}
...
...
@@ -1639,6 +1642,12 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
taosHashPut
(
pRsp
->
useDbs
,
key
,
strlen
(
key
),
&
ref
,
sizeof
(
ref
));
taosMemoryFree
(
key
);
}
// since 3.0.7.0
if
(
!
tDecodeIsEnd
(
pDecoder
))
{
if
(
tDecodeI32
(
pDecoder
,
&
pRsp
->
passVer
)
<
0
)
return
-
1
;
}
else
{
pRsp
->
passVer
=
0
;
}
}
return
0
;
...
...
@@ -3024,59 +3033,6 @@ void tFreeSUserAuthBatchRsp(SUserAuthBatchRsp *pRsp) {
taosArrayDestroy
(
pRsp
->
pArray
);
}
int32_t
tSerializeSUserPassBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
SUserPassBatchRsp
*
pRsp
)
{
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
if
(
tStartEncode
(
&
encoder
)
<
0
)
return
-
1
;
int32_t
numOfBatch
=
taosArrayGetSize
(
pRsp
->
pArray
);
if
(
tEncodeI32
(
&
encoder
,
numOfBatch
)
<
0
)
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
numOfBatch
;
++
i
)
{
SGetUserPassRsp
*
pUserPassRsp
=
taosArrayGet
(
pRsp
->
pArray
,
i
);
if
(
tEncodeCStr
(
&
encoder
,
pUserPassRsp
->
user
)
<
0
)
return
-
1
;
if
(
tEncodeI32
(
&
encoder
,
pUserPassRsp
->
version
)
<
0
)
return
-
1
;
}
tEndEncode
(
&
encoder
);
int32_t
tlen
=
encoder
.
pos
;
tEncoderClear
(
&
encoder
);
return
tlen
;
}
int32_t
tDeserializeSUserPassBatchRsp
(
void
*
buf
,
int32_t
bufLen
,
SUserPassBatchRsp
*
pRsp
)
{
SDecoder
decoder
=
{
0
};
tDecoderInit
(
&
decoder
,
buf
,
bufLen
);
if
(
tStartDecode
(
&
decoder
)
<
0
)
return
-
1
;
int32_t
numOfBatch
=
taosArrayGetSize
(
pRsp
->
pArray
);
if
(
tDecodeI32
(
&
decoder
,
&
numOfBatch
)
<
0
)
return
-
1
;
pRsp
->
pArray
=
taosArrayInit
(
numOfBatch
,
sizeof
(
SGetUserPassRsp
));
if
(
pRsp
->
pArray
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
for
(
int32_t
i
=
0
;
i
<
numOfBatch
;
++
i
)
{
SGetUserPassRsp
rsp
=
{
0
};
if
(
tDecodeCStrTo
(
&
decoder
,
rsp
.
user
)
<
0
)
return
-
1
;
if
(
tDecodeI32
(
&
decoder
,
&
rsp
.
version
)
<
0
)
return
-
1
;
taosArrayPush
(
pRsp
->
pArray
,
&
rsp
);
}
tEndDecode
(
&
decoder
);
tDecoderClear
(
&
decoder
);
return
0
;
}
void
tFreeSUserPassBatchRsp
(
SUserPassBatchRsp
*
pRsp
)
{
if
(
pRsp
)
{
taosArrayDestroy
(
pRsp
->
pArray
);
}
}
int32_t
tSerializeSDbCfgReq
(
void
*
buf
,
int32_t
bufLen
,
SDbCfgReq
*
pReq
)
{
SEncoder
encoder
=
{
0
};
tEncoderInit
(
&
encoder
,
buf
,
bufLen
);
...
...
@@ -4181,13 +4137,13 @@ int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) {
if
(
!
tDecodeIsEnd
(
&
decoder
))
{
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
passVer
)
<
0
)
return
-
1
;
if
(
!
tDecodeIsEnd
(
&
decoder
))
{
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
authVer
)
<
0
)
return
-
1
;
}
else
{
pRsp
->
authVer
=
0
;
}
}
else
{
pRsp
->
passVer
=
0
;
}
// since 3.0.7.0
if
(
!
tDecodeIsEnd
(
&
decoder
))
{
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
authVer
)
<
0
)
return
-
1
;
}
else
{
pRsp
->
authVer
=
0
;
}
...
...
source/dnode/mnode/impl/inc/mndUser.h
浏览文件 @
387d6111
...
...
@@ -35,8 +35,6 @@ SHashObj *mndDupTableHash(SHashObj *pOld);
SHashObj
*
mndDupTopicHash
(
SHashObj
*
pOld
);
int32_t
mndValidateUserAuthInfo
(
SMnode
*
pMnode
,
SUserAuthVersion
*
pUsers
,
int32_t
numOfUses
,
void
**
ppRsp
,
int32_t
*
pRspLen
);
int32_t
mndValidateUserPassInfo
(
SMnode
*
pMnode
,
SUserPassVersion
*
pUsers
,
int32_t
numOfUses
,
void
**
ppRsp
,
int32_t
*
pRspLen
);
int32_t
mndUserRemoveDb
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
char
*
db
);
int32_t
mndUserRemoveTopic
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
char
*
topic
);
...
...
source/dnode/mnode/impl/src/mndPrivilege.c
浏览文件 @
387d6111
...
...
@@ -37,6 +37,7 @@ int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp
pRsp
->
superAuth
=
1
;
pRsp
->
enable
=
pUser
->
enable
;
pRsp
->
version
=
pUser
->
authVersion
;
pRsp
->
passVer
=
pUser
->
passVersion
;
pRsp
->
sysInfo
=
pUser
->
sysInfo
;
return
0
;
}
...
...
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
387d6111
...
...
@@ -552,16 +552,6 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb
}
break
;
}
case
HEARTBEAT_KEY_USER_PASSINFO
:
{
void
*
rspMsg
=
NULL
;
int32_t
rspLen
=
0
;
mndValidateUserPassInfo
(
pMnode
,
kv
->
value
,
kv
->
valueLen
/
sizeof
(
SUserPassVersion
),
&
rspMsg
,
&
rspLen
);
if
(
rspMsg
&&
rspLen
>
0
)
{
SKv
kv1
=
{.
key
=
HEARTBEAT_KEY_USER_PASSINFO
,
.
valueLen
=
rspLen
,
.
value
=
rspMsg
};
taosArrayPush
(
hbRsp
.
info
,
&
kv1
);
}
break
;
}
default:
mError
(
"invalid kv key:%d"
,
kv
->
key
);
hbRsp
.
status
=
TSDB_CODE_APP_ERROR
;
...
...
source/dnode/mnode/impl/src/mndUser.c
浏览文件 @
387d6111
...
...
@@ -824,7 +824,6 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
if
(
mndUserDupObj
(
pUser
,
&
newUser
)
!=
0
)
goto
_OVER
;
newUser
.
passVersion
=
pUser
->
passVersion
;
if
(
alterReq
.
alterType
==
TSDB_ALTER_USER_PASSWD
)
{
char
pass
[
TSDB_PASSWORD_LEN
+
1
]
=
{
0
};
taosEncryptPass_c
((
uint8_t
*
)
alterReq
.
pass
,
strlen
(
alterReq
.
pass
),
pass
);
...
...
@@ -1432,69 +1431,6 @@ _OVER:
return
code
;
}
int32_t
mndValidateUserPassInfo
(
SMnode
*
pMnode
,
SUserPassVersion
*
pUsers
,
int32_t
numOfUses
,
void
**
ppRsp
,
int32_t
*
pRspLen
)
{
int32_t
code
=
0
;
SUserPassBatchRsp
batchRsp
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
numOfUses
;
++
i
)
{
SUserObj
*
pUser
=
mndAcquireUser
(
pMnode
,
pUsers
[
i
].
user
);
if
(
pUser
==
NULL
)
{
mError
(
"user:%s, failed to validate user pass since %s"
,
pUsers
[
i
].
user
,
terrstr
());
continue
;
}
pUsers
[
i
].
version
=
ntohl
(
pUsers
[
i
].
version
);
if
(
pUser
->
passVersion
<=
pUsers
[
i
].
version
)
{
mTrace
(
"user:%s, not update since mnd passVer %d <= client passVer %d"
,
pUsers
[
i
].
user
,
pUser
->
passVersion
,
pUsers
[
i
].
version
);
mndReleaseUser
(
pMnode
,
pUser
);
continue
;
}
SGetUserPassRsp
rsp
=
{
0
};
memcpy
(
rsp
.
user
,
pUser
->
user
,
TSDB_USER_LEN
);
rsp
.
version
=
pUser
->
passVersion
;
if
(
!
batchRsp
.
pArray
&&
!
(
batchRsp
.
pArray
=
taosArrayInit
(
numOfUses
,
sizeof
(
SGetUserPassRsp
))))
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
mndReleaseUser
(
pMnode
,
pUser
);
goto
_OVER
;
}
taosArrayPush
(
batchRsp
.
pArray
,
&
rsp
);
mndReleaseUser
(
pMnode
,
pUser
);
}
if
(
taosArrayGetSize
(
batchRsp
.
pArray
)
<=
0
)
{
goto
_OVER
;
}
int32_t
rspLen
=
tSerializeSUserPassBatchRsp
(
NULL
,
0
,
&
batchRsp
);
if
(
rspLen
<
0
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
void
*
pRsp
=
taosMemoryMalloc
(
rspLen
);
if
(
pRsp
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_OVER
;
}
tSerializeSUserPassBatchRsp
(
pRsp
,
rspLen
,
&
batchRsp
);
*
ppRsp
=
pRsp
;
*
pRspLen
=
rspLen
;
_OVER:
if
(
code
)
{
*
ppRsp
=
NULL
;
*
pRspLen
=
0
;
}
tFreeSUserPassBatchRsp
(
&
batchRsp
);
return
code
;
}
int32_t
mndUserRemoveDb
(
SMnode
*
pMnode
,
STrans
*
pTrans
,
char
*
db
)
{
int32_t
code
=
0
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
...
...
tests/script/api/passwdTest.c
浏览文件 @
387d6111
...
...
@@ -166,22 +166,24 @@ void passVerTestMulti(const char *host, char *qstr) {
// calculate the nPassVerNotified for root and users
int
nConn
=
nRoot
+
nUser
;
for
(
int
i
=
0
;
i
<
15
;
++
i
)
{
for
(
int
i
=
1
;
i
<
15
;
++
i
)
{
if
(
nPassVerNotified
>=
nConn
)
break
;
sleep
(
1
);
printf
(
"%s:%d %d second(s) elasped, passVer notification received:%d, total:%d
\n
"
,
__func__
,
__LINE__
,
i
,
nPassVerNotified
,
nConn
);
}
// close the taos_conn
for
(
int
i
=
0
;
i
<
nRoot
;
++
i
)
{
taos_close
(
taos
[
i
]);
printf
(
"%s:%d close taos[%d]
\n
"
,
__func__
,
__LINE__
,
i
);
sleep
(
1
);
//
sleep(1);
}
for
(
int
i
=
0
;
i
<
nUser
;
++
i
)
{
taos_close
(
taosu
[
i
]);
printf
(
"%s:%d close taosu[%d]
\n
"
,
__func__
,
__LINE__
,
i
);
sleep
(
1
);
//
sleep(1);
}
if
(
nPassVerNotified
>=
nConn
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录