mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0048-options-allow-a-UUID-as-identifier-for-key.patch

498672
From 88c4dc1e5b9f9e545c89e8b8ee6878f57df3139c Mon Sep 17 00:00:00 2001
10436e
From: Pino Toscano <ptoscano@redhat.com>
10436e
Date: Fri, 29 Nov 2019 12:07:13 +0100
10436e
Subject: [PATCH] options: allow a UUID as identifier for --key
10436e
10436e
This way it is possible to specify the UUID of the LUKS device instead
10436e
of the libguestfs device name to decrypt a device during the inspection.
10436e
10436e
Make the usage of the new luks_uuid API conditional, so other projects
10436e
using the common submodule do not require a libguestfs version bump.
10436e
10436e
(cherry picked from commit bb4a2dc17a78b53437896d4215ae82df8e11b788
10436e
in libguestfs-common)
10436e
10436e
PT: the documentation was amended manually.
10436e
---
10436e
 cat/virt-cat.pod               | 4 ++--
10436e
 cat/virt-log.pod               | 4 ++--
10436e
 cat/virt-ls.pod                | 4 ++--
10436e
 cat/virt-tail.pod              | 4 ++--
10436e
 common/options/decrypt.c       | 8 +++++++-
10436e
 common/options/keys.c          | 4 ++--
10436e
 common/options/options.h       | 6 +++---
10436e
 customize/virt-customize.pod   | 4 ++--
10436e
 diff/virt-diff.pod             | 4 ++--
10436e
 edit/virt-edit.pod             | 4 ++--
10436e
 fish/guestfish.pod             | 4 ++--
10436e
 fuse/guestmount.pod            | 4 ++--
10436e
 get-kernel/virt-get-kernel.pod | 4 ++--
10436e
 inspector/virt-inspector.pod   | 4 ++--
10436e
 sparsify/virt-sparsify.pod     | 4 ++--
10436e
 sysprep/virt-sysprep.pod       | 4 ++--
10436e
 v2v/virt-v2v.pod               | 4 ++--
10436e
 17 files changed, 40 insertions(+), 34 deletions(-)
10436e
10436e
diff --git a/cat/virt-cat.pod b/cat/virt-cat.pod
10436e
index b0301d636..2cea291ac 100644
10436e
--- a/cat/virt-cat.pod
10436e
+++ b/cat/virt-cat.pod
10436e
@@ -124,8 +124,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/cat/virt-log.pod b/cat/virt-log.pod
10436e
index 0d447b3b5..888108d5f 100644
10436e
--- a/cat/virt-log.pod
10436e
+++ b/cat/virt-log.pod
10436e
@@ -108,8 +108,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/cat/virt-ls.pod b/cat/virt-ls.pod
10436e
index de02a473d..307e79395 100644
10436e
--- a/cat/virt-ls.pod
10436e
+++ b/cat/virt-ls.pod
10436e
@@ -355,8 +355,8 @@ L</RECURSIVE LONG LISTING> above.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/cat/virt-tail.pod b/cat/virt-tail.pod
10436e
index f00384f5d..a804f4cf3 100644
10436e
--- a/cat/virt-tail.pod
10436e
+++ b/cat/virt-tail.pod
10436e
@@ -126,8 +126,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/common/options/decrypt.c b/common/options/decrypt.c
10436e
index 3511d9fe9..683cf5ed4 100644
10436e
--- a/common/options/decrypt.c
10436e
+++ b/common/options/decrypt.c
10436e
@@ -86,7 +86,13 @@ inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
10436e
       char mapname[32];
10436e
       make_mapname (partitions[i], mapname, sizeof mapname);
10436e
 
10436e
-      CLEANUP_FREE_STRING_LIST char **keys = get_keys (ks, partitions[i]);
10436e
+#ifdef GUESTFS_HAVE_LUKS_UUID
10436e
+      CLEANUP_FREE char *uuid = guestfs_luks_uuid (g, partitions[i]);
10436e
+#else
10436e
+      const char *uuid = NULL;
10436e
+#endif
10436e
+
10436e
+      CLEANUP_FREE_STRING_LIST char **keys = get_keys (ks, partitions[i], uuid);
10436e
       assert (guestfs_int_count_strings (keys) > 0);
10436e
 
10436e
       /* Try each key in turn. */
10436e
diff --git a/common/options/keys.c b/common/options/keys.c
10436e
index 7c391acde..798315c2e 100644
10436e
--- a/common/options/keys.c
10436e
+++ b/common/options/keys.c
10436e
@@ -126,7 +126,7 @@ read_first_line_from_file (const char *filename)
10436e
  * keystore, ask the user.
10436e
  */
10436e
 char **
