[git] GnuPG - branch, master, updated. gnupg-2.1.2-85-gc238340

by Werner Koch cvs at cvs.gnupg.org
Mon Apr 6 21:22:15 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  c2383407bba5eefea486464a31e02846124c9da5 (commit)
       via  67a58118ab6171c0cf28b65a39973062690d1313 (commit)
       via  f577d5c1a747d673fa1d5c012ce3e3b78b699c6a (commit)
      from  c581ed717ad2cc4be90c46253baa44a0d3ba5b80 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c2383407bba5eefea486464a31e02846124c9da5
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 6 20:23:05 2015 +0200

    gpg: Print the user id in --fast-list-mode.
    
    * g10/keylist.c (list_keyblock_print, list_keyblock_colon): Change.

diff --git a/g10/keylist.c b/g10/keylist.c
index ac46691..d62bc20 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -998,7 +998,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr,
 
   for (kbctx = NULL; (node = walk_kbnode (keyblock, &kbctx, 0));)
     {
-      if (node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode)
+      if (node->pkt->pkttype == PKT_USER_ID)
 	{
 	  PKT_user_id *uid = node->pkt->pkt.user_id;
 
@@ -1370,7 +1370,7 @@ list_keyblock_colon (KBNODE keyblock, int secret, int has_secret, int fpr)
 
   for (kbctx = NULL; (node = walk_kbnode (keyblock, &kbctx, 0));)
     {
-      if (node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode)
+      if (node->pkt->pkttype == PKT_USER_ID)
 	{
 	  char *str;
 	  PKT_user_id *uid = node->pkt->pkt.user_id;

commit 67a58118ab6171c0cf28b65a39973062690d1313
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 6 19:46:25 2015 +0200

    gpg: Prepare to pass additional context to the list functions.
    
    * g10/keylist.c (struct sig_stats): Rename to keylist_context and add
    field check_sigs.
    (keylist_context_release): New.
    (list_all): Set listctx.check_sigs and call release func.
    (list_one): Ditto.
    (locate_one): Ditto.
    (list_keyblock_print): Use .check_sigs field.  Repalce arg opaque by
    listctx.
    (list_keyblock): Ditto.  Make static.
    (list_keyblock_direct): New.
    * g10/keygen.c (do_generate_keypair): Replace list_keyblock by
    list_keyblock_direct.
    --
    
    This is in preparation for the server mode and for a patch to speed up
    --list-sigs.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/keygen.c b/g10/keygen.c
index 4b0398a..ccd01f9 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -4152,7 +4152,7 @@ do_generate_keypair (struct para_data_s *para,
             {
               tty_printf (_("public and secret key created and signed.\n") );
               tty_printf ("\n");
-              list_keyblock (pub_root, 0, 1, 1, NULL);
+              list_keyblock_direct (pub_root, 0, 1, 1);
             }
 
 
diff --git a/g10/keylist.c b/g10/keylist.c
index 925109a..ac46691 100644
--- a/g10/keylist.c
+++ b/g10/keylist.c
@@ -50,17 +50,31 @@ static void list_one (strlist_t names, int secret, int mark_secret);
 static void locate_one (ctrl_t ctrl, strlist_t names);
 static void print_card_serialno (const char *serialno);
 
-struct sig_stats
+struct keylist_context
 {
-  int inv_sigs;
-  int no_key;
-  int oth_err;
+  int check_sigs;  /* If set signatures shall be verified.  */
+  int inv_sigs;    /* Counter used if CHECK_SIGS is set.  */
+  int no_key;      /* Counter used if CHECK_SIGS is set.  */
+  int oth_err;     /* Counter used if CHECK_SIGS is set.  */
 };
 
+
+static void list_keyblock (kbnode_t keyblock, int secret, int has_secret,
+                           int fpr, struct keylist_context *listctx);
+
+
 /* The stream used to write attribute packets to.  */
 static estream_t attrib_fp;
 
 
+/* Release resources from a keylist context.  */
+static void
+keylist_context_release (struct keylist_context *listctx)
+{
+  (void)listctx; /* Nothing to release.  */
+}
+
+
 /* List the keys.  If list is NULL, all available keys are listed.
    With LOCATE_MODE set the locate algorithm is used to find a
    key.  */
@@ -416,9 +430,13 @@ show_notation (PKT_signature * sig, int indent, int mode, int which)
   free_notation (notations);
 }
 
+
 static void
-print_signature_stats (struct sig_stats *s)
+print_signature_stats (struct keylist_context *s)
 {
+  if (!s->check_sigs)
+    return;  /* Signature checking was not requested.  */
+
   if (s->inv_sigs == 1)
     tty_printf (_("1 bad signature\n"));
   else if (s->inv_sigs)
@@ -446,9 +464,11 @@ list_all (int secret, int mark_secret)
   int rc = 0;
   int any_secret;
   const char *lastresname, *resname;
-  struct sig_stats stats;
+  struct keylist_context listctx;
 
-  memset (&stats, 0, sizeof (stats));
+  memset (&listctx, 0, sizeof (listctx));
+  if (opt.check_sigs)
+    listctx.check_sigs = 1;
 
   hd = keydb_new ();
   if (!hd)
@@ -499,7 +519,7 @@ list_all (int secret, int mark_secret)
             }
           merge_keys_and_selfsig (keyblock);
           list_keyblock (keyblock, secret, any_secret, opt.fingerprint,
-                         opt.check_sigs ? &stats : NULL);
+                         &listctx);
         }
       release_kbnode (keyblock);
       keyblock = NULL;
@@ -513,9 +533,10 @@ list_all (int secret, int mark_secret)
               keydb_get_skipped_counter (hd));
 
   if (opt.check_sigs && !opt.with_colons)
-    print_signature_stats (&stats);
+    print_signature_stats (&listctx);
 
-leave:
+ leave:
+  keylist_context_release (&listctx);
   release_kbnode (keyblock);
   keydb_release (hd);
 }
