Quoting variables properly prevents against accidental splitting. Some
have been left unquoted, as they are being intentionally split for now,
but future patches will use more arrays allowing us to drop at least a
couple of those variables.

Surrounding variables with `{}` makes it more clear where the variable
actually begins and ends, and is good practice in general.

Signed-off-by: Rahul Sandhu <[email protected]>
---
 eclass/selinux-policy-2.eclass | 86 +++++++++++++++++-----------------
 1 file changed, 43 insertions(+), 43 deletions(-)

diff --git a/eclass/selinux-policy-2.eclass b/eclass/selinux-policy-2.eclass
index 76ac40f2719e..96e0ae40f1ca 100644
--- a/eclass/selinux-policy-2.eclass
+++ b/eclass/selinux-policy-2.eclass
@@ -55,7 +55,7 @@ _SELINUX_POLICY_2_ECLASS=1
 # (space-separated) or a bash array.
 : "${POLICY_FILES:=""}"
 
-if [[ ${EAPI} = 7 ]]; then
+if [[ "${EAPI}" = 7 ]]; then
        # @ECLASS_VARIABLE: POLICY_TYPES
        # @DESCRIPTION:
        # This variable informs the eclass for which SELinux policies the 
module should
@@ -93,7 +93,7 @@ case ${BASEPOL} in
                ;;
 esac
 
-if [[ ${EAPI} != 7 ]]; then
+if [[ "${EAPI}" != 7 ]]; then
        # Build all policy types by default
        IUSE="+selinux_policy_types_targeted +selinux_policy_types_strict 
+selinux_policy_types_mcs +selinux_policy_types_mls"
        REQUIRED_USE="|| ( selinux_policy_types_targeted 
selinux_policy_types_strict selinux_policy_types_mcs selinux_policy_types_mls )"
@@ -121,7 +121,7 @@ else
        _BASE_POLICY_VERSION="${PV}"
 fi
 
-if [[ ${EAPI} = 7 ]]; then
+if [[ "${EAPI}" = 7 ]]; then
        RDEPEND="
                >=sys-apps/policycoreutils-2.5
                >=sec-policy/selinux-base-policy-${_BASE_POLICY_VERSION}
@@ -206,31 +206,31 @@ selinux-policy-2_src_prepare() {
 
        # Collect only those files needed for this particular module
        for i in ${MODS}; do
-               modfiles="$(find "${S}/refpolicy/policy/modules" -iname $i.te) 
$modfiles"
-               modfiles="$(find "${S}/refpolicy/policy/modules" -iname $i.fc) 
$modfiles"
-               modfiles="$(find "${S}/refpolicy/policy/modules" -iname $i.cil) 
$modfiles"
-               if [[ ${add_interfaces} -eq 1 ]]; then
-                       modfiles="$(find "${S}/refpolicy/policy/modules" -iname 
$i.if) $modfiles"
+               modfiles="$(find "${S}/refpolicy/policy/modules" -iname 
"${i}.te") ${modfiles}"
+               modfiles="$(find "${S}/refpolicy/policy/modules" -iname 
"${i}.fc") ${modfiles}"
+               modfiles="$(find "${S}/refpolicy/policy/modules" -iname 
"${i}.cil") ${modfiles}"
+               if [[ "${add_interfaces}" -eq 1 ]]; then
+                       modfiles="$(find "${S}/refpolicy/policy/modules" -iname 
"${i}.if") ${modfiles}"
                fi
        done
 
        _selinux_prepare_modules() {
-               mkdir "${S}"/${1} || die "Failed to create directory ${S}/${1}"
-               cp "${S}"/refpolicy/doc/Makefile.example "${S}"/${1}/Makefile \
+               mkdir "${S}/${1}" || die "Failed to create directory ${S}/${1}"
+               cp "${S}/refpolicy/doc/Makefile.example" "${S}/${1}/Makefile" \
                        || die "Failed to copy Makefile.example to 
${S}/${1}/Makefile"
 
-               cp ${modfiles} "${S}"/${1} \
+               cp ${modfiles} "${S}/${1}" \
                        || die "Failed to copy the module files to ${S}/${1}"
        }
 
-       if [[ ${EAPI} = 7 ]]; then
+       if [[ "${EAPI}" = 7 ]]; then
                for i in ${POLICY_TYPES}; do
-                       _selinux_prepare_modules $i
+                       _selinux_prepare_modules "${i}"
                done
        else
                for i in targeted strict mcs mls; do
-                       if use selinux_policy_types_${i}; then
-                               _selinux_prepare_modules $i
+                       if use "selinux_policy_types_${i}"; then
+                               _selinux_prepare_modules "${i}"
                        fi
                done
        fi
