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