|
|
d7b4b6 |
From 62082b7c8bdb82ebc956d0bd519695d150f515ba Mon Sep 17 00:00:00 2001
|
|
|
d7b4b6 |
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
|
|
|
d7b4b6 |
Date: Fri, 21 Jun 2019 14:31:07 +0200
|
|
|
d7b4b6 |
Subject: [PATCH] Made oscap-ssh to work with shell-sensitive args.
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
Fixes e.g. the problem of oscap arguments -p (all).
|
|
|
d7b4b6 |
Now, (all) is escaped, so it not intercepted by the shell.
|
|
|
d7b4b6 |
---
|
|
|
d7b4b6 |
utils/oscap-ssh | 9 ++++++++-
|
|
|
d7b4b6 |
1 file changed, 8 insertions(+), 1 deletion(-)
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
diff --git a/utils/oscap-ssh b/utils/oscap-ssh
|
|
|
d7b4b6 |
index 6d60a369e..658cc2ee4 100755
|
|
|
d7b4b6 |
--- a/utils/oscap-ssh
|
|
|
d7b4b6 |
+++ b/utils/oscap-ssh
|
|
|
d7b4b6 |
@@ -115,6 +115,13 @@ function scp_retreive_from_temp_dir {
|
|
|
d7b4b6 |
scp -o ControlPath="$MASTER_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$SSH_HOST:$REMOTE_TEMP_DIR/$1" "$2"
|
|
|
d7b4b6 |
}
|
|
|
d7b4b6 |
|
|
|
d7b4b6 |
+# $1: The name of the array holding command elements
|
|
|
d7b4b6 |
+# Returns: String, where individual command components are double-quoted, so they are not interpreted by the shell.
|
|
|
d7b4b6 |
+# For example, an array ('-p' '(all)') will be transformed to "\"-p\" \"(all)\"", so after the shell expansion, it will end up as "-p" "(all)".
|
|
|
d7b4b6 |
+function command_array_to_string {
|
|
|
d7b4b6 |
+ eval "printf '\"%s\" ' \"\${$1[@]}\""
|
|
|
d7b4b6 |
+}
|
|
|
d7b4b6 |
+
|
|
|
d7b4b6 |
function first_argument_is_sudo {
|
|
|
d7b4b6 |
[ "$1" == "sudo" ] || [ "$1" == "--sudo" ]
|
|
|
d7b4b6 |
return $?
|
|
|
d7b4b6 |
@@ -273,7 +280,7 @@ echo "Starting the evaluation..."
|
|
|
d7b4b6 |
# changing directory because of --oval-results support. oval results files are
|
|
|
d7b4b6 |
# dumped into PWD, and we can't be sure by the file names - we need controlled
|
|
|
d7b4b6 |
# environment
|
|
|
d7b4b6 |
-ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO oscap ${oscap_args[*]}" "$SSH_TTY_ALLOCATION_OPTION"
|
|
|
d7b4b6 |
+ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO oscap $(command_array_to_string oscap_args)" "$SSH_TTY_ALLOCATION_OPTION"
|
|
|
d7b4b6 |
OSCAP_EXIT_CODE=$?
|
|
|
d7b4b6 |
echo "oscap exit code: $OSCAP_EXIT_CODE"
|
|
|
d7b4b6 |
|