[Libguestfs] [PATCH common v2 3/3] options: Allow default --key parameters.

Richard W.M. Jones rjones at redhat.com
Tue Nov 26 16:40:48 UTC 2019


You can specify default keys which are tried against each device
(after more specific keys fail), eg:

  tool --key :key:defaultkey1 --key :key:defaultkey2

which would try "defaultkey1" and "defaultkey2" against all devices
in the guest.
---
 options/keys.c    | 3 ++-
 options/options.h | 5 ++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/options/keys.c b/options/keys.c
index 782bdb6..817508b 100644
--- a/options/keys.c
+++ b/options/keys.c
@@ -148,7 +148,8 @@ 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->device, device))
+      if (STRNEQ (key->device, "") &&
+          STRNEQ (key->device, device))
         continue;
 
       switch (key->type) {
diff --git a/options/options.h b/options/options.h
index 510e8a8..2f6bc5c 100644
--- a/options/options.h
+++ b/options/options.h
@@ -105,7 +105,10 @@ struct mp {
 /* A key in the key store. */
 struct key_store_key {
   /* The device this key refers to.  There may be multiple matching
-   * devices in the list.
+   * devices in the list.  It is never NULL but it may also be ""
+   * which is interpreted as a default key which is tried after any
+   * device-specific keys (there may be multiple defaults in the
+   * list).
    */
   char *device;
 
-- 
2.23.0




More information about the Libguestfs mailing list