render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
a41c76
From 055d76ce856aecab3dfe3106429c926df405143b Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <055d76ce856aecab3dfe3106429c926df405143b@dist-git>
a41c76
From: Peter Krempa <pkrempa@redhat.com>
a41c76
Date: Mon, 16 Mar 2020 22:11:53 +0100
a41c76
Subject: [PATCH] qemuDomainSecretAESSetupFromSecret: Use 'qemuAliasForSecret'
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Replace qemuDomainGetSecretAESAlias by the new function so that we can
a41c76
reuse qemuDomainSecretAESSetupFromSecret also for setting up other kinds
a41c76
of objects.
a41c76
a41c76
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
(cherry picked from commit 86fecaedf556dbd4d32efe28638c811be0e595d3)
a41c76
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1804750
a41c76
Message-Id: <88a582c0e5b8a73dd88f6872530c80b404149fb3.1584391727.git.pkrempa@redhat.com>
a41c76
Reviewed-by: Ján Tomko <jtomko@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_domain.c | 30 ++++++++++++++----------------
a41c76
 1 file changed, 14 insertions(+), 16 deletions(-)
a41c76
a41c76
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
a41c76
index 0047a1d316..3599e0c9aa 100644
a41c76
--- a/src/qemu/qemu_domain.c
a41c76
+++ b/src/qemu/qemu_domain.c
a41c76
@@ -1583,34 +1583,32 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
a41c76
  * qemuDomainSecretAESSetupFromSecret:
a41c76
  * @priv: pointer to domain private object
a41c76
  * @srcalias: Alias of the disk/hostdev used to generate the secret alias
a41c76
+ * @secretuse: specific usage for the secret (may be NULL if main object is using it)
a41c76
  * @usageType: The virSecretUsageType
a41c76
  * @username: username to use for authentication (may be NULL)
a41c76
  * @seclookupdef: Pointer to seclookupdef data
a41c76
- * @isLuks: True/False for is for luks (alias generation)
a41c76
  *
a41c76
  * Looks up a secret in the secret driver based on @usageType and @seclookupdef
a41c76
- * and builds qemuDomainSecretInfoPtr from it.
a41c76
+ * and builds qemuDomainSecretInfoPtr from it. @use describes the usage of the
a41c76
+ * secret in case if @srcalias requires more secrets for various usage cases.
a41c76
  */
a41c76
 static qemuDomainSecretInfoPtr
a41c76
 qemuDomainSecretAESSetupFromSecret(qemuDomainObjPrivatePtr priv,
a41c76
                                    const char *srcalias,
a41c76
+                                   const char *secretuse,
a41c76
                                    virSecretUsageType usageType,
a41c76
                                    const char *username,
a41c76
-                                   virSecretLookupTypeDefPtr seclookupdef,
a41c76
-                                   bool isLuks)
a41c76
+                                   virSecretLookupTypeDefPtr seclookupdef)
a41c76
 {
a41c76
     g_autoptr(virConnect) conn = virGetConnectSecret();
a41c76
     qemuDomainSecretInfoPtr secinfo;
a41c76
-    g_autofree char *alias = NULL;
a41c76
+    g_autofree char *alias = qemuAliasForSecret(srcalias, secretuse);
a41c76
     uint8_t *secret = NULL;
a41c76
     size_t secretlen = 0;
a41c76
 
a41c76
     if (!conn)
a41c76
         return NULL;
a41c76
 
a41c76
-    if (!(alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
a41c76
-        return NULL;
a41c76
-
a41c76
     if (virSecretGetSecretString(conn, seclookupdef, usageType,
a41c76
                                  &secret, &secretlen) < 0)
a41c76
         return NULL;
a41c76
@@ -1695,9 +1693,9 @@ qemuDomainSecretInfoTLSNew(qemuDomainObjPrivatePtr priv,
a41c76
     }
a41c76
     seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_UUID;
a41c76
 
a41c76
-    return qemuDomainSecretAESSetupFromSecret(priv, srcAlias,
a41c76
+    return qemuDomainSecretAESSetupFromSecret(priv, srcAlias, NULL,
a41c76
                                               VIR_SECRET_USAGE_TYPE_TLS,
a41c76
-                                              NULL, &seclookupdef, false);
a41c76
+                                              NULL, &seclookupdef);
a41c76
 }
a41c76
 
a41c76
 
a41c76
@@ -1788,10 +1786,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
a41c76
                                                             &src->auth->seclookupdef);
a41c76
         } else {
a41c76
             srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasprotocol,
a41c76
+                                                                  NULL,
a41c76
                                                                   usageType,
a41c76
                                                                   src->auth->username,
a41c76
-                                                                  &src->auth->seclookupdef,
a41c76
-                                                                  false);
a41c76
+                                                                  &src->auth->seclookupdef);
a41c76
         }
a41c76
 
a41c76
         if (!srcPriv->secinfo)
a41c76
@@ -1800,10 +1798,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
a41c76
 
a41c76
     if (hasEnc) {
a41c76
         if (!(srcPriv->encinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasformat,
a41c76
+                                                                    "luks",
a41c76
                                                                     VIR_SECRET_USAGE_TYPE_VOLUME,
a41c76
                                                                     NULL,
a41c76
-                                                                    &src->encryption->secrets[0]->seclookupdef,
a41c76
-                                                                    true)))
a41c76
+                                                                    &src->encryption->secrets[0]->seclookupdef)))
a41c76
               return -1;
a41c76
     }
a41c76
 
a41c76
@@ -1864,10 +1862,10 @@ qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
a41c76
             } else {
a41c76
                 srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv,
a41c76
                                                                       hostdev->info->alias,
a41c76
+                                                                      NULL,
a41c76
                                                                       usageType,
a41c76
                                                                       src->auth->username,
a41c76
-                                                                      &src->auth->seclookupdef,
a41c76
-                                                                      false);
a41c76
+                                                                      &src->auth->seclookupdef);
a41c76
             }
a41c76
 
a41c76
             if (!srcPriv->secinfo)
a41c76
-- 
a41c76
2.25.1
a41c76