gpg: Do not delete any keys if --dry-run is passed.
authorWerner Koch <wk@gnupg.org>
Mon, 20 May 2019 10:31:55 +0000 (12:31 +0200)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 1 Jul 2022 16:06:43 +0000 (17:06 +0100)
* g10/delkey.c (do_delete_key): Don't delete the keyblock on dry runs.
Do not clear the ownertrust.  Do not let the agent delete the key.
--

Co-authored-by: Matheus Afonso Martins Moreira
Signed-off-by: Werner Koch <wk@gnupg.org>
(cherry picked from commit 5c46c5f74540ad753b925b74593332ca92de47fa)

Gbp-Pq: Topic from-2.2.16
Gbp-Pq: Name gpg-Do-not-delete-any-keys-if-dry-run-is-passed.patch

g10/delkey.c

index bf8c4e93b1f1ab66f74d1dbf8d4b514366f06f36..461a2c886cc82a10fb1c17d4faff442409370f85 100644 (file)
@@ -190,7 +190,7 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force,
                * pre-caution is that since 2.1 the secret key may also
                * be used for other protocols and thus deleting it from
                * the gpg would also delete the key for other tools. */
-              if (!err)
+              if (!err && !opt.dry_run)
                 err = agent_delete_key (NULL, hexgrip, prompt,
                                         opt.answer_yes);
               xfree (prompt);
@@ -221,7 +221,7 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force,
        }
       else
        {
-         err = keydb_delete_keyblock (hd);
+         err = opt.dry_run? 0 : keydb_delete_keyblock (hd);
          if (err)
             {
               log_error (_("deleting keyblock failed: %s\n"),
@@ -234,7 +234,7 @@ do_delete_key (ctrl_t ctrl, const char *username, int secret, int force,
         revalidation_mark().  This makes sense - only deleting keys
         that have ownertrust set should trigger this. */
 
-      if (!secret && pk && clear_ownertrusts (ctrl, pk))
+      if (!secret && pk && !opt.dry_run && clear_ownertrusts (ctrl, pk))
         {
           if (opt.verbose)
             log_info (_("ownertrust information cleared\n"));