|
Lukas Vrabec |
37cf7d |
# Copyright (C) 2017 Red Hat, Inc. All rights reserved.
|
|
Lukas Vrabec |
37cf7d |
#
|
|
Lukas Vrabec |
37cf7d |
# Author: Petr Lautrbach <plautrba@redhat.com>
|
|
Lukas Vrabec |
37cf7d |
# Author: Lukáš Vrabec <lvrabec@redhat.com>
|
|
Petr Lautrbach |
c49229 |
#
|
|
Petr Lautrbach |
c49229 |
# This program is free software; you can redistribute it and/or
|
|
Petr Lautrbach |
c49229 |
# modify it under the terms of the GNU General Public License
|
|
Petr Lautrbach |
c49229 |
# as published by the Free Software Foundation; either version 2
|
|
Petr Lautrbach |
c49229 |
# of the License, or (at your option) any later version.
|
|
Petr Lautrbach |
c49229 |
#
|
|
Petr Lautrbach |
c49229 |
# This program is distributed in the hope that it will be useful,
|
|
Petr Lautrbach |
c49229 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Petr Lautrbach |
c49229 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Petr Lautrbach |
c49229 |
# GNU General Public License for more details.
|
|
Petr Lautrbach |
c49229 |
#
|
|
Petr Lautrbach |
c49229 |
# You should have received a copy of the GNU General Public License
|
|
Petr Lautrbach |
c49229 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
# RPM macros for packages installing SELinux modules
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
%_selinux_policy_version SELINUXPOLICYVERSION
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
%_file_context_file %{_sysconfdir}/selinux/${SELINUXTYPE}/contexts/files/file_contexts
|
|
Petr Lautrbach |
c49229 |
%_file_context_file_pre %{_localstatedir}/lib/rpm-state/file_contexts.pre
|
|
Petr Lautrbach |
c49229 |
|
|
Lukas Vrabec |
29c9d8 |
%_file_custom_defined_booleans %{_sharedstatedir}/selinux/${_policytype}/rpmbooleans.custom
|
|
Lukas Vrabec |
29c9d8 |
%_file_custom_defined_booleans_tmp %{_sharedstatedir}/selinux/${_policytype}/rpmbooleans.custom.tmp
|
|
Lukas Vrabec |
29c9d8 |
|
|
Lukas Vrabec |
37cf7d |
# %selinux_modules_install [-s <policytype>] [-p <modulepriority>] module [module]...
|
|
Lukas Vrabec |
37cf7d |
%selinux_modules_install("s:p:") \
|
|
Petr Lautrbach |
c49229 |
. /etc/selinux/config \
|
|
Petr Lautrbach |
c49229 |
_policytype=%{-s*} \
|
|
Petr Lautrbach |
c49229 |
if [ -z "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
_policytype="targeted" \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Lukas Vrabec |
37cf7d |
%{_sbindir}/semodule -n -s ${_policytype} -X %{!-p:200}%{-p*} -i %* \
|
|
Petr Lautrbach |
c49229 |
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
%{_sbindir}/load_policy \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
%{nil}
|
|
Petr Lautrbach |
c49229 |
|
|
Lukas Vrabec |
37cf7d |
# %selinux_modules_uninstall [-s <policytype>] [-p <modulepriority>] module [module]...
|
|
Lukas Vrabec |
37cf7d |
%selinux_modules_uninstall("s:p:") \
|
|
Petr Lautrbach |
c49229 |
. /etc/selinux/config \
|
|
Petr Lautrbach |
c49229 |
_policytype=%{-s*} \
|
|
Petr Lautrbach |
c49229 |
if [ -z "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
_policytype="targeted" \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
if [ $1 -eq 0 ]; then \
|
|
Lukas Vrabec |
37cf7d |
%{_sbindir}/semodule -n -X %{!-p:200}%{-p*} -r %* &> /dev/null || : \
|
|
Petr Lautrbach |
c49229 |
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
%{_sbindir}/load_policy \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
%{nil}
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
# %selinux_relabel_pre [-s <policytype>]
|
|
Petr Lautrbach |
c49229 |
%selinux_relabel_pre("s:") \
|
|
Petr Lautrbach |
c49229 |
. /etc/selinux/config \
|
|
Petr Lautrbach |
c49229 |
_policytype=%{-s*} \
|
|
Petr Lautrbach |
c49229 |
if [ -z "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
_policytype="targeted" \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
if %{_sbindir}/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
[ -f %{_file_context_file_pre} ] || cp -f %{_file_context_file} %{_file_context_file_pre} \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
%{nil}
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
|
|
Petr Lautrbach |
c49229 |
# %selinux_relabel_post [-s <policytype>]
|
|
Petr Lautrbach |
c49229 |
%selinux_relabel_post("s:") \
|
|
Petr Lautrbach |
c49229 |
. /etc/selinux/config \
|
|
Petr Lautrbach |
c49229 |
_policytype=%{-s*} \
|
|
Petr Lautrbach |
c49229 |
if [ -z "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
_policytype="targeted" \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
if /usr/sbin/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Petr Lautrbach |
c49229 |
if [ -f %{_file_context_file_pre} ]; then \
|
|
Petr Lautrbach |
c49229 |
%{_sbindir}/fixfiles -C %{_file_context_file_pre} restore \
|
|
Petr Lautrbach |
c49229 |
rm -f %{_file_context_file_pre} \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
fi \
|
|
Petr Lautrbach |
c49229 |
%{nil}
|
|
Lukas Vrabec |
6fa7bc |
|
|
Lukas Vrabec |
6fa7bc |
# %selinux_set_booleans [-s <policytype>] boolean [boolean]...
|
|
Lukas Vrabec |
6fa7bc |
%selinux_set_booleans("s:") \
|
|
Lukas Vrabec |
6fa7bc |
. /etc/selinux/config \
|
|
Lukas Vrabec |
6fa7bc |
_policytype=%{-s*} \
|
|
Lukas Vrabec |
6fa7bc |
if [ -z "${_policytype}" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
_policytype="targeted" \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
LOCAL_MODIFICATIONS=$(semanage boolean -E) \
|
|
Lukas Vrabec |
6fa7bc |
if [ ! -f %_file_custom_defined_booleans ]; then \
|
|
Lukas Vrabec |
29c9d8 |
echo "# This file is managed by macros.selinux-policy. Do not edit it manually" > %_file_custom_defined_booleans \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
semanage_import='' \
|
|
Lukas Vrabec |
6fa7bc |
for boolean in %*; do \
|
|
Lukas Vrabec |
6fa7bc |
boolean_name=${boolean%=*} \
|
|
Lukas Vrabec |
6fa7bc |
boolean_value=${boolean#*=} \
|
|
Lukas Vrabec |
6fa7bc |
boolean_local_string=$(grep "$boolean_name\$" <<<$LOCAL_MODIFICATIONS) \
|
|
Lukas Vrabec |
6fa7bc |
if [ -n "$boolean_local_string" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
semanage_import="${semanage_import}\\nboolean -m -$boolean_value $boolean_name" \
|
|
Lukas Vrabec |
6fa7bc |
boolean_customized_string=$(grep "$boolean_name\$" %_file_custom_defined_booleans | tail -n 1) \
|
|
Lukas Vrabec |
6fa7bc |
if [ -n "$boolean_customized_string" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
/bin/echo $boolean_customized_string >> %_file_custom_defined_booleans \
|
|
Lukas Vrabec |
6fa7bc |
else \
|
|
Lukas Vrabec |
6fa7bc |
/bin/echo $boolean_local_string >> %_file_custom_defined_booleans \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
else \
|
|
Lukas Vrabec |
6fa7bc |
semanage_import="${semanage_import}\\nboolean -m -$boolean_value $boolean_name" \
|
|
Lukas Vrabec |
6fa7bc |
boolean_default_value=$(semanage boolean -l | grep "^$boolean_name " | sed 's/[^(]*([^,]*, *\\(on\\|off\\).*/\\1/') \
|
|
Lukas Vrabec |
6fa7bc |
/bin/echo "boolean -m --$boolean_default_value $boolean_name" >> %_file_custom_defined_booleans \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
done; \
|
|
Lukas Vrabec |
6fa7bc |
if /usr/sbin/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
/bin/echo -e "$semanage_import" | %{_sbindir}/semanage import -S "${_policytype}" \
|
|
Lukas Vrabec |
6fa7bc |
else \
|
|
Lukas Vrabec |
6fa7bc |
echo -e "$semanage_import" | %{_sbindir}/semanage import -S "${_policytype} -N" \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
%{nil}
|
|
Lukas Vrabec |
6fa7bc |
|
|
Lukas Vrabec |
6fa7bc |
# %selinux_unset_booleans [-s <policytype>] boolean [boolean]...
|
|
Lukas Vrabec |
6fa7bc |
%selinux_unset_booleans("s:") \
|
|
Lukas Vrabec |
6fa7bc |
. /etc/selinux/config \
|
|
Lukas Vrabec |
6fa7bc |
_policytype=%{-s*} \
|
|
Lukas Vrabec |
6fa7bc |
if [ -z "${_policytype}" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
_policytype="targeted" \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
semanage_import='' \
|
|
Lukas Vrabec |
6fa7bc |
for boolean in %*; do \
|
|
Lukas Vrabec |
6fa7bc |
boolean_name=${boolean%=*} \
|
|
Lukas Vrabec |
6fa7bc |
boolean_customized_string=$(grep "$boolean_name\$" %_file_custom_defined_booleans | tail -n 1) \
|
|
Lukas Vrabec |
6fa7bc |
if [ -n "$boolean_customized_string" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
awk "/$boolean_customized_string/ && !f{f=1; next} 1" %_file_custom_defined_booleans > %_file_custom_defined_booleans_tmp && mv %_file_custom_defined_booleans_tmp %_file_custom_defined_booleans \
|
|
Lukas Vrabec |
6fa7bc |
if ! grep -q "$boolean_name\$" %_file_custom_defined_booleans; then \
|
|
Lukas Vrabec |
6fa7bc |
semanage_import="${semanage_import}\\n${boolean_customized_string}" \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
done; \
|
|
Lukas Vrabec |
6fa7bc |
if /usr/sbin/selinuxenabled && [ "${SELINUXTYPE}" = "${_policytype}" ]; then \
|
|
Lukas Vrabec |
6fa7bc |
/bin/echo -e "$semanage_import" | %{_sbindir}/semanage import -S "${_policytype}" \
|
|
Lukas Vrabec |
6fa7bc |
else \
|
|
Lukas Vrabec |
6fa7bc |
echo -e "$semanage_import" | %{_sbindir}/semanage import -S "${_policytype} -N" \
|
|
Lukas Vrabec |
6fa7bc |
fi \
|
|
Lukas Vrabec |
6fa7bc |
%{nil}
|