提交 2166750e 编写于 作者: R renwei

adapt dynamic file lable

Signed-off-by: Nrenwei <renwei8@huawei.com>
Change-Id: I62fdd2e626ee22a02de0c933a9950eb286b74ec1
上级 4ab46e62
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
#include "init_plugin_manager.h" #include "init_plugin_manager.h"
#include "init_service_manager.h" #include "init_service_manager.h"
#include "init_utils.h" #include "init_utils.h"
#ifdef WITH_SELINUX
#include "policycoreutils.h"
#endif
#include "securec.h" #include "securec.h"
static char *g_fileCryptOptions = NULL; static char *g_fileCryptOptions = NULL;
...@@ -321,6 +324,13 @@ static void DoMkDir(const struct CmdArgs *ctx) ...@@ -321,6 +324,13 @@ static void DoMkDir(const struct CmdArgs *ctx)
INIT_LOGE("DoMkDir, failed for '%s', err %d.", ctx->argv[0], errno); INIT_LOGE("DoMkDir, failed for '%s', err %d.", ctx->argv[0], errno);
return; return;
} }
#ifdef WITH_SELINUX
if (RestoreconRecurse(ctx->argv[0])) {
INIT_LOGE("DoMkDir, Restorecon failed for '%s', err %d.", ctx->argv[0], errno);
}
#endif
if (ctx->argc <= 1) { if (ctx->argc <= 1) {
return; return;
} }
......
...@@ -230,13 +230,14 @@ void SystemLoadSelinux(void) ...@@ -230,13 +230,14 @@ void SystemLoadSelinux(void)
{ {
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
// load selinux policy and context // load selinux policy and context
if (load_policy() < 0) { if (LoadPolicy() < 0) {
INIT_LOGE("main, load_policy failed."); INIT_LOGE("main, load_policy failed.");
} else { } else {
INIT_LOGI("main, load_policy success."); INIT_LOGI("main, load_policy success.");
} }
setcon("u:r:init:s0"); setcon("u:r:init:s0");
(void)RestoreconRecurse("/dev");
#endif // WITH_SELINUX #endif // WITH_SELINUX
} }
...@@ -272,6 +273,10 @@ void SystemConfig(void) ...@@ -272,6 +273,10 @@ void SystemConfig(void)
InitParamService(); InitParamService();
RegisterBootStateChange(BootStateChange); RegisterBootStateChange(BootStateChange);
// load SELinux context and policy
// Do not move position!
SystemLoadSelinux();
// parse parameters // parse parameters
LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL); LoadDefaultParams("/system/etc/param/ohos_const", LOAD_PARAM_NORMAL);
LoadDefaultParams("/vendor/etc/param", LOAD_PARAM_NORMAL); LoadDefaultParams("/vendor/etc/param", LOAD_PARAM_NORMAL);
...@@ -290,8 +295,6 @@ void SystemConfig(void) ...@@ -290,8 +295,6 @@ void SystemConfig(void)
PostTrigger(EVENT_TRIGGER_BOOT, "pre-init", strlen("pre-init")); PostTrigger(EVENT_TRIGGER_BOOT, "pre-init", strlen("pre-init"));
PostTrigger(EVENT_TRIGGER_BOOT, "init", strlen("init")); PostTrigger(EVENT_TRIGGER_BOOT, "init", strlen("init"));
PostTrigger(EVENT_TRIGGER_BOOT, "post-init", strlen("post-init")); PostTrigger(EVENT_TRIGGER_BOOT, "post-init", strlen("post-init"));
// load SELinux context and policy
SystemLoadSelinux();
} }
void SystemRun(void) void SystemRun(void)
......
...@@ -274,9 +274,14 @@ static void DoUmountFstabFile(const struct CmdArgs *ctx) ...@@ -274,9 +274,14 @@ static void DoUmountFstabFile(const struct CmdArgs *ctx)
static void DoRestorecon(const struct CmdArgs *ctx) static void DoRestorecon(const struct CmdArgs *ctx)
{ {
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
INIT_LOGI("start restorecon ......\n"); if (ctx->argc != 1) {
restorecon(); INIT_LOGE("DoRestorecon invalid arguments.");
INIT_LOGI("finish restorecon ......\n"); return;
}
if (RestoreconRecurse(ctx->argv[0])) {
INIT_LOGE("DoRestorecon failed for '%s', err %d.", ctx->argv[0], errno);
}
#endif #endif
return; return;
} }
...@@ -498,7 +503,7 @@ static const struct CmdTable g_cmdTable[] = { ...@@ -498,7 +503,7 @@ static const struct CmdTable g_cmdTable[] = {
{ "ifup ", 1, 1, DoIfup }, { "ifup ", 1, 1, DoIfup },
{ "mount_fstab ", 1, 1, DoMountFstabFile }, { "mount_fstab ", 1, 1, DoMountFstabFile },
{ "umount_fstab ", 1, 1, DoUmountFstabFile }, { "umount_fstab ", 1, 1, DoUmountFstabFile },
{ "restorecon ", 0, 1, DoRestorecon }, { "restorecon ", 1, 1, DoRestorecon },
{ "stopAllServices ", 0, 10, DoStopAllServices }, { "stopAllServices ", 0, 10, DoStopAllServices },
{ "umount ", 1, 1, DoUmount }, { "umount ", 1, 1, DoUmount },
{ "sync ", 0, 1, DoSync }, { "sync ", 0, 1, DoSync },
......
...@@ -99,6 +99,12 @@ if (defined(ohos_lite)) { ...@@ -99,6 +99,12 @@ if (defined(ohos_lite)) {
include_dirs = service_ueventd_include include_dirs = service_ueventd_include
deps = service_ueventd_deps deps = service_ueventd_deps
defines = [ "__RAMDISK__" ] defines = [ "__RAMDISK__" ]
cflags = []
if (build_selinux) {
external_deps = [ "selinux:librestorecon" ]
cflags += [ "-DWITH_SELINUX" ]
}
} }
ohos_executable("ueventd") { ohos_executable("ueventd") {
...@@ -114,6 +120,13 @@ if (defined(ohos_lite)) { ...@@ -114,6 +120,13 @@ if (defined(ohos_lite)) {
] ]
deps = service_ueventd_deps deps = service_ueventd_deps
deps += [ "//base/startup/init_lite/services/param:param_client" ] deps += [ "//base/startup/init_lite/services/param:param_client" ]
cflags = []
if (build_selinux) {
external_deps = [ "selinux:librestorecon" ]
cflags += [ "-DWITH_SELINUX" ]
}
install_images = [ install_images = [
"system", "system",
"updater", "updater",
......
...@@ -34,6 +34,9 @@ ...@@ -34,6 +34,9 @@
#include "securec.h" #include "securec.h"
#define INIT_LOG_TAG "ueventd" #define INIT_LOG_TAG "ueventd"
#include "init_log.h" #include "init_log.h"
#ifdef WITH_SELINUX
#include <policycoreutils.h>
#endif
static void CreateSymbolLinks(const char *deviceNode, char **symLinks) static void CreateSymbolLinks(const char *deviceNode, char **symLinks)
{ {
...@@ -79,6 +82,21 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid ...@@ -79,6 +82,21 @@ static inline void AdjustDeviceNodePermissions(const char *deviceNode, uid_t uid
} }
} }
static void SetDeviceLable(const char *dir, const char *path)
{
#ifdef WITH_SELINUX
int rc = 0;
if (!STRINGEQUAL(dir, "/dev")) {
rc = RestoreconRecurse(dir);
}
rc += Restorecon(path);
if (rc != 0) {
INIT_LOGI("restorecon device node[%s] failed. %d", path, errno);
}
#endif
}
static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, char **symLinks, bool isBlock) static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, char **symLinks, bool isBlock)
{ {
int rc = -1; int rc = -1;
...@@ -126,6 +144,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode, ...@@ -126,6 +144,7 @@ static int CreateDeviceNode(const struct Uevent *uevent, const char *deviceNode,
if (symLinks != NULL) { if (symLinks != NULL) {
CreateSymbolLinks(deviceNode, symLinks); CreateSymbolLinks(deviceNode, symLinks);
} }
SetDeviceLable(devicePath, deviceNode);
// No matter what result the symbol links returns, // No matter what result the symbol links returns,
// as long as create device node done, just returns success. // as long as create device node done, just returns success.
rc = 0; rc = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册