Debian Codegraph @

tests/probes/sysctl/test_sysctl_probe_all.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/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:/sbinscip-shell filesystem . . `/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin`.
10
11 function perform_testscip-shell shell shell-project 0.0.0 perform_test(). {
12 probecheck "sysctl" || return 255
13
14 name=$(basenamescip-shell system . . basename. $0 .sh)
15
16 result=$(mktempscip-shell system . . mktemp. ${name}.res.out.XXXXXX)
17 stderr=$(mktempscip-shell system . . mktemp. ${name}.err.out.XXXXXX)
18 ourNames=$(mktempscip-shell system . . mktemp. ${name}.our.out.XXXXXX)
19 sysctlNames=$(mktempscip-shell system . . mktemp. ${name}.sysctl.out.XXXXXX)
20
21 echoscip-shell system . . echo. "Result file: $result"
22 echoscip-shell system . . echo. "Our names file: $ourNames"
23 echoscip-shell system . . echo. "Sysctl names file: $sysctlNames"
24 echoscip-shell system . . echo. "Errors file: $stderr"
25
26 $OSCAP oval eval --results $result $srcdir/test_sysctl_probe_all.oval.xml > /dev/nullscip-shell filesystem . . `/dev/null`. 2>$stderr
27
28 case $(unamescip-shell system . . uname.) in
29 FreeBSD)
30 sysctlscip-shell system . . sysctl. -aN 2> /dev/nullscip-shell filesystem . . `/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 sysctlscip-shell system . . sysctl. -a --deprecated 2> /dev/nullscip-shell filesystem . . `/dev/null`. | trscip-shell system . . tr. "/scip-shell filesystem . . `/`." "." | cutscip-shell system . . cut. -d "=" -f 1 | trscip-shell system . . tr. -d " " | sortscip-shell system . . sort. -u > "$sysctlNames"
37 ;;
38 esac
39
40 grepscip-shell system . . grep. unix-sys:name "$result" | xsed -E 's;.*>(.*)<.*;\1;g' | sortscip-shell system . . sort. > "$ourNames"
41
42 echoscip-shell system . . echo. "Diff (sysctlNames / ourNames): ------"
43 diffscip-shell system . . diff. "$sysctlNames" "$ourNames"
44 echoscip-shell system . . echo. "-------------------------------------"
45
46 # remove oscap error message related to permissions from stderr
47 sedscip-shell system . . sed. -i -E "/^E: oscap: +Can't read sysctl value from /dscip-shell filesystem . . `/^E: oscap: +Can't read sysctl value from /d`." "$stderr"
48 sedscip-shell system . . 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 sedscip-shell system . . sed. -i -E "/^E: oscap: +An error.*14, Bad address/d" "$stderr"
54 sedscip-shell system . . sed. -i "/^.*hugepages.*$/d" "$stderr"
55
56 echoscip-shell system . . echo. "Errors (without messages related to permissions):"
57 catscip-shell system . . cat. "$stderr"
58
59 [scip-shell system . . `[`. ! -s $stderr ]
60
61 rmscip-shell system . . rm. $stderr $result $ourNames $sysctlNames
62 }
63
64 perform_testscip-shell shell shell-project 0.0.0 perform_test().