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

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