[git] GnuPG - branch, master, updated. gnupg-2.1.9-113-ge8c53fc

by Neal H. Walfield cvs at cvs.gnupg.org
Fri Nov 6 12:04:40 CET 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  e8c53fca954d33366e3494a6d4eecc3868282bcc (commit)
       via  f38bac8883ea2e9ed8e2836f97a953efb85e774c (commit)
       via  23e163473f050d1f2c08f589beb9dab283b7d624 (commit)
      from  a958ffd148a46f3757d1c309bb13555638044640 (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 e8c53fca954d33366e3494a6d4eecc3868282bcc
Author: Neal H. Walfield <neal at g10code.com>
Date:   Thu Nov 5 17:29:53 2015 +0100

    gpg: Check for ambiguous or non-matching key specs.
    
    * g10/gpg.c (check_user_ids): New function.
    (main): Check that any user id specifications passed to --local-user
    and --remote-user correspond to exactly 1 user.  Check that any user
    id specifications passed to --default-key correspond to at most 1
    user.  Warn if any user id specifications passed to --local-user or
    --default-user are possible ambiguous (are not specified by long keyid
    or fingerprint).
    * g10/getkey.c (parse_def_secret_key): Don't warn about possible
    ambiguous key descriptions here.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
    GnuPG-bug-id: 1128
    Debian-debug-id: 544490

diff --git a/g10/getkey.c b/g10/getkey.c
index b4086a2..9e123ee 100644
--- a/g10/getkey.c
+++ b/g10/getkey.c
@@ -1142,15 +1142,6 @@ parse_def_secret_key (ctrl_t ctrl)
           continue;
         }
 
-      if (! (desc.mode == KEYDB_SEARCH_MODE_LONG_KID
-             || desc.mode == KEYDB_SEARCH_MODE_FPR16
-             || desc.mode == KEYDB_SEARCH_MODE_FPR20
-             || desc.mode == KEYDB_SEARCH_MODE_FPR)
-          && ! warned)
-        log_info (_("Warning: value '%s' for --default-key"
-                    " should be a long keyid or a fingerprint.\n"),
-                  t->d);
-
       if (! hd)
         hd = keydb_new ();
       else
diff --git a/g10/gpg.c b/g10/gpg.c
index ef283b4..b15be91 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -2081,6 +2081,159 @@ get_default_configname (void)
   return configname;
 }
 
