Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
07fe4def
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
07fe4def
编写于
4月 03, 2020
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-93] add ref to users
上级
e068bf33
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
51 addition
and
80 deletion
+51
-80
src/inc/mnode.h
src/inc/mnode.h
+0
-2
src/mnode/inc/mgmtAcct.h
src/mnode/inc/mgmtAcct.h
+2
-0
src/mnode/inc/mgmtDb.h
src/mnode/inc/mgmtDb.h
+1
-1
src/mnode/src/mgmtAcct.c
src/mnode/src/mgmtAcct.c
+13
-20
src/mnode/src/mgmtSdb.c
src/mnode/src/mgmtSdb.c
+0
-2
src/mnode/src/mgmtShell.c
src/mnode/src/mgmtShell.c
+8
-13
src/mnode/src/mgmtUser.c
src/mnode/src/mgmtUser.c
+27
-42
未找到文件。
src/inc/mnode.h
浏览文件 @
07fe4def
...
@@ -181,7 +181,6 @@ typedef struct _user_obj {
...
@@ -181,7 +181,6 @@ typedef struct _user_obj {
int8_t
writeAuth
;
int8_t
writeAuth
;
int8_t
reserved
[
13
];
int8_t
reserved
[
13
];
int8_t
updateEnd
[
1
];
int8_t
updateEnd
[
1
];
struct
_user_obj
*
prev
,
*
next
;
struct
_acctObj
*
pAcct
;
struct
_acctObj
*
pAcct
;
SQqueryList
*
pQList
;
// query list
SQqueryList
*
pQList
;
// query list
SStreamList
*
pSList
;
// stream list
SStreamList
*
pSList
;
// stream list
...
@@ -216,7 +215,6 @@ typedef struct _acctObj {
...
@@ -216,7 +215,6 @@ typedef struct _acctObj {
int8_t
updateEnd
[
1
];
int8_t
updateEnd
[
1
];
SAcctInfo
acctInfo
;
SAcctInfo
acctInfo
;
SDbObj
*
pHead
;
SDbObj
*
pHead
;
SUserObj
*
pUser
;
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
}
SAcctObj
;
}
SAcctObj
;
...
...
src/mnode/inc/mgmtAcct.h
浏览文件 @
07fe4def
...
@@ -30,6 +30,8 @@ typedef enum {
...
@@ -30,6 +30,8 @@ typedef enum {
int32_t
acctInit
();
int32_t
acctInit
();
void
acctCleanUp
();
void
acctCleanUp
();
SAcctObj
*
acctGetAcct
(
char
*
acctName
);
SAcctObj
*
acctGetAcct
(
char
*
acctName
);
void
acctIncRef
(
SAcctObj
*
pAcct
);
void
acctDecRef
(
SAcctObj
*
pAcct
);
int32_t
acctCheck
(
SAcctObj
*
pAcct
,
EAcctGrantType
type
);
int32_t
acctCheck
(
SAcctObj
*
pAcct
,
EAcctGrantType
type
);
void
acctAddDb
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
void
acctAddDb
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
);
...
...
src/mnode/inc/mgmtDb.h
浏览文件 @
07fe4def
...
@@ -28,7 +28,7 @@ void mgmtCleanUpDbs();
...
@@ -28,7 +28,7 @@ void mgmtCleanUpDbs();
SDbObj
*
mgmtGetDb
(
char
*
db
);
SDbObj
*
mgmtGetDb
(
char
*
db
);
SDbObj
*
mgmtGetDbByTableId
(
char
*
db
);
SDbObj
*
mgmtGetDbByTableId
(
char
*
db
);
void
mgmtIncDbRef
(
SDbObj
*
pDb
);
void
mgmtIncDbRef
(
SDbObj
*
pDb
);
void
mgmtDecDbRef
(
SDbObj
*
pDb
)
void
mgmtDecDbRef
(
SDbObj
*
pDb
)
;
bool
mgmtCheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
);
bool
mgmtCheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
);
void
mgmtDropAllDbs
(
SAcctObj
*
pAcct
);
void
mgmtDropAllDbs
(
SAcctObj
*
pAcct
);
...
...
src/mnode/src/mgmtAcct.c
浏览文件 @
07fe4def
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#include "taoserror.h"
#include "taoserror.h"
#include "mnode.h"
#include "mnode.h"
#include "mgmtAcct.h"
#include "mgmtAcct.h"
#include "mgmtDb.h"
#include "mgmtUser.h"
#ifndef _ACCOUNT
#ifndef _ACCOUNT
static
SAcctObj
tsAcctObj
=
{
0
};
static
SAcctObj
tsAcctObj
=
{
0
};
...
@@ -30,6 +32,8 @@ int32_t acctInit() {
...
@@ -30,6 +32,8 @@ int32_t acctInit() {
void
acctCleanUp
()
{}
void
acctCleanUp
()
{}
SAcctObj
*
acctGetAcct
(
char
*
acctName
)
{
return
&
tsAcctObj
;
}
SAcctObj
*
acctGetAcct
(
char
*
acctName
)
{
return
&
tsAcctObj
;
}
void
acctIncRef
(
SAcctObj
*
pAcct
)
{}
void
acctDecRef
(
SAcctObj
*
pAcct
)
{}
int32_t
acctCheck
(
SAcctObj
*
pAcct
,
EAcctGrantType
type
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
acctCheck
(
SAcctObj
*
pAcct
,
EAcctGrantType
type
)
{
return
TSDB_CODE_SUCCESS
;
}
#endif
#endif
...
@@ -46,6 +50,8 @@ void acctAddDb(SAcctObj *pAcct, SDbObj *pDb) {
...
@@ -46,6 +50,8 @@ void acctAddDb(SAcctObj *pAcct, SDbObj *pDb) {
pAcct
->
pHead
=
pDb
;
pAcct
->
pHead
=
pDb
;
pAcct
->
acctInfo
.
numOfDbs
++
;
pAcct
->
acctInfo
.
numOfDbs
++
;
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
mgmtIncDbRef
(
pDb
);
}
}
void
acctRemoveDb
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
void
acctRemoveDb
(
SAcctObj
*
pAcct
,
SDbObj
*
pDb
)
{
...
@@ -64,37 +70,24 @@ void acctRemoveDb(SAcctObj *pAcct, SDbObj *pDb) {
...
@@ -64,37 +70,24 @@ void acctRemoveDb(SAcctObj *pAcct, SDbObj *pDb) {
pAcct
->
acctInfo
.
numOfDbs
--
;
pAcct
->
acctInfo
.
numOfDbs
--
;
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
mgmtDecDbRef
(
pDb
);
}
}
void
acctAddUser
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
void
acctAddUser
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
pthread_mutex_lock
(
&
pAcct
->
mutex
);
pthread_mutex_lock
(
&
pAcct
->
mutex
);
pUser
->
next
=
pAcct
->
pUser
;
pUser
->
prev
=
NULL
;
if
(
pAcct
->
pUser
)
{
pAcct
->
pUser
->
prev
=
pUser
;
}
pAcct
->
pUser
=
pUser
;
pAcct
->
acctInfo
.
numOfUsers
++
;
pAcct
->
acctInfo
.
numOfUsers
++
;
pUser
->
pAcct
=
pAcct
;
pUser
->
pAcct
=
pAcct
;
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
mgmtIncUserRef
(
pUser
);
}
}
void
acctRemoveUser
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
void
acctRemoveUser
(
SAcctObj
*
pAcct
,
SUserObj
*
pUser
)
{
pthread_mutex_lock
(
&
pAcct
->
mutex
);
pthread_mutex_lock
(
&
pAcct
->
mutex
);
if
(
pUser
->
prev
)
{
pUser
->
prev
->
next
=
pUser
->
next
;
}
if
(
pUser
->
next
)
{
pUser
->
next
->
prev
=
pUser
->
prev
;
}
if
(
pUser
->
prev
==
NULL
)
{
pAcct
->
pUser
=
pUser
->
next
;
}
pAcct
->
acctInfo
.
numOfUsers
--
;
pAcct
->
acctInfo
.
numOfUsers
--
;
pUser
->
pAcct
=
NULL
;
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
pthread_mutex_unlock
(
&
pAcct
->
mutex
);
mgmtDecUserRef
(
pUser
);
}
}
\ No newline at end of file
src/mnode/src/mgmtSdb.c
浏览文件 @
07fe4def
...
@@ -325,7 +325,6 @@ static int32_t sdbInitTableByFile(SSdbTable *pTable) {
...
@@ -325,7 +325,6 @@ static int32_t sdbInitTableByFile(SSdbTable *pTable) {
.
pObj
=
pMetaRow
.
pObj
=
pMetaRow
};
};
sdbDecRef
(
pTable
,
pMetaRow
);
sdbDecRef
(
pTable
,
pMetaRow
);
(
*
pTable
->
destroyFp
)(
&
oper
);
(
*
sdbDeleteIndexFp
[
pTable
->
keyType
])(
pTable
->
iHandle
,
rowHead
->
data
);
(
*
sdbDeleteIndexFp
[
pTable
->
keyType
])(
pTable
->
iHandle
,
rowHead
->
data
);
pTable
->
numOfRows
--
;
pTable
->
numOfRows
--
;
sdbTrace
(
"table:%s, version:%"
PRId64
" numOfRows:%d, read deleted record:%s"
,
sdbTrace
(
"table:%s, version:%"
PRId64
" numOfRows:%d, read deleted record:%s"
,
...
@@ -342,7 +341,6 @@ static int32_t sdbInitTableByFile(SSdbTable *pTable) {
...
@@ -342,7 +341,6 @@ static int32_t sdbInitTableByFile(SSdbTable *pTable) {
.
pObj
=
pMetaRow
.
pObj
=
pMetaRow
};
};
sdbDecRef
(
pTable
,
pMetaRow
);
sdbDecRef
(
pTable
,
pMetaRow
);
(
*
pTable
->
destroyFp
)(
&
oper
);
(
*
sdbDeleteIndexFp
[
pTable
->
keyType
])(
pTable
->
iHandle
,
rowHead
->
data
);
(
*
sdbDeleteIndexFp
[
pTable
->
keyType
])(
pTable
->
iHandle
,
rowHead
->
data
);
int32_t
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
int32_t
code
=
(
*
pTable
->
decodeFp
)(
&
oper
);
...
...
src/mnode/src/mgmtShell.c
浏览文件 @
07fe4def
...
@@ -117,6 +117,7 @@ void mgmtAddShellShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
...
@@ -117,6 +117,7 @@ void mgmtAddShellShowRetrieveHandle(uint8_t msgType, SShowRetrieveFp fp) {
void
mgmtProcessTranRequest
(
SSchedMsg
*
sched
)
{
void
mgmtProcessTranRequest
(
SSchedMsg
*
sched
)
{
SQueuedMsg
*
queuedMsg
=
sched
->
msg
;
SQueuedMsg
*
queuedMsg
=
sched
->
msg
;
(
*
tsMgmtProcessShellMsgFp
[
queuedMsg
->
msgType
])(
queuedMsg
);
(
*
tsMgmtProcessShellMsgFp
[
queuedMsg
->
msgType
])(
queuedMsg
);
mgmtDecUserRef
(
queuedMsg
->
pUser
);
rpcFreeCont
(
queuedMsg
->
pCont
);
rpcFreeCont
(
queuedMsg
->
pCont
);
free
(
queuedMsg
);
free
(
queuedMsg
);
}
}
...
@@ -167,6 +168,7 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
...
@@ -167,6 +168,7 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
queuedMsg
.
pUser
=
pUser
;
queuedMsg
.
pUser
=
pUser
;
queuedMsg
.
usePublicIp
=
usePublicIp
;
queuedMsg
.
usePublicIp
=
usePublicIp
;
(
*
tsMgmtProcessShellMsgFp
[
rpcMsg
->
msgType
])(
&
queuedMsg
);
(
*
tsMgmtProcessShellMsgFp
[
rpcMsg
->
msgType
])(
&
queuedMsg
);
mgmtDecUserRef
(
pUser
);
rpcFreeCont
(
rpcMsg
->
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
}
else
{
}
else
{
SQueuedMsg
*
queuedMsg
=
calloc
(
1
,
sizeof
(
SQueuedMsg
));
SQueuedMsg
*
queuedMsg
=
calloc
(
1
,
sizeof
(
SQueuedMsg
));
...
@@ -354,9 +356,11 @@ static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secr
...
@@ -354,9 +356,11 @@ static int mgmtShellRetriveAuth(char *user, char *spi, char *encrypt, char *secr
SUserObj
*
pUser
=
mgmtGetUser
(
user
);
SUserObj
*
pUser
=
mgmtGetUser
(
user
);
if
(
pUser
==
NULL
)
{
if
(
pUser
==
NULL
)
{
*
secret
=
0
;
*
secret
=
0
;
mgmtDecUserRef
(
pUser
);
return
TSDB_CODE_INVALID_USER
;
return
TSDB_CODE_INVALID_USER
;
}
else
{
}
else
{
memcpy
(
secret
,
pUser
->
pass
,
TSDB_KEY_LEN
);
memcpy
(
secret
,
pUser
->
pass
,
TSDB_KEY_LEN
);
mgmtDecUserRef
(
pUser
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
}
}
...
@@ -372,28 +376,19 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
...
@@ -372,28 +376,19 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
}
}
int32_t
code
;
int32_t
code
;
SUserObj
*
pUser
=
mgmtGetUser
(
connInfo
.
user
);
if
(
pUser
==
NULL
)
{
code
=
TSDB_CODE_INVALID_USER
;
goto
connect_over
;
}
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_GRANT_EXPIRED
;
code
=
TSDB_CODE_GRANT_EXPIRED
;
goto
connect_over
;
goto
connect_over
;
}
}
SAcctObj
*
pAcct
=
acctGetAcct
(
pUser
->
acct
);
if
(
pAcct
==
NULL
)
{
code
=
TSDB_CODE_INVALID_ACCT
;
goto
connect_over
;
}
code
=
taosCheckVersion
(
pConnectMsg
->
clientVersion
,
version
,
3
);
code
=
taosCheckVersion
(
pConnectMsg
->
clientVersion
,
version
,
3
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
connect_over
;
goto
connect_over
;
}
}
SUserObj
*
pUser
=
pMsg
->
pUser
;
SAcctObj
*
pAcct
=
pUser
->
pAcct
;
if
(
pConnectMsg
->
db
[
0
])
{
if
(
pConnectMsg
->
db
[
0
])
{
char
dbName
[
TSDB_TABLE_ID_LEN
*
3
]
=
{
0
};
char
dbName
[
TSDB_TABLE_ID_LEN
*
3
]
=
{
0
};
sprintf
(
dbName
,
"%x%s%s"
,
pAcct
->
acctId
,
TS_PATH_DELIMITER
,
pConnectMsg
->
db
);
sprintf
(
dbName
,
"%x%s%s"
,
pAcct
->
acctId
,
TS_PATH_DELIMITER
,
pConnectMsg
->
db
);
...
@@ -415,7 +410,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
...
@@ -415,7 +410,7 @@ static void mgmtProcessConnectMsg(SQueuedMsg *pMsg) {
pConnectRsp
->
writeAuth
=
pUser
->
writeAuth
;
pConnectRsp
->
writeAuth
=
pUser
->
writeAuth
;
pConnectRsp
->
superAuth
=
pUser
->
superAuth
;
pConnectRsp
->
superAuth
=
pUser
->
superAuth
;
if
(
connInfo
.
serverIp
==
tsPublicIpInt
)
{
if
(
pMsg
->
usePublicIp
)
{
mgmtGetMnodePublicIpList
(
&
pConnectRsp
->
ipList
);
mgmtGetMnodePublicIpList
(
&
pConnectRsp
->
ipList
);
}
else
{
}
else
{
mgmtGetMnodePrivateIpList
(
&
pConnectRsp
->
ipList
);
mgmtGetMnodePrivateIpList
(
&
pConnectRsp
->
ipList
);
...
...
src/mnode/src/mgmtUser.c
浏览文件 @
07fe4def
...
@@ -25,14 +25,10 @@
...
@@ -25,14 +25,10 @@
#include "mgmtShell.h"
#include "mgmtShell.h"
#include "mgmtUser.h"
#include "mgmtUser.h"
void
*
tsUserSdb
=
NULL
;
static
void
*
tsUserSdb
=
NULL
;
static
int32_t
tsUserUpdateSize
=
0
;
static
int32_t
tsUserUpdateSize
=
0
;
static
int32_t
mgmtDropUser
(
SAcctObj
*
pAcct
,
char
*
name
);
static
int32_t
mgmtUpdateUser
(
SUserObj
*
pUser
);
static
int32_t
mgmtGetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtGetUserMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mgmtRetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mgmtRetrieveUsers
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
void
mgmtProcessCreateUserMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessCreateUserMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessAlterUserMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessAlterUserMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessDropUserMsg
(
SQueuedMsg
*
pMsg
);
static
void
mgmtProcessDropUserMsg
(
SQueuedMsg
*
pMsg
);
...
@@ -48,7 +44,7 @@ static int32_t mgmtUserActionInsert(SSdbOperDesc *pOper) {
...
@@ -48,7 +44,7 @@ static int32_t mgmtUserActionInsert(SSdbOperDesc *pOper) {
if
(
pAcct
!=
NULL
)
{
if
(
pAcct
!=
NULL
)
{
acctAddUser
(
pAcct
,
pUser
);
acctAddUser
(
pAcct
,
pUser
);
mgmtIncUserRef
(
pUser
);
acctDecRef
(
pAcct
);
}
}
else
{
else
{
mError
(
"user:%s, acct:%s info not exist in sdb"
,
pUser
->
user
,
pUser
->
acct
);
mError
(
"user:%s, acct:%s info not exist in sdb"
,
pUser
->
user
,
pUser
->
acct
);
...
@@ -64,7 +60,7 @@ static int32_t mgmtUserActionDelete(SSdbOperDesc *pOper) {
...
@@ -64,7 +60,7 @@ static int32_t mgmtUserActionDelete(SSdbOperDesc *pOper) {
if
(
pAcct
!=
NULL
)
{
if
(
pAcct
!=
NULL
)
{
acctRemoveUser
(
pAcct
,
pUser
);
acctRemoveUser
(
pAcct
,
pUser
);
mgmtDecUserRef
(
pUser
);
acctDecRef
(
pAcct
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -122,6 +118,7 @@ int32_t mgmtInitUsers() {
...
@@ -122,6 +118,7 @@ int32_t mgmtInitUsers() {
mgmtCreateUser
(
pAcct
,
"root"
,
"taosdata"
);
mgmtCreateUser
(
pAcct
,
"root"
,
"taosdata"
);
mgmtCreateUser
(
pAcct
,
"monitor"
,
tsInternalPass
);
mgmtCreateUser
(
pAcct
,
"monitor"
,
tsInternalPass
);
mgmtCreateUser
(
pAcct
,
"_root"
,
tsInternalPass
);
mgmtCreateUser
(
pAcct
,
"_root"
,
tsInternalPass
);
acctDecRef
(
pAcct
);
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_USER
,
mgmtProcessCreateUserMsg
);
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_USER
,
mgmtProcessCreateUserMsg
);
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_USER
,
mgmtProcessAlterUserMsg
);
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_USER
,
mgmtProcessAlterUserMsg
);
...
@@ -159,7 +156,6 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
...
@@ -159,7 +156,6 @@ static int32_t mgmtUpdateUser(SUserObj *pUser) {
int32_t
code
=
sdbUpdateRow
(
&
oper
);
int32_t
code
=
sdbUpdateRow
(
&
oper
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
pUser
);
code
=
TSDB_CODE_SDB_ERROR
;
code
=
TSDB_CODE_SDB_ERROR
;
}
}
...
@@ -176,9 +172,10 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
...
@@ -176,9 +172,10 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return
TSDB_CODE_INVALID_MSG
;
return
TSDB_CODE_INVALID_MSG
;
}
}
SUserObj
*
pUser
=
(
SUserObj
*
)
sdbGetRow
(
tsUserSdb
,
name
);
SUserObj
*
pUser
=
mgmtGetUser
(
name
);
if
(
pUser
!=
NULL
)
{
if
(
pUser
!=
NULL
)
{
mTrace
(
"user:%s is already there"
,
name
);
mTrace
(
"user:%s is already there"
,
name
);
mgmtDecUserRef
(
pUser
);
return
TSDB_CODE_USER_ALREADY_EXIST
;
return
TSDB_CODE_USER_ALREADY_EXIST
;
}
}
...
@@ -214,19 +211,7 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
...
@@ -214,19 +211,7 @@ int32_t mgmtCreateUser(SAcctObj *pAcct, char *name, char *pass) {
return
code
;
return
code
;
}
}
static
int32_t
mgmtDropUser
(
SAcctObj
*
pAcct
,
char
*
name
)
{
static
int32_t
mgmtDropUser
(
SUserObj
*
pUser
)
{
SUserObj
*
pUser
;
pUser
=
(
SUserObj
*
)
sdbGetRow
(
tsUserSdb
,
name
);
if
(
pUser
==
NULL
)
{
mWarn
(
"user:%s is not there"
,
name
);
return
TSDB_CODE_INVALID_USER
;
}
if
(
strcmp
(
pAcct
->
user
,
pUser
->
acct
)
!=
0
)
{
return
TSDB_CODE_NO_RIGHTS
;
}
SSdbOperDesc
oper
=
{
SSdbOperDesc
oper
=
{
.
type
=
SDB_OPER_TYPE_GLOBAL
,
.
type
=
SDB_OPER_TYPE_GLOBAL
,
.
table
=
tsUserSdb
,
.
table
=
tsUserSdb
,
...
@@ -278,9 +263,9 @@ static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon
...
@@ -278,9 +263,9 @@ static int32_t mgmtGetUserMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pCon
}
}
pShow
->
numOfRows
=
pUser
->
pAcct
->
acctInfo
.
numOfUsers
;
pShow
->
numOfRows
=
pUser
->
pAcct
->
acctInfo
.
numOfUsers
;
pShow
->
pNode
=
pUser
->
pAcct
->
pUser
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
mgmtDecUserRef
(
pUser
);
return
0
;
return
0
;
}
}
...
@@ -291,10 +276,9 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
...
@@ -291,10 +276,9 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
char
*
pWrite
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
while
(
numOfRows
<
rows
)
{
p
User
=
(
SUserObj
*
)
pShow
->
pNode
;
p
Show
->
pNode
=
sdbFetchRow
(
tsUserSdb
,
pShow
->
pNode
,
(
void
**
)
&
pUser
)
;
if
(
pUser
==
NULL
)
break
;
if
(
pUser
==
NULL
)
break
;
pShow
->
pNode
=
(
void
*
)
pUser
->
next
;
cols
=
0
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
...
@@ -316,6 +300,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
...
@@ -316,6 +300,7 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
cols
++
;
cols
++
;
numOfRows
++
;
numOfRows
++
;
mgmtDecUserRef
(
pUser
);
}
}
pShow
->
numOfReads
+=
numOfRows
;
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
return
numOfRows
;
...
@@ -367,6 +352,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
...
@@ -367,6 +352,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtDecUserRef
(
pUser
);
return
;
return
;
}
}
...
@@ -396,10 +382,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
...
@@ -396,10 +382,7 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
}
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
}
else
if
((
pAlter
->
flag
&
TSDB_ALTER_USER_PRIVILEGES
)
!=
0
)
{
}
if
((
pAlter
->
flag
&
TSDB_ALTER_USER_PRIVILEGES
)
!=
0
)
{
bool
hasRight
=
false
;
bool
hasRight
=
false
;
if
(
strcmp
(
pUser
->
user
,
"root"
)
==
0
)
{
if
(
strcmp
(
pUser
->
user
,
"root"
)
==
0
)
{
...
@@ -441,10 +424,11 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
...
@@ -441,10 +424,11 @@ static void mgmtProcessAlterUserMsg(SQueuedMsg *pMsg) {
}
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
return
;
}
else
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
}
}
mgmt
SendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmt
DecUserRef
(
pUser
);
}
}
static
void
mgmtProcessDropUserMsg
(
SQueuedMsg
*
pMsg
)
{
static
void
mgmtProcessDropUserMsg
(
SQueuedMsg
*
pMsg
)
{
...
@@ -463,6 +447,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
...
@@ -463,6 +447,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
strcmp
(
pUser
->
user
,
pUser
->
acct
)
==
0
||
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
strcmp
(
pUser
->
user
,
pUser
->
acct
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_NO_RIGHTS
);
mgmtDecUserRef
(
pUser
);
return
;
return
;
}
}
...
@@ -474,9 +459,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
...
@@ -474,9 +459,7 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
}
else
if
(
strcmp
(
pUser
->
user
,
pOperUser
->
user
)
==
0
)
{
}
else
if
(
strcmp
(
pUser
->
user
,
pOperUser
->
user
)
==
0
)
{
hasRight
=
false
;
hasRight
=
false
;
}
else
if
(
pOperUser
->
superAuth
)
{
}
else
if
(
pOperUser
->
superAuth
)
{
if
(
strcmp
(
pUser
->
user
,
"root"
)
==
0
)
{
if
(
strcmp
(
pOperUser
->
acct
,
pUser
->
acct
)
!=
0
)
{
hasRight
=
false
;
}
else
if
(
strcmp
(
pOperUser
->
acct
,
pUser
->
acct
)
!=
0
)
{
hasRight
=
false
;
hasRight
=
false
;
}
else
{
}
else
{
hasRight
=
true
;
hasRight
=
true
;
...
@@ -484,22 +467,23 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
...
@@ -484,22 +467,23 @@ static void mgmtProcessDropUserMsg(SQueuedMsg *pMsg) {
}
}
if
(
hasRight
)
{
if
(
hasRight
)
{
code
=
mgmtDropUser
(
pUser
->
pAcct
,
pDrop
->
user
);
code
=
mgmtDropUser
(
pUser
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"user:%s is dropped by %s, result:%
d
"
,
pUser
->
user
,
pOperUser
->
user
,
tstrerror
(
code
));
mLPrint
(
"user:%s is dropped by %s, result:%
s
"
,
pUser
->
user
,
pOperUser
->
user
,
tstrerror
(
code
));
}
}
}
else
{
}
else
{
code
=
TSDB_CODE_NO_RIGHTS
;
code
=
TSDB_CODE_NO_RIGHTS
;
}
}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
mgmtDecUserRef
(
pUser
);
}
}
void
mgmtDropAllUsers
(
SAcctObj
*
pAcct
)
{
void
mgmtDropAllUsers
(
SAcctObj
*
pAcct
)
{
void
*
pNode
=
NULL
;
void
*
pNode
=
NULL
;
void
*
pLastNode
=
NULL
;
void
*
pLastNode
=
NULL
;
int32_t
numOfUsers
=
0
;
int32_t
numOfUsers
=
0
;
int32_t
acctNameLen
=
strlen
(
pAcct
->
user
);
int32_t
acctNameLen
=
strlen
(
pAcct
->
user
);
SUserObj
*
pUser
=
NULL
;
SUserObj
*
pUser
=
NULL
;
while
(
1
)
{
while
(
1
)
{
...
@@ -516,8 +500,9 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
...
@@ -516,8 +500,9 @@ void mgmtDropAllUsers(SAcctObj *pAcct) {
sdbDeleteRow
(
&
oper
);
sdbDeleteRow
(
&
oper
);
pNode
=
pLastNode
;
pNode
=
pLastNode
;
numOfUsers
++
;
numOfUsers
++
;
continue
;
}
}
mgmtDecUserRef
(
pUser
);
}
}
mTrace
(
"acct:%s, all users:%d is dropped from sdb"
,
pAcct
->
user
,
numOfUsers
);
mTrace
(
"acct:%s, all users:%d is dropped from sdb"
,
pAcct
->
user
,
numOfUsers
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录