Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
6d70eb69
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6d70eb69
编写于
3月 30, 2022
作者:
O
openharmony_ci
提交者:
Gitee
3月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
!445 修复param set的bug
Merge pull request !445 from 熊磊/fixbug
上级
e1871f58
ac5d117c
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
165 addition
and
167 deletion
+165
-167
services/begetctl/param_cmd.c
services/begetctl/param_cmd.c
+5
-5
services/begetctl/shell/shell_bas.c
services/begetctl/shell/shell_bas.c
+4
-1
services/begetctl/shell/shell_bas.h
services/begetctl/shell/shell_bas.h
+1
-1
services/etc/group
services/etc/group
+1
-0
services/etc/param/ohos.para.dac
services/etc/param/ohos.para.dac
+14
-17
services/loopevent/include/loop_event.h
services/loopevent/include/loop_event.h
+1
-1
services/param/adapter/param_dac.c
services/param/adapter/param_dac.c
+39
-37
services/param/client/param_request.c
services/param/client/param_request.c
+3
-0
services/param/include/param_manager.h
services/param/include/param_manager.h
+2
-1
services/param/include/param_utils.h
services/param/include/param_utils.h
+2
-0
services/param/manager/param_manager.c
services/param/manager/param_manager.c
+17
-0
services/param/manager/param_utils.c
services/param/manager/param_utils.c
+67
-0
services/param/service/param_service.c
services/param/service/param_service.c
+9
-104
未找到文件。
services/begetctl/param_cmd.c
100644 → 100755
浏览文件 @
6d70eb69
...
...
@@ -91,7 +91,7 @@ static char *GetRealParameter(BShellHandle shell, const char *name, char *buffer
}
else
{
realLen
=
sprintf_s
(
buffer
,
buffSize
,
"%s"
,
name
);
}
BSH_CHECK
(
realLen
>
0
,
return
NULL
,
"Failed to format buffer"
);
BSH_CHECK
(
realLen
>
=
0
,
return
NULL
,
"Failed to format buffer"
);
buffer
[
realLen
]
=
'\0'
;
BSH_LOGV
(
"GetRealParameter current %s input %s real %s"
,
current
,
name
,
buffer
);
return
buffer
;
...
...
@@ -159,7 +159,7 @@ static void ShowParam(BShellHandle shell, const char *name, const char *value)
BSH_LOGE
(
"Failed to get param security for %s"
,
name
);
return
;
}
char
permissionStr
[
MASK_LENGTH_MAX
]
=
{
'-'
,
'-'
,
'-'
,
0
};
char
permissionStr
[
3
][
MASK_LENGTH_MAX
]
=
{};
// 3 permission
struct
passwd
*
user
=
getpwuid
(
auditData
.
dacData
.
uid
);
struct
group
*
group
=
getgrgid
(
auditData
.
dacData
.
gid
);
if
(
user
==
NULL
||
group
==
NULL
)
{
...
...
@@ -168,9 +168,9 @@ static void ShowParam(BShellHandle shell, const char *name, const char *value)
}
BShellEnvOutput
(
shell
,
"Parameter infomation:
\r\n
"
);
BShellEnvOutput
(
shell
,
" dac : %s(%s) %s(%s) (%s)
\r\n
"
,
user
->
pw_name
,
GetPermissionString
(
auditData
.
dacData
.
mode
,
0
,
permissionStr
,
MASK_LENGTH_MAX
),
group
->
gr_name
,
GetPermissionString
(
auditData
.
dacData
.
mode
,
DAC_GROUP_START
,
permissionStr
,
MASK_LENGTH_MAX
),
GetPermissionString
(
auditData
.
dacData
.
mode
,
DAC_OTHER_START
,
permissionStr
,
MASK_LENGTH_MAX
));
user
->
pw_name
,
GetPermissionString
(
auditData
.
dacData
.
mode
,
0
,
permissionStr
[
0
]
,
MASK_LENGTH_MAX
),
group
->
gr_name
,
GetPermissionString
(
auditData
.
dacData
.
mode
,
DAC_GROUP_START
,
permissionStr
[
1
]
,
MASK_LENGTH_MAX
),
GetPermissionString
(
auditData
.
dacData
.
mode
,
DAC_OTHER_START
,
permissionStr
[
2
],
MASK_LENGTH_MAX
));
// 2 other
BShellEnvOutput
(
shell
,
" name : %s
\r\n
"
,
name
);
if
(
value
!=
NULL
)
{
BShellEnvOutput
(
shell
,
" value: %s
\r\n
"
,
value
);
...
...
services/begetctl/shell/shell_bas.c
浏览文件 @
6d70eb69
...
...
@@ -99,6 +99,9 @@ int32_t BShellEnvOutput(BShellHandle handle, char *fmt, ...)
int
len
=
vsnprintf_s
(
shell
->
data
,
sizeof
(
shell
->
data
),
sizeof
(
shell
->
data
)
-
1
,
fmt
,
list
);
va_end
(
list
);
if
(
len
<=
0
)
{
va_start
(
list
,
fmt
);
vfprintf
(
stdout
,
fmt
,
list
);
va_end
(
list
);
return
-
1
;
}
return
BShellEnvOutputString
(
handle
,
shell
->
data
);
...
...
@@ -301,7 +304,7 @@ static void BShellEnvHandleNormal(BShellHandle handle, uint8_t data)
}
else
{
BShellEnvOutputString
(
shell
,
BShellEnvErrString
(
handle
,
BSH_CMD_TOO_LONG
));
BShellEnvOutputString
(
shell
,
shell
->
prompt
);
BShellEnvOutputString
(
shell
,
shell
->
buffer
);
shell
->
cursor
=
shell
->
length
;
}
}
...
...
services/begetctl/shell/shell_bas.h
浏览文件 @
6d70eb69
...
...
@@ -27,7 +27,7 @@
#define BSH_KEY_CTRLC 0x03 // ctr + c
#define BSH_KEY_ESC 0x1B // ecs
#define BSH_COMMAND_MAX_LENGTH
256
#define BSH_COMMAND_MAX_LENGTH
(5 * 1024)
#define BSH_PARAMETER_MAX_NUMBER 10
#define BSH_CMD_NAME_END 48
#define BSH_CMD_MAX_KEY 5
...
...
services/etc/group
浏览文件 @
6d70eb69
...
...
@@ -25,6 +25,7 @@ logd:x:1036:
shared_relro:x:1037:
audio:x:1041:
cameraserver:x:1047:
servicectrl:x:1050:root,shell,system,samgr,hdf_devmgr
shell:x:2000:
cache:x:2001:
net_bw_stats:x:3006:
...
...
services/etc/param/ohos.para.dac
浏览文件 @
6d70eb69
...
...
@@ -11,23 +11,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.
build_version root:root:0777
hw_sc.build.os.enable root:root:0777
hw_sc.build.os.apiversion root:root:0777
hw_sc.build.os.version root:root:0777
hw_sc.build.os.releasetype root:root:0777
build_version
=
root:root:0777
hw_sc.build.os.enable
=
root:root:0777
hw_sc.build.os.apiversion
=
root:root:0777
hw_sc.build.os.version
=
root:root:0777
hw_sc.build.os.releasetype
=
root:root:0777
const.actionable_compatible_property.enabled root:root:0777
const.postinstall.fstab.prefix root:root:0777
const.secure root:root:0777
security.perf_harden root:root:0777
const.allow.mock.location root:root:0777
const.debuggable root:root:0777
persist.sys.usb.config root:root:0777
const.actionable_compatible_property.enabled
=
root:root:0777
const.postinstall.fstab.prefix
=
root:root:0777
const.secure
=
root:root:0777
security.perf_harden
=
root:root:0777
const.allow.mock.location
=
root:root:0777
const.debuggable
=
root:root:0777
persist.sys.usb.config
=
root:root:0777
# default forbit other user to start service
ohos.servicectrl. system:root:0777
test.permission. root:root:0770
test.permission.read. root:root:0774
test.permission.write. root:root:0772
test.permission.watcher. root:root:0771
\ No newline at end of file
ohos.servicectrl. = system:servicectrl:0775
services/loopevent/include/loop_event.h
浏览文件 @
6d70eb69
...
...
@@ -27,7 +27,7 @@ extern "C" {
// 配置
#define LOOP_EVENT_USE_EPOLL 1
#define LOOP_DEFAULT_BUFFER
1024
#define LOOP_DEFAULT_BUFFER
(1024 * 5)
#define LOOP_MAX_BUFFER (1024 * 64)
#define LOOP_MAX_CLIENT 1024
...
...
services/param/adapter/param_dac.c
浏览文件 @
6d70eb69
...
...
@@ -25,10 +25,9 @@
#define OCT_BASE 8
static
ParamSecurityLabel
g_localSecurityLabel
=
{};
static
void
GetUserIdByName
(
FILE
*
fp
,
uid_t
*
uid
,
const
char
*
name
,
uint32_t
nameLen
)
static
void
GetUserIdByName
(
uid_t
*
uid
,
const
char
*
name
,
uint32_t
nameLen
)
{
*
uid
=
-
1
;
(
void
)
fp
;
struct
passwd
*
data
=
NULL
;
while
((
data
=
getpwent
())
!=
NULL
)
{
if
((
data
->
pw_name
!=
NULL
)
&&
(
strlen
(
data
->
pw_name
)
==
nameLen
)
&&
...
...
@@ -40,10 +39,9 @@ static void GetUserIdByName(FILE *fp, uid_t *uid, const char *name, uint32_t nam
endpwent
();
}
static
void
GetGroupIdByName
(
FILE
*
fp
,
gid_t
*
gid
,
const
char
*
name
,
uint32_t
nameLen
)
static
void
GetGroupIdByName
(
gid_t
*
gid
,
const
char
*
name
,
uint32_t
nameLen
)
{
*
gid
=
-
1
;
(
void
)
fp
;
struct
group
*
data
=
NULL
;
while
((
data
=
getgrent
())
!=
NULL
)
{
if
((
data
->
gr_name
!=
NULL
)
&&
(
strlen
(
data
->
gr_name
)
==
nameLen
)
&&
...
...
@@ -56,7 +54,7 @@ static void GetGroupIdByName(FILE *fp, gid_t *gid, const char *name, uint32_t na
}
// user:group:r|w
static
int
GetParamDacData
(
FILE
*
fpForGroup
,
FILE
*
fpForUser
,
ParamDacData
*
dacData
,
const
char
*
value
)
static
int
GetParamDacData
(
ParamDacData
*
dacData
,
const
char
*
value
)
{
if
(
dacData
==
NULL
)
{
return
-
1
;
...
...
@@ -69,8 +67,8 @@ static int GetParamDacData(FILE *fpForGroup, FILE *fpForUser, ParamDacData *dacD
if
(
mode
==
NULL
)
{
return
-
1
;
}
GetUserIdByName
(
fpForUser
,
&
dacData
->
uid
,
value
,
groupName
-
value
);
GetGroupIdByName
(
fpForGroup
,
&
dacData
->
gid
,
groupName
+
1
,
mode
-
groupName
-
1
);
GetUserIdByName
(
&
dacData
->
uid
,
value
,
groupName
-
value
);
GetGroupIdByName
(
&
dacData
->
gid
,
groupName
+
1
,
mode
-
groupName
-
1
);
dacData
->
mode
=
strtol
(
mode
+
1
,
NULL
,
OCT_BASE
);
return
0
;
}
...
...
@@ -116,45 +114,49 @@ static int DecodeSecurityLabel(ParamSecurityLabel **srcLabel, const char *buffer
return
0
;
}
typedef
struct
{
SecurityLabelFunc
label
;
void
*
context
;
}
LoadContext
;
static
int
LoadOneParam_
(
const
uint32_t
*
context
,
const
char
*
name
,
const
char
*
value
)
{
LoadContext
*
loadContext
=
(
LoadContext
*
)
context
;
ParamAuditData
auditData
=
{
0
};
auditData
.
name
=
name
;
#ifdef STARTUP_INIT_TEST
auditData
.
label
=
value
;
#endif
int
ret
=
GetParamDacData
(
&
auditData
.
dacData
,
value
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to get param info %d %s"
,
ret
,
name
);
ret
=
loadContext
->
label
(
&
auditData
,
loadContext
->
context
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to write param info %d
\"
%s
\"
"
,
ret
,
name
);
return
0
;
}
static
int
LoadParamLabels
(
const
char
*
fileName
,
SecurityLabelFunc
label
,
void
*
context
)
{
LoadContext
loadContext
=
{
label
,
context
};
uint32_t
infoCount
=
0
;
ParamAuditData
auditData
=
{
0
};
FILE
*
fpForGroup
=
fopen
(
GROUP_FILE_PATH
,
"r"
);
FILE
*
fpForUser
=
fopen
(
USER_FILE_PATH
,
"r"
);
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
char
*
buff
=
(
char
*
)
calloc
(
1
,
PARAM_BUFFER_SIZE
);
SubStringInfo
*
info
=
calloc
(
1
,
sizeof
(
SubStringInfo
)
*
(
SUBSTR_INFO_DAC
+
1
));
while
(
fp
!=
NULL
&&
fpForGroup
!=
NULL
&&
fpForUser
!=
NULL
&&
info
!=
NULL
&&
buff
!=
NULL
&&
fgets
(
buff
,
PARAM_BUFFER_SIZE
,
fp
)
!=
NULL
)
{
buff
[
PARAM_BUFFER_SIZE
-
1
]
=
'\0'
;
int
subStrNumber
=
GetSubStringInfo
(
buff
,
strlen
(
buff
),
' '
,
info
,
SUBSTR_INFO_DAC
+
1
);
if
(
subStrNumber
<=
SUBSTR_INFO_DAC
)
{
const
uint32_t
buffSize
=
PARAM_NAME_LEN_MAX
+
PARAM_CONST_VALUE_LEN_MAX
+
10
;
// 10 size
char
*
buff
=
(
char
*
)
calloc
(
1
,
buffSize
);
while
(
fp
!=
NULL
&&
buff
!=
NULL
&&
fgets
(
buff
,
buffSize
,
fp
)
!=
NULL
)
{
buff
[
buffSize
-
1
]
=
'\0'
;
int
ret
=
SpliteString
(
buff
,
NULL
,
0
,
LoadOneParam_
,
(
uint32_t
*
)
&
loadContext
);
if
(
ret
!=
0
)
{
PARAM_LOGE
(
"Failed to splite string %s fileName %s"
,
buff
,
fileName
);
continue
;
}
auditData
.
name
=
info
[
SUBSTR_INFO_NAME
].
value
;
#ifdef STARTUP_INIT_TEST
auditData
.
label
=
info
[
SUBSTR_INFO_NAME
].
value
;
#endif
int
ret
=
GetParamDacData
(
fpForGroup
,
fpForUser
,
&
auditData
.
dacData
,
info
[
SUBSTR_INFO_DAC
].
value
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to get param info %d %s"
,
ret
,
buff
);
ret
=
label
(
&
auditData
,
context
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to write param info %d %s"
,
ret
,
buff
);
infoCount
++
;
}
PARAM_LOGI
(
"Load parameter label total %u success %s"
,
infoCount
,
fileName
);
if
(
fp
!=
NULL
)
{
(
void
)
fclose
(
fp
);
}
if
(
info
!=
NULL
)
{
free
(
info
);
}
if
(
fpForGroup
!=
NULL
)
{
(
void
)
fclose
(
fpForGroup
);
}
if
(
fpForUser
!=
NULL
)
{
(
void
)
fclose
(
fpForUser
);
}
if
(
buff
!=
NULL
)
{
free
(
buff
);
}
...
...
@@ -246,10 +248,10 @@ static int CheckParamPermission(const ParamSecurityLabel *srcLabel, const ParamA
if
((
auditData
->
dacData
.
mode
&
localMode
)
!=
0
)
{
ret
=
DAC_RESULT_PERMISSION
;
}
PARAM_LOG
V
(
"Src label gid:%d uid:%d "
,
srcLabel
->
cred
.
gid
,
srcLabel
->
cred
.
uid
);
PARAM_LOG
V
(
"local label gid:%d uid:%d mode %o"
,
PARAM_LOG
I
(
"Src label gid:%d uid:%d "
,
srcLabel
->
cred
.
gid
,
srcLabel
->
cred
.
uid
);
PARAM_LOG
I
(
"local label gid:%d uid:%d mode %o"
,
auditData
->
dacData
.
gid
,
auditData
->
dacData
.
uid
,
auditData
->
dacData
.
mode
);
PARAM_LOG
V
(
"%s check %o localMode %o ret %d"
,
auditData
->
name
,
mode
,
localMode
,
ret
);
PARAM_LOG
I
(
"%s check %o localMode %o ret %d"
,
auditData
->
name
,
mode
,
localMode
,
ret
);
return
ret
;
#endif
}
...
...
services/param/client/param_request.c
浏览文件 @
6d70eb69
...
...
@@ -182,6 +182,9 @@ int SystemSetParameter(const char *name, const char *value)
PARAM_CHECK
(
name
!=
NULL
&&
value
!=
NULL
,
return
-
1
,
"Invalid name or value"
);
int
ret
=
CheckParamName
(
name
,
0
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Illegal param name %s"
,
name
);
ret
=
CheckParamValue
(
&
g_clientSpace
.
paramSpace
.
paramSpace
,
NULL
,
name
,
value
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Illegal param value %s"
,
value
);
uint32_t
msgSize
=
sizeof
(
ParamMessage
)
+
sizeof
(
ParamMsgContent
)
+
PARAM_ALIGN
(
strlen
(
value
)
+
1
);
uint32_t
labelLen
=
0
;
ParamSecurityOps
*
ops
=
GetClientParamSecurityOps
();
...
...
services/param/include/param_manager.h
浏览文件 @
6d70eb69
...
...
@@ -43,7 +43,7 @@ typedef struct {
ParamTaskPtr
serverTask
;
ParamTaskPtr
timer
;
ParamTaskPtr
watcherTask
;
char
buffer
[
PARAM_NAME_LEN_MAX
+
PARAM_CONST_VALUE_LEN_MAX
];
char
buffer
[
PARAM_NAME_LEN_MAX
+
PARAM_CONST_VALUE_LEN_MAX
+
10
];
// 10 max len
}
ParamWorkSpace
;
typedef
struct
{
...
...
@@ -61,6 +61,7 @@ int ReadParamValue(const ParamWorkSpace *workSpace, ParamHandle handle, char *va
int
ReadParamName
(
const
ParamWorkSpace
*
workSpace
,
ParamHandle
handle
,
char
*
name
,
uint32_t
len
);
int
ReadParamCommitId
(
const
ParamWorkSpace
*
workSpace
,
ParamHandle
handle
,
uint32_t
*
commitId
);
int
CheckParamValue
(
const
WorkSpace
*
workSpace
,
const
ParamTrieNode
*
node
,
const
char
*
name
,
const
char
*
value
);
int
CheckParamName
(
const
char
*
name
,
int
paramInfo
);
int
CheckParamPermission
(
const
ParamWorkSpace
*
workSpace
,
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
);
...
...
services/param/include/param_utils.h
浏览文件 @
6d70eb69
...
...
@@ -118,6 +118,8 @@ typedef struct {
void
CheckAndCreateDir
(
const
char
*
fileName
);
int
GetSubStringInfo
(
const
char
*
buff
,
uint32_t
buffLen
,
char
delimiter
,
SubStringInfo
*
info
,
int
subStrNumber
);
int
SpliteString
(
char
*
line
,
const
char
*
exclude
[],
uint32_t
count
,
int
(
*
result
)(
const
uint32_t
*
context
,
const
char
*
name
,
const
char
*
value
),
const
uint32_t
*
context
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/param/manager/param_manager.c
浏览文件 @
6d70eb69
...
...
@@ -165,6 +165,22 @@ int ReadParamName(const ParamWorkSpace *workSpace, ParamHandle handle, char *nam
return
0
;
}
int
CheckParamValue
(
const
WorkSpace
*
workSpace
,
const
ParamTrieNode
*
node
,
const
char
*
name
,
const
char
*
value
)
{
if
(
IS_READY_ONLY
(
name
))
{
PARAM_CHECK
(
strlen
(
value
)
<
PARAM_CONST_VALUE_LEN_MAX
,
return
PARAM_CODE_INVALID_VALUE
,
"Illegal param value %s"
,
value
);
if
(
node
!=
NULL
&&
node
->
dataIndex
!=
0
)
{
PARAM_LOGE
(
"Read-only param was already set %s"
,
name
);
return
PARAM_CODE_READ_ONLY
;
}
}
else
{
PARAM_CHECK
(
strlen
(
value
)
<
PARAM_VALUE_LEN_MAX
,
return
PARAM_CODE_INVALID_VALUE
,
"Illegal param value %s"
,
value
);
}
return
0
;
}
int
CheckParamName
(
const
char
*
name
,
int
info
)
{
PARAM_CHECK
(
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid param"
);
...
...
@@ -290,6 +306,7 @@ int CheckParamPermission(const ParamWorkSpace *workSpace,
if
(
mode
==
DAC_WRITE
)
{
int
ret
=
CheckParamPermissionWithSelinux
(
srcLabel
,
name
,
mode
);
if
(
ret
==
DAC_RESULT_PERMISSION
)
{
PARAM_LOGI
(
"CheckParamPermission %s"
,
name
);
return
DAC_RESULT_PERMISSION
;
}
}
...
...
services/param/manager/param_utils.c
浏览文件 @
6d70eb69
...
...
@@ -106,4 +106,71 @@ int GetSubStringInfo(const char *buff, uint32_t buffLen, char delimiter, SubStri
curr
++
;
}
return
curr
;
}
int
SpliteString
(
char
*
line
,
const
char
*
exclude
[],
uint32_t
count
,
int
(
*
result
)(
const
uint32_t
*
context
,
const
char
*
name
,
const
char
*
value
),
const
uint32_t
*
context
)
{
// Skip spaces
char
*
name
=
line
;
while
(
isspace
(
*
name
)
&&
(
*
name
!=
'\0'
))
{
name
++
;
}
// Empty line or Comment line
if
(
*
name
==
'\0'
||
*
name
==
'#'
)
{
return
0
;
}
char
*
value
=
name
;
// find the first delimiter '='
while
(
*
value
!=
'\0'
)
{
if
(
*
value
==
'='
)
{
(
*
value
)
=
'\0'
;
value
=
value
+
1
;
break
;
}
value
++
;
}
// Skip spaces
char
*
tmp
=
name
;
while
((
tmp
<
value
)
&&
(
*
tmp
!=
'\0'
))
{
if
(
isspace
(
*
tmp
))
{
(
*
tmp
)
=
'\0'
;
break
;
}
tmp
++
;
}
// empty name, just ignore this line
if
(
*
value
==
'\0'
)
{
return
0
;
}
// Filter excluded parameters
for
(
uint32_t
i
=
0
;
i
<
count
;
i
++
)
{
if
(
strncmp
(
name
,
exclude
[
i
],
strlen
(
exclude
[
i
]))
==
0
)
{
return
0
;
}
}
// Skip spaces for value
while
(
isspace
(
*
value
)
&&
(
*
value
!=
'\0'
))
{
value
++
;
}
// Trim the ending spaces of value
char
*
pos
=
value
+
strlen
(
value
);
pos
--
;
while
(
isspace
(
*
pos
)
&&
pos
>
value
)
{
(
*
pos
)
=
'\0'
;
pos
--
;
}
// Strip starting and ending " for value
if
((
*
value
==
'"'
)
&&
(
pos
>
value
)
&&
(
*
pos
==
'"'
))
{
value
=
value
+
1
;
*
pos
=
'\0'
;
}
return
result
(
context
,
name
,
value
);
}
\ No newline at end of file
services/param/service/param_service.c
浏览文件 @
6d70eb69
...
...
@@ -102,23 +102,6 @@ static int UpdateParam(const WorkSpace *workSpace, uint32_t *dataIndex, const ch
return
0
;
}
static
int
CheckParamValue
(
const
WorkSpace
*
workSpace
,
const
ParamTrieNode
*
node
,
const
char
*
name
,
const
char
*
value
)
{
if
(
IS_READY_ONLY
(
name
))
{
PARAM_CHECK
(
strlen
(
value
)
<
PARAM_CONST_VALUE_LEN_MAX
,
return
PARAM_CODE_INVALID_VALUE
,
"Illegal param value %s"
,
value
);
if
(
node
!=
NULL
&&
node
->
dataIndex
!=
0
)
{
PARAM_LOGE
(
"Read-only param was already set %s"
,
name
);
return
PARAM_CODE_READ_ONLY
;
}
}
else
{
// 限制非read only的参数,防止参数值修改后,原空间不能保存
PARAM_CHECK
(
strlen
(
value
)
<
PARAM_VALUE_LEN_MAX
,
return
PARAM_CODE_INVALID_VALUE
,
"Illegal param value %s"
,
value
);
}
return
0
;
}
int
WriteParam
(
const
WorkSpace
*
workSpace
,
const
char
*
name
,
const
char
*
value
,
uint32_t
*
dataIndex
,
int
onlyAdd
)
{
PARAM_CHECK
(
workSpace
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid workSpace"
);
...
...
@@ -144,7 +127,7 @@ PARAM_STATIC int AddSecurityLabel(const ParamAuditData *auditData, void *context
PARAM_CHECK
(
context
!=
NULL
,
return
-
1
,
"Invalid context"
);
ParamWorkSpace
*
workSpace
=
(
ParamWorkSpace
*
)
context
;
int
ret
=
CheckParamName
(
auditData
->
name
,
1
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Illegal param name
%s
"
,
auditData
->
name
);
PARAM_CHECK
(
ret
==
0
,
return
ret
,
"Illegal param name
\"
%s
\"
"
,
auditData
->
name
);
ParamTrieNode
*
node
=
FindTrieNode
(
&
workSpace
->
paramSpace
,
auditData
->
name
,
strlen
(
auditData
->
name
),
NULL
);
if
(
node
==
NULL
)
{
...
...
@@ -543,78 +526,10 @@ PARAM_STATIC int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *m
return
0
;
}
static
int
LoadOneParam_
(
char
*
line
,
uint32_t
mode
,
const
char
*
exclude
[],
uint32_t
count
)
static
int
LoadOneParam_
(
const
uint32_t
*
context
,
const
char
*
name
,
const
char
*
value
)
{
char
*
name
;
char
*
value
;
char
*
pos
;
// Skip spaces
name
=
line
;
while
(
isspace
(
*
name
)
&&
(
*
name
!=
'\0'
))
{
name
++
;
}
// Empty line
if
(
*
name
==
'\0'
)
{
return
0
;
}
// Comment line
if
(
*
name
==
'#'
)
{
return
0
;
}
value
=
name
;
// find the first delimiter '='
while
(
*
value
!=
'\0'
)
{
if
(
*
value
==
'='
)
{
(
*
value
)
=
'\0'
;
value
=
value
+
1
;
break
;
}
value
++
;
}
// empty name, just ignore this line
if
(
*
name
==
'\0'
)
{
return
0
;
}
// Trim the ending spaces of name
pos
=
value
-
1
;
pos
-=
1
;
while
(
isspace
(
*
pos
)
&&
pos
>
name
)
{
(
*
pos
)
=
'\0'
;
pos
--
;
}
// Filter excluded parameters
for
(
uint32_t
i
=
0
;
i
<
count
;
i
++
)
{
if
(
strncmp
(
name
,
exclude
[
i
],
strlen
(
exclude
[
i
]))
==
0
)
{
return
0
;
}
}
// Skip spaces for value
while
(
isspace
(
*
value
)
&&
(
*
value
!=
'\0'
))
{
value
++
;
}
// Trim the ending spaces of value
pos
=
value
+
strlen
(
value
);
pos
--
;
while
(
isspace
(
*
pos
)
&&
pos
>
value
)
{
(
*
pos
)
=
'\0'
;
pos
--
;
}
// Strip starting and ending " for value
if
((
*
value
==
'"'
)
&&
(
pos
>
value
)
&&
(
*
pos
==
'"'
))
{
value
=
value
+
1
;
*
pos
=
'\0'
;
}
uint32_t
mode
=
*
(
uint32_t
*
)
context
;
int
ret
=
CheckParamName
(
name
,
0
);
// Invalid name, just ignore
if
(
ret
!=
0
)
{
return
0
;
}
...
...
@@ -623,32 +538,22 @@ static int LoadOneParam_(char *line, uint32_t mode, const char *exclude[], uint3
name
,
value
,
NULL
,
mode
&
LOAD_PARAM_ONLY_ADD
);
}
static
int
LoadDefaultParam_
(
const
char
*
fileName
,
uint32_t
mode
,
const
char
*
exclude
[],
uint32_t
count
)
static
int
LoadDefaultParam_
(
const
char
*
fileName
,
uint32_t
mode
,
const
char
*
exclude
[],
uint32_t
count
)
{
// max length for each line of para files: max name length + max value length + spaces
#define PARAM_LINE_MAX_LENGTH (PARAM_NAME_LEN_MAX + PARAM_CONST_VALUE_LEN_MAX + 10)
uint32_t
paramNum
=
0
;
FILE
*
fp
=
fopen
(
fileName
,
"r"
);
if
(
fp
==
NULL
)
{
return
-
1
;
}
char
*
buff
=
calloc
(
1
,
PARAM_LINE_MAX_LENGTH
);
if
(
buff
==
NULL
)
{
(
void
)
fclose
(
fp
);
return
-
1
;
}
while
(
fgets
(
buff
,
PARAM_LINE_MAX_LENGTH
,
fp
)
!=
NULL
)
{
buff
[
PARAM_LINE_MAX_LENGTH
-
1
]
=
'\0'
;
int
ret
=
LoadOneParam_
(
buff
,
mode
,
exclude
,
count
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to set param %d %s"
,
ret
,
buff
);
while
(
fgets
(
g_paramWorkSpace
.
buffer
,
sizeof
(
g_paramWorkSpace
.
buffer
),
fp
)
!=
NULL
)
{
g_paramWorkSpace
.
buffer
[
sizeof
(
g_paramWorkSpace
.
buffer
)
-
1
]
=
'\0'
;
int
ret
=
SpliteString
(
g_paramWorkSpace
.
buffer
,
exclude
,
count
,
LoadOneParam_
,
&
mode
);
PARAM_CHECK
(
ret
==
0
,
continue
,
"Failed to set param %d %s"
,
ret
,
g_paramWorkSpace
.
buffer
);
paramNum
++
;
}
(
void
)
fclose
(
fp
);
free
(
buff
);
PARAM_LOGI
(
"Load parameters success %s total %u"
,
fileName
,
paramNum
);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录