diff options
author | Werner Koch <wk@gnupg.org> | 2009-09-04 13:52:03 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2009-09-04 13:52:03 +0200 |
commit | 999a909708e6d27eaf486165183e2fe47465b7ce (patch) | |
tree | f588c1f132754cac88870de2ade8d69b8158b874 /g10/keyedit.c | |
parent | Fix bug#1122. (diff) | |
download | gnupg2-999a909708e6d27eaf486165183e2fe47465b7ce.tar.xz gnupg2-999a909708e6d27eaf486165183e2fe47465b7ce.zip |
Allow uid sand key election using a '*'.
Diffstat (limited to '')
-rw-r--r-- | g10/keyedit.c | 179 |
1 files changed, 104 insertions, 75 deletions
diff --git a/g10/keyedit.c b/g10/keyedit.c index 3e6b966b9..bc79e8fa8 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1,6 +1,6 @@ /* keyedit.c - keyedit stuff * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - * 2008 Free Software Foundation, Inc. + * 2008, 2009 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -1743,12 +1743,22 @@ keyedit_menu( const char *username, strlist_t locusr, if(strlen(arg_string)==NAMEHASH_LEN*2) redisplay=menu_select_uid_namehash(cur_keyblock,arg_string); else - redisplay=menu_select_uid(cur_keyblock,arg_number); + { + if (*arg_string == '*' + && (!arg_string[1] || spacep (arg_string+1))) + arg_number = -1; /* Select all. */ + redisplay = menu_select_uid (cur_keyblock, arg_number); + } break; case cmdSELKEY: - if( menu_select_key( cur_keyblock, arg_number ) ) + { + if (*arg_string == '*' + && (!arg_string[1] || spacep (arg_string+1))) + arg_number = -1; /* Select all. */ + if (menu_select_key( cur_keyblock, arg_number)) redisplay = 1; + } break; case cmdCHECK: @@ -4437,51 +4447,62 @@ menu_set_notation(const char *string,KBNODE pub_keyblock,KBNODE sec_keyblock) } -/**************** - * Select one user id or remove all selection if index is 0. - * Returns: True if the selection changed; +/* + * Select one user id or remove all selection if IDX is 0 or select + * all if IDX is -1. Returns: True if the selection changed. */ static int -menu_select_uid( KBNODE keyblock, int idx ) +menu_select_uid (KBNODE keyblock, int idx) { - KBNODE node; - int i; - - /* first check that the index is valid */ - if( idx ) { - for( i=0, node = keyblock; node; node = node->next ) { - if( node->pkt->pkttype == PKT_USER_ID ) { - if( ++i == idx ) - break; - } - } - if( !node ) { - tty_printf(_("No user ID with index %d\n"), idx ); - return 0; - } + KBNODE node; + int i; + + if (idx == -1) /* Select all. */ + { + for (node = keyblock; node; node = node->next) + if (node->pkt->pkttype == PKT_USER_ID) + node->flag |= NODFLG_SELUID; + return 1; } - else { /* reset all */ - for (node = keyblock; node; node = node->next) { - if( node->pkt->pkttype == PKT_USER_ID ) - node->flag &= ~NODFLG_SELUID; + else if (idx) /* Toggle. */ + { + for (i=0, node = keyblock; node; node = node->next) + { + if (node->pkt->pkttype == PKT_USER_ID) + if (++i == idx) + break; } - return 1; - } - /* and toggle the new index */ - for( i=0, node = keyblock; node; node = node->next ) { - if( node->pkt->pkttype == PKT_USER_ID ) { - if( ++i == idx ) { - if( (node->flag & NODFLG_SELUID) ) - node->flag &= ~NODFLG_SELUID; - else - node->flag |= NODFLG_SELUID; - } + if (!node) + { + tty_printf (_("No user ID with index %d\n"), idx ); + return 0; } - } - return 1; + for (i=0, node = keyblock; node; node = node->next) + { + if (node->pkt->pkttype == PKT_USER_ID) + { + if (++i == idx) + { + if ((node->flag & NODFLG_SELUID)) + node->flag &= ~NODFLG_SELUID; + else + node->flag |= NODFLG_SELUID; + } + } + } + } + else /* Unselect all */ + { + for (node = keyblock; node; node = node->next) + if (node->pkt->pkttype == PKT_USER_ID) + node->flag &= ~NODFLG_SELUID; + } + + return 1; } + /* Search in the keyblock for a uid that matches namehash */ static int menu_select_uid_namehash( KBNODE keyblock, const char *namehash ) @@ -4523,50 +4544,58 @@ menu_select_uid_namehash( KBNODE keyblock, const char *namehash ) /**************** * Select secondary keys - * Returns: True if the selection changed; + * Returns: True if the selection changed. */ static int -menu_select_key( KBNODE keyblock, int idx ) +menu_select_key (KBNODE keyblock, int idx) { - KBNODE node; - int i; + KBNODE node; + int i; - /* first check that the index is valid */ - if( idx ) { - for( i=0, node = keyblock; node; node = node->next ) { - if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY - || node->pkt->pkttype == PKT_SECRET_SUBKEY ) { - if( ++i == idx ) - break; - } - } - if( !node ) { - tty_printf(_("No subkey with index %d\n"), idx ); - return 0; - } + if (idx == -1) /* Select all. */ + { + for (node = keyblock; node; node = node->next) + if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY + || node->pkt->pkttype == PKT_SECRET_SUBKEY) + node->flag |= NODFLG_SELKEY; } - else { /* reset all */ - for ( node = keyblock; node; node = node->next ) { - if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY - || node->pkt->pkttype == PKT_SECRET_SUBKEY ) - node->flag &= ~NODFLG_SELKEY; - } - return 1; + else if (idx) /* Toggle selection. */ + { + for (i=0, node = keyblock; node; node = node->next) + { + if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY + || node->pkt->pkttype == PKT_SECRET_SUBKEY) + if (++i == idx) + break; + } + if (!node) + { + tty_printf (_("No subkey with index %d\n"), idx ); + return 0; + } + + for (i=0, node = keyblock; node; node = node->next) + { + if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY + || node->pkt->pkttype == PKT_SECRET_SUBKEY ) + if (++i == idx) + { + if ((node->flag & NODFLG_SELKEY)) + node->flag &= ~NODFLG_SELKEY; + else + node->flag |= NODFLG_SELKEY; + } + } } - /* and set the new index */ - for( i=0, node = keyblock; node; node = node->next ) { - if( node->pkt->pkttype == PKT_PUBLIC_SUBKEY - || node->pkt->pkttype == PKT_SECRET_SUBKEY ) { - if( ++i == idx ) { - if( (node->flag & NODFLG_SELKEY) ) - node->flag &= ~NODFLG_SELKEY; - else - node->flag |= NODFLG_SELKEY; - } - } + else /* Unselect all. */ + { + for (node = keyblock; node; node = node->next) + if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY + || node->pkt->pkttype == PKT_SECRET_SUBKEY) + node->flag &= ~NODFLG_SELKEY; } - return 1; + return 1; } |