policychecker: skip preprocessor iso_dsdl_include.xsl 36/216136/3
authorsanghyeok.oh <sanghyeok.oh@samsung.com>
Mon, 21 Oct 2019 08:15:10 +0000 (17:15 +0900)
committersanghyeok.oh <sanghyeok.oh@samsung.com>
Mon, 21 Oct 2019 09:03:08 +0000 (18:03 +0900)
* change option argument (--system,--session) to (-s,-u)
* add option (-v, -p) for checker developement

* skip preprocessor
policy checker using single schema file(rules.xsl) and it doesn't need XPath syntax check.
This reduce policy checking time. (3min -> 19sec at tm1)

Schematron's readme.txt states this:

1) First, preprocess your Schematron schema with iso_dsdl_include.xsl.
This is a macro processor to assemble the schema from various parts.
If your schema is not in separate parts, you can skip this stage.
This stage also generates error messages for some common XPath syntax problems.

Change-Id: Id8dbf03d3a4a5107440823b9bcb0ce1830cc4380
Signed-off-by: sanghyeok.oh <sanghyeok.oh@samsung.com>
policychecker/check.in

index 3e5b6ecf73bd59fa86e2413af975c2da36d2e21f..393785a5c34f2b9c1e1f145048fdca1f9d072c59 100755 (executable)
@@ -4,14 +4,14 @@ PATH="/usr/bin:/bin:/usr/sbin:/sbin"
 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"
@@ -25,18 +25,58 @@ cleanup() {
 
 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
@@ -87,8 +127,12 @@ function check_policy_file(){
 
        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