All of lore.kernel.org
 help / color / mirror / Atom feed
From: "José Pekkarinen" <jose.pekkarinen@unikie.com>
To: buildroot@buildroot.org
Cc: "José Pekkarinen" <jose.pekkarinen@unikie.com>
Subject: [Buildroot] [PATCH] package/policycoreutils: Add service to handle selinux autorelabel
Date: Tue,  7 Sep 2021 15:58:41 +0300	[thread overview]
Message-ID: <20210907125841.509792-1-jose.pekkarinen@unikie.com> (raw)

This patch adds a system service to check whether the
autorelabel via is requested or not, and produce the
labeling of the system under the loaded final kernel,
including automatically populated fs by the kernel.

Signed-off-by: José Pekkarinen <jose.pekkarinen@unikie.com>
---
 .../policycoreutils/S00selinux-autorelabel    | 49 +++++++++++++++++++
 package/policycoreutils/policycoreutils.mk    |  5 ++
 2 files changed, 54 insertions(+)
 create mode 100644 package/policycoreutils/S00selinux-autorelabel

diff --git a/package/policycoreutils/S00selinux-autorelabel b/package/policycoreutils/S00selinux-autorelabel
new file mode 100644
index 0000000000..7a47db891f
--- /dev/null
+++ b/package/policycoreutils/S00selinux-autorelabel
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+DAEMON="Autorelabel check"
+
+start() {
+    printf 'Starting %s: ' "$DAEMON"
+
+    if [ -f /.autorelabel ]; then
+        echo "Relabeling"
+        echo "*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required."
+        echo "*** Relabeling could take a very long time, depending on file"
+        echo "*** system size and speed of hard drives."
+        mount -a
+        setfiles -m -r /
+
+        # Remove label
+        rm -f  /.autorelabel || failed "Failed to remove the autorelabel flag"
+
+        # Reboot to activate relabeled file system
+        echo "Automatic reboot in progress."
+        reboot -f
+    fi
+
+    echo "OK"
+    return 0
+}
+
+stop() {
+    printf 'Stopping %s: ' "$DAEMON"
+    echo "OK"
+    return 0
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+case "$1" in
+	start|stop|restart)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
diff --git a/package/policycoreutils/policycoreutils.mk b/package/policycoreutils/policycoreutils.mk
index 5290c5b9f8..f698698059 100644
--- a/package/policycoreutils/policycoreutils.mk
+++ b/package/policycoreutils/policycoreutils.mk
@@ -93,5 +93,10 @@ define HOST_POLICYCOREUTILS_INSTALL_CMDS
 	)
 endef
 
+define POLICYCOREUTILS_INSTALL_INIT_SYSV
+	$(INSTALL) -m 0755 -D package/policycoreutils/S00selinux-autorelabel \
+		$(TARGET_DIR)/etc/init.d/S00selinux-autorelabel
+endef
+
 $(eval $(generic-package))
 $(eval $(host-generic-package))
-- 
2.25.1

_______________________________________________
buildroot mailing list
buildroot@lists.buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

             reply	other threads:[~2021-09-07 12:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07 12:58 José Pekkarinen [this message]
2021-09-29 11:37 ` [Buildroot] [PATCH] package/policycoreutils: Add service to handle selinux autorelabel José Pekkarinen
2021-09-29 20:46   ` Arnout Vandecappelle
2021-09-30  8:58 ` Antoine Tenart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210907125841.509792-1-jose.pekkarinen@unikie.com \
    --to=jose.pekkarinen@unikie.com \
    --cc=buildroot@buildroot.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.