+gpg_error_t
+check_user_ids (strlist_t *sp,
+                int warn_possibly_ambiguous,
+                int error_if_not_found)
+{
+  strlist_t s = *sp;
+  strlist_t s2 = NULL;
+  strlist_t t;
+
+  gpg_error_t rc = 0;
+  gpg_error_t err;
+
+  KEYDB_HANDLE hd = NULL;
+
+  if (! s)
+    return 0;
+
+  for (t = s; t; t = t->next)
+    {
+      const char *option;
+
+      KEYDB_SEARCH_DESC desc;
+      KBNODE kb;
+      PKT_public_key *pk;
+      char fingerprint_bin[MAX_FINGERPRINT_LEN];
+      size_t fingerprint_bin_len = sizeof (fingerprint_bin);
+      char fingerprint[2 * MAX_FINGERPRINT_LEN + 1];
+
+
+      switch (t->flags >> 2)
+        {
+        case oDefaultKey: option = "--default-key"; break;
+        case oEncryptTo: option = "--encrypt-to"; break;
+        case oHiddenEncryptTo: option = "--hidden-encrypt-to"; break;
+        case oEncryptToDefaultKey: option = "--encrypt-to-default-key"; break;
+        case oRecipient: option = "--recipient"; break;
+        case oHiddenRecipient: option = "--hidden-recipient"; break;
+        case oLocalUser: option = "--local-user"; break;
+        default: log_bug ("Unsupport option: %d\n", t->flags >> 2);
+        }
+
+      err = classify_user_id (t->d, &desc, 1);
+      if (err)
+        {
+          if (! rc)
+            rc = err;
+
+          log_error (_("Invalid value ('%s')."), t->d);
+          if (!opt.quiet)
+            log_info (_("(check argument of option '%s')\n"), option);
+          continue;
+        }
+
+      if (warn_possibly_ambiguous
+          && ! (desc.mode == KEYDB_SEARCH_MODE_LONG_KID
+                || desc.mode == KEYDB_SEARCH_MODE_FPR16
+                || desc.mode == KEYDB_SEARCH_MODE_FPR20
+                || desc.mode == KEYDB_SEARCH_MODE_FPR))
+        log_info (_("Warning: value '%s' for %s"
+                    " should be a long keyid or a fingerprint.\n"),
+                  t->d, option);
+
+      if (! hd)
+        hd = keydb_new ();
+      else
+        keydb_search_reset (hd);
+
+      err = keydb_search (hd, &desc, 1, NULL);
+      if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
+        {
+          if (error_if_not_found)
+            {
+              if (! rc)
+                rc = err;
+
+              log_error (_("no such key corresponding to '%s'\n"), t->d);
+              if (!opt.quiet)
+                log_info (_("(check argument of option '%s')\n"), option);
+            }
+          continue;
+        }
+      if (err)
+        {
+          if (! rc)
+            rc = err;
+
+          log_error (_("error looking up '%s' in keyring: %s.\n"),
+                     t->d, gpg_strerror (err));
+          break;
+        }
+
+      err = keydb_get_keyblock (hd, &kb);
+      if (err)
+        {
+          if (! rc)
+            rc = err;
+
+          log_error (_("error reading key block for '%s': %s\n"),
+                     t->d, gpg_strerror (err));
+          continue;
+        }
+
+      pk = kb->pkt->pkt.public_key;
+      fingerprint_from_pk (pk, fingerprint_bin, &fingerprint_bin_len);
+      assert (fingerprint_bin_len == sizeof (fingerprint_bin));
+      bin2hex (fingerprint_bin, MAX_FINGERPRINT_LEN, fingerprint);
+      add_to_strlist (&s2, fingerprint);
+      s2->flags = s->flags;
+
+      release_kbnode (kb);
+
+      /* Continue the search.  */
+      err = keydb_search (hd, &desc, 1, NULL);
+      if (! (gpg_err_code (err) == GPG_ERR_NOT_FOUND
+             || gpg_err_code (err) == GPG_ERR_EOF))
+        {
+          char fingerprint_bin2[MAX_FINGERPRINT_LEN];
+          size_t fingerprint_bin2_len = sizeof (fingerprint_bin2);
+          char fingerprint2[2 * MAX_FINGERPRINT_LEN + 1];
+
+          log_error (_("Error: the key specification '%s' is ambiguous.\n"),
+                     t->d);
+          if (!opt.quiet)
+            log_info (_("(check argument of option '%s')\n"), option);
+
+          err = keydb_get_keyblock (hd, &kb);
+          if (err)
+            log_error (_("error reading key block for '%s': %s.\n"),
+                       t->d, gpg_strerror (err));
+          else
+            {
+              pk = kb->pkt->pkt.public_key;
+              fingerprint_from_pk (pk, fingerprint_bin2, &fingerprint_bin2_len);
+              assert (fingerprint_bin2_len == sizeof (fingerprint_bin2));
+              bin2hex (fingerprint_bin2, MAX_FINGERPRINT_LEN, fingerprint2);
+
+              log_error ("'%s' matches at least: %s and %s.\n",
+                         t->d, fingerprint, fingerprint2);
+
+              release_kbnode (kb);
+            }
+        }
+    }
+
+  strlist_rev (&s2);
+
+  if (hd)
+    keydb_release (hd);
+
+  free_strlist (s);
+  *sp = s2;
+  return rc;
+}
 
 int
 main (int argc, char **argv)
@@ -2582,7 +2735,8 @@ main (int argc, char **argv)
 
 #endif /*!NO_TRUST_MODELS*/
 	  case oDefaultKey:
-            add_to_strlist (&opt.def_secret_key, pargs.r.ret_str);
+            sl = add_to_strlist (&opt.def_secret_key, pargs.r.ret_str);
+            sl->flags = (pargs.r_opt << 2);
             break;
 	  case oDefRecipient:
             if( *pargs.r.ret_str )
@@ -2774,22 +2928,23 @@ main (int argc, char **argv)
 	  case oNoEncryptTo: opt.no_encrypt_to = 1; break;
 	  case oEncryptTo: /* store the recipient in the second list */
 	    sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings );
-	    sl->flags = 1;
+	    sl->flags = (pargs.r_opt << 2) | 1;
 	    break;
 	  case oHiddenEncryptTo: /* store the recipient in the second list */
 	    sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings );
-	    sl->flags = 1|2;
+	    sl->flags = (pargs.r_opt << 2) | 1|2;
 	    break;
           case oEncryptToDefaultKey:
             opt.encrypt_to_default_key = 1;
             break;
 	  case oRecipient: /* store the recipient */