@@ -530,9 +551,11 @@ list_one (strlist_t names, int secret, int mark_secret)
   const char *resname;
   const char *keyring_str = _("Keyring");
   int i;
-  struct sig_stats stats;
+  struct keylist_context listctx;
 
-  memset (&stats, 0, sizeof (stats));
+  memset (&listctx, 0, sizeof (listctx));
+  if (!secret && opt.check_sigs)
+    listctx.check_sigs = 1;
 
   /* fixme: using the bynames function has the disadvantage that we
    * don't know wether one of the names given was not found.  OTOH,
@@ -561,15 +584,16 @@ list_one (strlist_t names, int secret, int mark_secret)
             es_putc ('-', es_stdout);
           es_putc ('\n', es_stdout);
         }
-      list_keyblock (keyblock, secret, mark_secret, opt.fingerprint,
-                     (!secret && opt.check_sigs)? &stats : NULL);
+      list_keyblock (keyblock, secret, mark_secret, opt.fingerprint, &listctx);
       release_kbnode (keyblock);
     }
   while (!getkey_next (ctx, NULL, &keyblock));
   getkey_end (ctx);
 
   if (opt.check_sigs && !opt.with_colons)
-    print_signature_stats (&stats);
+    print_signature_stats (&listctx);
+
+  keylist_context_release (&listctx);
 }
 
 
@@ -580,9 +604,11 @@ locate_one (ctrl_t ctrl, strlist_t names)
   strlist_t sl;
   GETKEY_CTX ctx = NULL;
   KBNODE keyblock = NULL;
-  struct sig_stats stats;
+  struct keylist_context listctx;
 
-  memset (&stats, 0, sizeof (stats));
+  memset (&listctx, 0, sizeof (listctx));
+  if (opt.check_sigs)
+    listctx.check_sigs = 1;
 
   for (sl = names; sl; sl = sl->next)
     {
@@ -596,8 +622,7 @@ locate_one (ctrl_t ctrl, strlist_t names)
 	{
 	  do
 	    {
-	      list_keyblock (keyblock, 0, 0, opt.fingerprint,
-			     opt.check_sigs ? &stats : NULL);
+	      list_keyblock (keyblock, 0, 0, opt.fingerprint, &listctx);
 	      release_kbnode (keyblock);
 	    }
 	  while (ctx && !get_pubkey_next (ctx, NULL, &keyblock));
@@ -607,7 +632,9 @@ locate_one (ctrl_t ctrl, strlist_t names)
     }
 
   if (opt.check_sigs && !opt.with_colons)
-    print_signature_stats (&stats);
+    print_signature_stats (&listctx);
+
+  keylist_context_release (&listctx);
 }
 
 
@@ -869,13 +896,13 @@ list_keyblock_pka (kbnode_t keyblock)
 
 
 static void
-list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
+list_keyblock_print (KBNODE keyblock, int secret, int fpr,
+                     struct keylist_context *listctx)
 {
   int rc;
   KBNODE kbctx;
   KBNODE node;
   PKT_public_key *pk;
-  struct sig_stats *stats = opaque;
   int skip_sigs = 0;
   int s2k_char;
   char *hexgrip = NULL;
@@ -1103,7 +1130,7 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
 	  int sigrc;
 	  char *sigstr;
 
-	  if (stats)
+	  if (listctx->check_sigs)
 	    {
 	      rc = check_key_signature (keyblock, node, NULL);
 	      switch (gpg_err_code (rc))
@@ -1112,15 +1139,15 @@ list_keyblock_print (KBNODE keyblock, int secret, int fpr, void *opaque)
 		  sigrc = '!';
 		  break;
 		case GPG_ERR_BAD_SIGNATURE:
-		  stats->inv_sigs++;
+		  listctx->inv_sigs++;
 		  sigrc = '-';
 		  break;
 		case GPG_ERR_NO_PUBKEY:
 		case GPG_ERR_UNUSABLE_PUBKEY:
-		  stats->no_key++;
+		  listctx->no_key++;
 		  continue;
 		default:
-		  stats->oth_err++;
+		  listctx->oth_err++;
 		  sigrc = '%';
 		  break;
 		}
@@ -1641,9 +1668,9 @@ reorder_keyblock (KBNODE keyblock)
   do_reorder_keyblock (keyblock, 0);
 }
 
-void
+static void
 list_keyblock (KBNODE keyblock, int secret, int has_secret, int fpr,
-               void *opaque)
+               struct keylist_context *listctx)
 {
   reorder_keyblock (keyblock);
   if (opt.print_pka_records)
@@ -1651,12 +1678,24 @@ list_keyblock (KBNODE keyblock, int secret, int has_secret, int fpr,
   else if (opt.with_colons)
     list_keyblock_colon (keyblock, secret, has_secret, fpr);
   else
-    list_keyblock_print (keyblock, secret, fpr, opaque);
+    list_keyblock_print (keyblock, secret, fpr, listctx);
   if (secret)
     es_fflush (es_stdout);
 }
 
 
+/* Public function used by keygen to list a keyblock.  */
+void
+list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret, int fpr)
+{
+  struct keylist_context listctx;
+
+  memset (&listctx, 0, sizeof (listctx));
+  list_keyblock (keyblock, secret, has_secret, fpr, &listctx);
+  keylist_context_release (&listctx);
+}
+
+
 /* Print an hex digit in ICAO spelling.  */
 static void
 print_icao_hexdigit (estream_t fp, int c)
