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