render / rpms / libvirt

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