summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXin Ouyang <Xin.Ouyang@windriver.com>2012-09-19 16:31:24 +0800
committerXin Ouyang <Xin.Ouyang@windriver.com>2012-10-18 11:07:45 +0800
commit3b2088b2bd2d7667c6a47c07dba32ec7ddc5a3ae (patch)
treeba0ccddd8b662bceeda021892f2b6fca8ea94684
parentad05ee24950baaf4c97aba374662065361d15908 (diff)
downloadmeta-selinux-3b2088b2bd2d7667c6a47c07dba32ec7ddc5a3ae.tar.gz
selinux-config: add init script
This script will be installed as 0selinux-init, in runlevel S and sequence number 0. It will start before any other init script. * relabel /dev for restorecon/fixfiles running * rebuild policy and relabel the rootfs if /.autorelabel placed. * relabel the rootfs if it is first booting. Signed-off-by: Xin Ouyang <Xin.Ouyang@windriver.com>
-rw-r--r--recipes-security/selinux/selinux-config/selinux-init.sh39
-rw-r--r--recipes-security/selinux/selinux-config_0.1.bb16
2 files changed, 53 insertions, 2 deletions
diff --git a/recipes-security/selinux/selinux-config/selinux-init.sh b/recipes-security/selinux/selinux-config/selinux-init.sh
new file mode 100644
index 0000000..55c503f
--- /dev/null
+++ b/recipes-security/selinux/selinux-config/selinux-init.sh
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3/usr/sbin/selinuxenabled 2>/dev/null || exit 0
4
5# Because /dev/console is not relabeled by kernel, many commands
6# would can not use it, including restorecon.
7if [ -x /usr/bin/chcon ]; then
8 /usr/bin/chcon -t null_device_t /dev/null
9 /usr/bin/chcon -t console_device_t /dev/console
10fi
11
12
13# If /.autorelabel placed, the whole file system should be relabeled
14test ! -x /sbin/fixfiles ||
15if [ -f /.autorelabel ]; then
16 echo "Checking SELinux security contexts:"
17 echo " * /.autorelabel placed, filesystem will be relabeled..."
18 /sbin/fixfiles -F -f relabel
19 /bin/rm -f /.autorelabel
20 echo " * Relabel done, rebooting the system."
21 /sbin/reboot -f
22fi
23
24# If first booting, the security context type of init would be
25# "kernel_t", and the whole file system should be relabeled.
26test ! -x /sbin/restorecon ||
27if [ "`/usr/bin/secon -t --pid 1`" = "kernel_t" ]; then
28 echo "Checking SELinux security contexts:"
29 echo " * First booting, filesystem will be relabeled..."
30 test -x /etc/init.d/auditd && /etc/init.d/auditd start
31 /usr/sbin/setenforce 0
32 /sbin/restorecon -R /
33 /sbin/restorecon /
34 echo " * Relabel done, rebooting the system."
35 /sbin/reboot -f
36fi
37
38# Now, we should relabel /dev for most services.
39test ! -x /sbin/restorecon || /sbin/restorecon -R /dev
diff --git a/recipes-security/selinux/selinux-config_0.1.bb b/recipes-security/selinux/selinux-config_0.1.bb
index c0ed158..48b9362 100644
--- a/recipes-security/selinux/selinux-config_0.1.bb
+++ b/recipes-security/selinux/selinux-config_0.1.bb
@@ -8,13 +8,25 @@ This is the configuration files for SELinux on WRLinux system. \
8SECTION = "base" 8SECTION = "base"
9LICENSE = "MIT" 9LICENSE = "MIT"
10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" 10LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
11PR = "r0" 11PR = "r1"
12 12
13CONFFILES_${PN} += "${sysconfdir}/selinux/config" 13SRC_URI = "file://selinux-init.sh"
14
15inherit update-rc.d
16
17INITSCRIPT_NAME = "0selinux-init"
18INITSCRIPT_PARAMS = "start 00 S ."
19
20CONFFILES_${PN} += "${sysconfdir}/selinux/config \
21 ${sysconfdir}/init.d/0selinux-init \
22 "
14 23
15PACKAGE_ARCH = "${MACHINE_ARCH}" 24PACKAGE_ARCH = "${MACHINE_ARCH}"
16 25
17do_install () { 26do_install () {
27 install -d ${D}${sysconfdir}/init.d/
28 install -m 0755 ${WORKDIR}/selinux-init.sh ${D}${sysconfdir}/init.d/0selinux-init
29
18 echo "\ 30 echo "\
19# This file controls the state of SELinux on the system. 31# This file controls the state of SELinux on the system.
20# SELINUX= can take one of these three values: 32# SELINUX= can take one of these three values: