#!/bin/bash # vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # runtest.sh of /CoreOS/policycoreutils/Sanity/restorecon # Description: does restorecon work correctly ? # Author: Milos Malik # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # Copyright (c) 2011 Red Hat, Inc. All rights reserved. # # This copyrighted material is made available to anyone wishing # to use, modify, copy, or redistribute it subject to the terms # and conditions of the GNU General Public License version 2. # # This program is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR # PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program; if not, write to the Free # Software Foundation, Inc., 51 Franklin Street, Fifth Floor, # Boston, MA 02110-1301, USA. # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Include rhts environment . /usr/bin/rhts-environment.sh . /usr/share/beakerlib/beakerlib.sh PACKAGE="policycoreutils" rlJournalStart rlPhaseStartSetup rlAssertRpm ${PACKAGE} rlServiceStop mcstrans mcstransd rlRun "rpm -qf `which restorecon` | grep ${PACKAGE}" rlRun "setenforce 1" rlRun "sestatus" rlRun "setsebool allow_domain_fd_use on" rlPhaseEnd rlPhaseStartTest "Functional test" TESTDIR="/opt/restorecon_testdir" DIRS="correct.dir incorrect1.dir incorrect2.dir customizable.dir" FILES="correct.file incorrect.file customizable.file" rlRun "make -f /usr/share/selinux/devel/Makefile" rlRun "semodule -i testpolicy.pp" rlFileBackup /etc/selinux/targeted/contexts/customizable_types rlRun "echo 'customizable_t' >> /etc/selinux/targeted/contexts/customizable_types" # Here is the testing dirs and files structure # all the files have initial context corresponding to their names # ./ # correct.file # incorrect.file # customizable.file # correct.dir/ # correct.file # incorrect.file # customizable.file # incorrect1.dir/ # correct.file # incorrect.file # customizable.file # incorrect2.dir/ # correct.file # incorrect.file # customizable.file # customizable.dir/ # correct.file # incorrect.file # customizable.file # Function to set initial contexts function set_contexts { # Set the intended contexts rlLog "Setting initial contexts of testing dirs..." restorecon -R $TESTDIR for ITEM in `find . -name 'incorrect*'`; do chcon -t incorrect_t $ITEM done for ITEM in `find . -name 'customizable*'`; do chcon -t customizable_t $ITEM done } # Check that files in dir $1 have the initial contexts function check_initial_contexts { if echo $1 | grep -q 'incorrect.dir'; then rlRun "ls -ladZ $1 | grep :incorrect_t" elif echo $1 | grep -q 'correct.dir'; then rlRun "ls -ladZ $1 | grep :correct_t" elif echo $1 | grep -q 'customizable.dir'; then rlRun "ls -ladZ $1 | grep :customizable_t" fi rlRun "ls -ladZ $1/* | grep '\ ../file_list <