Public feed #889942

Something

public text v1 · immutable
Raw Edit
·published 2008-02-03 10:09 UTC
rendered paste body
# Check SELinux status
selinuxfs="$(fstab_decode_str `LC_ALL=C awk '/ selinuxfs / { print $2 }' /proc/mounts`)"
SELINUX_STATE=
if [ -n "$selinuxfs" ] && [ "`cat /proc/self/attr/current`" != "kernel" ]; then
	if [ -r "$selinuxfs/enforce" ] ; then
		SELINUX_STATE=`cat "$selinuxfs/enforce"`
	else
		# assume enforcing if you can't read it
		SELINUX_STATE=1
	fi
fi

if [ -n "$SELINUX_STATE" -a -x /sbin/restorecon ] && LC_ALL=C fgrep -q " /dev " /proc/mounts ; then
	/sbin/restorecon  -R /dev 2>/dev/null
fi

disable_selinux() {
	echo $"*** Warning -- SELinux is active"
	echo $"*** Disabling security enforcement for system recovery."
	echo $"*** Run 'setenforce 1' to reenable."
	echo "0" > "$selinuxfs/enforce"
}

relabel_selinux() {
    if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
	chvt 1
    fi
    # if /sbin/init is not labeled correctly this process is running in the 
    # wrong context, so a reboot will be required after relabel
    REBOOTFLAG=`restorecon -v /sbin/init`
    AUTORELABEL=
    . /etc/selinux/config
    if [ "$AUTORELABEL" = "0" ]; then
 	rm -f  /.autorelabel 

 	echo
	echo $"*** Warning -- SELinux ${SELINUXTYPE} policy relabel is required. "
 	echo $"*** /etc/selinux/config indicates you want to manually fix labeling"
 	echo $"*** problems. Dropping you to a shell; the system will reboot"
 	echo $"*** when you leave the shell."
 	echo "0" > $selinuxfs/enforce
 	sulogin
 
 	echo $"Unmounting file systems"
 	umount -a
 	mount -n -o remount,ro /
 	echo $"Automatic reboot in progress."
 	reboot -f
    else
 	echo
 	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."
 
 	echo "0" > $selinuxfs/enforce
 	/sbin/fixfiles restore > /dev/null 2>&1 
 	rm -f  /.autorelabel 
 	if [ ! -z "$REBOOTFLAG" ]; then 
 	    echo $"Automatic reboot in progress."
 	    reboot -f
 	fi
 	echo $SELINUX_STATE > $selinuxfs/enforce
 	if [ -x /usr/bin/rhgb-client ] && /usr/bin/rhgb-client --ping ; then
 	    chvt 8
 	fi
    fi
}

key_is_random() {
    [ "$1" = "/dev/urandom" -o "$1" = "/dev/hw_random" \
	-o "$1" = "/dev/random" ]
}