[PATCH] new option: --show-keyring

David Champion dgc at uchicago.edu
Fri Dec 14 20:51:01 CET 2001


Several of my public keys were on the wrong keyring, and I needed to
know which one they were on so that I could relocate them. This patch
provides --show-keyring. Used with "--list-keys foo" or "--list-secret
foo", it makes gpg tell you which keyring a key resides on. It also
works with --list-sigs.

Example:
unix$ gpg --show-keyring --list-keys koch
gpg: NOTE: THIS IS A DEVELOPMENT VERSION!
gpg: It is only intended for test purposes and should NOT be
gpg: used in a production environment or with production keys!
Keyring: /home/dgc/.gnupg/automatic.gpg
---------------------------------------
pub  1024D/57548DCD 1998-07-07 Werner Koch (gnupg sig) <dd9jn at gnu.org>

Keyring: /home/dgc/.gnupg/automatic.gpg
---------------------------------------
pub  1024D/621CC013 1998-07-07 Werner Koch <wk at openit.de>
sub  1536g/ADF6A6E1 1999-02-20 [expires: 2002-11-01]


Or, suppose I accidentally download my own key and install it on my
automatic keyring, in addition to my personal keyring:

unix$ gpg --show-keyring --list-keys 0xAB61503F
gpg: NOTE: THIS IS A DEVELOPMENT VERSION!
gpg: It is only intended for test purposes and should NOT be
gpg: used in a production environment or with production keys!
Keyring: /home/dgc/.gnupg/personal.gpg
--------------------------------------
pub  1024D/AB61503F 1999-12-09 David Champion (1999 online) <dgc at uchicago.edu>
uid                            David Champion (personal)
uid                            David Champion <dgc at uchicago.edu>
sub  1024g/07D6E6DD 1999-12-09

Keyring: /home/dgc/.gnupg/automatic.gpg
---------------------------------------
pub  1024D/AB61503F 1999-12-09 David Champion <dgc at uchicago.edu>
uid                            David Champion (1999 online) <dgc at uchicago.edu>
uid                            David Champion (personal)
sub  1024g/07D6E6DD 1999-12-09

(Yes, this key is expired.)

Use as you will. Patch is against current CVS.

-- 
 -D.	dgc at uchicago.edu	NSIT	University of Chicago
-------------- next part --------------
Index: doc/gpg.sgml
===================================================================
RCS file: /cvs/gnupg/gnupg/doc/gpg.sgml,v
retrieving revision 1.13.2.55
diff -u -r1.13.2.55 gpg.sgml
--- doc/gpg.sgml	2001/11/09 09:35:22	1.13.2.55
+++ doc/gpg.sgml	2001/12/14 19:33:32
@@ -211,6 +211,16 @@
 
 
 <varlistentry>
+<term>--show-keyring</term>
+<listitem><para>
+Causes --list-keys, --list-public-keys, and --list-secret-keys to
+display the name of the keyring a given key resides on. This is only
+useful when you're listing a specific key or set of keys. It has no
+effect when listig all keys.
+</para></listitem></varlistentry>
+
+
+<varlistentry>
 <term>--list-sigs &OptParmNames;</term>
 <listitem><para>
 Same as --list-keys, but the signatures are listed too.
Index: g10/g10.c
===================================================================
RCS file: /cvs/gnupg/gnupg/g10/Attic/g10.c,v
retrieving revision 1.129.2.64
diff -u -r1.129.2.64 g10.c
--- g10/g10.c	2001/12/07 15:24:31	1.129.2.64
+++ g10/g10.c	2001/12/14 19:33:32
@@ -129,6 +129,7 @@
     oNoDefCheckLevel,
     oKeyring,
     oSecretKeyring,
+    oShowKeyring,
     oDefaultKey,
     oDefRecipient,
     oDefRecipientSelf,
@@ -345,6 +346,7 @@
     { oAnswerNo,  "no",        0, N_("assume no on most questions")},
     { oKeyring, "keyring"   ,2, N_("add this keyring to the list of keyrings")},
     { oSecretKeyring, "secret-keyring" ,2, N_("add this secret keyring to the list")},