-	    add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings );
+	    sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings );
+	    sl->flags = (pargs.r_opt << 2);
             any_explicit_recipient = 1;
 	    break;
 	  case oHiddenRecipient: /* store the recipient with a flag */
 	    sl = add_to_strlist2( &remusr, pargs.r.ret_str, utf8_strings );
-	    sl->flags = 2;
+	    sl->flags = (pargs.r_opt << 2) | 2;
             any_explicit_recipient = 1;
 	    break;
 
@@ -2832,7 +2987,8 @@ main (int argc, char **argv)
 	  case oAskCertLevel: opt.ask_cert_level = 1; break;
 	  case oNoAskCertLevel: opt.ask_cert_level = 0; break;
 	  case oLocalUser: /* store the local users */
-	    add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings );
+	    sl = add_to_strlist2( &locusr, pargs.r.ret_str, utf8_strings );
+            sl->flags = (pargs.r_opt << 2);
 	    break;
 	  case oCompress:
 	    /* this is the -z command line option */
@@ -3740,19 +3896,33 @@ main (int argc, char **argv)
         break;
       }
 
-    if (opt.encrypt_to_default_key)
-      {
-        const char *default_key = parse_def_secret_key (ctrl);
-        if (default_key)
-          {
-            sl = add_to_strlist2 (&remusr, default_key, utf8_strings);
-            sl->flags = 1;
-          }
-        else if (opt.def_secret_key)
-          log_info (_("--encrypt-to-default-key specified, but no valid default keys specified.\n"));
-        else
-          log_info (_("--encrypt-to-default-key specified, but --default-key not specified.\n"));
-      }
+    {
+      int have_def_secret_key = opt.def_secret_key != NULL;
+
+      rc = check_user_ids (&locusr, 1, 1);
+      if (rc)
+        g10_exit (1);
+      rc = check_user_ids (&remusr, 0, 1);
+      if (rc)
+        g10_exit (1);
+      rc = check_user_ids (&opt.def_secret_key, 1, 0);
+      if (rc)
+        g10_exit (1);
+
+      if (opt.encrypt_to_default_key)
+        {
+          const char *default_key = parse_def_secret_key (ctrl);
+          if (default_key)
+            {
+              sl = add_to_strlist2 (&remusr, default_key, utf8_strings);
+              sl->flags = (oEncryptToDefaultKey << 2) | 1;
+            }
+          else if (have_def_secret_key)
+            log_info (_("--encrypt-to-default-key specified, but no valid default keys specified.\n"));
+          else
+            log_info (_("--encrypt-to-default-key specified, but --default-key not specified.\n"));
+        }
+    }
 
     /* The command dispatcher.  */
     switch( cmd )

commit f38bac8883ea2e9ed8e2836f97a953efb85e774c
Author: Neal H. Walfield <neal at g10code.com>
Date:   Fri Nov 6 10:51:35 2015 +0100

    common: Add new function strlist_rev.
    
    * common/strlist.c (strlist_rev): New function.
    * common/t-strlist.c: New file.
    * common/Makefile.am (common_sources): Add strlist.c and strlist.h.
    (module_tests): Add t-strlist.
    (t_strlist_LDADD): New variable.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>

diff --git a/common/Makefile.am b/common/Makefile.am
index f84cea1..678e1a2 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -85,7 +85,8 @@ common_sources = \
 	ssh-utils.c ssh-utils.h \
 	agent-opt.c \
 	helpfile.c \
-	mkdir_p.c mkdir_p.h
+	mkdir_p.c mkdir_p.h \
+	strlist.c strlist.h
 
 if HAVE_W32_SYSTEM
 common_sources += w32-reg.c w32-afunix.c w32-afunix.h
@@ -150,7 +151,7 @@ endif
 module_tests = t-stringhelp t-timestuff \
                t-convert t-percent t-gettime t-sysutils t-sexputil \
 	       t-session-env t-openpgp-oid t-ssh-utils \
-	       t-mapstrings t-zb32 t-mbox-util t-iobuf
+	       t-mapstrings t-zb32 t-mbox-util t-iobuf t-strlist
 if !HAVE_W32CE_SYSTEM
 module_tests += t-exechelp
 endif
@@ -198,6 +199,7 @@ t_zb32_LDADD = $(t_common_ldadd)
 
 t_mbox_util_LDADD = $(t_common_ldadd)
 t_iobuf_LDADD = $(t_common_ldadd)
+t_strlist_LDADD = $(t_common_ldadd)
 
 # System specific test
 if HAVE_W32_SYSTEM
