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