#!/bin/bash
# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/selinux-policy/Regression/boinc-and-similar
# Description: SELinux interferes with boinc and related programs
# Author: Milos Malik <mmalik@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2012 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 Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="selinux-policy"
ROOT_PASSWORD="redhat"
FILE_PATH="/usr/bin/boinc_client"
FILE_CONTEXT="boinc_exec_t"
SERVICE_PACKAGE="boinc-client"
SERVICE_NAME="boinc-client"
PROCESS_NAME="boinc"
PROCESS_CONTEXT="boinc_t"
rlJournalStart
rlPhaseStartSetup
rlRun "rlImport 'selinux-policy/common'" 0,1
rlSESatisfyRequires
rlAssertRpm ${PACKAGE}
rlAssertRpm ${PACKAGE}-targeted
rlAssertRpm ${SERVICE_PACKAGE}
rlServiceStop ${SERVICE_NAME}
rlFileBackup /etc/shadow
rlSESetEnforce
rlSEStatus
rlSESetTimestamp
sleep 2
rlPhaseEnd
rlPhaseStartTest "bz#1618683"
rlSEMatchPathCon "${FILE_PATH}" "${FILE_CONTEXT}"
if rlIsRHEL 5 ; then
SOURCE_TYPE="initrc_t"
BOOLEANS="[ ]"
elif rlIsRHEL 6 ; then
SOURCE_TYPE="initrc_t"
else # RHEL-7 etc.
SOURCE_TYPE="init_t" # systemd runs the process
fi
rlSESearchRule "allow ${SOURCE_TYPE} ${FILE_CONTEXT} : file { getattr open read execute } $BOOLEANS"
rlSESearchRule "allow ${SOURCE_TYPE} ${PROCESS_CONTEXT} : process { transition } $BOOLEANS"
rlSESearchRule "type_transition ${SOURCE_TYPE} ${FILE_CONTEXT} : process ${PROCESS_CONTEXT} $BOOLEANS"
rlSESearchRule "allow boinc_t boinc_exec_t : file { execute_no_trans }"
rlPhaseEnd
rlPhaseStartTest "bz#1711682 + bz#1779070"
# /usr/bin/boinc and /usr/bin/boinc_client are hardlinks, share the same inode
rlSEMatchPathCon "/usr/bin/boinc_client" "boinc_exec_t"
rlSEMatchPathCon "/var/lib/boinc" "boinc_var_lib_t"
rlSEMatchPathCon "/run/systemd/unit-root/var/lib/boinc" "init_var_run_t"
rlSESearchRule "allow init_t boinc_var_lib_t : dir { mounton } [ ]"
# SELinux denials appear if the following line is in boinc-client system unit file
# ReadWritePaths=/var/lib/boinc
rlPhaseEnd
rlPhaseStartTest "real scenario -- standalone service"
rlRun "echo ${ROOT_PASSWORD} | passwd --stdin root"
if ! rlSEDefined ${PROCESS_CONTEXT} ; then
if rlIsRHEL 5 6 ; then
PROCESS_CONTEXT="initrc_t"
else
PROCESS_CONTEXT="unconfined_service_t"
fi
fi
rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "start status" 1
rlRun "restorecon -Rv /run /var -e /var/ARTIFACTS" 0-255
rlSEService ${ROOT_PASSWORD} ${SERVICE_NAME} ${PROCESS_NAME} ${PROCESS_CONTEXT} "restart status stop status" 1
rlPhaseEnd
rlPhaseStartCleanup
sleep 2
rlSECheckAVC
rlFileRestore
rlServiceRestore ${SERVICE_NAME}
rlPhaseEnd
rlJournalPrintText
rlJournalEnd