diff --git a/common/strlist.c b/common/strlist.c
index 9bd6195..760a460 100644
--- a/common/strlist.c
+++ b/common/strlist.c
@@ -231,3 +231,22 @@ strlist_length (strlist_t list)
 
   return i;
 }
+
+/* Reverse the list *LIST in place.  */
+strlist_t
+strlist_rev (strlist_t *list)
+{
+  strlist_t l = *list;
+  strlist_t lrev = NULL;
+
+  while (l)
+    {
+      strlist_t tail = l->next;
+      l->next = lrev;
+      lrev = l;
+      l = tail;
+    }
+
+  *list = lrev;
+  return lrev;
+}
diff --git a/common/strlist.h b/common/strlist.h
index fccce87..acb92f7 100644
--- a/common/strlist.h
+++ b/common/strlist.h
@@ -58,6 +58,7 @@ char * strlist_pop (strlist_t *list);
 strlist_t strlist_find (strlist_t haystack, const char *needle);
 int strlist_length (strlist_t list);
 
+strlist_t strlist_rev (strlist_t *haystack);
 
 #define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0)
 
diff --git a/common/t-strlist.c b/common/t-strlist.c
new file mode 100644
index 0000000..b033905
--- /dev/null
+++ b/common/t-strlist.c
@@ -0,0 +1,82 @@
+/* t-strlist.c - Regression tests for strist.c
+ * Copyright (C) 2015  g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify it
+ * under the terms of either
+ *
+ *   - the GNU Lesser General Public License as published by the Free
+ *     Software Foundation; either version 3 of the License, or (at
+ *     your option) any later version.
+ *
+ * or
+ *
+ *   - the GNU General Public License as published by the Free
+ *     Software Foundation; either version 2 of the License, or (at
+ *     your option) any later version.
+ *
+ * or both in parallel, as here.
+ *
+ * GnuPG is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copies of the GNU General Public License
+ * and the GNU Lesser General Public License along with this program;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include "strlist.h"
+
+#include "t-support.h"
+
+static void
+test_strlist_rev (void)
+{
+  strlist_t s = NULL;
+
+  /* Reversing an empty list should yield the empty list.  */
+  if (! (strlist_rev (&s) == NULL))
+    fail (1);
+
+  add_to_strlist (&s, "1");
+  add_to_strlist (&s, "2");
+  add_to_strlist (&s, "3");
+
+  if (strcmp (s->d, "3") != 0)
+    fail (2);
+  if (strcmp (s->next->d, "2") != 0)
+    fail (2);
+  if (strcmp (s->next->next->d, "1") != 0)
+    fail (2);
+  if (s->next->next->next)
+    fail (2);
+
+  strlist_rev (&s);
+
+  if (strcmp (s->d, "1") != 0)
+    fail (2);
+  if (strcmp (s->next->d, "2") != 0)
+    fail (2);
+  if (strcmp (s->next->next->d, "3") != 0)
+    fail (2);
+  if (s->next->next->next)
+    fail (2);
+}
+
+
+int
+main (int argc, char **argv)
+{
+  (void)argc;
+  (void)argv;
+
+  test_strlist_rev ();
+
+  return 0;
+}

commit 23e163473f050d1f2c08f589beb9dab283b7d624
Author: Neal H. Walfield <neal at g10code.com>
Date:   Fri Nov 6 10:49:09 2015 +0100

    common: Include required, but not included headers in t-support.h.
    
    * common/t-support.h: Include <stdlib.h> and <stdio.h>.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>

diff --git a/common/t-support.h b/common/t-support.h
index c0d0c8c..8ff2810 100644
--- a/common/t-support.h
+++ b/common/t-support.h
@@ -35,6 +35,9 @@
 #error The regression tests should not include with gcrypt.h
 #endif
 
+#include <stdlib.h>
+#include <stdio.h>
+
 #ifdef HAVE_W32CE_SYSTEM
 #include <gpg-error.h>  /* Defines strerror.  */
 #endif

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

Summary of changes:
 common/Makefile.am                  |   6 +-
 common/strlist.c                    |  19 ++++
 common/strlist.h                    |   1 +
 common/{t-w32-reg.c => t-strlist.c} |  60 ++++++-----
 common/t-support.h                  |   3 +
 g10/getkey.c                        |   9 --
 g10/gpg.c                           | 208 ++++++++++++++++++++++++++++++++----
 7 files changed, 247 insertions(+), 59 deletions(-)
 copy common/{t-w32-reg.c => t-strlist.c} (58%)


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




More information about the Gnupg-commits mailing list