diff --git a/g10/main.h b/g10/main.h
index 39a1feb..01eeb7f 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -346,8 +346,8 @@ void public_key_list (ctrl_t ctrl, strlist_t list, int locate_mode );
 void secret_key_list (ctrl_t ctrl, strlist_t list );
 void print_subpackets_colon(PKT_signature *sig);
 void reorder_keyblock (KBNODE keyblock);
-void list_keyblock (kbnode_t keyblock, int secret, int has_secret,
-                    int fpr, void *opaque);
+void list_keyblock_direct (kbnode_t keyblock, int secret, int has_secret,
+                           int fpr);
 void print_fingerprint (estream_t fp, PKT_public_key *pk, int mode);
 void print_revokers (estream_t fp, PKT_public_key *pk);
 void show_policy_url(PKT_signature *sig,int indent,int mode);

commit f577d5c1a747d673fa1d5c012ce3e3b78b699c6a
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Apr 6 18:57:05 2015 +0200

    gpg: Merge duplicated code for get_user_id et al.
    
    * g10/getkey.c (get_user_id_string): Add args mode and r_LEN.
    (get_user_id_string_native): Add new args.
    (get_long_user_id_string, get_user_id): Rewrite using
    get_user_id_string.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/getkey.c b/g10/getkey.c
index 998f111..20b37d8 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -2754,34 +2754,69 @@ enum_secret_keys (void **context, PKT_public_key *sk)
 /* Return a string with a printable representation of the user_id.
  * this string must be freed by xfree.   */
 static char *
