FEATURE: rmsig (edit-key feature)

Michael J. Pedersen marvin@keepthetouch.org
Wed, 6 Sep 2000 14:10:52 -0600


--pvezYHf7grwyp3Bc
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: quoted-printable

One feature that I have found myself wishing for gpg to have is the ability=
 to
delete a signature from a key b yway of an external script (ie: using perl =
to
issue the commands and have the sigs deleted). As such, I've created the
following modification, which allows just this. It creates a new command in
the 'edit-key' menu, named rmsig, which takes a single parameter, the keyid=
 of
the sig to be deleted. As cuh, for my previous defect, the following command
would be a valid command to issue:

gpg --edit-key 01E74468 uid 1 rmsig 4E98D834 save quit

And this command should have the effect of removing the signature. For any
other signature I've tired, it does :)

Please review it, as I'm sure I did some things differently than is desired.
However, I tried to stick to coding styles and practices I had already seen=
. I
hope this patch is of use.

-----<cut here>-----
*** keyedit.c.orig	Tue Sep  5 20:58:57 2000
--- keyedit.c	Wed Sep  6 12:22:28 2000
***************
*** 48,53 ****
--- 48,54 ----
  static int menu_adduid( KBNODE keyblock, KBNODE sec_keyblock );
  static void menu_deluid( KBNODE pub_keyblock, KBNODE sec_keyblock );
  static int  menu_delsig( KBNODE pub_keyblock );
+ static int  rmsig( KBNODE pub_keyblock, ulong sigid );
  static void menu_delkey( KBNODE pub_keyblock, KBNODE sec_keyblock );
  static int menu_expire( KBNODE pub_keyblock, KBNODE sec_keyblock );
  static int menu_select_uid( KBNODE keyblock, int idx );
***************
*** 554,560 ****
  	   cmdDEBUG, cmdSAVE, cmdADDUID, cmdDELUID, cmdADDKEY, cmdDELKEY,
  	   cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF, cmdEXPIRE,
  	   cmdENABLEKEY, cmdDISABLEKEY,
