render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From 899a3adeded6a120a9d8f1298af482247f4696fa Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <899a3adeded6a120a9d8f1298af482247f4696fa@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:12:03 +0100
a41c76
Subject: [PATCH] qemuDomainSecretStorageSourcePrepare: Setup secret for http
a41c76
 cookies
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
QEMU's curl driver requires the cookies concatenated and allows themi to
a41c76
be passed in via a secret. Prepare the value for the secret and encrypt
a41c76
it.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 877cd358873982d4d6a36b7e65a8605c663e5765)
a41c76
a41c76
Conflicts:
a41c76
  src/qemu/qemu_domain.c:
a41c76
  Refactor to virBufferTrim not backported.
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
Message-Id: <e61490666a540093eac6c219c07a12c6b7d4c72a.1584391727.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_domain.c | 33 ++++++++++++++++++++++++++++++++-
a41c76
 1 file changed, 32 insertions(+), 1 deletion(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
a41c76
index 9391bc37e0..cc47e7a2f0 100644
a41c76
--- a/src/qemu/qemu_domain.c
a41c76
+++ b/src/qemu/qemu_domain.c
a41c76
@@ -1740,6 +1740,30 @@ qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src)
a41c76
 }
a41c76
 
a41c76
 
a41c76
+static qemuDomainSecretInfoPtr
a41c76
+qemuDomainSecretStorageSourcePrepareCookies(qemuDomainObjPrivatePtr priv,
a41c76
+                                            virStorageSourcePtr src,
a41c76
+                                            const char *aliasprotocol)
a41c76
+{
a41c76
+    g_autofree char *secretalias = qemuAliasForSecret(aliasprotocol, "httpcookie");
a41c76
+    g_autofree char *cookies = NULL;
a41c76
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
a41c76
+    size_t i;
a41c76
+
a41c76
+    for (i = 0; i < src->ncookies; i++) {
a41c76
+        virStorageNetCookieDefPtr cookie = src->cookies[i];
a41c76
+
a41c76
+        virBufferAsprintf(&buf, "%s=%s; ", cookie->name, cookie->value);
a41c76
+    }
a41c76
+
a41c76
+    virBufferTrim(&buf, "; ", -1);
a41c76
+    cookies = virBufferContentAndReset(&buf;;
a41c76
+
a41c76
+    return qemuDomainSecretAESSetup(priv, secretalias, NULL,
a41c76
+                                    (uint8_t *) cookies, strlen(cookies));
a41c76
+}
a41c76
+
a41c76
+
a41c76
 /**
a41c76
  * qemuDomainSecretStorageSourcePrepare:
a41c76
  * @priv: domain private object
a41c76
@@ -1765,7 +1789,7 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
a41c76
     bool hasAuth = qemuDomainStorageSourceHasAuth(src);
a41c76
     bool hasEnc = qemuDomainDiskHasEncryptionSecret(src);
a41c76
 
a41c76
-    if (!hasAuth && !hasEnc)
a41c76
+    if (!hasAuth && !hasEnc && src->ncookies == 0)
a41c76
         return 0;
a41c76
 
a41c76
     if (!(src->privateData = qemuDomainStorageSourcePrivateNew()))
a41c76
@@ -1805,6 +1829,13 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
a41c76
               return -1;
a41c76
     }
a41c76
 
a41c76
+    if (src->ncookies &&
a41c76
+        virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) &&
a41c76
+        !(srcPriv->httpcookie = qemuDomainSecretStorageSourcePrepareCookies(priv,
a41c76
+                                                                            src,
a41c76
+                                                                            aliasprotocol)))
a41c76
+        return -1;
a41c76
+
a41c76
     return 0;
a41c76
 }
a41c76
 
a41c76
-- 
a41c76
2.25.1
a41c76