Blob Blame History Raw
From 055d76ce856aecab3dfe3106429c926df405143b Mon Sep 17 00:00:00 2001
Message-Id: <055d76ce856aecab3dfe3106429c926df405143b@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Mon, 16 Mar 2020 22:11:53 +0100
Subject: [PATCH] qemuDomainSecretAESSetupFromSecret: Use 'qemuAliasForSecret'
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Replace qemuDomainGetSecretAESAlias by the new function so that we can
reuse qemuDomainSecretAESSetupFromSecret also for setting up other kinds
of objects.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
(cherry picked from commit 86fecaedf556dbd4d32efe28638c811be0e595d3)

https://bugzilla.redhat.com/show_bug.cgi?id=1804750
Message-Id: <88a582c0e5b8a73dd88f6872530c80b404149fb3.1584391727.git.pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/qemu/qemu_domain.c | 30 ++++++++++++++----------------
 1 file changed, 14 insertions(+), 16 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0047a1d316..3599e0c9aa 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1583,34 +1583,32 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
  * qemuDomainSecretAESSetupFromSecret:
  * @priv: pointer to domain private object
  * @srcalias: Alias of the disk/hostdev used to generate the secret alias
+ * @secretuse: specific usage for the secret (may be NULL if main object is using it)
  * @usageType: The virSecretUsageType
  * @username: username to use for authentication (may be NULL)
  * @seclookupdef: Pointer to seclookupdef data
- * @isLuks: True/False for is for luks (alias generation)
  *
  * Looks up a secret in the secret driver based on @usageType and @seclookupdef
- * and builds qemuDomainSecretInfoPtr from it.
+ * and builds qemuDomainSecretInfoPtr from it. @use describes the usage of the
+ * secret in case if @srcalias requires more secrets for various usage cases.
  */
 static qemuDomainSecretInfoPtr
 qemuDomainSecretAESSetupFromSecret(qemuDomainObjPrivatePtr priv,
                                    const char *srcalias,
+                                   const char *secretuse,
                                    virSecretUsageType usageType,
                                    const char *username,
-                                   virSecretLookupTypeDefPtr seclookupdef,
-                                   bool isLuks)
+                                   virSecretLookupTypeDefPtr seclookupdef)
 {
     g_autoptr(virConnect) conn = virGetConnectSecret();
     qemuDomainSecretInfoPtr secinfo;
-    g_autofree char *alias = NULL;
+    g_autofree char *alias = qemuAliasForSecret(srcalias, secretuse);
     uint8_t *secret = NULL;
     size_t secretlen = 0;
 
     if (!conn)
         return NULL;
 
-    if (!(alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
-        return NULL;
-
     if (virSecretGetSecretString(conn, seclookupdef, usageType,
                                  &secret, &secretlen) < 0)
         return NULL;
@@ -1695,9 +1693,9 @@ qemuDomainSecretInfoTLSNew(qemuDomainObjPrivatePtr priv,
     }
     seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_UUID;
 
-    return qemuDomainSecretAESSetupFromSecret(priv, srcAlias,
+    return qemuDomainSecretAESSetupFromSecret(priv, srcAlias, NULL,
                                               VIR_SECRET_USAGE_TYPE_TLS,
-                                              NULL, &seclookupdef, false);
+                                              NULL, &seclookupdef);
 }
 
 
@@ -1788,10 +1786,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
                                                             &src->auth->seclookupdef);
         } else {
             srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasprotocol,
+                                                                  NULL,
                                                                   usageType,
                                                                   src->auth->username,
-                                                                  &src->auth->seclookupdef,
-                                                                  false);
+                                                                  &src->auth->seclookupdef);
         }
 
         if (!srcPriv->secinfo)
@@ -1800,10 +1798,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
 
     if (hasEnc) {
         if (!(srcPriv->encinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasformat,
+                                                                    "luks",
                                                                     VIR_SECRET_USAGE_TYPE_VOLUME,
                                                                     NULL,
-                                                                    &src->encryption->secrets[0]->seclookupdef,
-                                                                    true)))
+                                                                    &src->encryption->secrets[0]->seclookupdef)))
               return -1;
     }
 
@@ -1864,10 +1862,10 @@ qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
             } else {
                 srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv,
                                                                       hostdev->info->alias,
+                                                                      NULL,
                                                                       usageType,
                                                                       src->auth->username,
-                                                                      &src->auth->seclookupdef,
-                                                                      false);
+                                                                      &src->auth->seclookupdef);
             }
 
             if (!srcPriv->secinfo)
-- 
2.25.1