set -e
xslt_processor="xsltproc --nonet --novalid --maxdepth 25000"
-#xslt_processor="xsltproc --nonet --novalid --maxdepth 25000 --profile"
tmpdir=`mktemp -d`
checker_dir="@datadir@/dbus-tools/policychecker"
schematron_dir="@datadir@/dbus-tools/policychecker/xslt"
conf_path=("/usr/share/dbus-1" "/etc/dbus-1")
sub_conf_path=("system.d" "session.d")
bus_type=-1
-config_file=$1
+config_file=-1
+checker_include_all=0
schema_file="$checker_dir/rules.xsl"
system_privileges_file="$tmpdir/privileges_system"
trap cleanup 0
-if [ "$#" -ne 1 ]; then
- echo "Usage: $0 config-file"
- exit 1
-fi
+usage() {
+ echo "Usage: $0 [-v] [-p] [-s|-u|filename]"
+ echo ""
+ echo -e "\tfilename dbus policy configuration file"
+ echo -e "\t-s system bus"
+ echo -e "\t-u session bus"
+ echo -e "\t-v include every iso xsls"
+ echo -e "\t-p enable profile mode"
+}
-if [ $config_file == "--system" ]; then
- bus_type=0
-elif [ $config_file == "--session" ]; then
- bus_type=1
-elif [ ! -f $config_file ]; then
- echo "config file does not exist"
- exit 1
+# use "checker opt + config-file"
+# getopts doesn't support - "checker config-file + opt"
+while getopts :suvp opt
+do case "$opt" in
+ s) if [ $bus_type -eq -1 ]; then
+ bus_type=0
+ echo "check system bus"
+ fi
+ ;;
+ u) if [ $bus_type -eq -1 ]; then
+ bus_type=1
+ echo "check session bus"
+ fi
+ ;;
+ v) checker_include_all=1
+ echo "use iso_dsdl_include.xsl"
+ ;;
+ p) echo "enable profile mode"
+ xslt_processor="$xslt_processor --profile"
+ ;;
+ ?) echo "Unknown arg:$OPTARG"
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+shift $(( OPTIND - 1 ))
+
+if [ $bus_type -eq -1 ]; then
+ if [ "$#" -ne 1 ]; then
+ echo "unknown opts: $@"
+ usage
+ exit 1
+ fi
+
+ config_file=$1
+ if [ ! -f $config_file ]; then
+ echo "config file '$config_file' does not exist"
+ usage
+ exit 1
+ fi
fi
if [ ! -d $cynara_db ]; then
cat $schema_file | sed -e "s/USERS_TEST/$users_test/g" -e "s/GROUPS_TEST/$groups_test/g" > $tmpname.0
- $xslt_processor $schematron_dir/iso_dsdl_include.xsl $tmpname.0 > $tmpname.1
- $xslt_processor $schematron_dir/iso_abstract_expand.xsl $tmpname.1 > $tmpname.2
+ if [ $checker_include_all -eq 1 ]; then
+ $xslt_processor $schematron_dir/iso_dsdl_include.xsl $tmpname.0 > $tmpname.1
+ $xslt_processor $schematron_dir/iso_abstract_expand.xsl $tmpname.1 > $tmpname.2
+ else
+ $xslt_processor $schematron_dir/iso_abstract_expand.xsl $tmpname.0 > $tmpname.2
+ fi
$xslt_processor $schematron_dir/iso_svrl_for_xslt1.xsl $tmpname.2 > $tmpname.3
$xslt_processor $tmpname.3 $config_file > $tmpname.4
$xslt_processor $checker_dir/report.xsl $tmpname.4