@@ -254,23 +254,23 @@ selinux-policy-2_src_compile() {
                # build system.
                [[ "${useflag}" = selinux_policy_types_* ]] && continue
 
-               use ${useflag} && makeuse="${makeuse} -D use_${useflag}"
+               use "${useflag}" && makeuse="${makeuse} -D use_${useflag}"
        done
 
        _selinux_compile_modules() {
                # Support USE flags in builds
                export M4PARAM="${makeuse}"
-               emake NAME=$1 SHAREDIR="${EPREFIX}"/usr/share/selinux -C 
"${S}"/${1}
+               emake NAME="${1}" SHAREDIR="${EPREFIX}/usr/share/selinux" -C 
"${S}/${1}"
        }
 
-       if [[ ${EAPI} = 7 ]]; then
+       if [[ "${EAPI}" = 7 ]]; then
                for i in ${POLICY_TYPES}; do
-                       _selinux_compile_modules $i
+                       _selinux_compile_modules "${i}"
                done
        else
                for i in targeted strict mcs mls; do
-                       if use selinux_policy_types_${i}; then
-                               _selinux_compile_modules $i
+                       if use "selinux_policy_types_${i}"; then
+                               _selinux_compile_modules "${i}"
                        fi
                done
        fi
@@ -286,28 +286,28 @@ selinux-policy-2_src_install() {
        _selinux_install_modules() {
                for i in ${MODS}; do
                        einfo "Installing ${1} ${i} policy package"
-                       insinto ${BASEDIR}/${1}
+                       insinto "${BASEDIR}/${1}"
                        if [[ -f "${S}/${1}/${i}.pp" ]]; then
-                               doins "${S}"/${1}/${i}.pp || die "Failed to add 
${i}.pp to ${1}"
+                               doins "${S}/${1}/${i}.pp" || die "Failed to add 
${i}.pp to ${1}"
                        elif [[ -f "${S}/${1}/${i}.cil" ]]; then
-                               doins "${S}"/${1}/${i}.cil || die "Failed to 
add ${i}.cil to ${1}"
+                               doins "${S}/${1}/${i}.cil" || die "Failed to 
add ${i}.cil to ${1}"
                        fi
 
                        if [[ "${POLICY_FILES[@]}" = *"${i}.if"* ]]; then
-                               insinto ${BASEDIR}/${1}/include/3rd_party
-                               doins "${S}"/${1}/${i}.if || die "Failed to add 
${i}.if to ${1}"
+                               insinto "${BASEDIR}/${1}/include/3rd_party"
+                               doins "${S}/${1}/${i}.if" || die "Failed to add 
${i}.if to ${1}"
                        fi
                done
        }
 
-       if [[ ${EAPI} = 7 ]]; then
+       if [[ "${EAPI}" = 7 ]]; then
                for i in ${POLICY_TYPES}; do
-                       _selinux_install_modules $i
+                       _selinux_install_modules "${i}"
                done
        else
                for i in targeted strict mcs mls; do
-                       if use selinux_policy_types_${i}; then
-                               _selinux_install_modules $i
+                       if use "selinux_policy_types_${i}"; then
+                               _selinux_install_modules "${i}"
                        fi
                done
        fi
@@ -333,7 +333,7 @@ selinux-policy-2_pkg_postinst() {
                        return
                fi
 
-               einfo "Inserting the following modules into the $i module 
store: ${MODS}"
+               einfo "Inserting the following modules into the ${i} module 
store: ${MODS}"
 
                cd "${ROOT}/usr/share/selinux/${1}" || die "Could not enter 
/usr/share/selinux/${1}"
                for i in ${MODS}; do
@@ -344,11 +344,11 @@ selinux-policy-2_pkg_postinst() {
                        fi
                done
 
-               semodule ${root_opts} -s ${1} -i ${COMMAND}
+               semodule ${root_opts} -s "${1}" -i ${COMMAND}
                if [[ $? -ne 0 ]]; then
                        ewarn "SELinux module load failed. Trying full 
reload..."
 
-                       semodule ${root_opts} -s ${1} -i ./*.pp
+                       semodule ${root_opts} -s "${1}" -i ./*.pp
 
                        if [[ $? -ne 0 ]]; then
                                ewarn "Failed to reload SELinux policies."
@@ -373,14 +373,14 @@ selinux-policy-2_pkg_postinst() {
                COMMAND=""
        }
 
-       if [[ ${EAPI} = 7 ]]; then
+       if [[ "${EAPI}" = 7 ]]; then
                for i in ${POLICY_TYPES}; do
-                       _selinux_postinst $i
+                       _selinux_postinst "${i}"
                done
        else
                for i in targeted strict mcs mls; do
-                       if use selinux_policy_types_${i}; then
-                               _selinux_postinst $i
+                       if use "selinux_policy_types_${i}"; then
+                               _selinux_postinst "${i}"
                        fi
                done
        fi
@@ -443,9 +443,9 @@ selinux-policy-2_pkg_postrm() {
                done
 
                _selinux_postrm() {
-                       einfo "Removing the following modules from the $1 
module store: ${MODS}"
+                       einfo "Removing the following modules from the ${1} 
module store: ${MODS}"
 
-                       semodule ${root_opts} -s ${1} ${COMMAND}
+                       semodule ${root_opts} -s "${1}" ${COMMAND}
                        if [[ $? -ne 0 ]]; then
                                ewarn "SELinux module unload failed."
                        else
@@ -453,14 +453,14 @@ selinux-policy-2_pkg_postrm() {
                        fi
                }
 
-               if [[ ${EAPI} = 7 ]]; then
+               if [[ "${EAPI}" = 7 ]]; then
                        for i in ${POLICY_TYPES}; do
-                               _selinux_postrm $i
+                               _selinux_postrm "${i}"
                        done
                else
                        for i in targeted strict mcs mls; do
-                               if use selinux_policy_types_${i}; then
-                                       _selinux_postrm $i
+                               if use "selinux_policy_types_${i}"; then
+                                       _selinux_postrm "${i}"
                                fi
                        done
                fi
-- 
2.50.1


Reply via email to