diff --git a/utils/oscap-ssh b/utils/oscap-ssh index 658cc2ee4..bd2e209c4 100755 --- a/utils/oscap-ssh +++ b/utils/oscap-ssh @@ -280,7 +280,12 @@ echo "Starting the evaluation..." # changing directory because of --oval-results support. oval results files are # dumped into PWD, and we can't be sure by the file names - we need controlled # environment -ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO oscap $(command_array_to_string oscap_args)" "$SSH_TTY_ALLOCATION_OPTION" +if [ -z "$OSCAP_SUDO" ]; then + ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; oscap $(command_array_to_string oscap_args)" "$SSH_TTY_ALLOCATION_OPTION" +else + OSCAP_CMD="oscap $(command_array_to_string oscap_args); rc=\$?; chown \$SUDO_USER $REMOTE_TEMP_DIR/*; exit \$rc" + ssh_execute_with_command_and_options "cd $REMOTE_TEMP_DIR; $OSCAP_SUDO sh -c '$OSCAP_CMD'" "$SSH_TTY_ALLOCATION_OPTION" +fi OSCAP_EXIT_CODE=$? echo "oscap exit code: $OSCAP_EXIT_CODE"