From e355d9b35e713d3b5f814d5226bda359c93446d1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C4=9Bj=20T=C3=BD=C4=8D?= <matyc@redhat.com>
Date: Thu, 11 Oct 2018 15:18:49 +0200
Subject: [PATCH] Fixed a bug with sudo as the first argument.
A call to `shift` is necessarry outside of any function, because
one can't use `shift` to shift script's arguments from a function.
---
utils/oscap-ssh | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/utils/oscap-ssh b/utils/oscap-ssh
index ee6eb9c81..6d60a369e 100755
--- a/utils/oscap-ssh
+++ b/utils/oscap-ssh
@@ -115,6 +115,11 @@ function scp_retreive_from_temp_dir {
scp -o ControlPath="$MASTER_SOCKET" -P "$SSH_PORT" $SSH_ADDITIONAL_OPTIONS "$SSH_HOST:$REMOTE_TEMP_DIR/$1" "$2"
}
+function first_argument_is_sudo {
+ [ "$1" == "sudo" ] || [ "$1" == "--sudo" ]
+ return $?
+}
+
function sanity_check_arguments {
if [ $# -lt 1 ]; then
echo "No arguments provided."
@@ -123,7 +128,7 @@ function sanity_check_arguments {
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
usage
die
- elif [ "$1" == "sudo" ] || [ "$1" == "--sudo" ]; then
+ elif first_argument_is_sudo "$@"; then
OSCAP_SUDO="sudo"
# force pseudo-tty allocation so that users can type their password if necessary
SSH_TTY_ALLOCATION_OPTION="-t"
@@ -155,6 +160,7 @@ function check_oscap_arguments {
}
sanity_check_arguments "$@"
+first_argument_is_sudo "$@" && shift
SSH_HOST="$1"
SSH_PORT="$2"