mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-24 00:30:12 +00:00
support build musl with param base
Signed-off-by: an_xinwei <an_xinwei@hoperun.com>
This commit is contained in:
parent
33f32067ea
commit
5edb049d85
@ -16,6 +16,7 @@ declare_args() {
|
||||
enable_ohos_startup_init_feature_deviceinfo = true
|
||||
param_test = true
|
||||
control_test = false
|
||||
param_base_log = false
|
||||
|
||||
# init begetctl support liteos
|
||||
enable_ohos_startup_init_feature_begetctl_liteos = false
|
||||
|
@ -180,13 +180,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",
|
||||
@ -272,12 +276,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",
|
||||
|
@ -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_dirs += [
|
||||
"//third_party/selinux/libselinux/include/",
|
||||
"//base/security/selinux/interfaces/policycoreutils/include/",
|
||||
deps += [
|
||||
"//base/security/selinux:libselinux_parameter_static",
|
||||
"//third_party/selinux:libselinux",
|
||||
]
|
||||
deps += [ "//third_party/selinux:libselinux" ]
|
||||
external_deps += [ "selinux:libparaperm_checker" ]
|
||||
defines += [ "PARAM_SUPPORT_SELINUX" ]
|
||||
}
|
||||
|
||||
@ -140,12 +136,14 @@ if (defined(ohos_lite)) {
|
||||
include_dirs = common_include_dirs
|
||||
deps = [
|
||||
"//base/startup/init/interfaces/innerkits:libbegetutil",
|
||||
"//third_party/bounds_checking_function:libsec_static",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
|
||||
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" ]
|
||||
}
|
||||
|
||||
@ -183,19 +181,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" ]
|
||||
|
@ -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",
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -34,9 +34,56 @@
|
||||
#define CHECKER_UPDATER_LIB_NAME "/lib/libparaperm_checker.z.so"
|
||||
#endif
|
||||
|
||||
static SelinuxSpace g_selinuxSpace = {0};
|
||||
static int InitSelinuxOpsForInit(SelinuxSpace *selinuxSpace)
|
||||
{
|
||||
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 = 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 (selinuxSpace->getParamList == NULL) {
|
||||
selinuxSpace->getParamList = (ParamContextsList *(*)()) dlsym(handle, "GetParamList");
|
||||
PARAM_CHECK(selinuxSpace->getParamList != NULL, return -1, "Failed to dlsym getParamList %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 (selinuxSpace->initParamSelinux == NULL) {
|
||||
selinuxSpace->initParamSelinux = (int (*)())dlsym(handle, "InitParamSelinux");
|
||||
PARAM_CHECK(selinuxSpace->initParamSelinux != NULL, return -1, "Failed to dlsym initParamSelinux ");
|
||||
}
|
||||
if (selinuxSpace->readParamCheck == NULL) {
|
||||
selinuxSpace->readParamCheck = (int (*)(const char *))dlsym(handle, "ReadParamCheck");
|
||||
}
|
||||
if (selinuxSpace->setSelinuxLogCallback == NULL) {
|
||||
selinuxSpace->setSelinuxLogCallback = (void (*)())dlsym(handle, "SetInitSelinuxLog");
|
||||
}
|
||||
if (selinuxSpace->destroyParamList == NULL) {
|
||||
selinuxSpace->destroyParamList =
|
||||
(void (*)(ParamContextsList **))dlsym(handle, "DestroyParamList");
|
||||
PARAM_CHECK(selinuxSpace->destroyParamList != NULL,
|
||||
return -1, "Failed to dlsym destroyParamList %s", dlerror());
|
||||
}
|
||||
|
||||
// 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();
|
||||
@ -45,39 +92,18 @@ static int InitLocalSecurityLabel(ParamSecurityLabel *security, int isInit)
|
||||
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,
|
||||
return 0, "Failed to dlsym selinuxHandle, %s", dlerror());
|
||||
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();
|
||||
}
|
||||
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());
|
||||
}
|
||||
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 (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 (g_selinuxSpace.initParamSelinux == NULL) {
|
||||
g_selinuxSpace.initParamSelinux = (void (*)())dlsym(handle, "InitParamSelinux");
|
||||
PARAM_CHECK(g_selinuxSpace.initParamSelinux != NULL, return -1, "Failed to dlsym initParamSelinux ");
|
||||
}
|
||||
if (g_selinuxSpace.readParamCheck == NULL) {
|
||||
g_selinuxSpace.readParamCheck = (int (*)(const char *))dlsym(handle, "ReadParamCheck");
|
||||
}
|
||||
if (g_selinuxSpace.destroyParamList == NULL) {
|
||||
g_selinuxSpace.destroyParamList =
|
||||
(void (*)(ParamContextsList **))dlsym(handle, "DestroyParamList");
|
||||
PARAM_CHECK(g_selinuxSpace.destroyParamList != NULL,
|
||||
return -1, "Failed to dlsym destroyParamList %s", dlerror());
|
||||
}
|
||||
g_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
|
@ -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_static_library("parameterbase") {
|
||||
sources = base_sources
|
||||
ohos_source_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"
|
||||
}
|
||||
|
@ -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;
|
||||
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_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)
|
||||
INIT_INNER_API ParamWorkSpace *GetParamWorkSpace(void)
|
||||
{
|
||||
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);
|
||||
if (!PARAM_TEST_FLAG(g_paramWorkSpace.flags, WORKSPACE_FLAGS_INIT)) {
|
||||
PARAM_LOGE("GetParamWorkSpace %p", &g_paramWorkSpace);
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
@ -30,11 +30,19 @@ extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t updaterMode;
|
||||
InitCommLog logFunc;
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
int (*setfilecon)(const char *name, const char *content);
|
||||
#endif
|
||||
} PARAM_WORKSPACE_OPS;
|
||||
|
||||
INIT_INNER_API int InitParamWorkSpace(int onlyRead, const PARAM_WORKSPACE_OPS *ops);
|
||||
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
|
||||
|
@ -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 ¶mSpace->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(¶mSpace->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;
|
||||
}
|
@ -246,7 +246,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);
|
||||
@ -406,7 +406,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
|
||||
|
@ -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"
|
||||
@ -54,6 +55,10 @@ typedef struct {
|
||||
ListHead workSpaceList;
|
||||
#ifdef PARAMWORKSPACE_NEED_MUTEX
|
||||
ParamRWMutex rwlock;
|
||||
#endif
|
||||
PARAM_WORKSPACE_OPS ops;
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
SelinuxSpace selinuxSpace;
|
||||
#endif
|
||||
} ParamWorkSpace;
|
||||
|
||||
@ -99,17 +104,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_INNER_API int CheckParameterSet(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);
|
||||
#ifdef STARTUP_INIT_TEST
|
||||
ParamService *GetParamService();
|
||||
#endif
|
||||
|
@ -135,17 +135,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);
|
||||
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);
|
||||
|
||||
int ParamMutexCreate(ParamMutex *mutex);
|
||||
int ParamMutexPend(ParamMutex *mutex);
|
||||
int ParamMutexPost(ParamMutex *mutex);
|
||||
int ParamMutexDelete(ParamMutex *mutex);
|
||||
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)
|
||||
@ -174,8 +174,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__
|
||||
@ -197,5 +197,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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
]
|
||||
}
|
||||
|
||||
@ -112,6 +114,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/",
|
||||
@ -133,16 +139,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"
|
||||
}
|
||||
|
@ -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");
|
||||
uint32_t 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);
|
||||
}
|
@ -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;
|
||||
|
@ -18,9 +18,13 @@
|
||||
#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"
|
||||
@ -29,6 +33,11 @@
|
||||
#include "hookmgr.h"
|
||||
#include "init_running_hooks.h"
|
||||
#endif
|
||||
#ifdef PARAM_SUPPORT_SELINUX
|
||||
#include "selinux_parameter.h"
|
||||
#include <policycoreutils.h>
|
||||
#include <selinux/selinux.h>
|
||||
#endif
|
||||
|
||||
static ParamService g_paramService = {};
|
||||
|
||||
@ -425,7 +434,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");
|
||||
|
@ -16,6 +16,7 @@ param_include_dirs = [
|
||||
"//base/startup/init/interfaces/innerkits/include/syspara",
|
||||
"//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",
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "param_trie.h"
|
||||
#include "securec.h"
|
||||
#include "param_utils.h"
|
||||
#include "securec.h"
|
||||
|
||||
ParamNode *SystemCheckMatchParamWait(const char *name, const char *value)
|
||||
{
|
||||
@ -28,15 +28,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 *worksapce = GetWorkSpace(name);
|
||||
PARAM_CHECK(worksapce != NULL, return NULL, "Failed to get workspace %s", name);
|
||||
WorkSpace *workspace = GetWorkSpace(name);
|
||||
PARAM_CHECK(workspace != NULL, return NULL, "Failed to get workspace %s", name);
|
||||
PARAM_LOGV("SystemCheckMatchParamWait name %s", name);
|
||||
uint32_t nameLength = strlen(name);
|
||||
ParamTrieNode *node = FindTrieNode(worksapce, name, nameLength, NULL);
|
||||
ParamTrieNode *node = FindTrieNode(workspace, name, nameLength, NULL);
|
||||
if (node == NULL || node->dataIndex == 0) {
|
||||
return NULL;
|
||||
}
|
||||
ParamNode *param = (ParamNode *)GetTrieNode(worksapce, node->dataIndex);
|
||||
ParamNode *param = (ParamNode *)GetTrieNode(workspace, node->dataIndex);
|
||||
if (param == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@ -188,7 +188,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");
|
||||
@ -229,7 +229,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);
|
||||
@ -297,7 +298,7 @@ PARAM_STATIC char *GetServiceCtrlName(const char *name, const char *value)
|
||||
return key;
|
||||
}
|
||||
|
||||
INIT_INNER_API int CheckParameterSet(const char *name,
|
||||
INIT_LOCAL_API int CheckParameterSet(const char *name,
|
||||
const char *value, const ParamSecurityLabel *srcLabel, int *ctrlService)
|
||||
{
|
||||
ParamWorkSpace *paramSpace = GetParamWorkSpace();
|
||||
@ -332,3 +333,36 @@ INIT_INNER_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);
|
||||
}
|
@ -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)
|
||||
|
@ -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" ]
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user