Blame SOURCES/libvirt-virStorageSourceParseBackingJSONUri-Handle-undocumented-value-off-for-sslverify.patch

fbe740
From a5496b797498dc5393ccbf2775a2947e67a804eb Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <a5496b797498dc5393ccbf2775a2947e67a804eb@dist-git>
fbe740
From: Peter Krempa <pkrempa@redhat.com>
fbe740
Date: Mon, 16 Mar 2020 22:12:08 +0100
fbe740
Subject: [PATCH] virStorageSourceParseBackingJSONUri: Handle undocumented
fbe740
 value 'off' for sslverify
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
libguestfs abuses a quirk of qemu's parser to accept also other variants
fbe740
of the 'sslverify' field which would be valid on the command line but
fbe740
are not documented in the QMP schema.
fbe740
fbe740
If we encounter the 'off' string instead of an boolean handle it rather
fbe740
than erroring out to continue support of pre-blockdev configurations.
fbe740
fbe740
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
(cherry picked from commit 5179cc6b08a06fad92e8674d048fc0327d48f79e)
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
fbe740
Message-Id: <8f277a7bede59b7c8b6de9db9c7726b6cbe02192.1584391727.git.pkrempa@redhat.com>
fbe740
Reviewed-by: Ján Tomko <jtomko@redhat.com>
fbe740
---
fbe740
 src/util/virstoragefile.c | 21 ++++++++++++++-------
fbe740
 tests/virstoragetest.c    | 15 +++++++++++++++
fbe740
 2 files changed, 29 insertions(+), 7 deletions(-)
fbe740
fbe740
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
fbe740
index 931f2db6e9..9eca186e99 100644
fbe740
--- a/src/util/virstoragefile.c
fbe740
+++ b/src/util/virstoragefile.c
fbe740
@@ -3278,16 +3278,23 @@ virStorageSourceParseBackingJSONUri(virStorageSourcePtr src,
fbe740
     if (protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS ||
fbe740
         protocol == VIR_STORAGE_NET_PROTOCOL_FTPS) {
fbe740
         if (virJSONValueObjectHasKey(json, "sslverify")) {
fbe740
+            const char *tmpstr;
fbe740
             bool tmp;
fbe740
 
fbe740
-            if (virJSONValueObjectGetBoolean(json, "sslverify", &tmp) < 0) {
fbe740
-                virReportError(VIR_ERR_INVALID_ARG,
fbe740
-                               _("malformed 'sslverify' field in backing store definition '%s'"),
fbe740
-                               jsonstr);
fbe740
-                return -1;
fbe740
-            }
fbe740
+            /* libguestfs still uses undocumented legacy value of 'off' */
fbe740
+            if ((tmpstr = virJSONValueObjectGetString(json, "sslverify")) &&
fbe740
+                STREQ(tmpstr, "off")) {
fbe740
+                src->sslverify = VIR_TRISTATE_BOOL_NO;
fbe740
+            } else {
fbe740
+                if (virJSONValueObjectGetBoolean(json, "sslverify", &tmp) < 0) {
fbe740
+                    virReportError(VIR_ERR_INVALID_ARG,
fbe740
+                                   _("malformed 'sslverify' field in backing store definition '%s'"),
fbe740
+                                   jsonstr);
fbe740
+                    return -1;
fbe740
+                }
fbe740
 
fbe740
-            src->sslverify = virTristateBoolFromBool(tmp);
fbe740
+                src->sslverify = virTristateBoolFromBool(tmp);
fbe740
+            }
fbe740
         }
fbe740
     }
fbe740
 
fbe740
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
fbe740
index 63b991eb71..ca428f5ca7 100644
fbe740
--- a/tests/virstoragetest.c
fbe740
+++ b/tests/virstoragetest.c
fbe740
@@ -1621,6 +1621,21 @@ mymain(void)
fbe740
                            "  <timeout seconds='2000'/>\n"
fbe740
                            "</source>\n", 0);
fbe740
 
fbe740
+    TEST_BACKING_PARSE_FULL("json:{ \"file.cookie\": \"vmware_soap_session=\\\"0c8db85112873a79b7ef74f294cb70ef7f\\\"\","
fbe740
+                                   "\"file.sslverify\": \"off\","
fbe740
+                                   "\"file.driver\": \"https\","
fbe740
+                                   "\"file.url\": \"https://host/folder/esx6.5-rhel7.7-x86%5f64/esx6.5-rhel7.7-x86%5f64-flat.vmdk?dcPath=data&dsName=esx6.5-matrix\","
fbe740
+                                   "\"file.timeout\": 2000"
fbe740
+                                 "}",
fbe740
+                           "<source protocol='https' name='folder/esx6.5-rhel7.7-x86_64/esx6.5-rhel7.7-x86_64-flat.vmdk'>\n"
fbe740
+                           "  <host name='host' port='443'/>\n"
fbe740
+                           "  <ssl verify='no'/>\n"
fbe740
+                           "  <cookies>\n"
fbe740
+                           "    <cookie name='vmware_soap_session'>"0c8db85112873a79b7ef74f294cb70ef7f"</cookie>\n"
fbe740
+                           "  </cookies>\n"
fbe740
+                           "  <timeout seconds='2000'/>\n"
fbe740
+                           "</source>\n", 0);
fbe740
+
fbe740
 #endif /* WITH_YAJL */
fbe740
 
fbe740
  cleanup:
fbe740
-- 
fbe740
2.25.1
fbe740