|
|
2f7d90 |
From 47a2662bccb8e6f2f192acf46c26d862fe3bbcfb Mon Sep 17 00:00:00 2001
|
|
|
2f7d90 |
From: Evgeny Kolesnikov <ekolesni@redhat.com>
|
|
|
2f7d90 |
Date: Fri, 17 Jan 2020 10:24:07 +0100
|
|
|
2f7d90 |
Subject: [PATCH 1/2] Covscan fixes
|
|
|
2f7d90 |
|
|
|
2f7d90 |
Error: FORWARD_NULL (CWE-476): [#def17]
|
|
|
2f7d90 |
xccdf_policy_remediate.c:383: var_compare_op: Comparing "rr" to null implies that "rr" might be null.
|
|
|
2f7d90 |
xccdf_policy_remediate.c:384: var_deref_model: Passing null pointer "rr" to "_rule_add_info_message", which dereferences it.
|
|
|
2f7d90 |
|
|
|
2f7d90 |
Error: FORWARD_NULL (CWE-476): [#def18]
|
|
|
2f7d90 |
test_fsdev_is_local_fs.c:35: assign_zero: Assigning: "ment.mnt_fsname" = "NULL".
|
|
|
2f7d90 |
test_fsdev_is_local_fs.c:37: var_deref_model: Passing "&ment" to "is_local_fs", which dereferences null "ment.mnt_fsname".
|
|
|
2f7d90 |
---
|
|
|
2f7d90 |
src/OVAL/probes/fsdev.c | 4 ++++
|
|
|
2f7d90 |
src/XCCDF_POLICY/xccdf_policy_remediate.c | 12 ++++++++++--
|
|
|
2f7d90 |
2 files changed, 14 insertions(+), 2 deletions(-)
|
|
|
2f7d90 |
|
|
|
2f7d90 |
diff --git a/src/OVAL/probes/fsdev.c b/src/OVAL/probes/fsdev.c
|
|
|
2f7d90 |
index bd8e52fbf..a6b36f5e0 100644
|
|
|
2f7d90 |
--- a/src/OVAL/probes/fsdev.c
|
|
|
2f7d90 |
+++ b/src/OVAL/probes/fsdev.c
|
|
|
2f7d90 |
@@ -97,6 +97,10 @@ static int is_local_fs(struct mntent *ment)
|
|
|
2f7d90 |
return 0;
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
+ if (ment->mnt_fsname == NULL) {
|
|
|
2f7d90 |
+ return 0;
|
|
|
2f7d90 |
+ }
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
s = ment->mnt_fsname;
|
|
|
2f7d90 |
/* If the fsname begins with "//", it is probably CIFS. */
|
|
|
2f7d90 |
if (s[0] == '/' && s[1] == '/')
|
|
|
2f7d90 |
diff --git a/src/XCCDF_POLICY/xccdf_policy_remediate.c b/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
2f7d90 |
index 389a7d1bd..f59737727 100644
|
|
|
2f7d90 |
--- a/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
2f7d90 |
+++ b/src/XCCDF_POLICY/xccdf_policy_remediate.c
|
|
|
2f7d90 |
@@ -380,7 +380,11 @@ static inline int _xccdf_fix_decode_xml(struct xccdf_fix *fix, char **result)
|
|
|
2f7d90 |
#if defined(unix) || defined(__unix__) || defined(__unix)
|
|
|
2f7d90 |
static inline int _xccdf_fix_execute(struct xccdf_rule_result *rr, struct xccdf_fix *fix)
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
- if (fix == NULL || rr == NULL || oscap_streq(xccdf_fix_get_content(fix), NULL)) {
|
|
|
2f7d90 |
+ if (rr == NULL) {
|
|
|
2f7d90 |
+ return 1;
|
|
|
2f7d90 |
+ }
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+ if (fix == NULL || oscap_streq(xccdf_fix_get_content(fix), NULL)) {
|
|
|
2f7d90 |
_rule_add_info_message(rr, "No fix available.");
|
|
|
2f7d90 |
return 1;
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
@@ -481,7 +485,11 @@ static inline int _xccdf_fix_execute(struct xccdf_rule_result *rr, struct xccdf_
|
|
|
2f7d90 |
#else
|
|
|
2f7d90 |
static inline int _xccdf_fix_execute(struct xccdf_rule_result *rr, struct xccdf_fix *fix)
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
- if (fix == NULL || rr == NULL || oscap_streq(xccdf_fix_get_content(fix), NULL)) {
|
|
|
2f7d90 |
+ if (rr == NULL) {
|
|
|
2f7d90 |
+ return 1;
|
|
|
2f7d90 |
+ }
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+ if (fix == NULL || oscap_streq(xccdf_fix_get_content(fix), NULL)) {
|
|
|
2f7d90 |
_rule_add_info_message(rr, "No fix available.");
|
|
|
2f7d90 |
return 1;
|
|
|
2f7d90 |
} else {
|
|
|
2f7d90 |
|
|
|
2f7d90 |
From 7bccc09eabd30e0581cf0fdf4f20fa481db12e91 Mon Sep 17 00:00:00 2001
|
|
|
2f7d90 |
From: Evgeny Kolesnikov <ekolesni@redhat.com>
|
|
|
2f7d90 |
Date: Fri, 17 Jan 2020 11:04:13 +0100
|
|
|
2f7d90 |
Subject: [PATCH 2/2] Covscan fixes (SHELLCHECK), small refactoring in Shell
|
|
|
2f7d90 |
wrappers
|
|
|
2f7d90 |
|
|
|
2f7d90 |
Error: SHELLCHECK_WARNING:
|
|
|
2f7d90 |
warning: die references arguments, but none are ever passed. [SC2120]
|
|
|
2f7d90 |
|
|
|
2f7d90 |
Error: SHELLCHECK_WARNING:
|
|
|
2f7d90 |
warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164]
|
|
|
2f7d90 |
|
|
|
2f7d90 |
Error: SHELLCHECK_WARNING:
|
|
|
2f7d90 |
warning: Declare and assign separately to avoid masking return values. [SC2155]
|
|
|
2f7d90 |
---
|
|
|
2f7d90 |
utils/oscap-chroot | 20 ++++++++++++--------
|
|
|
2f7d90 |
utils/oscap-podman | 42 +++++++++++++++++++++---------------------
|
|
|
2f7d90 |
utils/oscap-ssh | 39 ++++++++++++++++++++++-----------------
|
|
|
2f7d90 |
utils/oscap-vm | 19 +++++++++++--------
|
|
|
2f7d90 |
4 files changed, 66 insertions(+), 54 deletions(-)
|
|
|
2f7d90 |
|
|
|
2f7d90 |
diff --git a/utils/oscap-chroot b/utils/oscap-chroot
|
|
|
2f7d90 |
index 6518d7a2c..318f55a91 100755
|
|
|
2f7d90 |
--- a/utils/oscap-chroot
|
|
|
2f7d90 |
+++ b/utils/oscap-chroot
|
|
|
2f7d90 |
@@ -25,6 +25,13 @@ function die()
|
|
|
2f7d90 |
exit 1
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
+function invalid()
|
|
|
2f7d90 |
+{
|
|
|
2f7d90 |
+ echo -e "$*\n" >&2
|
|
|
2f7d90 |
+ usage
|
|
|
2f7d90 |
+ exit 1
|
|
|
2f7d90 |
+}
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
function usage()
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
echo "oscap-chroot -- Tool for offline SCAP evaluation of filesystems mounted in arbitrary paths."
|
|
|
2f7d90 |
@@ -74,26 +81,23 @@ function usage()
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ $# -lt 1 ]; then
|
|
|
2f7d90 |
- echo "No arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "No arguments provided."
|
|
|
2f7d90 |
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
|
2f7d90 |
usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ exit 0
|
|
|
2f7d90 |
elif [ "$#" -gt 1 ]; then
|
|
|
2f7d90 |
true
|
|
|
2f7d90 |
else
|
|
|
2f7d90 |
- echo "Invalid arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "Invalid arguments provided."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
# Learn more at https://www.redhat.com/archives/open-scap-list/2013-July/msg00000.html
|
|
|
2f7d90 |
export OSCAP_PROBE_ROOT
|
|
|
2f7d90 |
-OSCAP_PROBE_ROOT="$(cd "$1"; pwd)"
|
|
|
2f7d90 |
+OSCAP_PROBE_ROOT="$(cd "$1" && pwd)" || die "Invalid CHROOT_PATH argument."
|
|
|
2f7d90 |
export OSCAP_EVALUATION_TARGET="chroot://$OSCAP_PROBE_ROOT"
|
|
|
2f7d90 |
shift 1
|
|
|
2f7d90 |
|
|
|
2f7d90 |
oscap "$@"
|
|
|
2f7d90 |
EXIT_CODE=$?
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
exit $EXIT_CODE
|
|
|
2f7d90 |
diff --git a/utils/oscap-podman b/utils/oscap-podman
|
|
|
2f7d90 |
index 32ec0cfcb..6b9f4a3de 100755
|
|
|
2f7d90 |
--- a/utils/oscap-podman
|
|
|
2f7d90 |
+++ b/utils/oscap-podman
|
|
|
2f7d90 |
@@ -16,13 +16,19 @@
|
|
|
2f7d90 |
# License along with this library; if not, write to the Free Software
|
|
|
2f7d90 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
2f7d90 |
|
|
|
2f7d90 |
-
|
|
|
2f7d90 |
function die()
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
echo "$*" >&2
|
|
|
2f7d90 |
exit 1
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
+function invalid()
|
|
|
2f7d90 |
+{
|
|
|
2f7d90 |
+ echo -e "$*\n" >&2
|
|
|
2f7d90 |
+ usage
|
|
|
2f7d90 |
+ exit 1
|
|
|
2f7d90 |
+}
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
function usage()
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
echo "oscap-podman -- Tool for SCAP evaluation of Podman images and containers."
|
|
|
2f7d90 |
@@ -39,30 +45,24 @@ function usage()
|
|
|
2f7d90 |
OSCAP_BINARY=oscap
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ $# -lt 1 ]; then
|
|
|
2f7d90 |
- echo "No arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "No arguments provided."
|
|
|
2f7d90 |
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
|
2f7d90 |
usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ exit 0
|
|
|
2f7d90 |
elif [[ "$1" == --oscap=* ]] && [ $# -gt 2 ]; then
|
|
|
2f7d90 |
OSCAP_BINARY=${1#"--oscap="}
|
|
|
2f7d90 |
shift
|
|
|
2f7d90 |
elif [ "$#" -gt 1 ]; then
|
|
|
2f7d90 |
true
|
|
|
2f7d90 |
else
|
|
|
2f7d90 |
- echo "Invalid arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "Invalid arguments provided."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ $(id -u) -ne 0 ]; then
|
|
|
2f7d90 |
- echo "This script cannot run in rootless mode." >&2
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ die "This script cannot run in rootless mode."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
if grep -q "\-\-remediate" <<< "$@"; then
|
|
|
2f7d90 |
- echo "This script does not support '--remediate' option." >&2
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ die "This script does not support '--remediate' option."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
IMAGE_NAME=$(podman image exists "$1" \
|
|
|
2f7d90 |
@@ -72,14 +72,13 @@ CONTAINER_NAME=$(podman container exists "$1" \
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ -n "$IMAGE_NAME" ] && [ -n "$CONTAINER_NAME" ]; then
|
|
|
2f7d90 |
echo "Ambiguous target, container image and container with the same name detected: '$1'." >&2
|
|
|
2f7d90 |
- echo "Please rather use an unique ID to specify the target of the scan." >&2
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ die "Please rather use an unique ID to specify the target of the scan."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
# Check if the target of scan is image or container.
|
|
|
2f7d90 |
CLEANUP=0
|
|
|
2f7d90 |
if [ -n "$IMAGE_NAME" ]; then
|
|
|
2f7d90 |
- ID=$(podman create $1) || die
|
|
|
2f7d90 |
+ ID=$(podman create $1) || die "Unable to create a container."
|
|
|
2f7d90 |
TARGET="podman-image://$IMAGE_NAME"
|
|
|
2f7d90 |
CLEANUP=1
|
|
|
2f7d90 |
elif [ -n "$CONTAINER_NAME" ]; then
|
|
|
2f7d90 |
@@ -87,14 +86,13 @@ elif [ -n "$CONTAINER_NAME" ]; then
|
|
|
2f7d90 |
ID=$1
|
|
|
2f7d90 |
TARGET="podman-container://$CONTAINER_NAME"
|
|
|
2f7d90 |
else
|
|
|
2f7d90 |
- echo "Target of the scan not found: '$1'." >&2
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ die "Target of the scan not found: '$1'."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
# podman init creates required files such as: /run/.containerenv - we don't care about output and exit code
|
|
|
2f7d90 |
podman init $ID &> /dev/null || true
|
|
|
2f7d90 |
|
|
|
2f7d90 |
-DIR=$(podman mount $ID) || die
|
|
|
2f7d90 |
+DIR=$(podman mount $ID) || die "Failed to mount."
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ ! -f "$DIR/run/.containerenv" ]; then
|
|
|
2f7d90 |
# ubi8-init image does not create .containerenv when running podman init, but we need to make sure that the file is there
|
|
|
2f7d90 |
@@ -105,14 +103,16 @@ for VAR in `podman inspect $ID --format '{{join .Config.Env " "}}'`; do
|
|
|
2f7d90 |
eval "export OSCAP_OFFLINE_$VAR"
|
|
|
2f7d90 |
done
|
|
|
2f7d90 |
|
|
|
2f7d90 |
-export OSCAP_PROBE_ROOT="$(cd "$DIR"; pwd)"
|
|
|
2f7d90 |
+export OSCAP_PROBE_ROOT
|
|
|
2f7d90 |
+OSCAP_PROBE_ROOT="$(cd "$DIR" && pwd)" || die "Unable to change current directory to OSCAP_PROBE_ROOT (DIR)."
|
|
|
2f7d90 |
export OSCAP_EVALUATION_TARGET="$TARGET"
|
|
|
2f7d90 |
shift 1
|
|
|
2f7d90 |
|
|
|
2f7d90 |
$OSCAP_BINARY "$@"
|
|
|
2f7d90 |
EXIT_CODE=$?
|
|
|
2f7d90 |
-podman umount $ID > /dev/null || die
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+podman umount $ID > /dev/null || die "Failed to unmount."
|
|
|
2f7d90 |
if [ $CLEANUP -eq 1 ]; then
|
|
|
2f7d90 |
- podman rm $ID > /dev/null || die
|
|
|
2f7d90 |
+ podman rm $ID > /dev/null || die "Failed to clean up."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
exit $EXIT_CODE
|
|
|
2f7d90 |
diff --git a/utils/oscap-ssh b/utils/oscap-ssh
|
|
|
2f7d90 |
index 08c8bcd2b..cd3600180 100755
|
|
|
2f7d90 |
--- a/utils/oscap-ssh
|
|
|
2f7d90 |
+++ b/utils/oscap-ssh
|
|
|
2f7d90 |
@@ -22,9 +22,12 @@ function die()
|
|
|
2f7d90 |
exit 1
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
-hash ssh 2> /dev/null || die "Cannot find ssh, please install the OpenSSH client."
|
|
|
2f7d90 |
-hash scp 2> /dev/null || die "Cannot find scp, please install the OpenSSH client."
|
|
|
2f7d90 |
-hash mktemp 2> /dev/null || die "Cannot find mktemp, please install coreutils."
|
|
|
2f7d90 |
+function invalid()
|
|
|
2f7d90 |
+{
|
|
|
2f7d90 |
+ echo -e "$*\n" >&2
|
|
|
2f7d90 |
+ usage
|
|
|
2f7d90 |
+ exit 1
|
|
|
2f7d90 |
+}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
function usage()
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
@@ -87,10 +90,6 @@ function usage()
|
|
|
2f7d90 |
echo "See \`man oscap\` to learn more about semantics of these options."
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
-OSCAP_SUDO=""
|
|
|
2f7d90 |
-# SSH_ADDITIONAL_OPTIONS may be defined in the calling shell
|
|
|
2f7d90 |
-SSH_TTY_ALLOCATION_OPTION=""
|
|
|
2f7d90 |
-
|
|
|
2f7d90 |
# $1, $2, ... SSH options (pass them as separate arguments)
|
|
|
2f7d90 |
function ssh_execute_with_options {
|
|
|
2f7d90 |
ssh -o ControlPath="$MASTER_SOCKET" $SSH_ADDITIONAL_OPTIONS "$@" -p "$SSH_PORT" "$SSH_HOST"
|
|
|
2f7d90 |
@@ -118,22 +117,20 @@ function scp_retreive_from_temp_dir {
|
|
|
2f7d90 |
# Returns: String, where individual command components are double-quoted, so they are not interpreted by the shell.
|
|
|
2f7d90 |
# For example, an array ('-p' '(all)') will be transformed to "\"-p\" \"(all)\"", so after the shell expansion, it will end up as "-p" "(all)".
|
|
|
2f7d90 |
function command_array_to_string {
|
|
|
2f7d90 |
- eval "printf '\"%s\" ' \"\${$1[@]}\""
|
|
|
2f7d90 |
+ eval "printf '\"%s\" ' \"\${$1[@]}\""
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
function first_argument_is_sudo {
|
|
|
2f7d90 |
- [ "$1" == "sudo" ] || [ "$1" == "--sudo" ]
|
|
|
2f7d90 |
- return $?
|
|
|
2f7d90 |
+ [ "$1" == "sudo" ] || [ "$1" == "--sudo" ]
|
|
|
2f7d90 |
+ return $?
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
function sanity_check_arguments {
|
|
|
2f7d90 |
if [ $# -lt 1 ]; then
|
|
|
2f7d90 |
- echo "No arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "No arguments provided."
|
|
|
2f7d90 |
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
|
2f7d90 |
usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ exit 0
|
|
|
2f7d90 |
elif first_argument_is_sudo "$@"; then
|
|
|
2f7d90 |
OSCAP_SUDO="sudo"
|
|
|
2f7d90 |
# force pseudo-tty allocation so that users can type their password if necessary
|
|
|
2f7d90 |
@@ -141,9 +138,7 @@ function sanity_check_arguments {
|
|
|
2f7d90 |
shift
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
if [ $# -lt 2 ]; then
|
|
|
2f7d90 |
- echo "Missing ssh host and ssh port."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "Missing ssh host and ssh port."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
@@ -165,6 +160,16 @@ function check_oscap_arguments {
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+hash ssh 2> /dev/null || die "Cannot find ssh, please install the OpenSSH client."
|
|
|
2f7d90 |
+hash scp 2> /dev/null || die "Cannot find scp, please install the OpenSSH client."
|
|
|
2f7d90 |
+hash mktemp 2> /dev/null || die "Cannot find mktemp, please install coreutils."
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
+OSCAP_SUDO=""
|
|
|
2f7d90 |
+# SSH_ADDITIONAL_OPTIONS may be defined in the calling shell
|
|
|
2f7d90 |
+SSH_TTY_ALLOCATION_OPTION=""
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
sanity_check_arguments "$@"
|
|
|
2f7d90 |
first_argument_is_sudo "$@" && shift
|
|
|
2f7d90 |
|
|
|
2f7d90 |
diff --git a/utils/oscap-vm b/utils/oscap-vm
|
|
|
2f7d90 |
index 02f8c6396..6557eb3a7 100755
|
|
|
2f7d90 |
--- a/utils/oscap-vm
|
|
|
2f7d90 |
+++ b/utils/oscap-vm
|
|
|
2f7d90 |
@@ -22,6 +22,13 @@ function die()
|
|
|
2f7d90 |
exit 1
|
|
|
2f7d90 |
}
|
|
|
2f7d90 |
|
|
|
2f7d90 |
+function invalid()
|
|
|
2f7d90 |
+{
|
|
|
2f7d90 |
+ echo -e "$*\n" >&2
|
|
|
2f7d90 |
+ usage
|
|
|
2f7d90 |
+ exit 1
|
|
|
2f7d90 |
+}
|
|
|
2f7d90 |
+
|
|
|
2f7d90 |
function usage()
|
|
|
2f7d90 |
{
|
|
|
2f7d90 |
echo "oscap-vm -- Tool for offline SCAP evaluation of virtual machines."
|
|
|
2f7d90 |
@@ -76,12 +83,10 @@ function usage()
|
|
|
2f7d90 |
OSCAP_BINARY=oscap
|
|
|
2f7d90 |
|
|
|
2f7d90 |
if [ $# -lt 1 ]; then
|
|
|
2f7d90 |
- echo "No arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "No arguments provided."
|
|
|
2f7d90 |
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
|
|
2f7d90 |
usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ exit 0
|
|
|
2f7d90 |
elif [[ "$1" == --oscap=* ]] && [ $# -gt 3 ]; then
|
|
|
2f7d90 |
OSCAP_BINARY=${1#"--oscap="}
|
|
|
2f7d90 |
shift
|
|
|
2f7d90 |
@@ -90,9 +95,7 @@ elif [ "$1" == "image" ] && [ $# -gt 2 ]; then
|
|
|
2f7d90 |
elif [ "$1" == "domain" ] && [ $# -gt 2 ]; then
|
|
|
2f7d90 |
true
|
|
|
2f7d90 |
else
|
|
|
2f7d90 |
- echo "Invalid arguments provided."
|
|
|
2f7d90 |
- usage
|
|
|
2f7d90 |
- die
|
|
|
2f7d90 |
+ invalid "Invalid arguments provided."
|
|
|
2f7d90 |
fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
hash guestmount 2> /dev/null || die "Cannot find guestmount, please install libguestfs utilities."
|
|
|
2f7d90 |
@@ -128,7 +131,7 @@ fi
|
|
|
2f7d90 |
|
|
|
2f7d90 |
# Learn more at https://www.redhat.com/archives/open-scap-list/2013-July/msg00000.html
|
|
|
2f7d90 |
export OSCAP_PROBE_ROOT
|
|
|
2f7d90 |
-OSCAP_PROBE_ROOT="$(cd "$MOUNTPOINT"; pwd)"
|
|
|
2f7d90 |
+OSCAP_PROBE_ROOT="$(cd "$MOUNTPOINT" && pwd)" || die "Unable to change current directory to OSCAP_PROBE_ROOT (MOUNTPOINT)."
|
|
|
2f7d90 |
export OSCAP_EVALUATION_TARGET="oscap-vm $1 $2"
|
|
|
2f7d90 |
shift 2
|
|
|
2f7d90 |
|