[Pkg-gnupg-commit] [gnupg2] 05/06: more patches from usptream
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Tue Mar 21 16:47:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gnupg2.
commit f5ccfb8278c7d2832e2fa34a0394854ceb5bfecf
Author: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
Date: Tue Mar 21 12:33:32 2017 -0400
more patches from usptream
---
...tests-Create-temporary-directories-in-tmp.patch | 70 +++
...0-dirmngr-Load-the-hosts-file-into-libdns.patch | 60 +++
.../patches/0071-dirmngr-Fix-error-handling.patch | 26 ++
...072-gpg-New-command-quick-set-primary-uid.patch | 481 +++++++++++++++++++++
...se-GetTempPath-to-get-the-path-for-tempor.patch | 66 +++
.../0074-tests-Test-quick-set-primary-uid.patch | 35 ++
debian/patches/series | 6 +
7 files changed, 744 insertions(+)
diff --git a/debian/patches/0069-tests-Create-temporary-directories-in-tmp.patch b/debian/patches/0069-tests-Create-temporary-directories-in-tmp.patch
new file mode 100644
index 0000000..d206315
--- /dev/null
+++ b/debian/patches/0069-tests-Create-temporary-directories-in-tmp.patch
@@ -0,0 +1,70 @@
+From: Justus Winter <justus at g10code.com>
+Date: Tue, 21 Mar 2017 13:15:38 +0100
+Subject: tests: Create temporary directories in '/tmp'.
+
+* tests/gpgscm/tests.scm (mkdtemp): Create temporary directories in
+'/tmp' on UNIX, or in '%Temp' on Windows.
+* tests/migrations/common.scm (run-test): Turn error into a warning.
+* tests/openpgp/defs.scm (start-agent): Likewise.
+--
+
+This fixes the problem of GnuPG components being unable to communicate
+because of too long GnuPG home directories in important build
+environments like the Debian build servers despite the use of socket
+directories.
+
+This reverts d75d20909d9f60d33ffd210def92278c0f383aad.
+
+Signed-off-by: Justus Winter <justus at g10code.com>
+(cherry picked from commit 06f1f163e96f1039304fd3cf565cf9de1ca45849)
+---
+ tests/gpgscm/tests.scm | 8 +++++---
+ tests/migrations/common.scm | 2 +-
+ tests/openpgp/defs.scm | 2 +-
+ 3 files changed, 7 insertions(+), 5 deletions(-)
+
+diff --git a/tests/gpgscm/tests.scm b/tests/gpgscm/tests.scm
+index 0c02c34..329a31a 100644
+--- a/tests/gpgscm/tests.scm
++++ b/tests/gpgscm/tests.scm
+@@ -271,9 +271,11 @@
+ ;; generic name is used. Returns an absolute path.
+ (define (mkdtemp . components)
+ (canonical-path (_mkdtemp (if (null? components)
+- (string-append "gpgscm-" (get-isotime) "-"
+- (basename-suffix *scriptname* ".scm")
+- "-XXXXXX")
++ (path-join
++ (if *win32* (getenv "Temp") "/tmp")
++ (string-append "gpgscm-" (get-isotime) "-"
++ (basename-suffix *scriptname* ".scm")
++ "-XXXXXX"))
+ (apply path-join components)))))
+
+ (define-macro (with-temporary-working-directory . expressions)
+diff --git a/tests/migrations/common.scm b/tests/migrations/common.scm
+index b1c90aa..fa8f129 100644
+--- a/tests/migrations/common.scm
++++ b/tests/migrations/common.scm
+@@ -53,7 +53,7 @@
+ (untar-armored src-tarball)
+ (setenv "GNUPGHOME" (getcwd) #t)
+
+- (catch (fail "Creating socket directory failed (see README):" (car *error*))
++ (catch (log "Warning: Creating socket directory failed:" (car *error*))
+ (call-popen `(,gpgconf --create-socketdir) ""))
+ (test (getcwd))
+ (catch (log "Warning: Removing socket directory failed.")
+diff --git a/tests/openpgp/defs.scm b/tests/openpgp/defs.scm
+index 64c086d..7c8e10a 100644
+--- a/tests/openpgp/defs.scm
++++ b/tests/openpgp/defs.scm
+@@ -446,7 +446,7 @@
+ (atexit (lambda ()
+ (with-home-directory gnupghome
+ (stop-agent)))))
+- (catch (fail "Creating socket directory failed (see README):" (car *error*))
++ (catch (log "Warning: Creating socket directory failed:" (car *error*))
+ (call-popen `(,(tool 'gpgconf) --create-socketdir) ""))
+ (call-check `(,(tool 'gpg-connect-agent) --verbose
+ ,(string-append "--agent-program=" (tool 'gpg-agent)
diff --git a/debian/patches/0070-dirmngr-Load-the-hosts-file-into-libdns.patch b/debian/patches/0070-dirmngr-Load-the-hosts-file-into-libdns.patch
new file mode 100644
index 0000000..422461d
--- /dev/null
+++ b/debian/patches/0070-dirmngr-Load-the-hosts-file-into-libdns.patch
@@ -0,0 +1,60 @@
+From: Justus Winter <justus at g10code.com>
+Date: Tue, 21 Mar 2017 14:18:25 +0100
+Subject: dirmngr: Load the hosts file into libdns.
+
+* dirmngr/dns-stuff.c (libdns_init): Actually load the hosts file into
+libdns.
+--
+
+Previously, connecting to key servers specified in /etc/hosts was not
+possible because libdns' hosts structure was initialized, but not
+filled with the content of the hosts file.
+
+GnuPG-bug-id: 2977
+Signed-off-by: Justus Winter <justus at g10code.com>
+(cherry picked from commit 88f1505f0613894d5544290a170119eb538921e5)
+---
+ dirmngr/dns-stuff.c | 26 +++++++++++++++++++++++++-
+ 1 file changed, 25 insertions(+), 1 deletion(-)
+
+diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
+index f083058..6484089 100644
+--- a/dirmngr/dns-stuff.c
++++ b/dirmngr/dns-stuff.c
+@@ -533,11 +533,35 @@ libdns_init (void)
+ ld.hosts = dns_hosts_open (&derr);
+ if (!ld.hosts)
+ {
+- log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
+ err = libdns_error_to_gpg_error (derr);
++ log_error ("failed to initialize hosts file: %s\n", gpg_strerror (err));
+ goto leave;
+ }
+
++
++ {
++#if HAVE_W32_SYSTEM
++ char *hosts_path = xtryasprintf ("%s\System32\drivers\etc\hosts",
++ getenv ("SystemRoot"));
++ if (! hosts_path)
++ {
++ err = gpg_error_from_syserror ();
++ goto leave;
++ }
++
++ derr = dns_hosts_loadpath (ld.hosts, hosts_path);
++ xfree (hosts_path);
++#else
++ derr = dns_hosts_loadpath (ld.hosts, "/etc/hosts");
++#endif
++ if (derr)
++ {
++ err = libdns_error_to_gpg_error (derr);
++ log_error ("failed to load hosts file: %s\n", gpg_strerror (err));
++ goto leave;
++ }
++ }
++
+ /* dns_hints_local for stub mode, dns_hints_root for recursive. */
+ ld.hints = (recursive_resolver
+ ? dns_hints_root (ld.resolv_conf, &derr)
diff --git a/debian/patches/0071-dirmngr-Fix-error-handling.patch b/debian/patches/0071-dirmngr-Fix-error-handling.patch
new file mode 100644
index 0000000..3a8baa0
--- /dev/null
+++ b/debian/patches/0071-dirmngr-Fix-error-handling.patch
@@ -0,0 +1,26 @@
+From: Justus Winter <justus at g10code.com>
+Date: Tue, 21 Mar 2017 14:22:13 +0100
+Subject: dirmngr: Fix error handling.
+
+* dirmngr/dns-stuff.c (libdns_init): Convert error before printing it.
+
+Signed-off-by: Justus Winter <justus at g10code.com>
+(cherry picked from commit 483c1288a8f86dc6bf93d0d3f2865ecc246aecba)
+---
+ dirmngr/dns-stuff.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/dirmngr/dns-stuff.c b/dirmngr/dns-stuff.c
+index 6484089..4724e81 100644
+--- a/dirmngr/dns-stuff.c
++++ b/dirmngr/dns-stuff.c
+@@ -568,8 +568,8 @@ libdns_init (void)
+ : dns_hints_local (ld.resolv_conf, &derr));
+ if (!ld.hints)
+ {
+- log_error ("failed to load DNS hints: %s\n", gpg_strerror (err));
+ err = libdns_error_to_gpg_error (derr);
++ log_error ("failed to load DNS hints: %s\n", gpg_strerror (err));
+ goto leave;
+ }
+
diff --git a/debian/patches/0072-gpg-New-command-quick-set-primary-uid.patch b/debian/patches/0072-gpg-New-command-quick-set-primary-uid.patch
new file mode 100644
index 0000000..575dcbf
--- /dev/null
+++ b/debian/patches/0072-gpg-New-command-quick-set-primary-uid.patch
@@ -0,0 +1,481 @@
+From: Werner Koch <wk at gnupg.org>
+Date: Tue, 21 Mar 2017 14:47:21 +0100
+Subject: gpg: New command --quick-set-primary-uid.
+
+* g10/gpg.c (aQuickSetPrimaryUid): New const.
+(opts): New command --quick-set-primary-uid.
+(main): Implement it.
+* g10/keyedit.c (keyedit_quick_adduid): Factor some code out to ...
+(quick_find_keyblock): new func.
+(keyedit_quick_revuid): Use quick_find_keyblock.
+(keyedit_quick_set_primary): New.
+
+Signed-off-by: Werner Koch <wk at gnupg.org>
+(cherry picked from commit 74c1f30ad6616186f0ab9dbaf34db6c17b1e40c4)
+---
+ doc/gpg.texi | 21 ++++--
+ g10/gpg.c | 20 +++++-
+ g10/keyedit.c | 225 ++++++++++++++++++++++++++++++++++++----------------------
+ g10/main.h | 2 +
+ 4 files changed, 174 insertions(+), 94 deletions(-)
+
+diff --git a/doc/gpg.texi b/doc/gpg.texi
+index 0e107ec..37e1ff1 100644
+--- a/doc/gpg.texi
++++ b/doc/gpg.texi
+@@ -1096,19 +1096,28 @@ on its form are applied.
+
+ @item --quick-revoke-uid @var{user-id} @var{user-id-to-revoke}
+ @opindex quick-revoke-uid
+-This command revokes a User ID on an existing key. It cannot be used
+-to revoke the last User ID on key (some non-revoked User ID must
++This command revokes a user ID on an existing key. It cannot be used
++to revoke the last user ID on key (some non-revoked user ID must
+ remain), with revocation reason ``User ID is no longer valid''. If
+ you want to specify a different revocation reason, or to supply
+ supplementary revocation text, you should use the interactive
+ sub-command @code{revuid} of @option{--edit-key}.
+
+- at item --change-passphrase @var{user_id}
++ at item --quick-set-primary-uid @var{user-id} @var{primary-user-id}
++ at opindex quick-set-primary-uid
++This command sets or updates the primary user ID flag on an existing
++key. @var{user-id} specifies the key and @var{primary-user-id} the
++user ID which shall be flagged as the primary user ID. The primary
++user ID flag is removed from all other user ids and the timestamp of
++all affected self-signatures is set one second ahead.
++
++
++ at item --change-passphrase @var{user-id}
+ @opindex change-passphrase
+- at itemx --passwd @var{user_id}
++ at itemx --passwd @var{user-id}
+ @opindex passwd
+ Change the passphrase of the secret key belonging to the certificate
+-specified as @var{user_id}. This is a shortcut for the sub-command
++specified as @var{user-id}. This is a shortcut for the sub-command
+ @code{passwd} of the edit key menu.
+
+ @end table
+@@ -1767,7 +1776,7 @@ when verifying signatures made by keys that are not on the local
+ keyring.
+
+ If the method "wkd" is included in the list of methods given to
+- at option{auto-key-locate}, the Signer's User ID is part of the
++ at option{auto-key-locate}, the signer's user ID is part of the
+ signature, and the option @option{--disable-signer-uid} is not used,
+ the "wkd" method may also be used to retrieve a key.
+
+diff --git a/g10/gpg.c b/g10/gpg.c
+index eeda60f..b3d606b 100644
+--- a/g10/gpg.c
++++ b/g10/gpg.c
+@@ -1,7 +1,7 @@
+ /* gpg.c - The GnuPG utility (main for gpg)
+ * Copyright (C) 1998-2011 Free Software Foundation, Inc.
+- * Copyright (C) 1997-2016 Werner Koch
+- * Copyright (C) 2015-2016 g10 Code GmbH
++ * Copyright (C) 1997-2017 Werner Koch
++ * Copyright (C) 2015-2017 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+@@ -124,6 +124,7 @@ enum cmd_and_opt_values
+ aQuickAddKey,
+ aQuickRevUid,
+ aQuickSetExpire,
++ aQuickSetPrimaryUid,
+ aListConfig,
+ aListGcryptConfig,
+ aGPGConfList,
+@@ -460,6 +461,7 @@ static ARGPARSE_OPTS opts[] = {
+ ARGPARSE_c (aQuickRevUid, "quick-revuid", "@"),
+ ARGPARSE_c (aQuickSetExpire, "quick-set-expire",
+ N_("quickly set a new expiration date")),
++ ARGPARSE_c (aQuickSetPrimaryUid, "quick-set-primary-uid", "@"),
+ ARGPARSE_c (aFullKeygen, "full-generate-key" ,
+ N_("full featured key pair generation")),
+ ARGPARSE_c (aFullKeygen, "full-gen-key", "@"),
+@@ -2581,6 +2583,7 @@ main (int argc, char **argv)
+ case aQuickAddKey:
+ case aQuickRevUid:
+ case aQuickSetExpire:
++ case aQuickSetPrimaryUid:
+ case aExportOwnerTrust:
+ case aImportOwnerTrust:
+ case aRebuildKeydbCaches:
+@@ -4002,6 +4005,7 @@ main (int argc, char **argv)
+ case aQuickAddUid:
+ case aQuickAddKey:
+ case aQuickRevUid:
++ case aQuickSetPrimaryUid:
+ case aFullKeygen:
+ case aKeygen:
+ case aImport:
+@@ -4445,6 +4449,18 @@ main (int argc, char **argv)
+ }
+ break;
+
++ case aQuickSetPrimaryUid:
++ {
++ const char *uid, *primaryuid;
++
++ if (argc != 2)
++ wrong_args ("--quick-set-primary-uid USER-ID PRIMARY-USER-ID");
++ uid = *argv++; argc--;
++ primaryuid = *argv++; argc--;
++ keyedit_quick_set_primary (ctrl, uid, primaryuid);
++ }
++ break;
++
+ case aFastImport:
+ opt.import_options |= IMPORT_FAST;
+ case aImport:
+diff --git a/g10/keyedit.c b/g10/keyedit.c
+index 2b0f45e..9a7fe13 100644
+--- a/g10/keyedit.c
++++ b/g10/keyedit.c
+@@ -1,6 +1,6 @@
+ /* keyedit.c - Edit properties of a key
+ * Copyright (C) 1998-2010 Free Software Foundation, Inc.
+- * Copyright (C) 1998-2016 Werner Koch
++ * Copyright (C) 1998-2017 Werner Koch
+ * Copyright (C) 2015, 2016 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+@@ -2860,36 +2860,28 @@ leave:
+ }
+
+
+-/* Unattended adding of a new keyid. USERNAME specifies the
+- key. NEWUID is the new user id to add to the key. */
+-void
+-keyedit_quick_adduid (ctrl_t ctrl, const char *username, const char *newuid)
++/* Helper for quick commands to find the keyblock for USERNAME.
++ * Returns on success the key database handle at R_KDBHD and the
++ * keyblock at R_KEYBLOCK. */
++static gpg_error_t
++quick_find_keyblock (ctrl_t ctrl, const char *username,
++ KEYDB_HANDLE *r_kdbhd, kbnode_t *r_keyblock)
+ {
+ gpg_error_t err;
+ KEYDB_HANDLE kdbhd = NULL;
+- KEYDB_SEARCH_DESC desc;
+ kbnode_t keyblock = NULL;
++ KEYDB_SEARCH_DESC desc;
+ kbnode_t node;
+- char *uidstring = NULL;
+
+- uidstring = xstrdup (newuid);
+- trim_spaces (uidstring);
+- if (!*uidstring)
+- {
+- log_error ("%s\n", gpg_strerror (GPG_ERR_INV_USER_ID));
+- goto leave;
+- }
+-
+-#ifdef HAVE_W32_SYSTEM
+- /* See keyedit_menu for why we need this. */
+- check_trustdb_stale (ctrl);
+-#endif
++ *r_kdbhd = NULL;
++ *r_keyblock = NULL;
+
+ /* Search the key; we don't want the whole getkey stuff here. */
+ kdbhd = keydb_new ();
+ if (!kdbhd)
+ {
+ /* Note that keydb_new has already used log_error. */
++ err = gpg_error_from_syserror ();
+ goto leave;
+ }
+
+@@ -2917,24 +2909,65 @@ keyedit_quick_adduid (ctrl_t ctrl, const char *username, const char *newuid)
+
+ if (!err)
+ {
+- /* We require the secret primary key to add a UID. */
++ /* We require the secret primary key to set the primary UID. */
+ node = find_kbnode (keyblock, PKT_PUBLIC_KEY);
+- if (!node)
+- BUG ();
++ log_assert (node);
+ err = agent_probe_secret_key (ctrl, node->pkt->pkt.public_key);
+ }
+ }
++ else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
++ err = gpg_error (GPG_ERR_NO_PUBKEY);
++
+ if (err)
+ {
+- log_error (_("secret key \"%s\" not found: %s\n"),
++ log_error (_("key \"%s\" not found: %s\n"),
+ username, gpg_strerror (err));
+ goto leave;
+ }
+
+ fix_keyblock (&keyblock);
+-
+ merge_keys_and_selfsig (keyblock);
+
++ *r_keyblock = keyblock;
++ keyblock = NULL;
++ *r_kdbhd = kdbhd;
++ kdbhd = NULL;
++
++ leave:
++ release_kbnode (keyblock);
++ keydb_release (kdbhd);
++ return err;
++}
++
++
++/* Unattended adding of a new keyid. USERNAME specifies the
++ key. NEWUID is the new user id to add to the key. */
++void
++keyedit_quick_adduid (ctrl_t ctrl, const char *username, const char *newuid)
++{
++ gpg_error_t err;
++ KEYDB_HANDLE kdbhd = NULL;
++ kbnode_t keyblock = NULL;
++ char *uidstring = NULL;
++
++ uidstring = xstrdup (newuid);
++ trim_spaces (uidstring);
++ if (!*uidstring)
++ {
++ log_error ("%s\n", gpg_strerror (GPG_ERR_INV_USER_ID));
++ goto leave;
++ }
++
++#ifdef HAVE_W32_SYSTEM
++ /* See keyedit_menu for why we need this. */
++ check_trustdb_stale (ctrl);
++#endif
++
++ /* Search the key; we don't want the whole getkey stuff here. */
++ err = quick_find_keyblock (ctrl, username, &kdbhd, &keyblock);
++ if (err)
++ goto leave;
++
+ if (menu_adduid (ctrl, keyblock, 0, NULL, uidstring))
+ {
+ err = keydb_update_keyblock (ctrl, kdbhd, keyblock);
+@@ -2954,6 +2987,7 @@ keyedit_quick_adduid (ctrl_t ctrl, const char *username, const char *newuid)
+ keydb_release (kdbhd);
+ }
+
++
+ /* Unattended revocation of a keyid. USERNAME specifies the
+ key. UIDTOREV is the user id revoke from the key. */
+ void
+@@ -2961,7 +2995,6 @@ keyedit_quick_revuid (ctrl_t ctrl, const char *username, const char *uidtorev)
+ {
+ gpg_error_t err;
+ KEYDB_HANDLE kdbhd = NULL;
+- KEYDB_SEARCH_DESC desc;
+ kbnode_t keyblock = NULL;
+ kbnode_t node;
+ int modified = 0;
+@@ -2974,65 +3007,20 @@ keyedit_quick_revuid (ctrl_t ctrl, const char *username, const char *uidtorev)
+ #endif
+
+ /* Search the key; we don't want the whole getkey stuff here. */
+- kdbhd = keydb_new ();
+- if (!kdbhd)
+- {
+- /* Note that keydb_new has already used log_error. */
+- goto leave;
+- }
+-
+- err = classify_user_id (username, &desc, 1);
+- if (!err)
+- err = keydb_search (kdbhd, &desc, 1, NULL);
+- if (!err)
+- {
+- err = keydb_get_keyblock (kdbhd, &keyblock);
+- if (err)
+- {
+- log_error (_("error reading keyblock: %s\n"), gpg_strerror (err));
+- goto leave;
+- }
+- /* Now with the keyblock retrieved, search again to detect an
+- ambiguous specification. We need to save the found state so
+- that we can do an update later. */
+- keydb_push_found_state (kdbhd);
+- err = keydb_search (kdbhd, &desc, 1, NULL);
+- if (!err)
+- err = gpg_error (GPG_ERR_AMBIGUOUS_NAME);
+- else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
+- err = 0;
+- keydb_pop_found_state (kdbhd);
+-
+- if (!err)
+- {
+- /* We require the secret primary key to revoke a UID. */
+- node = find_kbnode (keyblock, PKT_PUBLIC_KEY);
+- if (!node)
+- BUG ();
+- err = agent_probe_secret_key (ctrl, node->pkt->pkt.public_key);
+- }
+- }
++ err = quick_find_keyblock (ctrl, username, &kdbhd, &keyblock);
+ if (err)
+- {
+- log_error (_("secret key \"%s\" not found: %s\n"),
+- username, gpg_strerror (err));
+- goto leave;
+- }
+-
+- fix_keyblock (&keyblock);
+- merge_keys_and_selfsig (keyblock);
++ goto leave;
+
+ /* Too make sure that we do not revoke the last valid UID, we first
+ count how many valid UIDs there are. */
+ valid_uids = 0;
+ for (node = keyblock; node; node = node->next)
+- valid_uids +=
+- node->pkt->pkttype == PKT_USER_ID
+- && ! node->pkt->pkt.user_id->flags.revoked
+- && ! node->pkt->pkt.user_id->flags.expired;
++ valid_uids += (node->pkt->pkttype == PKT_USER_ID
++ && !node->pkt->pkt.user_id->flags.revoked
++ && !node->pkt->pkt.user_id->flags.expired);
+
++ /* Find the right UID. */
+ revlen = strlen (uidtorev);
+- /* find the right UID */
+ for (node = keyblock; node; node = node->next)
+ {
+ if (node->pkt->pkttype == PKT_USER_ID
+@@ -3046,7 +3034,8 @@ keyedit_quick_revuid (ctrl_t ctrl, const char *username, const char *uidtorev)
+ && ! node->pkt->pkt.user_id->flags.revoked
+ && ! node->pkt->pkt.user_id->flags.expired)
+ {
+- log_error (_("Cannot revoke the last valid user ID.\n"));
++ log_error (_("cannot revoke the last valid user ID.\n"));
++ err = gpg_error (GPG_ERR_INV_USER_ID);
+ goto leave;
+ }
+
+@@ -3054,11 +3043,7 @@ keyedit_quick_revuid (ctrl_t ctrl, const char *username, const char *uidtorev)
+ err = core_revuid (ctrl, keyblock, node, reason, &modified);
+ release_revocation_reason_info (reason);
+ if (err)
+- {
+- log_error (_("User ID revocation failed: %s\n"),
+- gpg_strerror (err));
+- goto leave;
+- }
++ goto leave;
+ err = keydb_update_keyblock (ctrl, kdbhd, keyblock);
+ if (err)
+ {
+@@ -3066,13 +3051,81 @@ keyedit_quick_revuid (ctrl_t ctrl, const char *username, const char *uidtorev)
+ goto leave;
+ }
+
+- if (update_trust)
+- revalidation_mark ();
++ revalidation_mark ();
+ goto leave;
+ }
+ }
++ err = gpg_error (GPG_ERR_NO_USER_ID);
+
+- log_error (_("User ID revocation failed: %s\n"), gpg_strerror (GPG_ERR_NOT_FOUND));
++
++ leave:
++ if (err)
++ log_error (_("revoking the user ID failed: %s\n"), gpg_strerror (err));
++ release_kbnode (keyblock);
++ keydb_release (kdbhd);
++}
++
++
++/* Unattended setting of the primary uid. USERNAME specifies the key.
++ PRIMARYUID is the user id which shall be primary. */
++void
++keyedit_quick_set_primary (ctrl_t ctrl, const char *username,
++ const char *primaryuid)
++{
++ gpg_error_t err;
++ KEYDB_HANDLE kdbhd = NULL;
++ kbnode_t keyblock = NULL;
++ kbnode_t node;
++ size_t primaryuidlen;
++ int any;
++
++#ifdef HAVE_W32_SYSTEM
++ /* See keyedit_menu for why we need this. */
++ check_trustdb_stale (ctrl);
++#endif
++
++ err = quick_find_keyblock (ctrl, username, &kdbhd, &keyblock);
++ if (err)
++ goto leave;
++
++ /* Find and mark the UID - we mark only the first valid one. */
++ primaryuidlen = strlen (primaryuid);
++ any = 0;
++ for (node = keyblock; node; node = node->next)
++ {
++ if (node->pkt->pkttype == PKT_USER_ID
++ && !any
++ && !node->pkt->pkt.user_id->flags.revoked
++ && !node->pkt->pkt.user_id->flags.expired
++ && primaryuidlen == node->pkt->pkt.user_id->len
++ && !memcmp (node->pkt->pkt.user_id->name, primaryuid, primaryuidlen))
++ {
++ node->flag |= NODFLG_SELUID;
++ any = 1;
++ }
++ else
++ node->flag &= ~NODFLG_SELUID;
++ }
++
++ if (!any)
++ err = gpg_error (GPG_ERR_NO_USER_ID);
++ else if (menu_set_primary_uid (keyblock))
++ {
++ merge_keys_and_selfsig (keyblock);
++ err = keydb_update_keyblock (ctrl, kdbhd, keyblock);
++ if (err)
++ {
++ log_error (_("update failed: %s\n"), gpg_strerror (err));
++ goto leave;
++ }
++ revalidation_mark ();
++ }
++ else
++ err = gpg_error (GPG_ERR_GENERAL);
++
++ if (err)
++ log_error (_("setting the primary user ID failed: %s\n"),
++ gpg_strerror (err));
+
+ leave:
+ release_kbnode (keyblock);
+@@ -5205,7 +5258,7 @@ change_primary_uid_cb (PKT_signature * sig, void *opaque)
+
+ /*
+ * Set the primary uid flag for the selected UID. We will also reset
+- * all other primary uid flags. For this to work with have to update
++ * all other primary uid flags. For this to work we have to update
+ * all the signature timestamps. If we would do this with the current
+ * time, we lose quite a lot of information, so we use a kludge to
+ * do this: Just increment the timestamp by one second which is
+diff --git a/g10/main.h b/g10/main.h
+index c9c3454..32d323b 100644
+--- a/g10/main.h
++++ b/g10/main.h
+@@ -300,6 +300,8 @@ void keyedit_quick_sign (ctrl_t ctrl, const char *fpr,
+ strlist_t uids, strlist_t locusr, int local);
+ void keyedit_quick_set_expire (ctrl_t ctrl,
+ const char *fpr, const char *expirestr);
++void keyedit_quick_set_primary (ctrl_t ctrl, const char *username,
++ const char *primaryuid);
+ void show_basic_key_info (KBNODE keyblock);
+
+ /*-- keygen.c --*/
diff --git a/debian/patches/0073-tests-w32-Use-GetTempPath-to-get-the-path-for-tempor.patch b/debian/patches/0073-tests-w32-Use-GetTempPath-to-get-the-path-for-tempor.patch
new file mode 100644
index 0000000..c35420a
--- /dev/null
+++ b/debian/patches/0073-tests-w32-Use-GetTempPath-to-get-the-path-for-tempor.patch
@@ -0,0 +1,66 @@
+From: Justus Winter <justus at g10code.com>
+Date: Tue, 21 Mar 2017 15:52:47 +0100
+Subject: tests,w32: Use GetTempPath to get the path for temporary files.
+
+* tests/gpgscm/ffi.c (do_get_temp_path): New function.
+(ffi_init): Make function available.
+* tests/gpgscm/tests.scm (mkdtemp): Use the new function.
+
+Fixes-commit: 06f1f163e96f1039304fd3cf565cf9de1ca45849
+Signed-off-by: Justus Winter <justus at g10code.com>
+(cherry picked from commit d17840c3f40111beaf97d96ad3ca52047976e221)
+---
+ tests/gpgscm/ffi.c | 19 +++++++++++++++++++
+ tests/gpgscm/tests.scm | 2 +-
+ 2 files changed, 20 insertions(+), 1 deletion(-)
+
+diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c
+index 34e573f..3af3328 100644
+--- a/tests/gpgscm/ffi.c
++++ b/tests/gpgscm/ffi.c
+@@ -342,6 +342,24 @@ do_seek (scheme *sc, pointer args)
+ }
+
+ static pointer
++do_get_temp_path (scheme *sc, pointer args)
++{
++ FFI_PROLOG ();
++#ifdef HAVE_W32_SYSTEM
++ char buffer[MAX_PATH+1];
++#endif
++ FFI_ARGS_DONE_OR_RETURN (sc, args);
++
++#ifdef HAVE_W32_SYSTEM
++ if (GetTempPath (MAX_PATH+1, buffer) == 0)
++ FFI_RETURN_STRING (sc, "/temp");
++ FFI_RETURN_STRING (sc, buffer);
++#else
++ FFI_RETURN_STRING (sc, "/tmp");
++#endif
++}
++
++static pointer
+ do_mkdtemp (scheme *sc, pointer args)
+ {
+ FFI_PROLOG ();
+@@ -1352,6 +1370,7 @@ ffi_init (scheme *sc, const char *argv0, const char *scriptname,
+ ffi_define_function (sc, fdopen);
+ ffi_define_function (sc, close);
+ ffi_define_function (sc, seek);
++ ffi_define_function (sc, get_temp_path);
+ ffi_define_function_name (sc, "_mkdtemp", mkdtemp);
+ ffi_define_function (sc, unlink);
+ ffi_define_function (sc, unlink_recursively);
+diff --git a/tests/gpgscm/tests.scm b/tests/gpgscm/tests.scm
+index 329a31a..a4339ca 100644
+--- a/tests/gpgscm/tests.scm
++++ b/tests/gpgscm/tests.scm
+@@ -272,7 +272,7 @@
+ (define (mkdtemp . components)
+ (canonical-path (_mkdtemp (if (null? components)
+ (path-join
+- (if *win32* (getenv "Temp") "/tmp")
++ (get-temp-path)
+ (string-append "gpgscm-" (get-isotime) "-"
+ (basename-suffix *scriptname* ".scm")
+ "-XXXXXX"))
diff --git a/debian/patches/0074-tests-Test-quick-set-primary-uid.patch b/debian/patches/0074-tests-Test-quick-set-primary-uid.patch
new file mode 100644
index 0000000..95f0b6c
--- /dev/null
+++ b/debian/patches/0074-tests-Test-quick-set-primary-uid.patch
@@ -0,0 +1,35 @@
+From: Justus Winter <justus at g10code.com>
+Date: Tue, 21 Mar 2017 16:21:49 +0100
+Subject: tests: Test '--quick-set-primary-uid'.
+
+* tests/openpgp/quick-key-manipulation.scm: Test
+'--quick-set-primary-uid'.
+
+Signed-off-by: Justus Winter <justus at g10code.com>
+(cherry picked from commit fde885bbc47a4bf14a8570ac62e68adc8cf47a6e)
+---
+ tests/openpgp/quick-key-manipulation.scm | 11 +++++++++++
+ 1 file changed, 11 insertions(+)
+
+diff --git a/tests/openpgp/quick-key-manipulation.scm b/tests/openpgp/quick-key-manipulation.scm
+index 9fd5b6b..85e56ca 100755
+--- a/tests/openpgp/quick-key-manipulation.scm
++++ b/tests/openpgp/quick-key-manipulation.scm
+@@ -73,6 +73,17 @@
+ (assert (= 2 (count-uids-of-secret-key alpha)))
+ (assert (= 2 (count-uids-of-secret-key bravo)))
+
++(info "Checking that we can mark an user ID as primary.")
++(call-check `(, at gpg --quick-set-primary-uid ,(exact alpha) ,alpha))
++(call-check `(, at gpg --quick-set-primary-uid ,(exact alpha) ,bravo))
++;; XXX I don't know how to verify this. The keylisting does not seem
++;; to indicate the primary UID.
++
++(info "Checking that we get an error making non-existant user ID the primary one.")
++(catch '()
++ (call-check `(, at GPG --quick-set-primary-uid ,(exact alpha) ,charlie))
++ (error "Expected an error, but get none."))
++
+ (info "Checking that we can revoke a user ID...")
+ (call-check `(, at GPG --quick-revoke-uid ,(exact bravo) ,alpha))
+
diff --git a/debian/patches/series b/debian/patches/series
index da3ee88..e5db74e 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -66,3 +66,9 @@ gpg-agent-idling/0011-agent-Avoid-scheduled-checks-on-socket-when-inotify-.patch
0066-gpg-Add-new-field-no-18-to-the-colon-listing.patch
0067-tests-Fail-if-we-cannot-create-the-socket-directory.patch
0068-tests-Remove-debugging-remnants.patch
+0069-tests-Create-temporary-directories-in-tmp.patch
+0070-dirmngr-Load-the-hosts-file-into-libdns.patch
+0071-dirmngr-Fix-error-handling.patch
+0072-gpg-New-command-quick-set-primary-uid.patch
+0073-tests-w32-Use-GetTempPath-to-get-the-path-for-tempor.patch
+0074-tests-Test-quick-set-primary-uid.patch
--
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