xf.li | 8611891 | 2025-03-19 20:07:27 -0700 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | |
| 3 | /usr/sbin/selinuxenabled 2>/dev/null || exit 0 |
| 4 | |
| 5 | CHCON=/usr/bin/chcon |
| 6 | MATCHPATHCON=/usr/sbin/matchpathcon |
| 7 | RESTORECON=/sbin/restorecon |
| 8 | SECON=/usr/bin/secon |
| 9 | SETENFORCE=/usr/sbin/setenforce |
| 10 | |
| 11 | for i in ${CHCON} ${MATCHPATHCON} ${RESTORECON} ${SECON} ${SETENFORCE}; do |
| 12 | test -x $i && continue |
| 13 | echo "$i is missing in the system." |
| 14 | echo "Please add \"selinux=0\" in the kernel command line to disable SELinux." |
| 15 | exit 1 |
| 16 | done |
| 17 | |
| 18 | check_rootfs() |
| 19 | { |
| 20 | ${CHCON} `${MATCHPATHCON} -n /` / >/dev/null 2>&1 && return 0 |
| 21 | echo "" |
| 22 | echo "* SELinux requires the root '/' filesystem support extended" |
| 23 | echo " filesystem attributes (XATTRs). It does not appear that this" |
| 24 | echo " filesystem has extended attribute support or it is not enabled." |
| 25 | echo "" |
| 26 | echo " - To continue using SELinux you will need to enable extended" |
| 27 | echo " attribute support on the root device." |
| 28 | echo "" |
| 29 | echo " - To disable SELinux, please add \"selinux=0\" in the kernel" |
| 30 | echo " command line." |
| 31 | echo "" |
| 32 | echo "* Halting the system now." |
| 33 | /sbin/shutdown -f -h now |
| 34 | } |
| 35 | |
| 36 | # Contents will be added to selinux-init.sh to support relabelling with sysvinit |
| 37 | # If first booting, the security context type of init would be |
| 38 | # "kernel_t", and the whole file system should be relabeled. |
| 39 | if [ "`${SECON} -t --pid 1`" = "kernel_t" ]; then |
| 40 | echo "Checking SELinux security contexts:" |
| 41 | check_rootfs |
| 42 | echo " * First booting, filesystem will be relabeled..." |
| 43 | test -x /etc/init.d/auditd && /etc/init.d/auditd start |
| 44 | ${SETENFORCE} 0 |
| 45 | ${RESTORECON} -RF / |
| 46 | ${RESTORECON} -F / |
| 47 | echo " * Relabel done, rebooting the system." |
| 48 | /sbin/reboot |
| 49 | fi |
| 50 | |
| 51 | exit 0 |