Debian Codegraph @

tests/mitre/test_mitre_common.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 # Author:
4 # Peter Vrabec, <[email protected]>
5 # Daniel Kopecek <[email protected]>
6
7
8 MITRE_FILES="/tmp/supportscip-shell filesystem . . `/tmp/support`."
9 EXTVARFILE="${MITRE_FILES}/var/linux-external-variables.xml"
10
11 DISTRO="$(catscip-shell system . . cat. /etc/*-release | headscip-shell system . . head. -n1)"
12 DISTRO_NAME="$(catscip-shell system . . cat. /etc/*-release | awkscip-shell system . . awk. '{print $1}' | headscip-shell system . . head. -n1)"
13 DISTRO_RELEASE="$(catscip-shell system . . cat. /etc/*-release | sedscip-shell system . . sed. -n 's|^[^0-9]*\([0-9]*\).*$|\1|p' | headscip-shell system . . head. -n1)"
14 SELINUX_ENABLED=$(grepscip-shell system . . grep. -iqE "(SELINUX=enforcing|SELINUX=permissive)" \
15 /etc/selinux/config 2>/dev/null; echo $?)
16
17 function test_mitrescip-shell shell shell-project 0.0.0 test_mitre(). {
18
19 require "egrep" || return 255
20 require "awk" || return 255
21
22 if [scip-shell system . . `[`. ! -d "$MITRE_FILES" ]; then
23 tarscip-shell system . . tar. zxf ${srcdir}/support.tgz -C /tmpscip-shell filesystem . . `/tmp`.
24 # workaround file access time issue
25 findscip-shell system . . find. "$MITRE_FILES"
26 # workaround old schema version in linux-external-variables.xml
27 sedscip-shell system . . sed. -i 's/5.0/5.5/' "$EXTVARFILE"
28 fi
29
30 local ret_val=0;
31 local DEFFILE=${srcdir}/$1
32 local RESFILE=$1.results
33
34 [scip-shell system . . `[`. -f $RESFILE ] && rmscip-shell system . . rm. -f $RESFILE
35 $OSCAP oval eval --results "$RESFILE" --variables "$EXTVARFILE" "$DEFFILE"
36 # catch error from oscap tool
37 ret_val=$?
38 if [scip-shell system . . `[`. $ret_val -eq 1 ]; then
39 return 1
40 fi
41
42 if [scip-shell system . . `[`. -n "$3" ]; then
43 # only check the individual results specified in the arg list
44 shift 1
45 while [scip-shell system . . `[`. -n "$1" -a -n "$2" ]; do
46 def_id="$1"
47 def_res="$2"
48 grepscip-shell system . . grep. -q "definition_id=\"$def_id\".*result=\"$def_res\"" "$RESFILE" || return 1
49 shift 2
50 done
51 return 0
52 fi
53
54 # assume all definitions should have the same result
55
56 LINES=`grepscip-shell system . . grep. definition_id "$RESFILE"`
57 # catch error from grep
58 ret_val=$?
59 if [scip-shell system . . `[`. $ret_val -eq 2 ]; then
60 return 1
61 fi
62
63 # calculate return code
64 echoscip-shell system . . echo. "$LINES" | grepscip-shell system . . grep. -q -v "result=\"$2\""
65 ret_val=$?
66 if [scip-shell system . . `[`. $ret_val -eq 1 ]; then
67 return 0;
68 elif [scip-shell system . . `[`. $ret_val -eq 0 ]; then
69 return 1;
70 else
71 return "$ret_val"
72 fi
73 }
74
75 function cleanup_mitrescip-shell shell shell-project 0.0.0 cleanup_mitre(). {
76 rmscip-shell system . . rm. -rf "$MITRE_FILES"
77 }