! 	   cmdINVCMD, cmdNOP };
      static struct { const char *name;
  		    enum cmdids id;
  		    int need_sk;
--- 555,561 ----
  	   cmdDEBUG, cmdSAVE, cmdADDUID, cmdDELUID, cmdADDKEY, cmdDELKEY,
  	   cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF, cmdEXPIRE,
  	   cmdENABLEKEY, cmdDISABLEKEY,
! 	   cmdINVCMD, cmdNOP, cmdRMSIG };
      static struct { const char *name;
  		    enum cmdids id;
  		    int need_sk;
***************
*** 582,587 ****
--- 583,589 ----
  	{ N_("addkey")  , cmdADDKEY    , 1,0, N_("add a secondary key") },
  	{ N_("delkey")  , cmdDELKEY    , 0,0, N_("delete a secondary key") },
  	{ N_("delsig")  , cmdDELSIG    , 0,0, N_("delete signatures") },
+ 	{ N_("rmsig")   , cmdRMSIG     , 0,0, N_("forcibly remove signature KEYI=
D") },
  	{ N_("expire")  , cmdEXPIRE    , 1,0, N_("change the expire date") },
  	{ N_("toggle")  , cmdTOGGLE    , 1,0, N_("toggle between secret "
  						 "and public key listing") },
***************
*** 656,661 ****
--- 658,664 ----
      cur_keyblock =3D keyblock;
      for(;;) { /* main loop */
  	int i, arg_number;
+ 	ulong sigid=3D0;
  	char *p;
 =20
  	tty_printf("\n");
***************
*** 677,682 ****
--- 680,691 ----
  		else
  		    have_commands =3D 0;
  	    }
+ 		if( strcmp(answer,"rmsig") =3D=3D 0 ) {
+ 			if ( commands ) {
+ 				sigid =3D strtoul(commands->d,NULL,16);
+ 				commands =3D commands->next;
+ 			}
+ 		}
  	    if( !have_commands ) {
  		answer =3D cpr_get("", _("Command> "));
  		cpr_kill_prompt();
***************
*** 698,704 ****
  		*p++ =3D 0;
  		trim_spaces(answer);
  		trim_spaces(p);
! 		arg_number =3D atoi(p);
  	    }
 =20
  	    for(i=3D0; cmds[i].name; i++ ) {
--- 707,719 ----
  		*p++ =3D 0;
  		trim_spaces(answer);
  		trim_spaces(p);
! 		printf("strlen(p): %d\n",strlen(p));
! 		if ( strcmp(answer,"rmsig") =3D=3D 0 ) {
! 			sigid =3D strtoul(p, NULL, 16);
! 		}
! 		else {
! 			arg_number =3D atoi(p);
! 		}
  	    }
 =20
  	    for(i=3D0; cmds[i].name; i++ ) {
***************
*** 824,829 ****
--- 839,858 ----
  	    }
  	    break;
 =20
+ 	  case cmdRMSIG: {
+ 		int n1;
+=20
+ 		if( !(n1=3Dcount_selected_uids(keyblock)) )
+ 		    tty_printf(_("You must select at least one user ID.\n"));
+ 		else if( rmsig( keyblock, sigid ) ) {
+ 		    /* no redisplay here, because it may scroll away some
+ 		     * status output of delsig */
+ 		    modified =3D 1;
+ 		}
+ 	    }
+ 	    break;
+=20
+=20
  	  case cmdADDKEY:
  	    if( generate_subkeypair( keyblock, sec_keyblock ) ) {
  		redisplay =3D 1;
***************
*** 1372,1377 ****
--- 1401,1448 ----
 =20
      return changed;
  }
+=20
+=20
+ static int
+ rmsig( KBNODE pub_keyblock, ulong sid )
+ {
+     KBNODE node;
+     PKT_user_id *uid =3D NULL;
+ 	PKT_signature *sig =3D NULL;
+ 	ulong sigid =3D 0;
+     int changed=3D0;
+=20
+     for( node =3D pub_keyblock; node; node =3D node->next ) {
+ 	if( node->pkt->pkttype =3D=3D PKT_USER_ID ) {
+ 	    uid =3D (node->flag & NODFLG_SELUID)? node->pkt->pkt.user_id : NULL;
+ 	}
+ 	else if( uid && node->pkt->pkttype =3D=3D PKT_SIGNATURE ) {
+ 	   sig =3D node->pkt->pkt.signature;
+ 	   sigid =3D sig->keyid[1];
+=20
+ 	   if( sigid =3D=3D sid ) {
+ 		   delete_kbnode( node );
+ 		   changed++;
+        }
+=20
+ 	   sig =3D NULL;
+ 	}
+ 	else if( node->pkt->pkttype =3D=3D PKT_PUBLIC_SUBKEY )
+ 	    uid =3D NULL;
+     }
+=20
+     if( changed ) {
+ 	commit_kbnode( &pub_keyblock );
+ 	tty_printf( changed =3D=3D 1? _("Deleted %d signature.\n")
+ 				: _("Deleted %d signatures.\n"), changed );
+     }
+     else
+ 	tty_printf( _("Nothing deleted.\n") );
+ 	/*printf("%lX\n",sid);*/
+=20
+     return changed;
+ }
+=20
 =20
 =20
  /****************
-----<cut here>-----
-----
Michael J. Pedersen
Get GnuPG at http://www.gnupg.org
My GnuPG Key Fingerprint: C31C 7E90 5992 9E5E 9A02 233D D8DD 985E 4E72 4A60
My GnuPG Public Key Available At: http://www.keyserver.net

--pvezYHf7grwyp3Bc
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE5tqTM2N2YXk5ySmARAqy1AJ0dYUy9fN34aJdpxTuKovbYttC02ACgxuLS
h0XnTO2qH3an+pwM2097P8k=
=YLx/
-----END PGP SIGNATURE-----

--pvezYHf7grwyp3Bc--