Debian Codegraph @

tests/probes/sysctl/test_sysctl_probe_all.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 . $builddir/tests/test_common.sh
4
5 set -e -o pipefail
6
7 # on some systems sysctl might live in sbin, which can cause problems for
8 # non root users
9 PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
10
11 function perform_test {
12 probecheck "sysctl" || return 255
13
14 name=$(basename $0 .sh)
15
16 result=$(mktemp ${name}.res.out.XXXXXX)
17 stderr=$(mktemp ${name}.err.out.XXXXXX)
18 ourNames=$(mktemp ${name}.our.out.XXXXXX)
19 sysctlNames=$(mktemp ${name}.sysctl.out.XXXXXX)
20
21 echo "Result file: $result"
22 echo "Our names file: $ourNames"
23 echo "Sysctl names file: $sysctlNames"
24 echo "Errors file: $stderr"
25
26 $OSCAP oval eval --results $result $srcdir/test_sysctl_probe_all.oval.xml > /dev/null 2>$stderr
27
28 case $(uname) in
29 FreeBSD)
30 sysctl -aN 2> /dev/null > "$sysctlNames"
31 ;;
32 Linux)
33 # sysctl has duplicities in output
34 # hide permission errors like: "sysctl: permission denied on key 'fs.protected_hardlinks'"
35 # kernel parameters might use "/" and "." separators interchangeably - normalizing
36 sysctl -a --deprecated 2> /dev/null | tr "/" "." | cut -d "=" -f 1 | tr -d " " | sort -u > "$sysctlNames"
37 ;;
38 esac
39
40 grep unix-sys:name "$result" | xsed -E 's;.*>(.*)<.*;\1;g' | sort > "$ourNames"
41
42 echo "Diff (sysctlNames / ourNames): ------"
43 diff "$sysctlNames" "$ourNames"
44 echo "-------------------------------------"
45
46 # remove oscap error message related to permissions from stderr
47 sed -i -E "/^E: oscap: +Can't read sysctl value from /d" "$stderr"
48 sed -i -E "/^E: oscap: +An error.*, Operation not permitted/d" "$stderr"
49
50 # remove oscap error message related to gibberish binary entries
51 # that can't fit into 8K buffer and result in errno 14
52 # (for example /proc/sys/kernel/spl/hostid could be the case)
53 sed -i -E "/^E: oscap: +An error.*14, Bad address/d" "$stderr"
54 sed -i "/^.*hugepages.*$/d" "$stderr"
55
56 echo "Errors (without messages related to permissions):"
57 cat "$stderr"
58
59 [ ! -s $stderr ]
60
61 rm $stderr $result $ourNames $sysctlNames
62 }
63
64 perform_test