install_policy.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. set -e
  4. if [ `id -u` -ne 0 ]; then
  5. echo "$0: must be root to install the selinux policy"
  6. exit 1
  7. fi
  8. SF=`which setfiles`
  9. if [ $? -eq 1 ]; then
  10. echo "Could not find setfiles"
  11. echo "Do you have policycoreutils installed?"
  12. exit 1
  13. fi
  14. CP=`which checkpolicy`
  15. if [ $? -eq 1 ]; then
  16. echo "Could not find checkpolicy"
  17. echo "Do you have checkpolicy installed?"
  18. exit 1
  19. fi
  20. VERS=`$CP -V | awk '{print $1}'`
  21. ENABLED=`which selinuxenabled`
  22. if [ $? -eq 1 ]; then
  23. echo "Could not find selinuxenabled"
  24. echo "Do you have libselinux-utils installed?"
  25. exit 1
  26. fi
  27. if selinuxenabled; then
  28. echo "SELinux is already enabled"
  29. echo "This prevents safely relabeling all files."
  30. echo "Boot with selinux=0 on the kernel command-line or"
  31. echo "SELINUX=disabled in /etc/selinux/config."
  32. exit 1
  33. fi
  34. cd mdp
  35. ./mdp -m policy.conf file_contexts
  36. $CP -U allow -M -o policy.$VERS policy.conf
  37. mkdir -p /etc/selinux/dummy/policy
  38. mkdir -p /etc/selinux/dummy/contexts/files
  39. echo "__default__:user_u:s0" > /etc/selinux/dummy/seusers
  40. echo "base_r:base_t:s0" > /etc/selinux/dummy/contexts/failsafe_context
  41. echo "base_r:base_t:s0 base_r:base_t:s0" > /etc/selinux/dummy/default_contexts
  42. cat > /etc/selinux/dummy/contexts/x_contexts <<EOF
  43. client * user_u:base_r:base_t:s0
  44. property * user_u:object_r:base_t:s0
  45. extension * user_u:object_r:base_t:s0
  46. selection * user_u:object_r:base_t:s0
  47. event * user_u:object_r:base_t:s0
  48. EOF
  49. touch /etc/selinux/dummy/contexts/virtual_domain_context
  50. touch /etc/selinux/dummy/contexts/virtual_image_context
  51. cp file_contexts /etc/selinux/dummy/contexts/files
  52. cp dbus_contexts /etc/selinux/dummy/contexts
  53. cp policy.$VERS /etc/selinux/dummy/policy
  54. FC_FILE=/etc/selinux/dummy/contexts/files/file_contexts
  55. if [ ! -d /etc/selinux ]; then
  56. mkdir -p /etc/selinux
  57. fi
  58. if [ -f /etc/selinux/config ]; then
  59. echo "/etc/selinux/config exists, moving to /etc/selinux/config.bak."
  60. mv /etc/selinux/config /etc/selinux/config.bak
  61. fi
  62. echo "Creating new /etc/selinux/config for dummy policy."
  63. cat > /etc/selinux/config << EOF
  64. SELINUX=permissive
  65. SELINUXTYPE=dummy
  66. EOF
  67. cd /etc/selinux/dummy/contexts/files
  68. $SF -F file_contexts /
  69. mounts=`cat /proc/$$/mounts | \
  70. egrep "ext[234]|jfs|xfs|reiserfs|jffs2|gfs2|btrfs|f2fs|ocfs2" | \
  71. awk '{ print $2 '}`
  72. $SF -F file_contexts $mounts
  73. echo "-F" > /.autorelabel