#!/bin/sh

set -eu

. /usr/share/geordi/_functions

info "Setting and checking permissions"


debug "Setting permissions on chroot base"
chmod 711 "${RT}"

debug "Setting '644' permissions"
chmod 644 "${RT}/prelude.a" "${RT}/prelude.hpp.gch"

debug "Setting read-write permissions"
chmod 666 "${RT}/t.cpp" "${RT}/t.s" "${RT}/t.o"

debug "Setting read-write-execute permissions"
chmod 777 "${RT}/t"


debug "Checking writable files"
if [ $(find "${RT}" -perm -o+w 2>/dev/null | wc -l) -gt 4 ]
then
	error "More than 4 writable files in chroot"
fi

debug "Checking file ownership"
if [ $(find "${RT}" -user nobody 2>/dev/null | wc -l) -gt 0 ]
then
	error "Files owned by 'nobody' in chroot"
fi

debug "Checking setuid files"
if [ $(find "${RT}" -perm -4000 2>/dev/null | wc -l) -gt 0 ]
then
	error "Setuid files in chroot"
fi
