588789
#!/bin/bash
588789
588789
function usage {
588789
    echo "Usage: $0 [ -c | -t [ -M ] ] <macro>"
588789
    echo "Options:
588789
  -c     generate CIL output
588789
  -t     generate standard policy source format (.te) allow rules - this is default
588789
  -M     generate complete module .te output
588789
"
588789
}
588789
588789
function cleanup {
588789
    rm -rf $TEMP_STORE
588789
}
588789
588789
while getopts "chMt" opt; do
588789
    case $opt in
588789
        c) GENCIL=1
588789
           ;;
588789
        t) GENTE=1
588789
           ;;
588789
        M) GENTEMODULE=1
588789
           ;;
588789
        h) usage
588789
           exit 0
588789
           ;;
588789
        \?) usage
588789
           exit 1
588789
           ;;
588789
    esac
588789
done
588789
588789
shift $((OPTIND-1))
588789
588789
SELINUX_MACRO=$1
588789
588789
if [ -z "$SELINUX_MACRO" ]
588789
then
588789
    exit 1
588789
fi
588789
588789
TEMP_STORE="$(mktemp -d)"
588789
cd $TEMP_STORE || exit 1
588789
588789
IFS="("
588789
set $1
588789
SELINUX_DOMAIN="${2::-1}"
588789
588789
echo -e "policy_module(expander, 1.0.0) \n" \
588789
     "gen_require(\`\n" \
588789
     "type $SELINUX_DOMAIN ; \n" \
588789
     "')" > expander.te
588789
588789
echo "$SELINUX_MACRO" >> expander.te
588789
588789
make -f /usr/share/selinux/devel/Makefile tmp/all_interfaces.conf &> /dev/null
588789
588789
if [ "x$GENCIL" = "x1" ]; then
588789
588789
    make -f /usr/share/selinux/devel/Makefile expander.pp &> /dev/null
588789
    MAKE_RESULT=$?
588789
588789
    if [ $MAKE_RESULT -ne 2 ]
588789
    then
588789
        /usr/libexec/selinux/hll/pp < $TEMP_STORE/expander.pp > $TEMP_STORE/expander.cil 2> /dev/null
588789
        grep -v "cil_gen_require" $TEMP_STORE/expander.cil | sort -u
588789
    fi
588789
fi
588789
588789
if [ "$GENTE" = "1" ] || [ "x$GENCIL" != "x1" ]; then
588789
    m4 -D enable_mcs -D distro_redhat -D hide_broken_symptoms -D mls_num_sens=16 -D mls_num_cats=1024 -D mcs_num_cats=1024 -s /usr/share/selinux/devel/include/support/file_patterns.spt /usr/share/selinux/devel/include/support/ipc_patterns.spt /usr/share/selinux/devel/include/support/obj_perm_sets.spt /usr/share/selinux/devel/include/support/misc_patterns.spt /usr/share/selinux/devel/include/support/misc_macros.spt /usr/share/selinux/devel/include/support/all_perms.spt /usr/share/selinux/devel/include/support/mls_mcs_macros.spt /usr/share/selinux/devel/include/support/loadable_module.spt tmp/all_interfaces.conf expander.te > expander.tmp 2> /dev/null
588789
    if [ "x$GENTEMODULE" = "x1" ]; then
588789
       #    sed '/^#.*$/d;/^\s*$/d;/^\s*class .*/d;/^\s*category .*/d;s/^\s*//' expander.tmp
588789
        sed '/^#.*$/d;/^\s*$/d;/^\s*category .*/d;s/^\s*//' expander.tmp
588789
    else
588789
        grep  '^\s*allow' expander.tmp | sed 's/^\s*//'
588789
    fi
588789
fi
588789
588789
cd - > /dev/null || exit 1
588789
cleanup