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