| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Copyright 2016 Red Hat Inc., Durham, North Carolina. |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or |
| 6 | # modify it under the terms of the GNU Lesser General Public |
| 7 | # License as published by the Free Software Foundation; either |
| 8 | # version 2 of the License, or (at your option) any later version. |
| 9 | # |
| 10 | # This library is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | # Lesser General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU Lesser General Public |
| 16 | # License along with this library; if not, write to the Free Software |
| 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | # |
| 19 | # Authors: |
| 20 | # Martin Preisler <[email protected]> |
| 21 | |
| 22 | function die() |
| 23 | { |
| 24 | echo "$*" >&2 |
| 25 | exit 1 |
| 26 | } |
| 27 | |
| 28 | function invalid() |
| 29 | { |
| 30 | echo -e "$*\n" >&2 |
| 31 | usage |
| 32 | exit 1 |
| 33 | } |
| 34 | |
| 35 | function usage() |
| 36 | { |
| 37 | echo "oscap-chroot -- Tool for offline SCAP evaluation of filesystems mounted in arbitrary paths." |
| 38 | echo |
| 39 | echo "Usage:" |
| 40 | echo |
| 41 | echo "$ oscap-chroot CHROOT_PATH xccdf eval [options] INPUT_CONTENT" |
| 42 | echo |
| 43 | echo "supported oscap xccdf eval options are:" |
| 44 | echo " --profile" |
| 45 | echo " --tailoring-file" |
| 46 | echo " --tailoring-id" |
| 47 | echo " --cpe (external OVAL dependencies are not supported yet!)" |
| 48 | echo " --oval-results" |
| 49 | echo " --check-engine-results" |
| 50 | echo " --results" |
| 51 | echo " --results-arf" |
| 52 | echo " --report" |
| 53 | echo " --skip-validation" |
| 54 | echo " --fetch-remote-resources" |
| 55 | echo " --local-files" |
| 56 | echo " --progress" |
| 57 | echo " --datastream-id" |
| 58 | echo " --xccdf-id" |
| 59 | echo " --benchmark-id" |
| 60 | echo |
| 61 | echo "$ oscap-chroot CHROOT_PATH oval eval [options] INPUT_CONTENT" |
| 62 | echo |
| 63 | echo "supported oscap oval eval options are:" |
| 64 | echo " --id" |
| 65 | echo " --variables" |
| 66 | echo " --directives" |
| 67 | echo " --results" |
| 68 | echo " --report" |
| 69 | echo " --skip-validation" |
| 70 | echo " --datastream-id" |
| 71 | echo " --oval-id" |
| 72 | echo |
| 73 | echo "$ oscap-chroot CHROOT_PATH oval collect [options] INPUT_CONTENT" |
| 74 | echo |
| 75 | echo "supported oscap oval collect options are:" |
| 76 | echo " --id" |
| 77 | echo " --syschar" |
| 78 | echo " --variables" |
| 79 | echo " --skip-validation" |
| 80 | echo |
| 81 | echo "See \`man oscap\` to learn more about semantics of these options." |
| 82 | } |
| 83 | |
| 84 | if [ $# -lt 1 ]; then |
| 85 | invalid "No arguments provided." |
| 86 | elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then |
| 87 | usage |
| 88 | exit 0 |
| 89 | elif [ "$#" -gt 1 ]; then |
| 90 | true |
| 91 | else |
| 92 | invalid "Invalid arguments provided." |
| 93 | fi |
| 94 | |
| 95 | # Learn more at https://www.redhat.com/archives/open-scap-list/2013-July/msg00000.html |
| 96 | export OSCAP_PROBE_ROOT |
| 97 | OSCAP_PROBE_ROOT="$(cd "$1" && pwd)" || die "Invalid CHROOT_PATH argument." |
| 98 | export OSCAP_EVALUATION_TARGET="chroot://$OSCAP_PROBE_ROOT" |
| 99 | shift 1 |
| 100 | |
| 101 | oscap "$@" |
| 102 | EXIT_CODE=$? |
| 103 | |
| 104 | exit $EXIT_CODE |