10436e
-get_keys (struct key_store *ks, const char *device)
10436e
+get_keys (struct key_store *ks, const char *device, const char *uuid)
10436e
 {
10436e
   size_t i, j, len;
10436e
   char **r;
10436e
@@ -148,7 +148,7 @@ get_keys (struct key_store *ks, const char *device)
10436e
     for (i = 0; i < ks->nr_keys; ++i) {
10436e
       struct key_store_key *key = &ks->keys[i];
10436e
 
10436e
-      if (STRNEQ (key->id, device))
10436e
+      if (STRNEQ (key->id, device) && (uuid && STRNEQ (key->id, uuid)))
10436e
         continue;
10436e
 
10436e
       switch (key->type) {
10436e
diff --git a/common/options/options.h b/common/options/options.h
10436e
index b83a92b06..9b7830220 100644
10436e
--- a/common/options/options.h
10436e
+++ b/common/options/options.h
10436e
@@ -104,8 +104,8 @@ struct mp {
10436e
 
10436e
 /* A key in the key store. */
10436e
 struct key_store_key {
10436e
-  /* An ID for the device this key refers to.  It must be the libguestfs
10436e
-   * device name.
10436e
+  /* An ID for the device this key refers to.  It can be either the libguestfs
10436e
+   * device name, or the UUID.
10436e
    *
10436e
    * There may be multiple matching devices in the list.
10436e
    */
10436e
@@ -150,7 +150,7 @@ extern void print_inspect_prompt (void);
10436e
 
10436e
 /* in key.c */
10436e
 extern char *read_key (const char *param);
10436e
-extern char **get_keys (struct key_store *ks, const char *device);
10436e
+extern char **get_keys (struct key_store *ks, const char *device, const char *uuid);
10436e
 extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char *selector);
10436e
 extern struct key_store *key_store_import_key (struct key_store *ks, const struct key_store_key *key);
10436e
 extern void free_key_store (struct key_store *ks);
10436e
diff --git a/customize/virt-customize.pod b/customize/virt-customize.pod
10436e
index 491606591..5d92486a2 100644
10436e
--- a/customize/virt-customize.pod
10436e
+++ b/customize/virt-customize.pod
10436e
@@ -141,8 +141,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/diff/virt-diff.pod b/diff/virt-diff.pod
10436e
index 22658072d..e67d09101 100644
10436e
--- a/diff/virt-diff.pod
10436e
+++ b/diff/virt-diff.pod
10436e
@@ -169,8 +169,8 @@ Display file sizes in human-readable format.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/edit/virt-edit.pod b/edit/virt-edit.pod
10436e
index 5a63cd05f..918fa66f2 100644
10436e
--- a/edit/virt-edit.pod
10436e
+++ b/edit/virt-edit.pod
10436e
@@ -156,8 +156,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/fish/guestfish.pod b/fish/guestfish.pod
10436e
index ccb57b159..f1fdf094d 100644
10436e
--- a/fish/guestfish.pod
10436e
+++ b/fish/guestfish.pod
10436e
@@ -283,8 +283,8 @@ were found.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/fuse/guestmount.pod b/fuse/guestmount.pod
10436e
index d9e957b8b..3a02c087c 100644
10436e
--- a/fuse/guestmount.pod
10436e
+++ b/fuse/guestmount.pod
10436e
@@ -249,8 +249,8 @@ mounted on the real virtual machine.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/get-kernel/virt-get-kernel.pod b/get-kernel/virt-get-kernel.pod
10436e
index f0ace2d6d..78fe66df4 100644
10436e
--- a/get-kernel/virt-get-kernel.pod
10436e
+++ b/get-kernel/virt-get-kernel.pod
10436e
@@ -92,8 +92,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/inspector/virt-inspector.pod b/inspector/virt-inspector.pod
10436e
index eac9dc3cd..625da876c 100644
10436e
--- a/inspector/virt-inspector.pod
10436e
+++ b/inspector/virt-inspector.pod
10436e
@@ -117,8 +117,8 @@ ensure the format is always specified.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/sparsify/virt-sparsify.pod b/sparsify/virt-sparsify.pod
10436e
index cf7970a5f..0767d07e6 100644
10436e
--- a/sparsify/virt-sparsify.pod
10436e
+++ b/sparsify/virt-sparsify.pod
10436e
@@ -233,8 +233,8 @@ See L</IN-PLACE SPARSIFICATION> below.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/sysprep/virt-sysprep.pod b/sysprep/virt-sysprep.pod
10436e
index d7ad7ee33..b38c76c70 100644
10436e
--- a/sysprep/virt-sysprep.pod
10436e
+++ b/sysprep/virt-sysprep.pod
10436e
@@ -189,8 +189,8 @@ security problem with malicious guests (CVE-2010-3851).
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
diff --git a/v2v/virt-v2v.pod b/v2v/virt-v2v.pod
10436e
index 8c2867814..25041d0ec 100644
10436e
--- a/v2v/virt-v2v.pod
10436e
+++ b/v2v/virt-v2v.pod
10436e
@@ -337,8 +337,8 @@ through VDDK.
10436e
 =item B<--key> SELECTOR
10436e
 
10436e
 Specify a key for LUKS, to automatically open a LUKS device when using
10436e
-the inspection.  C<ID> must be the libguestfs device name of the LUKS
10436e
-device.
10436e
+the inspection.  C<ID> can be either the libguestfs device name, or
10436e
+the UUID of the LUKS device.
10436e
 
10436e
 =over 4
10436e
 
10436e
-- 
498672
2.18.4
10436e