[Pkg-gnupg-commit] [gnupg2] 69/159: g10: fix regression of bkuptocard subcommand in --edit-key.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Jan 27 13:23:55 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg2.

commit 40959add1ba0efc1f4aa87fa075fa42423eff73c
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Thu Dec 24 09:54:23 2015 +0900

    g10: fix regression of bkuptocard subcommand in --edit-key.
    
    * g10/keyedit.c (keyedit_menu): Call transfer_secret_keys.
    * g10/import.c (transfer_secret_keys): Make it global function.
    Allow stats==NULL.
    
    --
    
    GnuPG-bug-id: 2169
---
 g10/import.c  | 15 ++++++++++-----
 g10/keyedit.c | 25 ++++++++++++++++---------
 g10/main.h    |  2 ++
 3 files changed, 28 insertions(+), 14 deletions(-)

diff --git a/g10/import.c b/g10/import.c
index 02d6b76..27bfece 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -1318,7 +1318,7 @@ import_one (ctrl_t ctrl,
    function prints diagnostics and returns an error code.  If BATCH is
    true the secret keys are stored by gpg-agent in the transfer format
    (i.e. no re-protection and aksing for passphrases). */
-static gpg_error_t
+gpg_error_t
 transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats, kbnode_t sec_keyblock,
                       int batch)
 {
@@ -1389,8 +1389,11 @@ transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats, kbnode_t sec_ke
       if (!ski)
         BUG ();
 
-      stats->count++;
-      stats->secret_read++;
+      if (stats)
+        {
+          stats->count++;
+          stats->secret_read++;
+        }
 
       /* We ignore stub keys.  The way we handle them in other parts
          of the code is by asking the agent whether any secret key is
@@ -1561,7 +1564,8 @@ transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats, kbnode_t sec_ke
           if (opt.verbose)
             log_info (_("key %s: secret key imported\n"),
                       keystr_from_pk_with_sub (main_pk, pk));
-          stats->secret_imported++;
+          if (stats)
+            stats->secret_imported++;
         }
       else if ( gpg_err_code (err) == GPG_ERR_EEXIST )
         {
@@ -1569,7 +1573,8 @@ transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats, kbnode_t sec_ke
             log_info (_("key %s: secret key already exists\n"),
                       keystr_from_pk_with_sub (main_pk, pk));
           err = 0;
-          stats->secret_dups++;
+          if (stats)
+            stats->secret_dups++;
         }
       else
         {
diff --git a/g10/keyedit.c b/g10/keyedit.c
index d958db8..15500ef 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -1922,7 +1922,6 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
 
 	case cmdBKUPTOCARD:
 	case cmdCHECKBKUPKEY:
-          log_debug ("FIXME: This needs to be changed\n");
 	  {
 	    /* Ask for a filename, check whether this is really a
 	       backup key as generated by the card generation, parse
@@ -1975,6 +1974,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
 
 	    if (cmd == cmdCHECKBKUPKEY)
 	      {
+		log_debug ("FIXME: This needs to be changed\n");
 		/* PKT_public_key *sk = node->pkt->pkt.secret_key; */
 		/* switch (is_secret_key_protected (sk)) */
 		/*   { */
@@ -1996,14 +1996,21 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
 		  /* } */
 	      }
 	    else		/* Store it.  */
-	      {
-		if (card_store_subkey (node, 0))
-		  {
-		    redisplay = 1;
-		    sec_shadowing = 1;
-		  }
-	      }
-	    release_kbnode (node);
+              {
+                /* We need to transfer it to gpg-agent.  */
+                err = transfer_secret_keys (ctrl, NULL, node, 1);
+
+                /* Then, treat the pkt as a public key to call
+                   card_store_subkey.  */
+                pkt->pkttype = PKT_PUBLIC_KEY;
+
+                if (card_store_subkey (node, 0))
+                  {
+                    redisplay = 1;
+                    sec_shadowing = 1;
+                  }
+              }
+            release_kbnode (node);
 	  }
 	  break;
 
diff --git a/g10/main.h b/g10/main.h
index c3a2114..06f2577 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -337,6 +337,8 @@ gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
 import_stats_t import_new_stats_handle (void);
 void import_release_stats_handle (import_stats_t hd);
 void import_print_stats (import_stats_t hd);
+gpg_error_t transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats,
+                                  kbnode_t sec_keyblock, int batch);
 
 int collapse_uids( KBNODE *keyblock );
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list