All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] package/policycoreutils: Add service to handle selinux autorelabel
@ 2021-09-07 12:58 José Pekkarinen
  2021-09-29 11:37 ` José Pekkarinen
  2021-09-30  8:58 ` Antoine Tenart
  0 siblings, 2 replies; 4+ messages in thread
From: José Pekkarinen @ 2021-09-07 12:58 UTC (permalink / raw)
  To: buildroot; +Cc: José Pekkarinen

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-30  8:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-07 12:58 [Buildroot] [PATCH] package/policycoreutils: Add service to handle selinux autorelabel José Pekkarinen
2021-09-29 11:37 ` José Pekkarinen
2021-09-29 20:46   ` Arnout Vandecappelle
2021-09-30  8:58 ` Antoine Tenart

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.