[Pkg-gnupg-commit] [gnupg2] 106/241: tools: Fix gpgkey2ssh's most gratuitous errors. Use gpg2, not gpg.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Wed Dec 9 20:32:02 UTC 2015


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

dkg pushed a commit to branch master
in repository gnupg2.

commit cd2d685230ecafb7df504ef2b16cf1ec9a014300
Author: Neal H. Walfield <neal at g10code.com>
Date:   Thu Nov 5 13:59:33 2015 +0100

    tools: Fix gpgkey2ssh's most gratuitous errors.  Use gpg2, not gpg.
    
    * tools/gpgkey2ssh.c (main): Add support for --help.  Replace the most
    gratuitous asserts with error messages.  Invoke gpg2, not gpg.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>
    Debian-bug-id: 380241
---
 tools/gpgkey2ssh.c | 47 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 38 insertions(+), 9 deletions(-)

diff --git a/tools/gpgkey2ssh.c b/tools/gpgkey2ssh.c
index d22c5ac..2054150 100644
--- a/tools/gpgkey2ssh.c
+++ b/tools/gpgkey2ssh.c
@@ -248,7 +248,7 @@ main (int argc, char **argv)
   int algorithm_id;
   pkdbuf_t *pkdbuf;
   size_t pkdbuf_n;
-  char *command;
+  char *command = NULL;
   FILE *fp;
   int ret;
   gcry_error_t err;
@@ -263,21 +263,50 @@ main (int argc, char **argv)
   algorithm_id = 0;  /* (avoid cc warning) */
   identifier = NULL; /* (avoid cc warning) */
 
-  assert (argc == 2);
+  if (argc != 2)
+    {
+      fprintf (stderr, "Usage: %s KEYID\n", argv[0]);
+      exit (1);
+    }
+  if (strcmp (argv[1], "--help") == 0)
+    {
+      fprintf (stderr, "Usage: %s KEYID\n", argv[0]);
+      fprintf (stderr, "\n");
+      fprintf (stderr,
+               "Convert a gpg key to a format appropriate for inclusion in an\n"
+               "ssh authorized_keys file.\n");
+      exit (0);
+    }
 
   keyid = argv[1];
 
-  ret = asprintf (&command,
-		  "gpg --list-keys --with-colons --with-key-data '%s'",
-		  keyid);
-  assert (ret > 0);
+  asprintf (&command,
+            "gpg2 --list-keys --with-colons --with-key-data '%s'",
+            keyid);
+  if (! command)
+    {
+      fprintf (stderr, "Out of memory.\n");
+      exit (1);
+    }
 
   fp = popen (command, "r");
-  assert (fp);
+  if (! fp)
+    {
+      fprintf (stderr, "Failed to running: '%s'\n", command);
+      exit (1);
+    }
 
   err = retrieve_key_material (fp, keyid, &algorithm_id, &pkdbuf, &pkdbuf_n);
-  assert (! err);
-  assert ((algorithm_id == 1) || (algorithm_id == 17));
+  if (err)
+    {
+      fprintf (stderr, "Error looking up key: %s\n", gpg_strerror (err));
+      exit (1);
+    }
+  if (! ((algorithm_id == 1) || (algorithm_id == 17)))
+    {
+      fprintf (stderr, "Unsupported algorithm: %d\n", algorithm_id);
+      exit (1);
+    }
 
   if (algorithm_id == 1)
     {

-- 
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