| 1 |
#!/bin/bash |
|---|
| 2 |
|
|---|
| 3 |
einfo() { |
|---|
| 4 |
echo -e " \e[32;01m*\e[0m $*" |
|---|
| 5 |
} |
|---|
| 6 |
|
|---|
| 7 |
eerror() { |
|---|
| 8 |
echo -e " \e[31;01m*\e[0m $*" |
|---|
| 9 |
} |
|---|
| 10 |
|
|---|
| 11 |
die() { |
|---|
| 12 |
[ -z "$1" ] || eerror $1 |
|---|
| 13 |
exit 1 |
|---|
| 14 |
} |
|---|
| 15 |
|
|---|
| 16 |
make_layer_test_policy() { |
|---|
| 17 |
mkdir -p $1/apps |
|---|
| 18 |
cat > $1/apps/testapp.te << EOF |
|---|
| 19 |
policy_module(testapp,1.0) |
|---|
| 20 |
type testapp_t; |
|---|
| 21 |
type testapp_exec_t; |
|---|
| 22 |
init_daemon_domain(testapp_t,testapp_exec_t) |
|---|
| 23 |
EOF |
|---|
| 24 |
|
|---|
| 25 |
cat > $1/apps/testapp.fc << EOF |
|---|
| 26 |
/usr/bin/testapp -- gen_context(system_u:object_r:testapp_exec_t,s0) |
|---|
| 27 |
EOF |
|---|
| 28 |
|
|---|
| 29 |
cat > $1/apps/testapp.if << EOF |
|---|
| 30 |
## <summary>Test application policy</summary> |
|---|
| 31 |
|
|---|
| 32 |
interface(\`testapp_domtrans',\` |
|---|
| 33 |
gen_require(\`type testapp_t, testapp_exec_t;') |
|---|
| 34 |
domtrans_pattern($1,testapp_exec_t,testapp_t) |
|---|
| 35 |
') |
|---|
| 36 |
EOF |
|---|
| 37 |
|
|---|
| 38 |
mkdir -p $1/services |
|---|
| 39 |
cat > $1/services/testsrv.te << EOF |
|---|
| 40 |
policy_module(testsrv,1.0) |
|---|
| 41 |
type testsrv_t; |
|---|
| 42 |
type testsrv_exec_t; |
|---|
| 43 |
init_daemon_domain(testsrv_t,testsrv_exec_t) |
|---|
| 44 |
EOF |
|---|
| 45 |
|
|---|
| 46 |
cat > $1/services/testsrv.fc << EOF |
|---|
| 47 |
/usr/bin/testsrv -- gen_context(system_u:object_r:testsrv_exec_t,s0) |
|---|
| 48 |
EOF |
|---|
| 49 |
|
|---|
| 50 |
cat > $1/services/testsrv.if << EOF |
|---|
| 51 |
## <summary>Test service policy</summary> |
|---|
| 52 |
|
|---|
| 53 |
interface(\`testsrv_domtrans',\` |
|---|
| 54 |
gen_require(\`type testsrv_t, testsrv_exec_t;') |
|---|
| 55 |
domtrans_pattern($1,testsrv_exec_t,testsrv_t) |
|---|
| 56 |
') |
|---|
| 57 |
EOF |
|---|
| 58 |
|
|---|
| 59 |
mkdir -p $1/test |
|---|
| 60 |
echo "<summary>external test layer</summary>" > $1/test/metadata.xml |
|---|
| 61 |
|
|---|
| 62 |
cat > $1/test/test.te << EOF |
|---|
| 63 |
policy_module(test,1.0) |
|---|
| 64 |
type test_t; |
|---|
| 65 |
type test_exec_t; |
|---|
| 66 |
init_daemon_domain(test_t,test_exec_t) |
|---|
| 67 |
EOF |
|---|
| 68 |
|
|---|
| 69 |
cat > $1/test/test.fc << EOF |
|---|
| 70 |
/usr/bin/test -- gen_context(system_u:object_r:testsrv_t,s0) |
|---|
| 71 |
EOF |
|---|
| 72 |
|
|---|
| 73 |
cat > $1/test/test.if << EOF |
|---|
| 74 |
## <summary>Test policy</summary> |
|---|
| 75 |
|
|---|
| 76 |
interface(\`test_domtrans',\` |
|---|
| 77 |
gen_require(\`type test_t, test_exec_t;') |
|---|
| 78 |
domtrans_pattern($1,test_exec_t,test_t) |
|---|
| 79 |
') |
|---|
| 80 |
EOF |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
if [ -x /usr/bin/sandbox ]; then |
|---|
| 84 |
SANDBOX=/usr/bin/sandbox |
|---|
| 85 |
else |
|---|
| 86 |
echo "Test is better with Gentoo's sandbox binary, which is missing." |
|---|
| 87 |
echo "Continuing without it, but no guarantees that there is no writing" |
|---|
| 88 |
echo "outside of the local policy directory." |
|---|
| 89 |
echo "Sandbox can be found at http://distfiles.gentoo.org/distfiles/sandbox-[ver].tar.bz2" |
|---|
| 90 |
fi |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
if [ ! -d policy/flask ]; then |
|---|
| 94 |
die "This should be run from the root of the refpolicy source tree." |
|---|
| 95 |
fi |
|---|
| 96 |
|
|---|
| 97 |
BOX=`mktemp -d` |
|---|
| 98 |
START=`pwd` |
|---|
| 99 |
PV=20 |
|---|
| 100 |
export SANDBOX_WRITE="/dev:/proc:$BOX/policy" |
|---|
| 101 |
|
|---|
| 102 |
einfo "Building generated files" |
|---|
| 103 |
make generate || die "Failed to build generated files!?!?!" |
|---|
| 104 |
|
|---|
| 105 |
export LOCAL_ROOT="$BOX/policy" |
|---|
| 106 |
|
|---|
| 107 |
################# external reference build (monolithic) |
|---|
| 108 |
mkdir -p ${LOCAL_ROOT} |
|---|
| 109 |
mkdir -p ${LOCAL_ROOT}/doc # should this be in the makefile? |
|---|
| 110 |
sed -r -e '/OUTPUT_POLICY/s/18/20/' -e '/OUTPUT_POLICY/s/^#//' ${START}/build.conf > ${LOCAL_ROOT}/build.conf |
|---|
| 111 |
cd ${LOCAL_ROOT} |
|---|
| 112 |
make_layer_test_policy policy/modules |
|---|
| 113 |
|
|---|
| 114 |
einfo "Building conf (extref; mon)" |
|---|
| 115 |
$SANDBOX make -C $START conf || die "Failed make conf (extref; mon)" |
|---|
| 116 |
grep -q ^testapp policy/modules.conf || die "testapp missing from modules.conf (extref; mon)" |
|---|
| 117 |
grep -q ^testsrv policy/modules.conf || die "testsrv missing from modules.conf (extref; mon)" |
|---|
| 118 |
grep -q '^test ' policy/modules.conf || die "test missing from modules.conf (extref; mon)" |
|---|
| 119 |
einfo "Building fc_sort" |
|---|
| 120 |
# need to figure out why this gets "Aborted" when run in sandbox |
|---|
| 121 |
make -C $START ${LOCAL_ROOT}/tmp/fc_sort || die |
|---|
| 122 |
einfo "Building policy (extref; mon)" |
|---|
| 123 |
$SANDBOX make -C $START policy || die "failed building policy (extref; mon)" |
|---|
| 124 |
grep -q 'type test_t;' policy.conf || die "test_t missing from policy.conf (extref; mon)" |
|---|
| 125 |
grep -q 'type testapp_t;' policy.conf || die "testapp_t missing from policy.conf (extref; mon)" |
|---|
| 126 |
grep -q 'type testsrv_t;' policy.conf || die "testsrv_t missing from policy.conf (extref; mon)" |
|---|
| 127 |
[ -f policy.20 ] || die "policy.20 is missing (extref; mon)" |
|---|
| 128 |
$SANDBOX make -C $START ${LOCAL_ROOT}/file_contexts || die "failed building file_contexts (extref; mon)" |
|---|
| 129 |
[ -f file_contexts ] || die "file_contexts is missing (extref; mon)" |
|---|
| 130 |
if [ ! -z "$SANDBOX" ]; then |
|---|
| 131 |
einfo "Touch test--this should fail (extref; mod)" |
|---|
| 132 |
$SANDBOX touch $START/EPERM && die "Touch test failed (extref; mon)" |
|---|
| 133 |
fi |
|---|
| 134 |
einfo "Cleaning up (extref; mon)" |
|---|
| 135 |
cd $START |
|---|
| 136 |
rm -fR $BOX/* |
|---|
| 137 |
|
|---|
| 138 |
################# external reference build (modular) |
|---|
| 139 |
mkdir -p ${LOCAL_ROOT} |
|---|
| 140 |
mkdir -p ${LOCAL_ROOT}/doc # should this be in the makefile? |
|---|
| 141 |
sed -r -e '/^MONOLITHIC/s/y$/n/' ${START}/build.conf > ${LOCAL_ROOT}/build.conf |
|---|
| 142 |
cd ${LOCAL_ROOT} |
|---|
| 143 |
make_layer_test_policy policy/modules |
|---|
| 144 |
|
|---|
| 145 |
einfo "Building conf (extref; mod)" |
|---|
| 146 |
$SANDBOX make -C $START conf || die |
|---|
| 147 |
grep -q ^testapp policy/modules.conf || die "testapp missing from modules.conf (extref; mod)" |
|---|
| 148 |
grep -q ^testsrv policy/modules.conf || die "testsrv missing from modules.conf (extref; mod)" |
|---|
| 149 |
einfo "Building fc_sort" |
|---|
| 150 |
# need to figure out why this gets "Aborted" when run in sandbox |
|---|
| 151 |
make -C $START ${LOCAL_ROOT}/tmp/fc_sort || die |
|---|
| 152 |
einfo "Building all policy (extref; mod)" |
|---|
| 153 |
$SANDBOX make -C $START base || die "failed building base module (extref; mod)" |
|---|
| 154 |
[ -f base.pp ] || die "base.pp is missing (extref; mod)" |
|---|
| 155 |
$SANDBOX make -C $START modules || die "failed building all modules (extref; mod)" |
|---|
| 156 |
[ -f apache.pp ] || die "apache.pp is missing (extref; mod)" |
|---|
| 157 |
[ -f testapp.pp ] || die "testapp.pp is missing (extref; mod)" |
|---|
| 158 |
einfo "Verifying policy linking (extref; mod)" |
|---|
| 159 |
$SANDBOX make -C $START validate || die "failed validating linking (extref; mod)" |
|---|
| 160 |
$SANDBOX make -C $START clean || die |
|---|
| 161 |
einfo "Building policy by name (extref; mod)" |
|---|
| 162 |
$SANDBOX make -C $START ${LOCAL_ROOT}/apache.pp ${LOCAL_ROOT}/testapp.pp || die "Failed building modules by name (extref; mod)" |
|---|
| 163 |
[ -f apache.pp ] || die "apache.pp is missing (extref; mod)" |
|---|
| 164 |
[ -f testapp.pp ] || die "testapp.pp is missing (extref; mod)" |
|---|
| 165 |
# need to figure out why this gets "Aborted" when run in sandbox |
|---|
| 166 |
make -C $START ${LOCAL_ROOT}/tmp/fc_sort || die |
|---|
| 167 |
$SANDBOX make -C $START ${LOCAL_ROOT}/base.pp || die "Failed building base by name (extref; mod)" |
|---|
| 168 |
[ -f base.pp ] || die "base.pp is missing (extref; mod)" |
|---|
| 169 |
if [ ! -z "$SANDBOX" ]; then |
|---|
| 170 |
einfo "Touch test--this should fail (extref; mod)" |
|---|
| 171 |
$SANDBOX touch $START/EPERM && die "Touch test failed (extref; mod)" |
|---|
| 172 |
fi |
|---|
| 173 |
einfo "Cleaning up (extref; mod)" |
|---|
| 174 |
cd $START |
|---|
| 175 |
rm -fR $BOX/* |
|---|
| 176 |
|
|---|
| 177 |
### change environment for headers tests |
|---|
| 178 |
unset LOCAL_ROOT |
|---|
| 179 |
export SHAREDIR="$BOX/usr/share/selinux" |
|---|
| 180 |
### |
|---|
| 181 |
|
|---|
| 182 |
################# headers build (flat) |
|---|
| 183 |
einfo "Installing headers (headers; flat)" |
|---|
| 184 |
make DESTDIR=$BOX install-headers || die "Failed to install headers (headers; flat)" |
|---|
| 185 |
mkdir $BOX/policy |
|---|
| 186 |
cp doc/example.* $BOX/policy |
|---|
| 187 |
cp doc/Makefile.example $BOX/policy/Makefile |
|---|
| 188 |
|
|---|
| 189 |
cd ${BOX}/policy |
|---|
| 190 |
einfo "Building all policy (headers; flat)" |
|---|
| 191 |
$SANDBOX make QUIET=n NAME=refpolicy all || die "Failed to build all policy (headers; flat)" |
|---|
| 192 |
[ -f example.pp ] || die "example.pp is missing (headers; flat)" |
|---|
| 193 |
$SANDBOX make QUIET=n NAME=refpolicy clean |
|---|
| 194 |
einfo "Building policy by name (headers; flat)" |
|---|
| 195 |
$SANDBOX make QUIET=n NAME=refpolicy example.pp || die "Failed to build by name (headers; flat)" |
|---|
| 196 |
[ -f example.pp ] || die "example.pp is missing (headers; flat)" |
|---|
| 197 |
einfo "Building XML (headers; flat)" |
|---|
| 198 |
$SANDBOX make QUIET=n NAME=refpolicy xml || die "Failed to build XML (headers; flat)" |
|---|
| 199 |
grep -q '<layer name="third_party">' doc/policy.xml || die "third_party layer missing from XML (headers; flat)" |
|---|
| 200 |
grep -q '<layer name="kernel">' doc/policy.xml || die "kernel layer missing from XML (headers; flat)" |
|---|
| 201 |
egrep -q '<module name="example" .*>' doc/policy.xml || die "example module missing from XML (headers; flat)" |
|---|
| 202 |
egrep -q '<module name="apache" .*>' doc/policy.xml || die "apache module missing from XML (headers; flat)" |
|---|
| 203 |
if [ ! -z "$SANDBOX" ]; then |
|---|
| 204 |
einfo "Touch test--this should fail (headers; flat)" |
|---|
| 205 |
$SANDBOX touch $BOX/usr/share/selinux/refpolicy/Makefile |
|---|
| 206 |
fi |
|---|
| 207 |
einfo "Cleaning up (headers; flat)" |
|---|
| 208 |
cd $START |
|---|
| 209 |
rm -fR $BOX/* |
|---|
| 210 |
|
|---|
| 211 |
################# headers build (layered) |
|---|
| 212 |
einfo "Installing headers (headers; layered)" |
|---|
| 213 |
make DESTDIR=$BOX install-headers |
|---|
| 214 |
mkdir $BOX/policy |
|---|
| 215 |
cp doc/Makefile.example $BOX/policy/Makefile |
|---|
| 216 |
cd ${BOX}/policy |
|---|
| 217 |
make_layer_test_policy . |
|---|
| 218 |
|
|---|
| 219 |
einfo "Building all policy (headers; layered)" |
|---|
| 220 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux all || die |
|---|
| 221 |
[ -f testsrv.pp ] || die "testsrv.pp is missing (headers; layered)" |
|---|
| 222 |
[ -f test.pp ] || die "test.pp is missing (headers; layered)" |
|---|
| 223 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux clean || die |
|---|
| 224 |
einfo "Building policy by name (headers; layered and flat)" |
|---|
| 225 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux testsrv.pp test.pp || die |
|---|
| 226 |
[ -f testsrv.pp ] || die "testsrv.pp is missing (headers; layered)" |
|---|
| 227 |
[ -f test.pp ] || die "test.pp is missing (headers; layered)" |
|---|
| 228 |
einfo "Building XML (headers; layered) (headers; layered)" |
|---|
| 229 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux xml || die |
|---|
| 230 |
grep -q '<layer name="kernel">' doc/policy.xml || die "kernel layer missing from XML (headers; layered)" |
|---|
| 231 |
grep -q '<layer name="test">' doc/policy.xml || die "test layer missing from XML (headers; layered)" |
|---|
| 232 |
egrep -q '<module name="test" .*>' doc/policy.xml || die "test module missing from XML (headers; layered)" |
|---|
| 233 |
egrep -q '<module name="testsrv" .*>' doc/policy.xml || die "testsrv module missing from XML (headers; layered)" |
|---|
| 234 |
egrep -q '<module name="testapp" .*>' doc/policy.xml || die "testapp module missing from XML (headers; layered)" |
|---|
| 235 |
egrep -q '<module name="apache" .*>' doc/policy.xml || die "apache module missing from XML (headers; layered)" |
|---|
| 236 |
if [ ! -z "$SANDBOX" ]; then |
|---|
| 237 |
einfo "Touch test--this should fail (headers; layered)" |
|---|
| 238 |
$SANDBOX touch $BOX/usr/share/selinux/refpolicy/Makefile |
|---|
| 239 |
fi |
|---|
| 240 |
einfo "Cleaning up (headers; layered)" |
|---|
| 241 |
cd $START |
|---|
| 242 |
rm -fR $BOX/* |
|---|
| 243 |
|
|---|
| 244 |
################# headers build (layered and flat) |
|---|
| 245 |
einfo "Installing headers (headers; layered and flat)" |
|---|
| 246 |
make DESTDIR=$BOX install-headers |
|---|
| 247 |
mkdir $BOX/policy |
|---|
| 248 |
cp doc/example.* $BOX/policy |
|---|
| 249 |
cp doc/Makefile.example $BOX/policy/Makefile |
|---|
| 250 |
cd ${BOX}/policy |
|---|
| 251 |
make_layer_test_policy . |
|---|
| 252 |
|
|---|
| 253 |
einfo "Building all policy (headers; layered and flat)" |
|---|
| 254 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux all || die |
|---|
| 255 |
[ -f example.pp ] || die "example.pp is missing (headers; layered and flat)" |
|---|
| 256 |
[ -f testapp.pp ] || die "testapp.pp is missing (headers; layered and flat)" |
|---|
| 257 |
[ -f testsrv.pp ] || die "testsrv.pp is missing (headers; layered and flat)" |
|---|
| 258 |
[ -f test.pp ] || die "test.pp is missing (headers; layered and flat)" |
|---|
| 259 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux clean || die |
|---|
| 260 |
einfo "Building policy by name (headers; layered and flat)" |
|---|
| 261 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux test.pp example.pp testapp.pp || die |
|---|
| 262 |
[ -f testapp.pp ] || die "testapp.pp is missing (headers; layered and flat)" |
|---|
| 263 |
[ -f test.pp ] || die "test.pp is missing (headers; layered and flat)" |
|---|
| 264 |
einfo "Building XML (headers; layered and flat)" |
|---|
| 265 |
$SANDBOX make QUIET=n NAME=refpolicy SHAREDIR=$BOX/usr/share/selinux xml || die |
|---|
| 266 |
grep -q '<layer name="kernel">' doc/policy.xml || die "kernel layer missing from XML (headers; layered and flat)" |
|---|
| 267 |
grep -q '<layer name="test">' doc/policy.xml || die "test layer missing from XML (headers; layered and flat)" |
|---|
| 268 |
grep -q '<layer name="third_party">' doc/policy.xml || die "third_party layer missing from XML (headers; layered and flat)" |
|---|
| 269 |
egrep -q '<module name="test" .*>' doc/policy.xml || die "test module missing from XML (headers; layered and flat)" |
|---|
| 270 |
egrep -q '<module name="testsrv" .*>' doc/policy.xml || die "testsrv module missing from XML (headers; layered and flat)" |
|---|
| 271 |
egrep -q '<module name="testapp" .*>' doc/policy.xml || die "testapp module missing from XML (headers; layered and flat)" |
|---|
| 272 |
egrep -q '<module name="apache" .*>' doc/policy.xml || die "apache module missing from XML (headers; layered and flat)" |
|---|
| 273 |
egrep -q '<module name="example" .*>' doc/policy.xml || die "example module missing from XML (headers; layered and flat)" |
|---|
| 274 |
if [ ! -z "$SANDBOX" ]; then |
|---|
| 275 |
einfo "Touch test--this should fail (headers; layered and flat)" |
|---|
| 276 |
$SANDBOX touch $BOX/usr/share/selinux/refpolicy/Makefile |
|---|
| 277 |
fi |
|---|
| 278 |
einfo "Cleaning up (headers; layered and flat)" |
|---|
| 279 |
cd $START |
|---|
| 280 |
rm -fR $BOX |
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
# |
|---|
| 284 |
# clean up |
|---|
| 285 |
# |
|---|
| 286 |
rm -fR $BOX |
|---|
| 287 |
make bare |
|---|
| 288 |
einfo "Completed successfully" |
|---|
| 289 |
exit 0 |
|---|
| 290 |
|
|---|