-get_user_id_string (u32 * keyid)
+get_user_id_string (u32 * keyid, int mode, size_t *r_len)
 {
   user_id_db_t r;
+  keyid_list_t a;
   int pass = 0;
+  char *p;
+
   /* Try it two times; second pass reads from key resources.  */
   do
     {
       for (r = user_id_db; r; r = r->next)
 	{
-	  keyid_list_t a;
 	  for (a = r->keyids; a; a = a->next)
 	    {
 	      if (a->keyid[0] == keyid[0] && a->keyid[1] == keyid[1])
 		{
-		  return xasprintf ("%s %.*s", keystr (keyid), r->len, r->name);
+                  if (mode == 2)
+                    {
+                      /* An empty string as user id is possible.  Make
+                         sure that the malloc allocates one byte and
+                         does not bail out.  */
+                      p = xmalloc (r->len? r->len : 1);
+                      memcpy (p, r->name, r->len);
+                      if (r_len)
+                        *r_len = r->len;
+                    }
+                  else
+                    {
+                      if (mode)
+                        p = xasprintf ("%08lX%08lX %.*s",
+                                       (ulong) keyid[0], (ulong) keyid[1],
+                                       r->len, r->name);
+                      else
+                        p = xasprintf ("%s %.*s", keystr (keyid),
+                                       r->len, r->name);
+                      if (r_len)
+                        *r_len = strlen (p);
+                    }
+
+                  return p;
 		}
 	    }
 	}
     }
   while (++pass < 2 && !get_pubkey (NULL, keyid));
-  return xasprintf ("%s [?]", keystr (keyid));
+
+  if (mode == 2)
+    p = xstrdup (user_id_not_found_utf8 ());
+  else if (mode)
+    p = xasprintf ("%08lX%08lX [?]", (ulong) keyid[0], (ulong) keyid[1]);
+  else
+    p = xasprintf ("%s [?]", keystr (keyid));
+
+  if (r_len)
+    *r_len = strlen (p);
+  return p;
 }
 
 
 char *
 get_user_id_string_native (u32 * keyid)
 {
-  char *p = get_user_id_string (keyid);
+  char *p = get_user_id_string (keyid, 0, NULL);
   char *p2 = utf8_to_native (p, strlen (p), 0);
   xfree (p);
   return p2;
@@ -2791,65 +2826,18 @@ get_user_id_string_native (u32 * keyid)
 char *
 get_long_user_id_string (u32 * keyid)
 {
-  user_id_db_t r;
-  keyid_list_t a;
-  int pass = 0;
-  /* Try it two times; second pass reads from key resources.  */
-  do
-    {
-      for (r = user_id_db; r; r = r->next)
-	{
-	  for (a = r->keyids; a; a = a->next)
-	    {
-	      if (a->keyid[0] == keyid[0] && a->keyid[1] == keyid[1])
-		{
-		  return xasprintf ("%08lX%08lX %.*s",
-                                    (ulong) keyid[0], (ulong) keyid[1],
-                                    r->len, r->name);
-		}
-	    }
-	}
-    }
-  while (++pass < 2 && !get_pubkey (NULL, keyid));
-  return xasprintf ("%08lX%08lX [?]", (ulong) keyid[0], (ulong) keyid[1]);
+  return get_user_id_string (keyid, 1, NULL);
 }
 
 
-/* Please try to use get_user_id_native instead of this one.  */
+/* Please try to use get_user_byfpr instead of this one.  */
 char *
 get_user_id (u32 * keyid, size_t * rn)
 {
-  user_id_db_t r;
-  char *p;
-  int pass = 0;
-
-  /* Try it two times; second pass reads from key resources.  */
-  do
-    {
-      for (r = user_id_db; r; r = r->next)
-	{
-	  keyid_list_t a;
-	  for (a = r->keyids; a; a = a->next)
-	    {
-	      if (a->keyid[0] == keyid[0] && a->keyid[1] == keyid[1])
-		{
-                  /* An empty string as user id is possible.  Make
-                     sure that the malloc allocates one byte and does
-                     not bail out.  */
-		  p = xmalloc (r->len? r->len : 1);
-		  memcpy (p, r->name, r->len);
-		  *rn = r->len;
-		  return p;
-		}
-	    }
-	}
-    }
-  while (++pass < 2 && !get_pubkey (NULL, keyid));
-  p = xstrdup (user_id_not_found_utf8 ());
-  *rn = strlen (p);
-  return p;
+  return get_user_id_string (keyid, 2, rn);
 }
 
+
 /* Please try to use get_user_id_byfpr_native instead of this one.  */
 char *
 get_user_id_native (u32 * keyid)
@@ -2863,7 +2851,7 @@ get_user_id_native (u32 * keyid)
 
 
 /* Return a user id from the caching by looking it up using the FPR
-   which mustbe of size MAX_FINGERPRINT_LEN.  */
+   which must be of size MAX_FINGERPRINT_LEN.  */
 char *
 get_user_id_byfpr (const byte *fpr, size_t *rn)
 {

-----------------------------------------------------------------------

Summary of changes:
 g10/getkey.c  | 102 ++++++++++++++++++++++++++--------------------------------
 g10/keygen.c  |   2 +-
 g10/keylist.c | 101 +++++++++++++++++++++++++++++++++++++++------------------
 g10/main.h    |   4 +--
 4 files changed, 118 insertions(+), 91 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list