#!/bin/bash

PATH=/bin:/usr/bin:/sbin:/usr/sbin
ONLYCAP_LIST="/etc/smack/onlycap"

# check initial boot
function check_init_boot
{
	if [ ! -e /opt/share/security-config/.smack_pre_labeling ]
	then
		touch /opt/share/security-config/.smack_pre_labeling
		return 1
	fi
	return 0
}

# Set default smack label for the specific file or folder
function set_smack_label
{
	if [ -e /csa ]
	then
		chsmack -r -a "_" /csa
		if [ -e /csa/nv ]
		then
			chown -R telephony:telephony /csa/nv
			chsmack -r -a "System" /csa/nv
		fi
	fi
}

check_init_boot

if [ "$?" == 1 ] # Init boot case
then
	set_smack_label
fi

echo $(cat $ONLYCAP_LIST) > /sys/fs/smackfs/onlycap
echo "1" > /sys/fs/smackfs/ptrace

# Smack ipv6 configuration for internet privilege
if [ -e /sys/fs/smackfs/ipv6host ]
then
	echo "00:00:00:00:00:00:00:00/0" System::Privilege::Internet > /sys/fs/smackfs/ipv6host
fi