+    { oShowKeyring, "show-keyring", 0, N_("show which keyring a listed key is on")},
     { oDefaultKey, "default-key" ,2, N_("|NAME|use NAME as default secret key")},
     { oKeyServer, "keyserver",2, N_("|HOST|use this keyserver to lookup keys")},
     { oKeyServerOptions, "keyserver-options",2,"@"},
@@ -914,6 +916,7 @@
 	  case oAnswerYes: opt.answer_yes = 1; break;
 	  case oAnswerNo: opt.answer_no = 1; break;
 	  case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
+	  case oShowKeyring: opt.show_keyring = 1; break;
 	  case oDebug: opt.debug |= pargs.r.ret_ulong; break;
 	  case oDebugAll: opt.debug = ~0; break;
 	  case oStatusFD:
Index: g10/getkey.c
===================================================================
RCS file: /cvs/gnupg/gnupg/g10/getkey.c,v
retrieving revision 1.66.2.37
diff -u -r1.66.2.37 getkey.c
--- g10/getkey.c	2001/12/07 00:57:50	1.66.2.37
+++ g10/getkey.c	2001/12/14 19:33:33
@@ -2194,4 +2194,8 @@
     return p;
 }
 
-
+const char*
+get_ctx_handle(GETKEY_CTX ctx)
+{
+	return ctx->kr_handle;
+}
Index: g10/keydb.h
===================================================================
RCS file: /cvs/gnupg/gnupg/g10/keydb.h,v
retrieving revision 1.53.2.16
diff -u -r1.53.2.16 keydb.h
--- g10/keydb.h	2001/12/07 01:14:15	1.53.2.16
+++ g10/keydb.h	2001/12/14 19:33:33
@@ -209,6 +209,7 @@
 char*get_user_id_string_native( u32 *keyid );
 char*get_long_user_id_string( u32 *keyid );
 char*get_user_id( u32 *keyid, size_t *rn );
+const char*get_ctx_handle(GETKEY_CTX ctx);
 
 /*-- keyid.c --*/
 int pubkey_letter( int algo );
Index: g10/keylist.c
===================================================================
RCS file: /cvs/gnupg/gnupg/g10/keylist.c,v
retrieving revision 1.24.2.30
diff -u -r1.24.2.30 keylist.c
--- g10/keylist.c	2001/12/12 19:31:13	1.24.2.30
+++ g10/keylist.c	2001/12/14 19:33:33
@@ -173,6 +173,9 @@
     int rc = 0;
     KBNODE keyblock = NULL;
     GETKEY_CTX ctx;
+    char *resname;
+    char *keyring_str = N_("Keyring");
+    int i;
 
     /* fixme: using the bynames function has the disadvantage that we
      * don't know wether one of the names given was not found.  OTOH,
@@ -191,6 +194,13 @@
 	    return;
 	}
 	do {
+	    if (opt.show_keyring) {
+		resname = keydb_get_resource_name (get_ctx_handle(ctx));
+		printf("%s: %s\n", keyring_str, resname);
+		for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
+		    putchar('-');
+		putchar('\n');
+	    }
 	    list_keyblock( keyblock, 1 );
 	    release_kbnode( keyblock );
 	} while( !get_seckey_next( ctx, NULL, &keyblock ) );
@@ -204,6 +214,13 @@
 	    return;
 	}
 	do {
+	    if (opt.show_keyring) {
+		resname = keydb_get_resource_name (get_ctx_handle(ctx));
+		printf("%s: %s\n", keyring_str, resname);
+		for(i = strlen(resname) + strlen(keyring_str) + 2; i; i-- )
+		    putchar('-');
+		putchar('\n');
+	    }
 	    list_keyblock( keyblock, 0 );
 	    release_kbnode( keyblock );
 	} while( !get_pubkey_next( ctx, NULL, &keyblock ) );
Index: g10/options.h
===================================================================
RCS file: /cvs/gnupg/gnupg/g10/options.h,v
retrieving revision 1.51.2.35
diff -u -r1.51.2.35 options.h
--- g10/options.h	2001/12/07 15:24:32	1.51.2.35
+++ g10/options.h	2001/12/14 19:33:33
@@ -135,6 +135,7 @@
     int no_auto_check_trustdb;
     int preserve_permissions;
     int no_homedir_creation;
+    int show_keyring;
 } opt;
 
 


More information about the Gnupg-devel mailing list