summaryrefslogtreecommitdiffstats
path: root/SELinux/rebuild-policy.sh
blob: 64fce3c85d7deb7de806b6d552411605acac7b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
#
# Try really hard to rebuild SELinux policy
#
tmpdir=$(mktemp -d -t qarshd-rebuild-policy.XXXX)
savetmp=""

mark_bad()
{
	echo "Avoiding: $1"
	echo $1 >> qarshd.bad-interfaces
}

lookup_rule()
{
	lineno=`grep -B1 $1 tmp/qarshd.tmp | head -n 1 | awk '{print $NF}'`;
	head -n $lineno qarshd.te | tail -n 1 | sed -e 's/(qarshd_t)//'
}

cp -a * $tmpdir
pushd $tmpdir

make || exit 1

until output=$(make load 2>&1); do
	badtype=`echo $output | perl -n -e'/libsepol.print_missing_requirements.*attribute (\S+)/ && print "$1\n"'`
	if [ -z "$badtype" ]; then
		echo "Error not found in make.log"
		echo "$output"
		exit 1
	fi
	badint=`lookup_rule $badtype`
	if [ -z "$badint" ]; then
		echo "Interface not found from bad type $badtype"
		exit 1
	fi
	mark_bad $badint
	echo "$output" > $tmpdir/$badint.log
	savetmp="yes"
done
popd

if [ -z "$savetmp" ]; then
	rm -rf $tmpdir
else
	echo "Saved policy rebuild logs in $tmpdir"
fi