FEATURE: rmsig (edit-key feature)
Michael J. Pedersen
marvin at keepthetouch.org
Wed Sep 6 15:10:52 CEST 2000
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 KEYID") },
{ 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 = keyblock;
for(;;) { /* main loop */
int i, arg_number;
+ ulong sigid=0;
char *p;
tty_printf("\n");
***************
*** 677,682 ****
--- 680,691 ----
else
have_commands = 0;
}
+ if( strcmp(answer,"rmsig") == 0 ) {
+ if ( commands ) {
+ sigid = strtoul(commands->d,NULL,16);
+ commands = commands->next;
+ }
+ }
if( !have_commands ) {
answer = cpr_get("", _("Command> "));
cpr_kill_prompt();
***************
*** 698,704 ****
*p++ = 0;
trim_spaces(answer);
trim_spaces(p);
! arg_number = atoi(p);
}
for(i=0; cmds[i].name; i++ ) {
--- 707,719 ----
*p++ = 0;
trim_spaces(answer);
trim_spaces(p);
! printf("strlen(p): %d\n",strlen(p));
! if ( strcmp(answer,"rmsig") == 0 ) {
! sigid = strtoul(p, NULL, 16);
! }
! else {
! arg_number = atoi(p);
! }
}
for(i=0; cmds[i].name; i++ ) {
***************
*** 824,829 ****
--- 839,858 ----
}
break;
+ case cmdRMSIG: {
+ int n1;
+
+ if( !(n1=count_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 = 1;
+ }
+ }
+ break;
+
+
case cmdADDKEY:
if( generate_subkeypair( keyblock, sec_keyblock ) ) {
redisplay = 1;
***************
*** 1372,1377 ****
--- 1401,1448 ----
return changed;
}
+
+
+ static int
+ rmsig( KBNODE pub_keyblock, ulong sid )
+ {
+ KBNODE node;
+ PKT_user_id *uid = NULL;
+ PKT_signature *sig = NULL;
+ ulong sigid = 0;
+ int changed=0;
+
+ for( node = pub_keyblock; node; node = node->next ) {
+ if( node->pkt->pkttype == PKT_USER_ID ) {
+ uid = (node->flag & NODFLG_SELUID)? node->pkt->pkt.user_id : NULL;
+ }
+ else if( uid && node->pkt->pkttype == PKT_SIGNATURE ) {
+ sig = node->pkt->pkt.signature;
+ sigid = sig->keyid[1];
+
+ if( sigid == sid ) {
+ delete_kbnode( node );
+ changed++;
+ }
+
+ sig = NULL;
+ }
+ else if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY )
+ uid = NULL;
+ }
+
+ if( changed ) {
+ commit_kbnode( &pub_keyblock );
+ tty_printf( changed == 1? _("Deleted %d signature.\n")
+ : _("Deleted %d signatures.\n"), changed );
+ }
+ else
+ tty_printf( _("Nothing deleted.\n") );
+ /*printf("%lX\n",sid);*/
+
+ return changed;
+ }
+
/****************
-----<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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
Url : /pipermail/attachments/20000906/d7819e2c/attachment.bin
More information about the Gnupg-devel
mailing list