Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7392e731
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看板
提交
7392e731
编写于
10月 18, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
default user
上级
e91c99eb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
115 addition
and
3 deletion
+115
-3
source/server/mnode/inc/mnodeDef.h
source/server/mnode/inc/mnodeDef.h
+2
-0
source/server/mnode/src/mnodeSdb.c
source/server/mnode/src/mnodeSdb.c
+1
-0
source/server/mnode/src/mnodeUser.c
source/server/mnode/src/mnodeUser.c
+112
-3
未找到文件。
source/server/mnode/inc/mnodeDef.h
浏览文件 @
7392e731
...
...
@@ -20,6 +20,7 @@
#include "tlog.h"
#include "trpc.h"
#include "ttimer.h"
#include "thash.h"
#include "cJSON.h"
#include "mnode.h"
...
...
@@ -177,6 +178,7 @@ typedef struct SUserObj {
int64_t
createdTime
;
int64_t
updateTime
;
int8_t
rootAuth
;
SHashObj
*
prohibitDbHash
;
SAcctObj
*
pAcct
;
}
SUserObj
;
...
...
source/server/mnode/src/mnodeSdb.c
浏览文件 @
7392e731
...
...
@@ -148,6 +148,7 @@ static int32_t sdbReadDataFile() {
pHead
->
status
=
MN_SDB_STAT_AVAIL
;
sdbInsertRow
(
pHead
->
type
,
pHead
);
free
(
pHead
);
cJSON_Delete
(
root
);
root
=
NULL
;
}
...
...
source/server/mnode/src/mnodeUser.c
浏览文件 @
7392e731
...
...
@@ -15,7 +15,116 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "mnodeInt.h"
#include "tkey.h"
#include "tglobal.h"
#include "mnodeSdb.h"
int32_t
mnodeInitUser
()
{
return
0
;
}
void
mnodeCleanupUser
()
{}
\ No newline at end of file
static
int32_t
mnodeCreateDefaultUser
(
char
*
acct
,
char
*
user
,
char
*
pass
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SUserObj
userObj
=
{
0
};
tstrncpy
(
userObj
.
user
,
user
,
TSDB_USER_LEN
);
tstrncpy
(
userObj
.
acct
,
acct
,
TSDB_USER_LEN
);
taosEncryptPass
((
uint8_t
*
)
pass
,
strlen
(
pass
),
userObj
.
pass
);
userObj
.
createdTime
=
taosGetTimestampMs
();
userObj
.
updateTime
=
taosGetTimestampMs
();
if
(
strcmp
(
user
,
TSDB_DEFAULT_USER
)
==
0
)
{
userObj
.
rootAuth
=
1
;
}
sdbInsertRow
(
MN_SDB_USER
,
&
userObj
);
}
static
void
mnodeCreateDefaultUsers
()
{
mnodeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_USER
,
TSDB_DEFAULT_PASS
);
mnodeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
"monitor"
,
tsInternalPass
);
mnodeCreateDefaultUser
(
TSDB_DEFAULT_USER
,
"_"
TSDB_DEFAULT_USER
,
tsInternalPass
);
}
int32_t
mnodeEncodeUser
(
SUserObj
*
pUser
,
char
*
buf
,
int32_t
maxLen
)
{
int32_t
len
=
0
;
char
*
base64
=
base64_encode
((
const
unsigned
char
*
)
pUser
->
pass
,
TSDB_KEY_LEN
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"{
\"
type
\"
:%d, "
,
MN_SDB_USER
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"
\"
user
\"
:
\"
%s
\"
, "
,
pUser
->
user
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"
\"
auth
\"
:
\"
%24s
\"
, "
,
base64
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"
\"
acct
\"
:
\"
%s
\"
, "
,
pUser
->
acct
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"
\"
createdTime
\"
:
\"
%"
PRIu64
"
\"
, "
,
pUser
->
createdTime
);
len
+=
snprintf
(
buf
+
len
,
maxLen
-
len
,
"
\"
updateTime
\"
:
\"
%"
PRIu64
"
\"
}
\n
"
,
pUser
->
updateTime
);
free
(
base64
);
return
len
;
}
SUserObj
*
mnodeDecodeUser
(
cJSON
*
root
)
{
int32_t
code
=
-
1
;
SUserObj
*
pUser
=
calloc
(
1
,
sizeof
(
SUserObj
));
cJSON
*
user
=
cJSON_GetObjectItem
(
root
,
"user"
);
if
(
!
user
||
user
->
type
!=
cJSON_String
)
{
mError
(
"failed to parse user since user not found"
);
goto
DECODE_USER_OVER
;
}
tstrncpy
(
pUser
->
user
,
user
->
valuestring
,
TSDB_USER_LEN
);
if
(
strcmp
(
pUser
->
user
,
TSDB_DEFAULT_USER
)
==
0
)
{
pUser
->
rootAuth
=
1
;
}
cJSON
*
pass
=
cJSON_GetObjectItem
(
root
,
"auth"
);
if
(
!
pass
||
pass
->
type
!=
cJSON_String
)
{
mError
(
"user:%s, failed to parse since auth not found"
,
pUser
->
user
);
goto
DECODE_USER_OVER
;
}
int32_t
outlen
=
0
;
char
*
base64
=
(
char
*
)
base64_decode
(
pass
->
valuestring
,
strlen
(
pass
->
valuestring
),
&
outlen
);
if
(
outlen
!=
TSDB_KEY_LEN
)
{
mError
(
"user:%s, failed to parse since invalid auth format"
,
pUser
->
user
);
free
(
base64
);
goto
DECODE_USER_OVER
;
}
else
{
memcpy
(
pUser
->
pass
,
base64
,
outlen
);
free
(
base64
);
}
cJSON
*
acct
=
cJSON_GetObjectItem
(
root
,
"acct"
);
if
(
!
acct
||
acct
->
type
!=
cJSON_String
)
{
mError
(
"user:%s, failed to parse since acct not found"
,
pUser
->
user
);
goto
DECODE_USER_OVER
;
}
tstrncpy
(
pUser
->
acct
,
acct
->
valuestring
,
TSDB_USER_LEN
);
cJSON
*
createdTime
=
cJSON_GetObjectItem
(
root
,
"createdTime"
);
if
(
!
createdTime
||
createdTime
->
type
!=
cJSON_String
)
{
mError
(
"user:%s, failed to parse since createdTime not found"
,
pUser
->
user
);
goto
DECODE_USER_OVER
;
}
pUser
->
createdTime
=
atol
(
createdTime
->
valuestring
);
cJSON
*
updateTime
=
cJSON_GetObjectItem
(
root
,
"updateTime"
);
if
(
!
updateTime
||
updateTime
->
type
!=
cJSON_String
)
{
mError
(
"user:%s, failed to parse since updateTime not found"
,
pUser
->
user
);
goto
DECODE_USER_OVER
;
}
pUser
->
updateTime
=
atol
(
updateTime
->
valuestring
);
code
=
0
;
mTrace
(
"user:%s, parse success"
,
pUser
->
user
);
DECODE_USER_OVER:
if
(
code
!=
0
)
{
free
(
pUser
);
pUser
=
NULL
;
}
return
pUser
;
}
int32_t
mnodeInitUser
()
{
sdbSetFp
(
MN_SDB_USER
,
MN_KEY_BINARY
,
mnodeCreateDefaultUsers
,
(
SdbEncodeFp
)
mnodeEncodeUser
,
(
SdbDecodeFp
)(
mnodeDecodeUser
),
sizeof
(
SUserObj
));
return
0
;
}
void
mnodeCleanupUser
()
{}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录