@@ -92,9 +92,14 @@ OSCAP_SUDO=""
92
92
# SSH_ADDITIONAL_OPTIONS may be defined in the calling shell
93
93
SSH_TTY_ALLOCATION_OPTION=" "
94
94
95
- # $1: The SSH command.
96
- # $2: More of additional options (optional, space-separated string)
95
+ # $1, $2, ... SSH options (pass them as separate arguments)
97
96
function ssh_execute_with_options {
97
+ ssh -o ControlPath=" $MASTER_SOCKET " $SSH_ADDITIONAL_OPTIONS " $@ " -p " $SSH_PORT " " $SSH_HOST "
98
+ }
99
+
100
+ # $1: The SSH command.
101
+ # $2: More of additional options (optional, pass one space-separated string)
102
+ function ssh_execute_with_command_and_options {
98
103
ssh -o ControlPath=" $MASTER_SOCKET " $SSH_ADDITIONAL_OPTIONS $2 -p " $SSH_PORT " " $SSH_HOST " " $1 "
99
104
}
100
105
@@ -145,7 +150,7 @@ function check_oscap_arguments {
145
150
elif [ " $1 $2 " == " oval collect" ]; then
146
151
true
147
152
else
148
- die " This script only supports '-h', '--help', '--v', '--version', 'info', 'xccdf eval', 'oval eval' and 'oval collect'."
153
+ die " This script only supports 'sudo' as first argument, ' -h', '--help', '--v', '--version', 'info', 'xccdf eval', 'oval eval' and 'oval collect'."
149
154
fi
150
155
}
151
156
@@ -162,10 +167,10 @@ MASTER_SOCKET_DIR=$(mktemp -d)
162
167
MASTER_SOCKET=" $MASTER_SOCKET_DIR /ssh_socket"
163
168
164
169
echo " Connecting to '$SSH_HOST ' on port '$SSH_PORT '..."
165
- ssh -M -f -N -o ServerAliveInterval=60 -o ControlPath= " $MASTER_SOCKET " -p " $SSH_PORT " $SSH_ADDITIONAL_OPTIONS " $SSH_HOST " || die " Failed to connect!"
170
+ ssh_execute_with_options -M -f -N -o ServerAliveInterval=60 || die " Failed to connect!"
166
171
echo " Connected!"
167
172
168
- REMOTE_TEMP_DIR=$( ssh_execute_with_options " mktemp -d" ) || die " Failed to create remote temporary directory!"
173
+ REMOTE_TEMP_DIR=$( ssh_execute_with_command_and_options " mktemp -d" ) || die " Failed to create remote temporary directory!"
169
174
170
175
oscap_args=(" $@ " )
171
176
@@ -262,7 +267,7 @@ echo "Starting the evaluation..."
262
267
# changing directory because of --oval-results support. oval results files are
263
268
# dumped into PWD, and we can't be sure by the file names - we need controlled
264
269
# environment
265
- ssh_execute_with_options " cd $REMOTE_TEMP_DIR ; $OSCAP_SUDO oscap ${oscap_args[*]} " " $SSH_TTY_ALLOCATION_OPTION "
270
+ ssh_execute_with_command_and_options " cd $REMOTE_TEMP_DIR ; $OSCAP_SUDO oscap ${oscap_args[*]} " " $SSH_TTY_ALLOCATION_OPTION "
266
271
OSCAP_EXIT_CODE=$?
267
272
echo " oscap exit code: $OSCAP_EXIT_CODE "
268
273
@@ -284,9 +289,9 @@ if [ "$OVAL_RESULTS" == "yes" ]; then
284
289
fi
285
290
286
291
echo " Removing remote temporary directory..."
287
- ssh_execute_with_options " rm -r $REMOTE_TEMP_DIR " || die " Failed to remove remote temporary directory!"
292
+ ssh_execute_with_command_and_options " rm -r $REMOTE_TEMP_DIR " || die " Failed to remove remote temporary directory!"
288
293
echo " Disconnecting ssh and removing master ssh socket directory..."
289
- ssh -o ControlPath= " $MASTER_SOCKET " $SSH_ADDITIONAL_OPTIONS -p " $SSH_PORT " " $SSH_HOST " -O exit || die " Failed to disconnect!"
294
+ ssh_execute_with_options -O exit || die " Failed to disconnect!"
290
295
rm -r " $MASTER_SOCKET_DIR " || die " Failed to remove local master SSH socket directory!"
291
296
292
297
exit $OSCAP_EXIT_CODE
0 commit comments