Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
3bec302f
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看板
未验证
提交
3bec302f
编写于
8月 11, 2022
作者:
O
openharmony_ci
提交者:
Gitee
8月 11, 2022
浏览文件
操作
浏览文件
下载
差异文件
!1031 支持param单独编译到musl库
Merge pull request !1031 from Mupceet/initmusl1
上级
21131b4a
49b9de30
变更
31
隐藏空白更改
内联
并排
Showing
31 changed file
with
670 addition
and
443 deletion
+670
-443
begetd.gni
begetd.gni
+1
-0
interfaces/innerkits/BUILD.gn
interfaces/innerkits/BUILD.gn
+10
-2
services/begetctl/BUILD.gn
services/begetctl/BUILD.gn
+21
-18
services/include/param/init_param.h
services/include/param/init_param.h
+1
-7
services/include/param/sys_param.h
services/include/param/sys_param.h
+46
-0
services/init/standard/BUILD.gn
services/init/standard/BUILD.gn
+5
-1
services/log/init_log.c
services/log/init_log.c
+2
-1
services/log/init_log.h
services/log/init_log.h
+11
-1
services/param/adapter/param_selinux.c
services/param/adapter/param_selinux.c
+85
-64
services/param/base/BUILD.gn
services/param/base/BUILD.gn
+48
-12
services/param/base/param_base.c
services/param/base/param_base.c
+51
-230
services/param/base/param_base.h
services/param/base/param_base.h
+2
-6
services/param/base/param_comm.c
services/param/base/param_comm.c
+195
-2
services/param/base/param_trie.c
services/param/base/param_trie.c
+2
-2
services/param/include/param_manager.h
services/param/include/param_manager.h
+14
-7
services/param/include/param_osadp.h
services/param/include/param_osadp.h
+14
-14
services/param/include/param_security.h
services/param/include/param_security.h
+2
-6
services/param/include/param_trie.h
services/param/include/param_trie.h
+1
-1
services/param/include/param_utils.h
services/param/include/param_utils.h
+13
-1
services/param/linux/BUILD.gn
services/param/linux/BUILD.gn
+9
-5
services/param/linux/param_osadp.c
services/param/linux/param_osadp.c
+14
-13
services/param/linux/param_request.c
services/param/linux/param_request.c
+13
-2
services/param/linux/param_service.c
services/param/linux/param_service.c
+18
-1
services/param/liteos/BUILD.gn
services/param/liteos/BUILD.gn
+1
-0
services/param/liteos/param_client.c
services/param/liteos/param_client.c
+1
-1
services/param/liteos/param_osadp.c
services/param/liteos/param_osadp.c
+25
-25
services/param/liteos/param_service.c
services/param/liteos/param_service.c
+1
-1
services/param/manager/param_manager.c
services/param/manager/param_manager.c
+40
-6
test/unittest/param/param_stub.cpp
test/unittest/param/param_stub.cpp
+9
-10
ueventd/BUILD.gn
ueventd/BUILD.gn
+10
-3
watchdog/BUILD.gn
watchdog/BUILD.gn
+5
-1
未找到文件。
begetd.gni
浏览文件 @
3bec302f
...
...
@@ -16,6 +16,7 @@ declare_args() {
enable_ohos_startup_init_feature_deviceinfo = true
param_test = true
control_test = false
param_base_log = false
enable_ohos_startup_init_feature_ab_partition = false
# init begetctl support liteos
...
...
interfaces/innerkits/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -182,13 +182,17 @@ if (defined(ohos_lite)) {
"//base/startup/init/interfaces/innerkits/socket:libsocket",
"//base/startup/init/services/log:agent_log",
"//base/startup/init/services/loopevent:loopevent",
"//base/startup/init/services/param/base:parameterbase",
"//base/startup/init/services/param/linux:param_client",
"//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/cJSON:cjson",
"//third_party/mbedtls:mbedtls_shared",
]
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [
"c_utils:utils",
"hilog_native:libhilog_base",
...
...
@@ -274,12 +278,16 @@ if (defined(ohos_lite)) {
deps = [
"//base/startup/init/services/log:agent_log",
"//base/startup/init/services/loopevent:loopevent",
"//base/startup/init/services/param/base:parameterbase",
"//base/startup/init/services/param/linux:param_client",
"//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_shared",
"//third_party/mbedtls:mbedtls_shared",
]
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [
"c_utils:utils",
"hilog_native:libhilog_base",
...
...
services/begetctl/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -25,7 +25,10 @@ common_include_dirs = [
"//base/startup/init/services/init/include",
"//base/startup/init/services/log",
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/innerkits/sandbox/include",
"//base/security/selinux/interfaces/policycoreutils/include",
"//third_party/bounds_checking_function/include",
"//third_party/selinux/libselinux/include",
]
if (defined(ohos_lite)) {
...
...
@@ -77,12 +80,7 @@ if (defined(ohos_lite)) {
defines += [ "PRODUCT_RK" ]
}
include_dirs = [
"//third_party/bounds_checking_function/include",
"//base/startup/init/interfaces/innerkits/sandbox/include",
"//base/startup/init/interfaces/innerkits/control_fd",
]
include_dirs += common_include_dirs
include_dirs = common_include_dirs
deps = [
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//base/startup/init/interfaces/innerkits/control_fd:libcontrolfd",
...
...
@@ -103,12 +101,10 @@ if (defined(ohos_lite)) {
}
if (build_selinux) {
include_dir
s += [
"//
third_party/selinux/libselinux/include/
",
"//
base/security/selinux/interfaces/policycoreutils/include/
",
dep
s += [
"//
base/security/selinux:libselinux_parameter_static
",
"//
third_party/selinux:libselinux
",
]
deps += [ "//third_party/selinux:libselinux" ]
external_deps += [ "selinux:libparaperm_checker" ]
defines += [ "PARAM_SUPPORT_SELINUX" ]
}
...
...
@@ -148,12 +144,14 @@ if (defined(ohos_lite)) {
include_dirs = common_include_dirs
deps = [
"//base/startup/init/interfaces/innerkits:libbegetutil",
"//third_party/bounds_checking_function:libsec_s
tatic
",
"//third_party/bounds_checking_function:libsec_s
hared
",
]
if (build_selinux) {
deps += [ "//third_party/selinux:libselinux" ]
external_deps = [ "selinux:libparaperm_checker" ]
deps += [
"//base/security/selinux:libselinux_parameter_static",
"//third_party/selinux:libselinux",
]
defines += [ "PARAM_SUPPORT_SELINUX" ]
}
...
...
@@ -191,19 +189,24 @@ if (defined(ohos_lite)) {
deps = [
"//base/startup/init/services/log:agent_log",
"//base/startup/init/services/loopevent:loopevent",
"//base/startup/init/services/param/base:parameterbase",
"//base/startup/init/services/param/linux:param_client",
"//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
external_deps = [
"c_utils:utils",
"hilog_native:libhilog_base",
]
if (build_selinux) {
deps += [ "//third_party/selinux:libselinux" ]
external_deps += [ "selinux:libparaperm_checker" ]
deps += [
"//base/security/selinux:libselinux_parameter_static",
"//third_party/selinux:libselinux",
]
defines += [ "PARAM_SUPPORT_SELINUX" ]
}
install_images = [ "system" ]
...
...
services/include/param/init_param.h
浏览文件 @
3bec302f
...
...
@@ -20,6 +20,7 @@
#ifdef PARAM_SUPPORT_TRIGGER
#include "cJSON.h"
#endif
#include "sys_param.h"
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
...
...
@@ -108,13 +109,6 @@ int LoadPersistParams(void);
*/
int
SystemWriteParam
(
const
char
*
name
,
const
char
*
value
);
/**
* Init 接口
* 查询参数。
*
*/
int
SystemReadParam
(
const
char
*
name
,
char
*
value
,
uint32_t
*
len
);
#ifdef PARAM_SUPPORT_TRIGGER
/**
* 对外接口
...
...
services/include/param/sys_param.h
0 → 100644
浏览文件 @
3bec302f
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef BASE_STARTUP_INIT_SYS_PARAM_H
#define BASE_STARTUP_INIT_SYS_PARAM_H
#include <stdarg.h>
#include <stdint.h>
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
#endif
#endif
typedef
struct
{
uint8_t
updaterMode
;
void
(
*
logFunc
)(
int
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
va_list
vargs
);
int
(
*
setfilecon
)(
const
char
*
name
,
const
char
*
content
);
}
PARAM_WORKSPACE_OPS
;
int
InitParamWorkSpace
(
int
onlyRead
,
const
PARAM_WORKSPACE_OPS
*
ops
);
/**
* Init 接口
* 查询参数。
*
*/
int
SystemReadParam
(
const
char
*
name
,
char
*
value
,
uint32_t
*
len
);
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif
\ No newline at end of file
services/init/standard/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -65,10 +65,14 @@ ohos_executable("init") {
"//base/startup/init/interfaces/innerkits/fs_manager:libfsmanager_static",
"//base/startup/init/interfaces/innerkits/sandbox:sandbox",
"//base/startup/init/services/loopevent:loopevent",
"//base/startup/init/services/param/base:parameterbase",
"//base/startup/init/services/param/linux:param_init",
"//base/startup/init/services/utils:libinit_utils",
]
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
deps += [
"//base/customization/config_policy/frameworks/config_policy:configpolicy_util_for_init_static",
...
...
services/log/init_log.c
浏览文件 @
3bec302f
...
...
@@ -116,7 +116,8 @@ static void PrintLog(InitLogLevel logLevel, unsigned int domain, const char *tag
#endif
}
static
void
InitLog
(
InitLogLevel
logLevel
,
unsigned
int
domain
,
const
char
*
tag
,
const
char
*
fmt
,
va_list
vargs
)
INIT_LOCAL_API
void
InitLog
(
InitLogLevel
logLevel
,
unsigned
int
domain
,
const
char
*
tag
,
const
char
*
fmt
,
va_list
vargs
)
{
if
(
g_logLevel
>
logLevel
)
{
return
;
...
...
services/log/init_log.h
浏览文件 @
3bec302f
...
...
@@ -37,7 +37,16 @@ extern "C" {
#endif
INIT_LOCAL_API
void
OpenLogDevice
(
void
);
INIT_LOCAL_API
void
InitLog
(
InitLogLevel
logLevel
,
unsigned
int
domain
,
const
char
*
tag
,
const
char
*
fmt
,
va_list
vargs
);
#ifdef PARAM_BASE
#define INIT_LOGV(fmt, ...)
#define INIT_LOGI(fmt, ...)
#define INIT_LOGW(fmt, ...)
#define INIT_LOGE(fmt, ...)
#define INIT_LOGF(fmt, ...)
#else
#define INIT_LOGV(fmt, ...) \
StartupLog
(
INIT_DEBUG
,
INIT_LOG_DOMAIN
,
INIT_LOG_TAG
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#define INIT_LOGI(fmt, ...) \
...
...
@@ -48,6 +57,7 @@ INIT_LOCAL_API void OpenLogDevice(void);
StartupLog
(
INIT_ERROR
,
INIT_LOG_DOMAIN
,
INIT_LOG_TAG
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#define INIT_LOGF(fmt, ...) \
StartupLog
(
INIT_FATAL
,
INIT_LOG_DOMAIN
,
INIT_LOG_TAG
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#endif
#ifndef UNLIKELY
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
...
...
services/param/adapter/param_selinux.c
浏览文件 @
3bec302f
...
...
@@ -34,50 +34,76 @@
#define CHECKER_UPDATER_LIB_NAME "/lib/libparaperm_checker.z.so"
#endif
static
SelinuxSpace
g_selinuxSpace
=
{
0
};
static
int
InitLocalSecurityLabel
(
ParamSecurityLabel
*
security
,
int
isInit
)
static
int
InitSelinuxOpsForInit
(
SelinuxSpace
*
selinuxSpace
)
{
UNUSED
(
isInit
);
PARAM_CHECK
(
security
!=
NULL
,
return
-
1
,
"Invalid security"
);
security
->
cred
.
pid
=
getpid
();
security
->
cred
.
uid
=
geteuid
();
security
->
cred
.
gid
=
getegid
();
security
->
flags
[
PARAM_SECURITY_SELINUX
]
=
0
;
PARAM_LOGV
(
"InitLocalSecurityLabel"
);
#if !(defined STARTUP_INIT_TEST || defined LOCAL_TEST)
if
(
g_selinuxSpace
.
selinuxHandle
==
NULL
)
{
const
char
*
libname
=
(
InUpdaterMode
()
==
1
)
?
CHECKER_UPDATER_LIB_NAME
:
CHECKER_LIB_NAME
;
g_selinuxSpace
.
selinuxHandle
=
dlopen
(
libname
,
RTLD_LAZY
);
PARAM_CHECK
(
g_selinuxSpace
.
selinuxHandle
!=
NULL
,
if
(
selinuxSpace
->
selinuxHandle
==
NULL
)
{
const
char
*
libname
=
(
GetParamWorkSpace
()
->
ops
.
updaterMode
==
1
)
?
CHECKER_UPDATER_LIB_NAME
:
CHECKER_LIB_NAME
;
selinuxSpace
->
selinuxHandle
=
dlopen
(
libname
,
RTLD_LAZY
);
PARAM_CHECK
(
selinuxSpace
->
selinuxHandle
!=
NULL
,
return
0
,
"Failed to dlsym selinuxHandle, %s"
,
dlerror
());
}
void
*
handle
=
g_selinuxSpace
.
selinuxHandle
;
if
(
g_selinuxSpace
.
setParamCheck
==
NULL
)
{
g_selinuxSpace
.
setParamCheck
=
(
SelinuxSetParamCheck
)
dlsym
(
handle
,
"SetParamCheck"
);
PARAM_CHECK
(
g_selinuxSpace
.
setParamCheck
!=
NULL
,
return
-
1
,
"Failed to dlsym setParamCheck %s"
,
dlerror
());
void
*
handle
=
selinuxSpace
->
selinuxHandle
;
if
(
selinuxSpace
->
setParamCheck
==
NULL
)
{
selinuxSpace
->
setParamCheck
=
(
SelinuxSetParamCheck
)
dlsym
(
handle
,
"SetParamCheck"
);
PARAM_CHECK
(
selinuxSpace
->
setParamCheck
!=
NULL
,
return
-
1
,
"Failed to dlsym setParamCheck %s"
,
dlerror
());
}
if
(
g_selinuxSpace
.
getParamList
==
NULL
)
{
g_selinuxSpace
.
getParamList
=
(
ParamContextsList
*
(
*
)())
dlsym
(
handle
,
"GetParamList"
);
PARAM_CHECK
(
g_selinuxSpace
.
getParamList
!=
NULL
,
return
-
1
,
"Failed to dlsym getParamList %s"
,
dlerror
());
if
(
selinuxSpace
->
getParamList
==
NULL
)
{
selinuxSpace
->
getParamList
=
(
ParamContextsList
*
(
*
)())
dlsym
(
handle
,
"GetParamList"
);
PARAM_CHECK
(
selinuxSpace
->
getParamList
!=
NULL
,
return
-
1
,
"Failed to dlsym getParamList %s"
,
dlerror
());
}
if
(
g_selinuxSpace
.
getParamLabel
==
NULL
)
{
g_selinuxSpace
.
getParamLabel
=
(
const
char
*
(
*
)(
const
char
*
))
dlsym
(
handle
,
"GetParamLabel"
);
PARAM_CHECK
(
g_selinuxSpace
.
getParamLabel
!=
NULL
,
return
-
1
,
"Failed to dlsym getParamLabel %s"
,
dlerror
());
if
(
selinuxSpace
->
getParamLabel
==
NULL
)
{
selinuxSpace
->
getParamLabel
=
(
const
char
*
(
*
)(
const
char
*
))
dlsym
(
handle
,
"GetParamLabel"
);
PARAM_CHECK
(
selinuxSpace
->
getParamLabel
!=
NULL
,
return
-
1
,
"Failed to dlsym getParamLabel %s"
,
dlerror
());
}
if
(
g_selinuxSpace
.
initParamSelinux
==
NULL
)
{
g_selinuxSpace
.
initParamSelinux
=
(
void
(
*
)())
dlsym
(
handle
,
"InitParamSelinux"
);
PARAM_CHECK
(
g_selinuxSpace
.
initParamSelinux
!=
NULL
,
return
-
1
,
"Failed to dlsym initParamSelinux "
);
if
(
selinuxSpace
->
initParamSelinux
==
NULL
)
{
selinuxSpace
->
initParamSelinux
=
(
int
(
*
)())
dlsym
(
handle
,
"InitParamSelinux"
);
PARAM_CHECK
(
selinuxSpace
->
initParamSelinux
!=
NULL
,
return
-
1
,
"Failed to dlsym initParamSelinux "
);
}
if
(
g_selinuxSpace
.
readParamCheck
==
NULL
)
{
g_selinuxSpace
.
readParamCheck
=
(
int
(
*
)(
const
char
*
))
dlsym
(
handle
,
"ReadParamCheck"
);
if
(
selinuxSpace
->
readParamCheck
==
NULL
)
{
selinuxSpace
->
readParamCheck
=
(
int
(
*
)(
const
char
*
))
dlsym
(
handle
,
"ReadParamCheck"
);
}
if
(
g_selinuxSpace
.
destroyParamList
==
NULL
)
{
g_selinuxSpace
.
destroyParamList
=
if
(
selinuxSpace
->
setSelinuxLogCallback
==
NULL
)
{
selinuxSpace
->
setSelinuxLogCallback
=
(
void
(
*
)())
dlsym
(
handle
,
"SetInitSelinuxLog"
);
}
if
(
selinuxSpace
->
destroyParamList
==
NULL
)
{
selinuxSpace
->
destroyParamList
=
(
void
(
*
)(
ParamContextsList
**
))
dlsym
(
handle
,
"DestroyParamList"
);
PARAM_CHECK
(
g_selinuxSpace
.
destroyParamList
!=
NULL
,
PARAM_CHECK
(
selinuxSpace
->
destroyParamList
!=
NULL
,
return
-
1
,
"Failed to dlsym destroyParamList %s"
,
dlerror
());
}
g_selinuxSpace
.
initParamSelinux
();
// init and open avc log
int
ret
=
selinuxSpace
->
initParamSelinux
();
if
(
selinuxSpace
->
setSelinuxLogCallback
!=
NULL
)
{
selinuxSpace
->
setSelinuxLogCallback
();
}
PARAM_LOGI
(
"Load selinux lib success."
);
return
ret
;
}
static
int
InitLocalSecurityLabel
(
ParamSecurityLabel
*
security
,
int
isInit
)
{
PARAM_CHECK
(
GetParamWorkSpace
()
!=
NULL
,
return
-
1
,
"Invalid workspace"
);
UNUSED
(
isInit
);
PARAM_CHECK
(
security
!=
NULL
,
return
-
1
,
"Invalid security"
);
security
->
cred
.
pid
=
getpid
();
security
->
cred
.
uid
=
geteuid
();
security
->
cred
.
gid
=
getegid
();
security
->
flags
[
PARAM_SECURITY_SELINUX
]
=
0
;
PARAM_LOGV
(
"InitLocalSecurityLabel"
);
#if !(defined STARTUP_INIT_TEST || defined LOCAL_TEST)
if
(
isInit
)
{
int
ret
=
InitSelinuxOpsForInit
(
&
GetParamWorkSpace
()
->
selinuxSpace
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to init selinux ops"
);
}
else
{
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
selinuxSpace
->
initParamSelinux
=
InitParamSelinux
;
selinuxSpace
->
getParamList
=
GetParamList
;
selinuxSpace
->
getParamLabel
=
GetParamLabel
;
selinuxSpace
->
destroyParamList
=
DestroyParamList
;
// init
selinuxSpace
->
initParamSelinux
();
}
#endif
PARAM_LOGV
(
"Load selinux lib success."
);
return
0
;
...
...
@@ -90,12 +116,14 @@ static int FreeLocalSecurityLabel(ParamSecurityLabel *srcLabel)
static
void
SetSelinuxFileCon
(
const
char
*
name
,
const
char
*
context
)
{
PARAM_CHECK
(
GetParamWorkSpace
()
!=
NULL
&&
GetParamWorkSpace
()
->
ops
.
setfilecon
!=
NULL
,
return
,
"Invalid workspace or setfilecon"
);
static
char
buffer
[
FILENAME_LEN_MAX
]
=
{
0
};
int
len
=
ParamSprintf
(
buffer
,
sizeof
(
buffer
),
"%s/%s"
,
PARAM_STORAGE_PATH
,
context
);
if
(
len
>
0
)
{
buffer
[
len
]
=
'\0'
;
PARAM_LOGI
(
"setfilecon name %s path: %s %s "
,
name
,
context
,
buffer
);
if
(
setfilecon
(
buffer
,
context
)
<
0
)
{
if
(
GetParamWorkSpace
()
->
ops
.
setfilecon
(
buffer
,
context
)
<
0
)
{
PARAM_LOGE
(
"Failed to setfilecon %s "
,
context
);
}
}
...
...
@@ -103,8 +131,9 @@ static void SetSelinuxFileCon(const char *name, const char *context)
static
int
SelinuxGetAllLabel
(
int
readOnly
)
{
PARAM_CHECK
(
g_selinuxSpace
.
getParamList
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"Invalid getParamList"
);
ParamContextsList
*
head
=
g_selinuxSpace
.
getParamList
();
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
PARAM_CHECK
(
selinuxSpace
->
getParamList
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"Invalid getParamList"
);
ParamContextsList
*
head
=
selinuxSpace
->
getParamList
();
ParamContextsList
*
node
=
head
;
int
count
=
0
;
...
...
@@ -153,11 +182,23 @@ static int CheckFilePermission(const ParamSecurityLabel *localLabel, const char
return
0
;
}
static
const
char
*
GetSelinuxContent
(
const
char
*
name
)
{
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
if
(
selinuxSpace
->
getParamLabel
!=
NULL
)
{
return
selinuxSpace
->
getParamLabel
(
name
);
}
else
{
PARAM_LOGE
(
"Can not init selinux"
);
return
WORKSPACE_NAME_DEF_SELINUX
;
}
}
static
int
SelinuxReadParamCheck
(
const
char
*
name
)
{
int
ret
=
DAC_RESULT_FORBIDED
;
if
(
g_selinuxSpace
.
readParamCheck
!=
NULL
)
{
ret
=
g_selinuxSpace
.
readParamCheck
(
name
);
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
if
(
selinuxSpace
->
readParamCheck
!=
NULL
)
{
ret
=
selinuxSpace
->
readParamCheck
(
name
);
PARAM_LOGI
(
"SelinuxReadParamCheck name %s ret %d"
,
name
,
ret
);
}
const
char
*
label
=
GetSelinuxContent
(
name
);
...
...
@@ -175,20 +216,21 @@ static int SelinuxReadParamCheck(const char *name)
static
int
SelinuxCheckParamPermission
(
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
)
{
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
int
ret
=
DAC_RESULT_FORBIDED
;
PARAM_CHECK
(
g_selinuxSpace
.
setParamCheck
!=
NULL
,
return
ret
,
"Invalid setParamCheck"
);
// check
struct
ucred
uc
;
uc
.
pid
=
srcLabel
->
cred
.
pid
;
uc
.
uid
=
srcLabel
->
cred
.
uid
;
uc
.
gid
=
srcLabel
->
cred
.
gid
;
if
(
mode
==
DAC_WRITE
)
{
ret
=
g_selinuxSpace
.
setParamCheck
(
name
,
&
uc
);
PARAM_CHECK
(
selinuxSpace
->
setParamCheck
!=
NULL
,
return
ret
,
"Invalid setParamCheck"
);
ret
=
selinuxSpace
->
setParamCheck
(
name
,
&
uc
);
}
else
{
#ifndef STARTUP_INIT_TEST
ret
=
SelinuxReadParamCheck
(
name
);
#else
ret
=
g_selinuxSpace
.
readParamCheck
(
name
);
ret
=
selinuxSpace
->
readParamCheck
(
name
);
#endif
}
if
(
ret
!=
0
)
{
...
...
@@ -207,12 +249,13 @@ static int UpdaterCheckParamPermission(const ParamSecurityLabel *srcLabel, const
INIT_LOCAL_API
int
RegisterSecuritySelinuxOps
(
ParamSecurityOps
*
ops
,
int
isInit
)
{
PARAM_CHECK
(
GetParamWorkSpace
()
!=
NULL
,
return
-
1
,
"Invalid workspace"
);
PARAM_CHECK
(
ops
!=
NULL
,
return
-
1
,
"Invalid param"
);
int
ret
=
ParamStrCpy
(
ops
->
name
,
sizeof
(
ops
->
name
),
"selinux"
);
ops
->
securityGetLabel
=
NULL
;
ops
->
securityInitLabel
=
InitLocalSecurityLabel
;
ops
->
securityCheckFilePermission
=
CheckFilePermission
;
if
(
InUpdaterMode
()
==
1
)
{
if
(
GetParamWorkSpace
()
->
ops
.
updaterMode
==
1
)
{
ops
->
securityCheckParamPermission
=
UpdaterCheckParamPermission
;
}
else
{
ops
->
securityCheckParamPermission
=
SelinuxCheckParamPermission
;
...
...
@@ -224,30 +267,8 @@ INIT_LOCAL_API int RegisterSecuritySelinuxOps(ParamSecurityOps *ops, int isInit)
return
ret
;
}
INIT_INNER_API
const
char
*
GetSelinuxContent
(
const
char
*
name
)
{
if
(
g_selinuxSpace
.
getParamLabel
!=
NULL
)
{
return
g_selinuxSpace
.
getParamLabel
(
name
);
}
else
{
PARAM_LOGE
(
"Can not init selinux"
);
return
WORKSPACE_NAME_DEF_SELINUX
;
}
}
INIT_LOCAL_API
void
OpenPermissionWorkSpace
(
void
)
{
// open workspace by readonly
SelinuxGetAllLabel
(
1
);
}
#if defined STARTUP_INIT_TEST || defined LOCAL_TEST
void
SetSelinuxOps
(
const
SelinuxSpace
*
space
)
{
g_selinuxSpace
.
setSelinuxLogCallback
=
space
->
setSelinuxLogCallback
;
g_selinuxSpace
.
setParamCheck
=
space
->
setParamCheck
;
g_selinuxSpace
.
getParamLabel
=
space
->
getParamLabel
;
g_selinuxSpace
.
readParamCheck
=
space
->
readParamCheck
;
g_selinuxSpace
.
getParamList
=
space
->
getParamList
;
g_selinuxSpace
.
destroyParamList
=
space
->
destroyParamList
;
}
#endif
\ No newline at end of file
services/param/base/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -24,9 +24,7 @@ config("exported_header_files") {
]
}
base_sources = [
"//base/startup/init/services/log/init_commlog.c",
"//base/startup/init/services/param/base/param_base.c",
comm_sources = [
"//base/startup/init/services/param/base/param_comm.c",
"//base/startup/init/services/param/base/param_trie.c",
"//base/startup/init/services/utils/init_hashmap.c",
...
...
@@ -38,12 +36,16 @@ base_include_dirs = [
"//base/startup/init/services/param/adapter",
"//base/startup/init/services/param/linux",
"//base/startup/init/services/param/base",
"//
base/security/selinux/interfaces/policycoreutils
/include",
"//
third_party/bounds_checking_function
/include",
]
if (defined(ohos_lite)) {
static_library("parameterbase") {
sources = base_sources
sources = comm_sources
sources += [
"//base/startup/init/services/log/init_commlog.c",
"//base/startup/init/services/param/base/param_base.c",
]
include_dirs = base_include_dirs
cflags = [ "-fPIC" ]
defines = [ "_GNU_SOURCE" ]
...
...
@@ -54,16 +56,12 @@ if (defined(ohos_lite)) {
"//base/startup/init/services/param/adapter/param_dac.c",
"//base/startup/init/services/param/linux/param_osadp.c",
]
defines += [
"__LINUX__",
"PARAM_BASE",
]
defines += [ "__LINUX__" ]
} else if (ohos_kernel_type == "liteos_a") {
sources += [
"//base/startup/init/services/param/liteos/param_litedac.c",
"//base/startup/init/services/param/liteos/param_osadp.c",
]
include_dirs += [ "//third_party/bounds_checking_function/include" ]
defines += [
"__LITEOS_A__",
"WORKSPACE_AREA_NEED_MUTEX",
...
...
@@ -73,21 +71,24 @@ if (defined(ohos_lite)) {
}
}
} else {
ohos_s
tatic_library
("parameterbase") {
sources =
base
_sources
ohos_s
ource_set
("parameterbase") {
sources =
comm
_sources
sources += [
"//base/startup/init/services/param/adapter/param_dac.c",
"//base/startup/init/services/param/base/param_base.c",
"//base/startup/init/services/param/linux/param_osadp.c",
]
cflags = [ "-fPIC" ]
include_dirs = base_include_dirs
public_configs = [ ":exported_header_files" ]
defines = [ "_GNU_SOURCE" ]
deps = []
if (use_musl) {
defines += [ "PARAM_BASE" ]
} else {
include_dirs += [ "//third_party/bounds_checking_function/include" ]
sources += [ "//base/startup/init/services/log/init_commlog.c" ]
}
if (build_selinux) {
include_dirs += [
...
...
@@ -100,6 +101,41 @@ if (defined(ohos_lite)) {
"PARAM_SUPPORT_SELINUX",
"PARAMWORKSPACE_NEED_MUTEX",
]
deps += [ "//base/security/selinux:libselinux_parameter_static" ]
}
if (param_base_log) {
defines += [ "PARAM_BASE_LOG" ]
}
part_name = "init"
}
# extend for base
ohos_static_library("parameterbase_ext") {
sources = comm_sources
sources += [
"//base/startup/init/services/log/init_commlog.c",
"//base/startup/init/services/param/linux/param_osadp.c",
]
cflags = [ "-fPIC" ]
include_dirs = base_include_dirs
public_configs = [ ":exported_header_files" ]
defines = [ "_GNU_SOURCE" ]
deps = []
include_dirs += [ "//third_party/bounds_checking_function/include" ]
if (build_selinux) {
include_dirs += [
"//third_party/selinux/libselinux/include/",
"//base/security/selinux/interfaces/policycoreutils/include/",
]
defines += [
"PARAM_SUPPORT_SELINUX",
"PARAMWORKSPACE_NEED_MUTEX",
]
deps += [ "//base/security/selinux:libselinux_parameter_static" ]
}
if (param_base_log) {
defines += [ "PARAM_BASE_LOG" ]
}
part_name = "init"
}
...
...
services/param/base/param_base.c
浏览文件 @
3bec302f
...
...
@@ -34,15 +34,6 @@ static int WorkSpaceKeyCompare(const HashNode *node1, const void *key)
return
strcmp
(
workSpace1
->
fileName
,
(
char
*
)
key
);
}
static
int
GenerateKeyHasCode
(
const
char
*
buff
,
size_t
len
)
{
int
code
=
0
;
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
code
+=
buff
[
i
]
-
'A'
;
}
return
code
;
}
static
int
WorkSpaceGetNodeHasCode
(
const
HashNode
*
node
)
{
WorkSpace
*
workSpace
=
HASHMAP_ENTRY
(
node
,
WorkSpace
,
hashNode
);
...
...
@@ -61,16 +52,6 @@ static void WorkSpaceFree(const HashNode *node)
WorkSpace
*
workSpace
=
HASHMAP_ENTRY
(
node
,
WorkSpace
,
hashNode
);
CloseWorkSpace
(
workSpace
);
}
INIT_INNER_API
ParamHandle
GetParamHandle
(
const
WorkSpace
*
workSpace
,
uint32_t
index
,
const
char
*
name
)
{
PARAM_CHECK
(
workSpace
!=
NULL
&&
workSpace
->
area
!=
NULL
,
return
-
1
,
"Invalid param"
);
uint32_t
hashCode
=
(
uint32_t
)
GenerateKeyHasCode
(
workSpace
->
fileName
,
strlen
(
workSpace
->
fileName
));
uint32_t
handle
=
(
hashCode
%
HASH_BUTT
)
<<
24
;
// 24 left shift
handle
=
handle
|
(
index
+
workSpace
->
area
->
startIndex
);
return
handle
;
}
static
int
InitParamSecurity
(
ParamWorkSpace
*
workSpace
,
RegisterSecurityOpsPtr
registerOps
,
ParamSecurityType
type
,
int
isInit
,
int
op
)
{
...
...
@@ -98,7 +79,7 @@ static int InitParamSecurity(ParamWorkSpace *workSpace,
return
0
;
}
PARAM_STATIC
int
RegisterSecurityOps
(
int
onlyRead
)
INIT_LOCAL_API
int
RegisterSecurityOps
(
int
onlyRead
)
{
int
isInit
=
0
;
int
op
=
DAC_READ
;
...
...
@@ -115,12 +96,48 @@ PARAM_STATIC int RegisterSecurityOps(int onlyRead)
return
ret
;
}
INIT_PUBLIC_API
int
InitParamWorkSpace
(
int
onlyRead
)
static
int
CheckNeedInit
(
int
onlyRead
,
const
PARAM_WORKSPACE_OPS
*
ops
)
{
PARAM_LOGI
(
"InitParamWorkSpace %p"
,
&
g_paramWorkSpace
);
if
(
ops
!=
NULL
)
{
g_paramWorkSpace
.
ops
.
updaterMode
=
ops
->
updaterMode
;
g_paramWorkSpace
.
ops
.
logFunc
=
ops
->
logFunc
;
#ifdef PARAM_SUPPORT_SELINUX
g_paramWorkSpace
.
ops
.
setfilecon
=
ops
->
setfilecon
;
#endif
}
PARAM_LOGI
(
"InitParamWorkSpace %p %x"
,
&
g_paramWorkSpace
,
g_paramWorkSpace
.
flags
);
if
(
PARAM_TEST_FLAG
(
g_paramWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
))
{
return
0
;
}
if
(
onlyRead
==
0
)
{
return
1
;
}
#if !(defined __LITEOS_A__ || defined __LITEOS_M__)
if
(
getpid
()
==
1
)
{
// init process only for write
return
0
;
}
// for ut, do not init workspace
char
path
[
PATH_MAX
]
=
{
0
};
(
void
)
readlink
(
"/proc/self/exe"
,
path
,
sizeof
(
path
));
char
*
name
=
strrchr
(
path
,
'/'
);
if
(
name
!=
NULL
)
{
name
++
;
}
else
{
name
=
path
;
}
if
(
strcmp
(
name
,
"init_unittest"
)
==
0
)
{
PARAM_LOGW
(
"Can not init client for init_test"
);
return
0
;
}
#endif
return
1
;
}
INIT_INNER_API
int
InitParamWorkSpace
(
int
onlyRead
,
const
PARAM_WORKSPACE_OPS
*
ops
)
{
if
(
CheckNeedInit
(
onlyRead
,
ops
)
==
0
)
{
return
0
;
}
paramMutexEnvInit
();
HashInfo
info
=
{
WorkSpaceNodeCompare
,
...
...
@@ -166,7 +183,7 @@ INIT_PUBLIC_API int InitParamWorkSpace(int onlyRead)
return
ret
;
}
INIT_
INNER
_API
void
CloseParamWorkSpace
(
void
)
INIT_
LOCAL
_API
void
CloseParamWorkSpace
(
void
)
{
PARAM_LOGI
(
"CloseParamWorkSpace %p"
,
&
g_paramWorkSpace
);
if
(
!
PARAM_TEST_FLAG
(
g_paramWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
))
{
...
...
@@ -189,127 +206,23 @@ INIT_INNER_API void CloseParamWorkSpace(void)
g_paramWorkSpace
.
flags
=
0
;
}
INIT_LOCAL_API
int
AddWorkSpace
(
const
char
*
name
,
int
onlyRead
,
uint32_t
spaceSize
)
INIT_LOCAL_API
void
ParamWorBaseLog
(
InitLogLevel
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
...
)
{
int
ret
=
0
;
// check exist
#ifdef PARAM_SUPPORT_SELINUX
const
char
*
realName
=
name
;
#else
const
char
*
realName
=
WORKSPACE_NAME_NORMAL
;
#endif
WORKSPACE_RW_LOCK
(
g_paramWorkSpace
);
HashNode
*
node
=
OH_HashMapGet
(
g_paramWorkSpace
.
workSpaceHashHandle
,
(
const
void
*
)
realName
);
if
(
node
!=
NULL
)
{
WORKSPACE_RW_UNLOCK
(
g_paramWorkSpace
);
return
0
;
}
PARAM_LOGV
(
"AddWorkSpace %s spaceSize: %u onlyRead %s"
,
name
,
spaceSize
,
onlyRead
?
"true"
:
"false"
);
WorkSpace
*
workSpace
=
NULL
;
do
{
ret
=
-
1
;
const
size_t
size
=
strlen
(
realName
)
+
1
;
workSpace
=
(
WorkSpace
*
)
malloc
(
sizeof
(
WorkSpace
)
+
size
);
PARAM_CHECK
(
workSpace
!=
NULL
,
break
,
"Failed to create workspace for %s"
,
realName
);
workSpace
->
flags
=
0
;
workSpace
->
area
=
NULL
;
OH_ListInit
(
&
workSpace
->
node
);
ret
=
ParamStrCpy
(
workSpace
->
fileName
,
size
,
realName
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to copy file name %s"
,
realName
);
HASHMAPInitNode
(
&
workSpace
->
hashNode
);
ret
=
InitWorkSpace
(
workSpace
,
onlyRead
,
spaceSize
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to init workspace %s"
,
realName
);
ret
=
OH_HashMapAdd
(
g_paramWorkSpace
.
workSpaceHashHandle
,
&
workSpace
->
hashNode
);
PARAM_CHECK
(
ret
==
0
,
CloseWorkSpace
(
workSpace
);
workSpace
=
NULL
;
break
,
"Failed to add hash node"
);
OH_ListAddTail
(
&
g_paramWorkSpace
.
workSpaceList
,
&
workSpace
->
node
);
ret
=
0
;
workSpace
=
NULL
;
}
while
(
0
);
if
(
workSpace
!=
NULL
)
{
free
(
workSpace
);
}
WORKSPACE_RW_UNLOCK
(
g_paramWorkSpace
);
PARAM_LOGV
(
"AddWorkSpace %s %s"
,
name
,
ret
==
0
?
"success"
:
"fail"
);
return
ret
;
}
static
uint32_t
ReadCommitId
(
ParamNode
*
entry
)
{
uint32_t
commitId
=
ATOMIC_LOAD_EXPLICIT
(
&
entry
->
commitId
,
memory_order_acquire
);
while
(
commitId
&
PARAM_FLAGS_MODIFY
)
{
futex_wait
(
&
entry
->
commitId
,
commitId
);
commitId
=
ATOMIC_LOAD_EXPLICIT
(
&
entry
->
commitId
,
memory_order_acquire
);
}
return
commitId
&
PARAM_FLAGS_COMMITID
;
}
static
int
ReadParamValue
(
ParamHandle
handle
,
char
*
value
,
uint32_t
*
length
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
length
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid param"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
if
(
value
==
NULL
)
{
*
length
=
entry
->
valueLength
+
1
;
return
0
;
if
(
g_paramWorkSpace
.
ops
.
logFunc
!=
NULL
)
{
va_list
vargs
;
va_start
(
vargs
,
fmt
);
g_paramWorkSpace
.
ops
.
logFunc
(
logLevel
,
domain
,
tag
,
fmt
,
vargs
);
va_end
(
vargs
);
}
PARAM_CHECK
(
*
length
>
entry
->
valueLength
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid value len %u %u"
,
*
length
,
entry
->
valueLength
);
uint32_t
commitId
=
ReadCommitId
(
entry
);
do
{
int
ret
=
ParamMemcpy
(
value
,
*
length
,
entry
->
data
+
entry
->
keyLength
+
1
,
entry
->
valueLength
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to copy value"
);
value
[
entry
->
valueLength
]
=
'\0'
;
*
length
=
entry
->
valueLength
;
}
while
(
commitId
!=
ReadCommitId
(
entry
));
return
0
;
}
static
int
ReadParamName
(
ParamHandle
handle
,
char
*
name
,
uint32_t
length
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid param"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
PARAM_CHECK
(
length
>
entry
->
keyLength
,
return
-
1
,
"Invalid param size %u %u"
,
entry
->
keyLength
,
length
);
int
ret
=
ParamMemcpy
(
name
,
length
,
entry
->
data
,
entry
->
keyLength
);
PARAM_CHECK
(
ret
==
0
,
return
PARAM_CODE_INVALID_PARAM
,
"Failed to copy name"
);
name
[
entry
->
keyLength
]
=
'\0'
;
return
0
;
}
INIT_INNER_API
int
CheckParamPermission
(
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
)
INIT_INNER_API
ParamWorkSpace
*
GetParamWorkSpace
(
void
)
{
PARAM_CHECK
(
srcLabel
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"The srcLabel is null"
);
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
DAC_RESULT_FORBIDED
,
"Invalid space"
);
int
ret
=
DAC_RESULT_PERMISSION
;
// for root, all permission
if
(
srcLabel
->
cred
.
uid
!=
0
)
{
for
(
int
i
=
0
;
i
<
PARAM_SECURITY_MAX
;
i
++
)
{
if
(
PARAM_TEST_FLAG
(
g_paramWorkSpace
.
securityLabel
.
flags
[
i
],
LABEL_ALL_PERMISSION
))
{
continue
;
}
ParamSecurityOps
*
ops
=
GetParamSecurityOps
(
i
);
if
(
ops
==
NULL
)
{
continue
;
}
if
(
ops
->
securityCheckParamPermission
==
NULL
)
{
continue
;
}
ret
=
ops
->
securityCheckParamPermission
(
srcLabel
,
name
,
mode
);
if
(
ret
==
DAC_RESULT_FORBIDED
)
{
PARAM_LOGW
(
"CheckParamPermission %s %s FORBID"
,
ops
->
name
,
name
);
break
;
}
}
if
(
!
PARAM_TEST_FLAG
(
g_paramWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
))
{
PARAM_LOGE
(
"GetParamWorkSpace %p"
,
&
g_paramWorkSpace
);
return
NULL
;
}
return
ret
;
return
&
g_paramWorkSpace
;
}
int
SystemReadParam
(
const
char
*
name
,
char
*
value
,
uint32_t
*
len
)
...
...
@@ -323,95 +236,3 @@ int SystemReadParam(const char *name, char *value, uint32_t *len)
}
return
ReadParamValue
(
handle
,
value
,
len
);
}
int
SystemGetParameterCommitId
(
ParamHandle
handle
,
uint32_t
*
commitId
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
handle
!=
0
&&
commitId
!=
NULL
,
return
-
1
,
"The handle is null"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
*
commitId
=
ReadCommitId
(
entry
);
return
0
;
}
long
long
GetSystemCommitId
(
void
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
0
,
"Invalid space"
);
WorkSpace
*
space
=
GetWorkSpace
(
WORKSPACE_NAME_DAC
);
if
(
space
==
NULL
||
space
->
area
==
NULL
)
{
return
0
;
}
return
ATOMIC_LOAD_EXPLICIT
(
&
space
->
area
->
commitId
,
memory_order_acquire
);
}
int
SystemGetParameterName
(
ParamHandle
handle
,
char
*
name
,
unsigned
int
len
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
name
!=
NULL
&&
handle
!=
0
,
return
-
1
,
"The name is null"
);
return
ReadParamName
(
handle
,
name
,
len
);
}
int
SystemGetParameterValue
(
ParamHandle
handle
,
char
*
value
,
unsigned
int
*
len
)
{
PARAM_WORKSPACE_CHECK
(
&
g_paramWorkSpace
,
return
-
1
,
"Invalid space"
);
PARAM_CHECK
(
len
!=
NULL
&&
handle
!=
0
,
return
-
1
,
"The value is null"
);
return
ReadParamValue
(
handle
,
value
,
len
);
}
INIT_INNER_API
ParamWorkSpace
*
GetParamWorkSpace
(
void
)
{
if
(
!
PARAM_TEST_FLAG
(
g_paramWorkSpace
.
flags
,
WORKSPACE_FLAGS_INIT
))
{
PARAM_LOGE
(
"GetParamWorkSpace %p"
,
&
g_paramWorkSpace
);
return
NULL
;
}
return
&
g_paramWorkSpace
;
}
INIT_LOCAL_API
int
ParamSprintf
(
char
*
buffer
,
size_t
buffSize
,
const
char
*
format
,
...)
{
int
len
=
-
1
;
va_list
vargs
;
va_start
(
vargs
,
format
);
#ifdef PARAM_BASE
len
=
vsnprintf
(
buffer
,
buffSize
-
1
,
format
,
vargs
);
#else
len
=
vsnprintf_s
(
buffer
,
buffSize
,
buffSize
-
1
,
format
,
vargs
);
#endif
va_end
(
vargs
);
return
len
;
}
INIT_LOCAL_API
int
ParamMemcpy
(
void
*
dest
,
size_t
destMax
,
const
void
*
src
,
size_t
count
)
{
int
ret
=
0
;
#ifdef PARAM_BASE
memcpy
(
dest
,
src
,
count
);
#else
ret
=
memcpy_s
(
dest
,
destMax
,
src
,
count
);
#endif
return
ret
;
}
INIT_LOCAL_API
int
ParamStrCpy
(
char
*
strDest
,
size_t
destMax
,
const
char
*
strSrc
)
{
int
ret
=
0
;
#ifdef PARAM_BASE
if
(
strlen
(
strSrc
)
>=
destMax
)
{
return
-
1
;
}
size_t
i
=
0
;
while
((
i
<
destMax
)
&&
*
strSrc
!=
'\0'
)
{
*
strDest
=
*
strSrc
;
strDest
++
;
strSrc
++
;
i
++
;
}
*
strDest
=
'\0'
;
#else
ret
=
strcpy_s
(
strDest
,
destMax
,
strSrc
);
#endif
return
ret
;
}
\ No newline at end of file
services/param/base/param_base.h
浏览文件 @
3bec302f
...
...
@@ -15,10 +15,7 @@
#ifndef BASE_STARTUP_PARAM_BASE_H
#define BASE_STARTUP_PARAM_BASE_H
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include "sys_param.h"
#include "beget_ext.h"
#ifndef PARAM_BASE
#include "securec.h"
...
...
@@ -30,11 +27,10 @@ extern "C" {
#endif
#endif
INIT_LOCAL_API
void
CloseParamWorkSpace
(
void
);
INIT_LOCAL_API
int
ParamSprintf
(
char
*
buffer
,
size_t
buffSize
,
const
char
*
format
,
...);
INIT_LOCAL_API
int
ParamMemcpy
(
void
*
dest
,
size_t
destMax
,
const
void
*
src
,
size_t
count
);
INIT_LOCAL_API
int
ParamStrCpy
(
char
*
strDest
,
size_t
destMax
,
const
char
*
strSrc
);
INIT_INNER_API
int
ReadFileInDir
(
const
char
*
dirPath
,
const
char
*
includeExt
,
int
(
*
processFile
)(
const
char
*
fileName
,
void
*
context
),
void
*
context
);
#ifdef __cplusplus
#if __cplusplus
...
...
services/param/base/param_comm.c
浏览文件 @
3bec302f
...
...
@@ -19,6 +19,24 @@
#include "param_trie.h"
#include "param_base.h"
INIT_LOCAL_API
int
GenerateKeyHasCode
(
const
char
*
buff
,
size_t
len
)
{
int
code
=
0
;
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
code
+=
buff
[
i
]
-
'A'
;
}
return
code
;
}
INIT_LOCAL_API
ParamHandle
GetParamHandle
(
const
WorkSpace
*
workSpace
,
uint32_t
index
,
const
char
*
name
)
{
PARAM_CHECK
(
workSpace
!=
NULL
&&
workSpace
->
area
!=
NULL
,
return
-
1
,
"Invalid param"
);
uint32_t
hashCode
=
(
uint32_t
)
GenerateKeyHasCode
(
workSpace
->
fileName
,
strlen
(
workSpace
->
fileName
));
uint32_t
handle
=
(
hashCode
%
HASH_BUTT
)
<<
24
;
// 24 left shift
handle
=
handle
|
(
index
+
workSpace
->
area
->
startIndex
);
return
handle
;
}
INIT_LOCAL_API
WorkSpace
*
GetWorkSpace
(
const
char
*
name
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
...
...
@@ -29,7 +47,8 @@ INIT_LOCAL_API WorkSpace *GetWorkSpace(const char *name)
tmpName
=
WORKSPACE_NAME_NORMAL
;
#else
if
(
strcmp
(
name
,
WORKSPACE_NAME_DAC
)
!=
0
)
{
tmpName
=
(
char
*
)
GetSelinuxContent
(
name
);
tmpName
=
(
paramSpace
->
selinuxSpace
.
getParamLabel
!=
NULL
)
?
(
char
*
)
paramSpace
->
selinuxSpace
.
getParamLabel
(
name
)
:
WORKSPACE_NAME_NORMAL
;
}
#endif
WorkSpace
*
space
=
NULL
;
...
...
@@ -376,7 +395,7 @@ INIT_LOCAL_API ParamSecurityLabel *GetParamSecurityLabel()
return
&
paramSpace
->
securityLabel
;
}
int
SplitParamString
(
char
*
line
,
const
char
*
exclude
[],
uint32_t
count
,
INIT_LOCAL_API
int
SplitParamString
(
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
...
...
@@ -441,4 +460,178 @@ int SplitParamString(char *line, const char *exclude[], uint32_t count,
*
pos
=
'\0'
;
}
return
result
(
context
,
name
,
value
);
}
INIT_LOCAL_API
int
AddWorkSpace
(
const
char
*
name
,
int
onlyRead
,
uint32_t
spaceSize
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid workspace"
);
int
ret
=
0
;
// check exist
#ifdef PARAM_SUPPORT_SELINUX
const
char
*
realName
=
name
;
#else
const
char
*
realName
=
WORKSPACE_NAME_NORMAL
;
#endif
WORKSPACE_RW_LOCK
(
*
paramSpace
);
HashNode
*
node
=
OH_HashMapGet
(
paramSpace
->
workSpaceHashHandle
,
(
const
void
*
)
realName
);
if
(
node
!=
NULL
)
{
WORKSPACE_RW_UNLOCK
(
*
paramSpace
);
return
0
;
}
PARAM_LOGV
(
"AddWorkSpace %s spaceSize: %u onlyRead %s"
,
name
,
spaceSize
,
onlyRead
?
"true"
:
"false"
);
WorkSpace
*
workSpace
=
NULL
;
do
{
ret
=
-
1
;
const
size_t
size
=
strlen
(
realName
)
+
1
;
workSpace
=
(
WorkSpace
*
)
malloc
(
sizeof
(
WorkSpace
)
+
size
);
PARAM_CHECK
(
workSpace
!=
NULL
,
break
,
"Failed to create workspace for %s"
,
realName
);
workSpace
->
flags
=
0
;
workSpace
->
area
=
NULL
;
OH_ListInit
(
&
workSpace
->
node
);
ret
=
ParamStrCpy
(
workSpace
->
fileName
,
size
,
realName
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to copy file name %s"
,
realName
);
HASHMAPInitNode
(
&
workSpace
->
hashNode
);
ret
=
InitWorkSpace
(
workSpace
,
onlyRead
,
spaceSize
);
PARAM_CHECK
(
ret
==
0
,
break
,
"Failed to init workspace %s"
,
realName
);
ret
=
OH_HashMapAdd
(
paramSpace
->
workSpaceHashHandle
,
&
workSpace
->
hashNode
);
PARAM_CHECK
(
ret
==
0
,
CloseWorkSpace
(
workSpace
);
workSpace
=
NULL
;
break
,
"Failed to add hash node"
);
OH_ListAddTail
(
&
paramSpace
->
workSpaceList
,
&
workSpace
->
node
);
ret
=
0
;
workSpace
=
NULL
;
}
while
(
0
);
if
(
workSpace
!=
NULL
)
{
free
(
workSpace
);
}
WORKSPACE_RW_UNLOCK
(
*
paramSpace
);
PARAM_LOGV
(
"AddWorkSpace %s %s"
,
name
,
ret
==
0
?
"success"
:
"fail"
);
return
ret
;
}
INIT_LOCAL_API
uint32_t
ReadCommitId
(
ParamNode
*
entry
)
{
uint32_t
commitId
=
ATOMIC_LOAD_EXPLICIT
(
&
entry
->
commitId
,
memory_order_acquire
);
while
(
commitId
&
PARAM_FLAGS_MODIFY
)
{
futex_wait
(
&
entry
->
commitId
,
commitId
);
commitId
=
ATOMIC_LOAD_EXPLICIT
(
&
entry
->
commitId
,
memory_order_acquire
);
}
return
commitId
&
PARAM_FLAGS_COMMITID
;
}
INIT_LOCAL_API
int
ReadParamValue
(
ParamHandle
handle
,
char
*
value
,
uint32_t
*
length
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid workspace"
);
PARAM_CHECK
(
length
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid param"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
if
(
value
==
NULL
)
{
*
length
=
entry
->
valueLength
+
1
;
return
0
;
}
PARAM_CHECK
(
*
length
>
entry
->
valueLength
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid value len %u %u"
,
*
length
,
entry
->
valueLength
);
uint32_t
commitId
=
ReadCommitId
(
entry
);
do
{
int
ret
=
ParamMemcpy
(
value
,
*
length
,
entry
->
data
+
entry
->
keyLength
+
1
,
entry
->
valueLength
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to copy value"
);
value
[
entry
->
valueLength
]
=
'\0'
;
*
length
=
entry
->
valueLength
;
}
while
(
commitId
!=
ReadCommitId
(
entry
));
return
0
;
}
INIT_LOCAL_API
int
ReadParamName
(
ParamHandle
handle
,
char
*
name
,
uint32_t
length
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid workspace"
);
PARAM_CHECK
(
name
!=
NULL
,
return
PARAM_CODE_INVALID_PARAM
,
"Invalid param"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
PARAM_CHECK
(
length
>
entry
->
keyLength
,
return
-
1
,
"Invalid param size %u %u"
,
entry
->
keyLength
,
length
);
int
ret
=
ParamMemcpy
(
name
,
length
,
entry
->
data
,
entry
->
keyLength
);
PARAM_CHECK
(
ret
==
0
,
return
PARAM_CODE_INVALID_PARAM
,
"Failed to copy name"
);
name
[
entry
->
keyLength
]
=
'\0'
;
return
0
;
}
INIT_LOCAL_API
int
CheckParamPermission
(
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
)
{
PARAM_CHECK
(
srcLabel
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"The srcLabel is null"
);
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
DAC_RESULT_FORBIDED
,
"Invalid workspace"
);
int
ret
=
DAC_RESULT_PERMISSION
;
// for root, all permission
if
(
srcLabel
->
cred
.
uid
!=
0
)
{
for
(
int
i
=
0
;
i
<
PARAM_SECURITY_MAX
;
i
++
)
{
if
(
PARAM_TEST_FLAG
(
paramSpace
->
securityLabel
.
flags
[
i
],
LABEL_ALL_PERMISSION
))
{
continue
;
}
ParamSecurityOps
*
ops
=
GetParamSecurityOps
(
i
);
if
(
ops
==
NULL
)
{
continue
;
}
if
(
ops
->
securityCheckParamPermission
==
NULL
)
{
continue
;
}
ret
=
ops
->
securityCheckParamPermission
(
srcLabel
,
name
,
mode
);
if
(
ret
==
DAC_RESULT_FORBIDED
)
{
PARAM_LOGW
(
"CheckParamPermission %s %s FORBID"
,
ops
->
name
,
name
);
break
;
}
}
}
return
ret
;
}
INIT_LOCAL_API
int
ParamSprintf
(
char
*
buffer
,
size_t
buffSize
,
const
char
*
format
,
...)
{
int
len
=
-
1
;
va_list
vargs
;
va_start
(
vargs
,
format
);
#ifdef PARAM_BASE
len
=
vsnprintf
(
buffer
,
buffSize
-
1
,
format
,
vargs
);
#else
len
=
vsnprintf_s
(
buffer
,
buffSize
,
buffSize
-
1
,
format
,
vargs
);
#endif
va_end
(
vargs
);
return
len
;
}
INIT_LOCAL_API
int
ParamMemcpy
(
void
*
dest
,
size_t
destMax
,
const
void
*
src
,
size_t
count
)
{
int
ret
=
0
;
#ifdef PARAM_BASE
memcpy
(
dest
,
src
,
count
);
#else
ret
=
memcpy_s
(
dest
,
destMax
,
src
,
count
);
#endif
return
ret
;
}
INIT_LOCAL_API
int
ParamStrCpy
(
char
*
strDest
,
size_t
destMax
,
const
char
*
strSrc
)
{
int
ret
=
0
;
#ifdef PARAM_BASE
if
(
strlen
(
strSrc
)
>=
destMax
)
{
return
-
1
;
}
size_t
i
=
0
;
while
((
i
<
destMax
)
&&
*
strSrc
!=
'\0'
)
{
*
strDest
=
*
strSrc
;
strDest
++
;
strSrc
++
;
i
++
;
}
*
strDest
=
'\0'
;
#else
ret
=
strcpy_s
(
strDest
,
destMax
,
strSrc
);
#endif
return
ret
;
}
\ No newline at end of file
services/param/base/param_trie.c
浏览文件 @
3bec302f
...
...
@@ -245,7 +245,7 @@ static ParamTrieNode *FindSubTrie(const WorkSpace *workSpace,
return
FindSubTrie
(
workSpace
,
subTrie
,
key
,
keyLen
,
matchLabel
);
}
ParamTrieNode
*
FindTrieNode_
(
const
WorkSpace
*
workSpace
,
const
char
*
key
,
uint32_t
keyLen
,
uint32_t
*
matchLabel
)
static
ParamTrieNode
*
FindTrieNode_
(
const
WorkSpace
*
workSpace
,
const
char
*
key
,
uint32_t
keyLen
,
uint32_t
*
matchLabel
)
{
PARAM_CHECK
(
key
!=
NULL
&&
keyLen
>
0
,
return
NULL
,
"Invalid key "
);
PARAM_CHECK
(
workSpace
!=
NULL
&&
workSpace
->
area
!=
NULL
,
return
0
,
"Invalid workSpace %s"
,
key
);
...
...
@@ -405,7 +405,7 @@ INIT_LOCAL_API ParamTrieNode *FindTrieNode(WorkSpace *workSpace,
return
node
;
}
uint32_t
GetParamMaxLen
(
uint8_t
type
)
INIT_LOCAL_API
uint32_t
GetParamMaxLen
(
uint8_t
type
)
{
static
const
uint32_t
typeLengths
[]
=
{
PARAM_VALUE_LEN_MAX
,
32
,
8
// 8 max bool length 32 max int length
...
...
services/param/include/param_manager.h
浏览文件 @
3bec302f
...
...
@@ -21,6 +21,7 @@
#include "init_param.h"
#include "list.h"
#include "param_base.h"
#include "param_osadp.h"
#include "param_persist.h"
#include "param_security.h"
...
...
@@ -58,6 +59,10 @@ typedef struct {
ListHead
workSpaceList
;
#ifdef PARAMWORKSPACE_NEED_MUTEX
ParamRWMutex
rwlock
;
#endif
PARAM_WORKSPACE_OPS
ops
;
#ifdef PARAM_SUPPORT_SELINUX
SelinuxSpace
selinuxSpace
;
#endif
}
ParamWorkSpace
;
...
...
@@ -110,17 +115,19 @@ INIT_LOCAL_API int InitPersistParamWorkSpace(void);
INIT_LOCAL_API
void
ClosePersistParamWorkSpace
(
void
);
INIT_LOCAL_API
int
WritePersistParam
(
const
char
*
name
,
const
char
*
value
);
INIT_LOCAL_API
uint32_t
ReadCommitId
(
ParamNode
*
entry
);
INIT_LOCAL_API
int
ReadParamName
(
ParamHandle
handle
,
char
*
name
,
uint32_t
length
);
INIT_LOCAL_API
int
ReadParamValue
(
ParamHandle
handle
,
char
*
value
,
uint32_t
*
length
);
INIT_LOCAL_API
int
CheckParameterSet
(
const
char
*
name
,
const
char
*
value
,
const
ParamSecurityLabel
*
srcLabel
,
int
*
ctrlService
);
INIT_INNER_API
ParamHandle
GetParamHandle
(
const
WorkSpace
*
workSpace
,
uint32_t
index
,
const
char
*
name
);
INIT_INNER_API
int
CheckParamPermission
(
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
);
INIT_INNER_API
int
InitParamWorkSpace
(
int
onlyRead
);
INIT_INNER_API
void
CloseParamWorkSpace
(
void
);
INIT_INNER_API
const
char
*
GetSelinuxContent
(
const
char
*
name
);
INIT_INNER_API
ParamWorkSpace
*
GetParamWorkSpace
(
void
);
INIT_LOCAL_API
ParamHandle
GetParamHandle
(
const
WorkSpace
*
workSpace
,
uint32_t
index
,
const
char
*
name
);
INIT_LOCAL_API
int
CheckParamPermission
(
const
ParamSecurityLabel
*
srcLabel
,
const
char
*
name
,
uint32_t
mode
);
INIT_LOCAL_API
int
SysCheckParamExist
(
const
char
*
name
);
INIT_LOCAL_API
int
GenerateKeyHasCode
(
const
char
*
buff
,
size_t
len
);
INIT_INNER_API
ParamWorkSpace
*
GetParamWorkSpace
(
void
);
INIT_INNER_API
int
GetParamSecurityAuditData
(
const
char
*
name
,
int
type
,
ParamAuditData
*
auditData
);
INIT_INNER_API
int
SysCheckParamExist
(
const
char
*
name
);
INIT_LOCAL_API
int
GetServiceCtrlInfo
(
const
char
*
name
,
const
char
*
value
,
ServiceCtrlInfo
**
ctrlInfo
);
#ifdef STARTUP_INIT_TEST
...
...
services/param/include/param_osadp.h
浏览文件 @
3bec302f
...
...
@@ -136,17 +136,17 @@ typedef struct {
}
ParamMutex
;
#endif
void
paramMutexEnvInit
(
void
);
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
);
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
);
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
);
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
);
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
);
int
ParamMutexCreate
(
ParamMutex
*
mutex
);
int
ParamMutexPend
(
ParamMutex
*
mutex
);
int
ParamMutexPost
(
ParamMutex
*
mutex
);
int
ParamMutexDelete
(
ParamMutex
*
mutex
);
INIT_LOCAL_API
void
paramMutexEnvInit
(
void
);
INIT_LOCAL_API
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
);
INIT_LOCAL_API
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
);
INIT_LOCAL_API
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
);
INIT_LOCAL_API
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
);
INIT_LOCAL_API
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
);
INIT_LOCAL_API
int
ParamMutexCreate
(
ParamMutex
*
mutex
);
INIT_LOCAL_API
int
ParamMutexPend
(
ParamMutex
*
mutex
);
INIT_LOCAL_API
int
ParamMutexPost
(
ParamMutex
*
mutex
);
INIT_LOCAL_API
int
ParamMutexDelete
(
ParamMutex
*
mutex
);
#ifdef WORKSPACE_AREA_NEED_MUTEX
#define PARAMSPACE_AREA_INIT_LOCK(workspace) ParamRWMutexCreate(&workspace->rwlock)
...
...
@@ -175,8 +175,8 @@ int ParamMutexDelete(ParamMutex *mutex);
typedef
struct
{
int
shmid
;
}
MemHandle
;
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
);
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
);
INIT_LOCAL_API
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
);
INIT_LOCAL_API
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
);
// for atomic
#ifdef __LITEOS_M__
...
...
@@ -198,5 +198,5 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize);
#endif
#endif
uint32_t
Difftime
(
time_t
curr
,
time_t
base
);
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
);
#endif // BASE_STARTUP_PARAM_MESSAGE_H
\ No newline at end of file
services/param/include/param_security.h
浏览文件 @
3bec302f
...
...
@@ -102,7 +102,7 @@ typedef struct SelinuxSpace_ {
void
(
*
setSelinuxLogCallback
)(
void
);
int
(
*
setParamCheck
)(
const
char
*
paraName
,
struct
ucred
*
uc
);
const
char
*
(
*
getParamLabel
)(
const
char
*
paraName
);
void
(
*
initParamSelinux
)(
void
);
int
(
*
initParamSelinux
)(
void
);
int
(
*
readParamCheck
)(
const
char
*
paraName
);
ParamContextsList
*
(
*
getParamList
)(
void
);
void
(
*
destroyParamList
)(
ParamContextsList
**
list
);
...
...
@@ -111,15 +111,11 @@ typedef struct SelinuxSpace_ {
INIT_LOCAL_API
int
RegisterSecuritySelinuxOps
(
ParamSecurityOps
*
ops
,
int
isInit
);
#endif
#if defined STARTUP_INIT_TEST || defined LOCAL_TEST
int
RegisterSecurityOps
(
int
onlyRead
);
void
SetSelinuxOps
(
const
SelinuxSpace
*
space
);
#endif
INIT_LOCAL_API
ParamSecurityOps
*
GetParamSecurityOps
(
int
type
);
INIT_LOCAL_API
void
LoadGroupUser
(
void
);
INIT_LOCAL_API
int
RegisterSecurityDacOps
(
ParamSecurityOps
*
ops
,
int
isInit
);
INIT_LOCAL_API
void
OpenPermissionWorkSpace
(
void
);
INIT_LOCAL_API
int
RegisterSecurityOps
(
int
onlyRead
);
#ifdef __cplusplus
#if __cplusplus
...
...
services/param/include/param_trie.h
浏览文件 @
3bec302f
...
...
@@ -118,7 +118,7 @@ INIT_LOCAL_API uint32_t AddParamSecurityNode(WorkSpace *workSpace, const ParamAu
INIT_LOCAL_API
uint32_t
AddParamNode
(
WorkSpace
*
workSpace
,
uint8_t
type
,
const
char
*
key
,
uint32_t
keyLen
,
const
char
*
value
,
uint32_t
valueLen
);
uint32_t
GetParamMaxLen
(
uint8_t
type
);
INIT_LOCAL_API
uint32_t
GetParamMaxLen
(
uint8_t
type
);
#ifdef __cplusplus
#if __cplusplus
...
...
services/param/include/param_utils.h
浏览文件 @
3bec302f
...
...
@@ -99,10 +99,22 @@ typedef struct cmdLineInfo {
#define PARAN_DOMAIN (BASE_DOMAIN + 2)
#endif
#define PARAN_LABEL "PARAM"
#ifdef PARAM_BASE
INIT_LOCAL_API
void
ParamWorBaseLog
(
InitLogLevel
logLevel
,
uint32_t
domain
,
const
char
*
tag
,
const
char
*
fmt
,
...);
#define PARAM_LOGV(fmt, ...) \
ParamWorBaseLog
(
INIT_DEBUG
,
PARAN_DOMAIN
,
PARAN_LABEL
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#define PARAM_LOGI(fmt, ...) \
ParamWorBaseLog
(
INIT_INFO
,
PARAN_DOMAIN
,
PARAN_LABEL
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#define PARAM_LOGW(fmt, ...) \
ParamWorBaseLog
(
INIT_WARN
,
PARAN_DOMAIN
,
PARAN_LABEL
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#define PARAM_LOGE(fmt, ...) \
ParamWorBaseLog
(
INIT_ERROR
,
PARAN_DOMAIN
,
PARAN_LABEL
,
"[%s:%d]"
fmt
,
(
FILE_NAME
),
(
__LINE__
),
##
__VA_ARGS__
)
#else
#define PARAM_LOGI(fmt, ...) STARTUP_LOGI(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
#define PARAM_LOGE(fmt, ...) STARTUP_LOGE(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
#define PARAM_LOGV(fmt, ...) STARTUP_LOGV(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
#define PARAM_LOGW(fmt, ...) STARTUP_LOGW(PARAN_DOMAIN, PARAN_LABEL, fmt, ##__VA_ARGS__)
#endif
#define PARAM_CHECK(retCode, exper, ...) \
if
(
!
(
retCode
))
{
\
...
...
@@ -134,7 +146,7 @@ typedef struct cmdLineInfo {
#define SUBSTR_INFO_DAC 1
#endif
int
SplitParamString
(
char
*
line
,
const
char
*
exclude
[],
uint32_t
count
,
INIT_LOCAL_API
int
SplitParamString
(
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/linux/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -19,6 +19,8 @@ config("exported_header_files") {
"//base/startup/init/interfaces/innerkits/include",
"//base/startup/init/interfaces/service/include/param",
"//base/startup/init/interfaces/service/param/include",
"//third_party/bounds_checking_function/include",
"//third_party/selinux/libselinux/include",
]
}
...
...
@@ -113,6 +115,10 @@ if (defined(ohos_lite)) {
defines += [ "BOOT_EXTENDED_CMDLINE=\"${boot_kernel_extended_cmdline}\"" ]
}
if (param_base_log) {
defines += [ "PARAM_BASE_LOG" ]
}
if (build_selinux) {
include_dirs += [
"//third_party/selinux/libselinux/include/",
...
...
@@ -134,16 +140,14 @@ if (defined(ohos_lite)) {
"INIT_AGENT",
]
if (build_selinux) {
deps += [
"//base/security/selinux:libload_policy",
"//base/security/selinux:librestorecon",
"//third_party/selinux:libselinux",
]
defines += [
"PARAM_SUPPORT_SELINUX",
"PARAMWORKSPACE_NEED_MUTEX",
]
}
if (param_base_log) {
defines += [ "PARAM_BASE_LOG" ]
}
part_name = "init"
subsystem_name = "startup"
}
...
...
services/param/linux/param_osadp.c
浏览文件 @
3bec302f
...
...
@@ -20,11 +20,11 @@
#include "param_message.h"
#include "param_utils.h"
void
paramMutexEnvInit
(
void
)
INIT_LOCAL_API
void
paramMutexEnvInit
(
void
)
{
}
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlockattr_t
rwlockatt
;
...
...
@@ -33,26 +33,27 @@ int ParamRWMutexCreate(ParamRWMutex *lock)
pthread_rwlock_init
(
&
lock
->
rwlock
,
&
rwlockatt
);
return
0
;
}
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_wrlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_rdlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_unlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
int
ret
=
pthread_rwlock_destroy
(
&
lock
->
rwlock
);
...
...
@@ -60,24 +61,24 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return
0
;
}
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
{
return
0
;
}
int
ParamMutexPend
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPend
(
ParamMutex
*
mutex
)
{
return
0
;
}
int
ParamMutexPost
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPost
(
ParamMutex
*
mutex
)
{
return
0
;
}
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
{
return
0
;
}
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
INIT_LOCAL_API
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
{
PARAM_CHECK
(
fileName
!=
NULL
,
return
NULL
,
"Invalid filename or handle"
);
int
mode
=
readOnly
?
O_RDONLY
:
O_CREAT
|
O_RDWR
|
O_TRUNC
;
...
...
@@ -96,13 +97,13 @@ void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize,
return
areaAddr
;
}
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
INIT_LOCAL_API
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
{
PARAM_CHECK
(
mem
!=
NULL
&&
handle
!=
NULL
,
return
,
"Invalid mem or handle"
);
munmap
((
char
*
)
mem
,
dataSize
);
}
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
{
return
(
uint32_t
)
difftime
(
curr
,
base
);
}
\ No newline at end of file
services/param/linux/param_request.c
浏览文件 @
3bec302f
...
...
@@ -21,7 +21,11 @@
#include <sys/socket.h>
#include <unistd.h>
#ifdef PARAM_BASE_LOG
#include "init_log.h"
#endif
#include "init_utils.h"
#include "param_base.h"
#include "param_manager.h"
#include "param_message.h"
#include "param_security.h"
...
...
@@ -38,12 +42,19 @@ __attribute__((constructor)) static void ParameterInit(void)
return
;
}
EnableInitLog
(
INIT_INFO
);
InitParamWorkSpace
(
1
);
PARAM_WORKSPACE_OPS
ops
=
{
0
};
ops
.
updaterMode
=
0
;
#ifdef PARAM_BASE_LOG
ops
.
logFunc
=
InitLog
;
#endif
#ifdef PARAM_SUPPORT_SELINUX
ops
.
setfilecon
=
NULL
;
#endif
InitParamWorkSpace
(
1
,
&
ops
);
}
__attribute__
((
destructor
))
static
void
ParameterDeinit
(
void
)
{
PARAM_LOGI
(
"ParameterDeinit "
);
if
(
g_clientFd
!=
INVALID_SOCKET
)
{
close
(
g_clientFd
);
g_clientFd
=
INVALID_SOCKET
;
...
...
services/param/linux/param_service.c
浏览文件 @
3bec302f
...
...
@@ -18,13 +18,22 @@
#include <string.h>
#include <sys/socket.h>
#ifdef PARAM_BASE_LOG
#include "init_log.h"
#endif
#include "init_param.h"
#include "init_utils.h"
#include "loop_event.h"
#include "param_base.h"
#include "param_manager.h"
#include "param_message.h"
#include "trigger_manager.h"
#include "securec.h"
#ifdef PARAM_SUPPORT_SELINUX
#include "selinux_parameter.h"
#include <policycoreutils.h>
#include <selinux/selinux.h>
#endif
static
ParamService
g_paramService
=
{};
...
...
@@ -369,7 +378,15 @@ void InitParamService(void)
CheckAndCreateDir
(
PIPE_NAME
);
CheckAndCreateDir
(
PARAM_STORAGE_PATH
"/"
);
// param space
int
ret
=
InitParamWorkSpace
(
0
);
PARAM_WORKSPACE_OPS
ops
=
{
0
};
ops
.
updaterMode
=
InUpdaterMode
();
#ifdef PARAM_BASE_LOG
ops
.
logFunc
=
InitLog
;
#endif
#ifdef PARAM_SUPPORT_SELINUX
ops
.
setfilecon
=
setfilecon
;
#endif
int
ret
=
InitParamWorkSpace
(
0
,
&
ops
);
PARAM_CHECK
(
ret
==
0
,
return
,
"Init parameter workspace fail"
);
ret
=
InitPersistParamWorkSpace
();
PARAM_CHECK
(
ret
==
0
,
return
,
"Init persist parameter workspace fail"
);
...
...
services/param/liteos/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -17,6 +17,7 @@ param_include_dirs = [
"//base/startup/init/services/modules/init_hook",
"//base/startup/init/services/param/include",
"//base/startup/init/services/param/adapter",
"//base/startup/init/services/param/base",
"//base/startup/init/services/include/param",
"//base/startup/init/services/include",
"//base/startup/init/services/init/include",
...
...
services/param/liteos/param_client.c
浏览文件 @
3bec302f
...
...
@@ -28,7 +28,7 @@ static int InitParamClient(void)
}
EnableInitLog
(
INIT_INFO
);
PARAM_LOGV
(
"InitParamClient"
);
int
ret
=
InitParamWorkSpace
(
1
);
int
ret
=
InitParamWorkSpace
(
1
,
NULL
);
PARAM_CHECK
(
ret
==
0
,
return
-
1
,
"Failed to init param workspace"
);
PARAM_SET_FLAG
(
g_flags
,
WORKSPACE_FLAGS_INIT
);
// init persist to save
...
...
services/param/liteos/param_osadp.c
浏览文件 @
3bec302f
...
...
@@ -109,7 +109,7 @@ void ParamTimerClose(ParamTaskPtr timer)
}
#ifdef __LITEOS_A__
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
INIT_LOCAL_API
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
{
PARAM_CHECK
(
fileName
!=
NULL
&&
handle
!=
NULL
,
return
NULL
,
"Invalid filename or handle"
);
int
mode
=
readOnly
?
O_RDONLY
:
O_CREAT
|
O_RDWR
;
...
...
@@ -130,19 +130,19 @@ void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize,
return
areaAddr
;
}
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
INIT_LOCAL_API
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
{
PARAM_CHECK
(
mem
!=
NULL
&&
handle
!=
NULL
,
return
,
"Invalid mem or handle"
);
shmdt
(
mem
);
shmctl
(
handle
->
shmid
,
IPC_RMID
,
NULL
);
}
void
paramMutexEnvInit
(
void
)
INIT_LOCAL_API
void
paramMutexEnvInit
(
void
)
{
return
;
}
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlockattr_t
rwlockatt
;
...
...
@@ -152,26 +152,26 @@ int ParamRWMutexCreate(ParamRWMutex *lock)
return
0
;
}
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_wrlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_rdlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
pthread_rwlock_unlock
(
&
lock
->
rwlock
);
return
0
;
}
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
pthread_rwlock_destroy
(
&
lock
->
rwlock
);
...
...
@@ -179,7 +179,7 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return
0
;
}
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid mutex"
);
pthread_mutexattr_t
mutexattr
;
...
...
@@ -188,7 +188,7 @@ int ParamMutexCreate(ParamMutex *mutex)
pthread_mutex_init
(
&
mutex
->
mutex
,
&
mutexattr
);
return
0
;
}
int
ParamMutexPend
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPend
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid mutex"
);
if
(
pthread_mutex_lock
(
&
mutex
->
mutex
)
!=
0
)
{
...
...
@@ -197,14 +197,14 @@ int ParamMutexPend(ParamMutex *mutex)
}
return
0
;
}
int
ParamMutexPost
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPost
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid mutex"
);
pthread_mutex_unlock
(
&
mutex
->
mutex
);
return
0
;
}
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
pthread_mutex_destroy
(
&
mutex
->
mutex
);
...
...
@@ -214,7 +214,7 @@ int ParamMutexDelete(ParamMutex *mutex)
#endif
#ifdef __LITEOS_M__
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
INIT_LOCAL_API
void
*
GetSharedMem
(
const
char
*
fileName
,
MemHandle
*
handle
,
uint32_t
spaceSize
,
int
readOnly
)
{
PARAM_CHECK
(
spaceSize
<=
PARAM_WORKSPACE_MAX
,
return
,
"Invalid spaceSize %u"
,
spaceSize
);
UNUSED
(
fileName
);
...
...
@@ -223,7 +223,7 @@ void *GetSharedMem(const char *fileName, MemHandle *handle, uint32_t spaceSize,
return
(
void
*
)
malloc
(
spaceSize
);
}
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
INIT_LOCAL_API
void
FreeSharedMem
(
const
MemHandle
*
handle
,
void
*
mem
,
uint32_t
dataSize
)
{
PARAM_CHECK
(
mem
!=
NULL
&&
handle
!=
NULL
,
return
,
"Invalid mem or handle"
);
UNUSED
(
handle
);
...
...
@@ -231,12 +231,12 @@ void FreeSharedMem(const MemHandle *handle, void *mem, uint32_t dataSize)
free
(
mem
);
}
void
paramMutexEnvInit
(
void
)
INIT_LOCAL_API
void
paramMutexEnvInit
(
void
)
{
return
;
}
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexCreate
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxCreate
(
&
lock
->
mutex
);
...
...
@@ -244,7 +244,7 @@ int ParamRWMutexCreate(ParamRWMutex *lock)
return
0
;
}
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexWRLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxPend
(
lock
->
mutex
,
LOS_WAIT_FOREVER
);
...
...
@@ -252,7 +252,7 @@ int ParamRWMutexWRLock(ParamRWMutex *lock)
return
0
;
}
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexRDLock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxPend
(
lock
->
mutex
,
LOS_WAIT_FOREVER
);
...
...
@@ -260,7 +260,7 @@ int ParamRWMutexRDLock(ParamRWMutex *lock)
return
0
;
}
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexUnlock
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxPost
(
lock
->
mutex
);
...
...
@@ -268,7 +268,7 @@ int ParamRWMutexUnlock(ParamRWMutex *lock)
return
0
;
}
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
INIT_LOCAL_API
int
ParamRWMutexDelete
(
ParamRWMutex
*
lock
)
{
PARAM_CHECK
(
lock
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxDelete
(
lock
->
mutex
);
...
...
@@ -276,7 +276,7 @@ int ParamRWMutexDelete(ParamRWMutex *lock)
return
0
;
}
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexCreate
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxCreate
(
&
mutex
->
mutex
);
...
...
@@ -284,7 +284,7 @@ int ParamMutexCreate(ParamMutex *mutex)
return
0
;
}
int
ParamMutexPend
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPend
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxPend
(
mutex
->
mutex
,
LOS_WAIT_FOREVER
);
...
...
@@ -292,7 +292,7 @@ int ParamMutexPend(ParamMutex *mutex)
return
0
;
}
int
ParamMutexPost
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexPost
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid lock"
);
uint32_t
ret
=
LOS_MuxPost
(
mutex
->
mutex
);
...
...
@@ -300,7 +300,7 @@ int ParamMutexPost(ParamMutex *mutex)
return
0
;
}
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
INIT_LOCAL_API
int
ParamMutexDelete
(
ParamMutex
*
mutex
)
{
PARAM_CHECK
(
mutex
!=
NULL
,
return
-
1
,
"Invalid mutex"
);
uint32_t
ret
=
LOS_MuxDelete
(
mutex
->
mutex
);
...
...
@@ -309,7 +309,7 @@ int ParamMutexDelete(ParamMutex *mutex)
}
#endif
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
INIT_LOCAL_API
uint32_t
Difftime
(
time_t
curr
,
time_t
base
)
{
#ifndef __LITEOS_M__
return
(
uint32_t
)
difftime
(
curr
,
base
);
...
...
services/param/liteos/param_service.c
浏览文件 @
3bec302f
...
...
@@ -64,7 +64,7 @@ void InitParamService(void)
CheckAndCreateDir
(
PARAM_STORAGE_PATH
"/"
);
CheckAndCreateDir
(
DATA_PATH
);
// param space
int
ret
=
InitParamWorkSpace
(
0
);
int
ret
=
InitParamWorkSpace
(
0
,
NULL
);
PARAM_CHECK
(
ret
==
0
,
return
,
"Init parameter workspace fail"
);
ret
=
InitPersistParamWorkSpace
();
PARAM_CHECK
(
ret
==
0
,
return
,
"Init persist parameter workspace fail"
);
...
...
services/param/manager/param_manager.c
浏览文件 @
3bec302f
...
...
@@ -30,15 +30,15 @@ ParamNode *SystemCheckMatchParamWait(const char *name, const char *value)
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
NULL
,
"Invalid paramSpace"
);
PARAM_WORKSPACE_CHECK
(
paramSpace
,
return
NULL
,
"Invalid space"
);
WorkSpace
*
works
ap
ce
=
GetWorkSpace
(
name
);
PARAM_CHECK
(
works
ap
ce
!=
NULL
,
return
NULL
,
"Failed to get workspace %s"
,
name
);
WorkSpace
*
works
pa
ce
=
GetWorkSpace
(
name
);
PARAM_CHECK
(
works
pa
ce
!=
NULL
,
return
NULL
,
"Failed to get workspace %s"
,
name
);
PARAM_LOGV
(
"SystemCheckMatchParamWait name %s"
,
name
);
uint32_t
nameLength
=
strlen
(
name
);
ParamTrieNode
*
node
=
FindTrieNode
(
works
ap
ce
,
name
,
nameLength
,
NULL
);
ParamTrieNode
*
node
=
FindTrieNode
(
works
pa
ce
,
name
,
nameLength
,
NULL
);
if
(
node
==
NULL
||
node
->
dataIndex
==
0
)
{
return
NULL
;
}
ParamNode
*
param
=
(
ParamNode
*
)
GetTrieNode
(
works
ap
ce
,
node
->
dataIndex
);
ParamNode
*
param
=
(
ParamNode
*
)
GetTrieNode
(
works
pa
ce
,
node
->
dataIndex
);
if
(
param
==
NULL
)
{
return
NULL
;
}
...
...
@@ -190,7 +190,7 @@ void SystemDumpParameters(int verbose)
PARAM_DUMP
(
"Dump all parameters finish
\n
"
);
}
INIT_
INNER
_API
int
SysCheckParamExist
(
const
char
*
name
)
INIT_
LOCAL
_API
int
SysCheckParamExist
(
const
char
*
name
)
{
ParamWorkSpace
*
paramSpace
=
GetParamWorkSpace
();
PARAM_CHECK
(
paramSpace
!=
NULL
,
return
-
1
,
"Invalid paramSpace"
);
...
...
@@ -231,7 +231,8 @@ INIT_INNER_API int GetParamSecurityAuditData(const char *name, int type, ParamAu
auditData
->
dacData
.
gid
=
node
->
gid
;
auditData
->
dacData
.
mode
=
node
->
mode
;
#ifdef PARAM_SUPPORT_SELINUX
const
char
*
tmpName
=
GetSelinuxContent
(
name
);
const
char
*
tmpName
=
(
paramSpace
->
selinuxSpace
.
getParamLabel
!=
NULL
)
?
paramSpace
->
selinuxSpace
.
getParamLabel
(
name
)
:
NULL
;
if
(
tmpName
!=
NULL
)
{
int
ret
=
strcpy_s
(
auditData
->
label
,
sizeof
(
auditData
->
label
),
tmpName
);
PARAM_CHECK
(
ret
==
0
,
return
0
,
"Failed to copy label for %s"
,
name
);
...
...
@@ -339,3 +340,36 @@ INIT_LOCAL_API int CheckParameterSet(const char *name,
}
return
ret
;
}
int
SystemGetParameterCommitId
(
ParamHandle
handle
,
uint32_t
*
commitId
)
{
PARAM_CHECK
(
handle
!=
0
&&
commitId
!=
NULL
,
return
-
1
,
"The handle is null"
);
ParamNode
*
entry
=
(
ParamNode
*
)
GetTrieNodeByHandle
(
handle
);
if
(
entry
==
NULL
)
{
return
-
1
;
}
*
commitId
=
ReadCommitId
(
entry
);
return
0
;
}
long
long
GetSystemCommitId
(
void
)
{
WorkSpace
*
space
=
GetWorkSpace
(
WORKSPACE_NAME_DAC
);
if
(
space
==
NULL
||
space
->
area
==
NULL
)
{
return
0
;
}
return
ATOMIC_LOAD_EXPLICIT
(
&
space
->
area
->
commitId
,
memory_order_acquire
);
}
int
SystemGetParameterName
(
ParamHandle
handle
,
char
*
name
,
unsigned
int
len
)
{
PARAM_CHECK
(
name
!=
NULL
&&
handle
!=
0
,
return
-
1
,
"The name is null"
);
return
ReadParamName
(
handle
,
name
,
len
);
}
int
SystemGetParameterValue
(
ParamHandle
handle
,
char
*
value
,
unsigned
int
*
len
)
{
PARAM_CHECK
(
len
!=
NULL
&&
handle
!=
0
,
return
-
1
,
"The value is null"
);
return
ReadParamValue
(
handle
,
value
,
len
);
}
\ No newline at end of file
test/unittest/param/param_stub.cpp
浏览文件 @
3bec302f
...
...
@@ -105,8 +105,8 @@ static void TestDestroyParamList(ParamContextsList **list)
ParamContextsList
*
head
=
*
list
;
while
(
head
!=
nullptr
)
{
ParamContextsList
*
next
=
head
->
next
;
free
(
head
->
info
.
paraName
);
free
(
head
->
info
.
paraContext
);
free
(
(
void
*
)
head
->
info
.
paraName
);
free
(
(
void
*
)
head
->
info
.
paraContext
);
free
(
head
);
head
=
next
;
}
...
...
@@ -137,15 +137,14 @@ static ParamContextsList *TestGetParamList(void)
void
TestSetSelinuxOps
(
void
)
{
SelinuxSpace
space
=
{};
space
.
setSelinuxLogCallback
=
TestSetSelinuxLogCallback
;
space
.
setParamCheck
=
TestSetParamCheck
;
space
.
getParamLabel
=
TestGetParamLabel
;
space
.
readParamCheck
=
TestReadParamCheck
;
space
.
getParamList
=
TestGetParamList
;
space
.
destroyParamList
=
TestDestroyParamList
;
#ifdef PARAM_SUPPORT_SELINUX
SetSelinuxOps
(
&
space
);
SelinuxSpace
*
selinuxSpace
=
&
GetParamWorkSpace
()
->
selinuxSpace
;
selinuxSpace
->
setSelinuxLogCallback
=
TestSetSelinuxLogCallback
;
selinuxSpace
->
setParamCheck
=
TestSetParamCheck
;
selinuxSpace
->
getParamLabel
=
TestGetParamLabel
;
selinuxSpace
->
readParamCheck
=
TestReadParamCheck
;
selinuxSpace
->
getParamList
=
TestGetParamList
;
selinuxSpace
->
destroyParamList
=
TestDestroyParamList
;
#endif
}
static
void
CreateTestFile
(
const
char
*
fileName
,
const
char
*
data
)
...
...
ueventd/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -74,7 +74,6 @@ if (defined(ohos_lite)) {
service_ueventd_deps = [
"//base/startup/init/interfaces/innerkits/socket:libsocket",
"//base/startup/init/services/log:init_log",
"//base/startup/init/services/param/base:parameterbase",
"//base/startup/init/services/utils:libinit_utils",
"//third_party/bounds_checking_function:libsec_static",
]
...
...
@@ -92,7 +91,11 @@ if (defined(ohos_lite)) {
deps = service_ueventd_deps
defines = [ "__RAMDISK__" ]
cflags = []
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
if (build_selinux) {
external_deps = [ "selinux:librestorecon" ]
cflags += [ "-DWITH_SELINUX" ]
...
...
@@ -116,7 +119,11 @@ if (defined(ohos_lite)) {
deps = service_ueventd_deps
deps += [ "//base/startup/init/services/param/linux:param_client" ]
cflags = []
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
if (build_selinux) {
external_deps = [ "selinux:librestorecon" ]
cflags += [ "-DWITH_SELINUX" ]
...
...
watchdog/BUILD.gn
浏览文件 @
3bec302f
...
...
@@ -35,9 +35,13 @@ if (defined(ohos_lite)) {
sources = [ "init_watchdog.c" ]
deps = [
"//base/startup/init/services/log:init_log",
"//base/startup/init/services/param/base:parameterbase",
"//third_party/bounds_checking_function:libsec_shared",
]
if (use_musl == false) {
deps += [ "//base/startup/init/services/param/base:parameterbase" ]
} else {
deps += [ "//base/startup/init/services/param/base:parameterbase_ext" ]
}
defines = [ "LINUX_WATCHDOG" ]
defines += [ "_GNU_SOURCE" ]
install_enable = true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录