This way it is possible to specify the UUID of the LUKS device instead
of the libguestfs device name to decrypt a device during the inspection.
Make the usage of the new luks_uuid API conditional, so other projects
using the common submodule do not require a libguestfs version bump.
---
options/decrypt.c | 8 +++++++-
options/key-option.pod | 4 ++--
options/keys.c | 4 ++--
options/options.h | 6 +++---
4 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/options/decrypt.c b/options/decrypt.c
index 3511d9f..683cf5e 100644
--- a/options/decrypt.c
+++ b/options/decrypt.c
@@ -86,7 +86,13 @@ inspect_do_decrypt (guestfs_h *g, struct key_store *ks)
char mapname[32];
make_mapname (partitions[i], mapname, sizeof mapname);
- CLEANUP_FREE_STRING_LIST char **keys = get_keys (ks, partitions[i]);
+#ifdef GUESTFS_HAVE_LUKS_UUID
+ CLEANUP_FREE char *uuid = guestfs_luks_uuid (g, partitions[i]);
+#else
+ const char *uuid = NULL;
+#endif
+
+ CLEANUP_FREE_STRING_LIST char **keys = get_keys (ks, partitions[i], uuid);
assert (guestfs_int_count_strings (keys) > 0);
/* Try each key in turn. */
diff --git a/options/key-option.pod b/options/key-option.pod
index 02dcf18..90a3b15 100644
--- a/options/key-option.pod
+++ b/options/key-option.pod
@@ -1,8 +1,8 @@
=item B<--key> SELECTOR
Specify a key for LUKS, to automatically open a LUKS device when using
-the inspection. C<ID> must be the libguestfs device name of the LUKS
-device.
+the inspection. C<ID> can be either the libguestfs device name, or
+the UUID of the LUKS device.
=over 4
diff --git a/options/keys.c b/options/keys.c
index 7c391ac..798315c 100644
--- a/options/keys.c
+++ b/options/keys.c
@@ -126,7 +126,7 @@ read_first_line_from_file (const char *filename)
* keystore, ask the user.
*/
char **
-get_keys (struct key_store *ks, const char *device)
+get_keys (struct key_store *ks, const char *device, const char *uuid)
{
size_t i, j, len;
char **r;
@@ -148,7 +148,7 @@ get_keys (struct key_store *ks, const char *device)
for (i = 0; i < ks->nr_keys; ++i) {
struct key_store_key *key = &ks->keys[i];
- if (STRNEQ (key->id, device))
+ if (STRNEQ (key->id, device) && (uuid && STRNEQ (key->id,
uuid)))
continue;
switch (key->type) {
diff --git a/options/options.h b/options/options.h
index b83a92b..9b78302 100644
--- a/options/options.h
+++ b/options/options.h
@@ -104,8 +104,8 @@ struct mp {
/* A key in the key store. */
struct key_store_key {
- /* An ID for the device this key refers to. It must be the libguestfs
- * device name.
+ /* An ID for the device this key refers to. It can be either the libguestfs
+ * device name, or the UUID.
*
* There may be multiple matching devices in the list.
*/
@@ -150,7 +150,7 @@ extern void print_inspect_prompt (void);
/* in key.c */
extern char *read_key (const char *param);
-extern char **get_keys (struct key_store *ks, const char *device);
+extern char **get_keys (struct key_store *ks, const char *device, const char *uuid);
extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char
*selector);
extern struct key_store *key_store_import_key (struct key_store *ks, const struct
key_store_key *key);
extern void free_key_store (struct key_store *ks);
--
2.21.0