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