1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-09-23 15:21:42 +02:00

* main.h, keyedit.c (keyedit_menu): Remove sign_mode and enhance the more

general command list functionality to replace it.

* g10.c (main): Use the general command functionality to implement
--sign-key, --lsign-key, --nrsign-key, and --nrlsign-key.
This commit is contained in:
David Shaw 2004-02-12 18:32:09 +00:00
parent 8765757006
commit 76f579b233
4 changed files with 107 additions and 110 deletions

View File

@ -1,5 +1,11 @@
2004-02-12 David Shaw <dshaw@jabberwocky.com> 2004-02-12 David Shaw <dshaw@jabberwocky.com>
* main.h, keyedit.c (keyedit_menu): Remove sign_mode and enhance
the more general command list functionality to replace it.
* g10.c (main): Use the general command functionality to implement
--sign-key, --lsign-key, --nrsign-key, and --nrlsign-key.
* import.c (import_one): Do the revocation check even in the case * import.c (import_one): Do the revocation check even in the case
when a key, a revocation key set in a direct key signature, and a when a key, a revocation key set in a direct key signature, and a
revocation from that revocation key, all arrive piecemeal. revocation from that revocation key, all arrive piecemeal.

View File

@ -2853,37 +2853,41 @@ main( int argc, char **argv )
} }
break; break;
case aSignKey: /* sign the key given as argument */ case aSignKey:
if( argc != 1 ) if( argc != 1 )
wrong_args(_("--sign-key user-id")); wrong_args(_("--sign-key user-id"));
username = make_username( fname ); /* fall through */
keyedit_menu(fname, locusr, NULL, 1 );
m_free(username);
break;
case aLSignKey: case aLSignKey:
if( argc != 1 ) if( argc != 1 )
wrong_args(_("--lsign-key user-id")); wrong_args(_("--lsign-key user-id"));
username = make_username( fname ); /* fall through */
keyedit_menu(fname, locusr, NULL, 2 );
m_free(username);
break;
case aNRSignKey: case aNRSignKey:
if( argc != 1 ) if( argc != 1 )
wrong_args(_("--nrsign-key user-id")); wrong_args(_("--nrsign-key user-id"));
username = make_username( fname ); /* fall through */
keyedit_menu(fname, locusr, NULL, 3 );
m_free(username);
break;
case aNRLSignKey: case aNRLSignKey:
if( argc != 1 ) if( argc != 1 )
wrong_args(_("--nrlsign-key user-id")); wrong_args(_("--nrlsign-key user-id"));
sl=NULL;
if(cmd==aSignKey)
append_to_strlist(&sl,"sign");
else if(cmd==aLSignKey)
append_to_strlist(&sl,"lsign");
else if(cmd==aNRSignKey)
append_to_strlist(&sl,"nrsign");
else if(cmd==aNRLSignKey)
append_to_strlist(&sl,"nrlsign");
else
BUG();
append_to_strlist( &sl, "save" );
username = make_username( fname ); username = make_username( fname );
keyedit_menu(fname, locusr, NULL, 4 ); keyedit_menu(fname, locusr, sl, 0, 0 );
m_free(username); m_free(username);
break; free_strlist(sl);
break;
case aEditKey: /* Edit a key signature */ case aEditKey: /* Edit a key signature */
if( !argc ) if( !argc )
@ -2893,11 +2897,11 @@ main( int argc, char **argv )
sl = NULL; sl = NULL;
for( argc--, argv++ ; argc; argc--, argv++ ) for( argc--, argv++ ; argc; argc--, argv++ )
append_to_strlist( &sl, *argv ); append_to_strlist( &sl, *argv );
keyedit_menu( username, locusr, sl, 0 ); keyedit_menu( username, locusr, sl, 0, 1 );
free_strlist(sl); free_strlist(sl);
} }
else else
keyedit_menu(username, locusr, NULL, 0 ); keyedit_menu(username, locusr, NULL, 0, 1 );
m_free(username); m_free(username);
break; break;

View File

@ -1093,15 +1093,16 @@ fix_keyblock( KBNODE keyblock )
} }
/**************** /****************
* Menu driven key editor. If sign_mode is true semi-automatical signing * Menu driven key editor. If seckey_check is true, then a secret key
* will be performed. commands are ignore in this case * that matches username will be looked for. If it is false, not all
* commands will be available.
* *
* Note: to keep track of some selection we use node->mark MARKBIT_xxxx. * Note: to keep track of some selection we use node->mark MARKBIT_xxxx.
*/ */
void void
keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, keyedit_menu( const char *username, STRLIST locusr,
int sign_mode ) STRLIST commands, int quiet, int seckey_check )
{ {
enum cmdids { cmdNONE = 0, enum cmdids { cmdNONE = 0,
cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN, cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN,
@ -1116,55 +1117,54 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
enum cmdids id; enum cmdids id;
int need_sk; int need_sk;
int not_with_sk; int not_with_sk;
int signmode;
const char *desc; const char *desc;
} cmds[] = { } cmds[] = {
{ N_("quit") , cmdQUIT , 0,0,1, N_("quit this menu") }, { N_("quit") , cmdQUIT , 0,0, N_("quit this menu") },
{ N_("q") , cmdQUIT , 0,0,1, NULL }, { N_("q") , cmdQUIT , 0,0, NULL },
{ N_("save") , cmdSAVE , 0,0,1, N_("save and quit") }, { N_("save") , cmdSAVE , 0,0, N_("save and quit") },
{ N_("help") , cmdHELP , 0,0,1, N_("show this help") }, { N_("help") , cmdHELP , 0,0, N_("show this help") },
{ "?" , cmdHELP , 0,0,1, NULL }, { "?" , cmdHELP , 0,0, NULL },
{ N_("fpr") , cmdFPR , 0,0,1, N_("show fingerprint") }, { N_("fpr") , cmdFPR , 0,0, N_("show fingerprint") },
{ N_("list") , cmdLIST , 0,0,1, N_("list key and user IDs") }, { N_("list") , cmdLIST , 0,0, N_("list key and user IDs") },
{ N_("l") , cmdLIST , 0,0,1, NULL }, { N_("l") , cmdLIST , 0,0, NULL },
{ N_("uid") , cmdSELUID , 0,0,1, N_("select user ID N") }, { N_("uid") , cmdSELUID , 0,0, N_("select user ID N") },
{ N_("key") , cmdSELKEY , 0,0,0, N_("select secondary key N") }, { N_("key") , cmdSELKEY , 0,0, N_("select secondary key N") },
{ N_("check") , cmdCHECK , 0,0,1, N_("list signatures") }, { N_("check") , cmdCHECK , 0,0, N_("list signatures") },
{ N_("c") , cmdCHECK , 0,0,1, NULL }, { N_("c") , cmdCHECK , 0,0, NULL },
{ N_("sign") , cmdSIGN , 0,1,1, N_("sign the key") }, { N_("sign") , cmdSIGN , 0,1, N_("sign the key") },
{ N_("s") , cmdSIGN , 0,1,1, NULL }, { N_("s") , cmdSIGN , 0,1, NULL },
{ N_("tsign") , cmdTSIGN , 0,1,1, N_("make a trust signature")}, { N_("tsign") , cmdTSIGN , 0,1, N_("make a trust signature")},
{ N_("lsign") , cmdLSIGN , 0,1,1, N_("sign the key locally") }, { N_("lsign") , cmdLSIGN , 0,1, N_("sign the key locally") },
{ N_("nrsign") , cmdNRSIGN , 0,1,1, N_("sign the key non-revocably") }, { N_("nrsign") , cmdNRSIGN , 0,1, N_("sign the key non-revocably") },
{ N_("nrlsign") , cmdNRLSIGN , 0,1,1, N_("sign the key locally and non-revocably") }, { N_("nrlsign") , cmdNRLSIGN , 0,1, N_("sign the key locally and non-revocably") },
{ N_("debug") , cmdDEBUG , 0,0,0, NULL }, { N_("debug") , cmdDEBUG , 0,0, NULL },
{ N_("adduid") , cmdADDUID , 1,1,0, N_("add a user ID") }, { N_("adduid") , cmdADDUID , 1,1, N_("add a user ID") },
{ N_("addphoto"), cmdADDPHOTO , 1,1,0, N_("add a photo ID") }, { N_("addphoto"), cmdADDPHOTO , 1,1, N_("add a photo ID") },
{ N_("deluid") , cmdDELUID , 0,1,0, N_("delete user ID") }, { N_("deluid") , cmdDELUID , 0,1, N_("delete user ID") },
/* delphoto is really deluid in disguise */ /* delphoto is really deluid in disguise */
{ N_("delphoto"), cmdDELUID , 0,1,0, NULL }, { N_("delphoto"), cmdDELUID , 0,1, NULL },
{ N_("addkey") , cmdADDKEY , 1,1,0, N_("add a secondary key") }, { N_("addkey") , cmdADDKEY , 1,1, N_("add a secondary key") },
{ N_("delkey") , cmdDELKEY , 0,1,0, N_("delete a secondary key") }, { N_("delkey") , cmdDELKEY , 0,1, N_("delete a secondary key") },
{ N_("addrevoker"),cmdADDREVOKER,1,1,0, N_("add a revocation key") }, { N_("addrevoker"),cmdADDREVOKER,1,1, N_("add a revocation key") },
{ N_("delsig") , cmdDELSIG , 0,1,0, N_("delete signatures") }, { N_("delsig") , cmdDELSIG , 0,1, N_("delete signatures") },
{ N_("expire") , cmdEXPIRE , 1,1,0, N_("change the expire date") }, { N_("expire") , cmdEXPIRE , 1,1, N_("change the expire date") },
{ N_("primary") , cmdPRIMARY , 1,1,0, N_("flag user ID as primary")}, { N_("primary") , cmdPRIMARY , 1,1, N_("flag user ID as primary")},
{ N_("toggle") , cmdTOGGLE , 1,0,0, N_("toggle between secret " { N_("toggle") , cmdTOGGLE , 1,0, N_("toggle between secret "
"and public key listing") }, "and public key listing") },
{ N_("t" ) , cmdTOGGLE , 1,0,0, NULL }, { N_("t" ) , cmdTOGGLE , 1,0, NULL },
{ N_("pref") , cmdPREF , 0,1,0, N_("list preferences (expert)") }, { N_("pref") , cmdPREF , 0,1, N_("list preferences (expert)")},
{ N_("showpref"), cmdSHOWPREF , 0,1,0, N_("list preferences (verbose)") }, { N_("showpref"), cmdSHOWPREF , 0,1, N_("list preferences (verbose)") },
{ N_("setpref") , cmdSETPREF , 1,1,0, N_("set preference list") }, { N_("setpref") , cmdSETPREF , 1,1, N_("set preference list") },
{ N_("updpref") , cmdUPDPREF , 1,1,0, N_("updated preferences") }, { N_("updpref") , cmdUPDPREF , 1,1, N_("updated preferences") },
{ N_("keyserver"),cmdPREFKS , 1,1,0, N_("set preferred keyserver URL")}, { N_("keyserver"),cmdPREFKS , 1,1, N_("set preferred keyserver URL")},
{ N_("passwd") , cmdPASSWD , 1,1,0, N_("change the passphrase") }, { N_("passwd") , cmdPASSWD , 1,1, N_("change the passphrase") },
{ N_("trust") , cmdTRUST , 0,1,0, N_("change the ownertrust") }, { N_("trust") , cmdTRUST , 0,1, N_("change the ownertrust") },
{ N_("revsig") , cmdREVSIG , 0,1,0, N_("revoke signatures") }, { N_("revsig") , cmdREVSIG , 0,1, N_("revoke signatures") },
{ N_("revuid") , cmdREVUID , 1,1,0, N_("revoke a user ID") }, { N_("revuid") , cmdREVUID , 1,1, N_("revoke a user ID") },
{ N_("revkey") , cmdREVKEY , 1,1,0, N_("revoke a secondary key") }, { N_("revkey") , cmdREVKEY , 1,1, N_("revoke a secondary key") },
{ N_("disable") , cmdDISABLEKEY, 0,1,0, N_("disable a key") }, { N_("disable") , cmdDISABLEKEY, 0,1, N_("disable a key") },
{ N_("enable") , cmdENABLEKEY , 0,1,0, N_("enable a key") }, { N_("enable") , cmdENABLEKEY , 0,1, N_("enable a key") },
{ N_("showphoto"),cmdSHOWPHOTO , 0,0,0, N_("show photo ID") }, { N_("showphoto"),cmdSHOWPHOTO , 0,0, N_("show photo ID") },
{ NULL, cmdNONE } }; { NULL, cmdNONE } };
enum cmdids cmd = 0; enum cmdids cmd = 0;
@ -1188,14 +1188,6 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
goto leave; goto leave;
} }
if( sign_mode ) {
commands = NULL;
append_to_strlist( &commands, sign_mode == 1? "sign":
sign_mode == 2?"lsign":
sign_mode == 3?"nrsign":"nrlsign");
have_commands = 1;
}
/* get the public key */ /* get the public key */
rc = get_pubkey_byname (NULL, username, &keyblock, &kdbhd, 1); rc = get_pubkey_byname (NULL, username, &keyblock, &kdbhd, 1);
if( rc ) if( rc )
@ -1206,7 +1198,8 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
modified++; modified++;
reorder_keyblock(keyblock); reorder_keyblock(keyblock);
if( !sign_mode ) {/* see whether we have a matching secret key */ if(seckey_check)
{/* see whether we have a matching secret key */
PKT_public_key *pk = keyblock->pkt->pkt.public_key; PKT_public_key *pk = keyblock->pkt->pkt.public_key;
sec_kdbhd = keydb_new (1); sec_kdbhd = keydb_new (1);
@ -1237,10 +1230,9 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
keydb_release (sec_kdbhd); sec_kdbhd = NULL; keydb_release (sec_kdbhd); sec_kdbhd = NULL;
rc = 0; rc = 0;
} }
}
if( sec_keyblock ) { if( sec_keyblock && !quiet )
tty_printf(_("Secret key is available.\n")); tty_printf(_("Secret key is available.\n"));
} }
toggle = 0; toggle = 0;
@ -1252,11 +1244,12 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
PKT_public_key *pk=keyblock->pkt->pkt.public_key; PKT_public_key *pk=keyblock->pkt->pkt.public_key;
tty_printf("\n"); tty_printf("\n");
if( redisplay ) { if( redisplay && !quiet )
{
show_key_with_all_names( cur_keyblock, 0, 1, 0, 1, 0 ); show_key_with_all_names( cur_keyblock, 0, 1, 0, 1, 0 );
tty_printf("\n"); tty_printf("\n");
redisplay = 0; redisplay = 0;
} }
do { do {
m_free(answer); m_free(answer);
if( have_commands ) { if( have_commands ) {
@ -1300,9 +1293,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
if( !ascii_strcasecmp( answer, cmds[i].name ) ) if( !ascii_strcasecmp( answer, cmds[i].name ) )
break; break;
} }
if( sign_mode && !cmds[i].signmode ) if( cmds[i].need_sk && !sec_keyblock ) {
cmd = cmdINVCMD;
else if( cmds[i].need_sk && !sec_keyblock ) {
tty_printf(_("Need the secret key to do this.\n")); tty_printf(_("Need the secret key to do this.\n"));
cmd = cmdNOP; cmd = cmdNOP;
} }
@ -1316,12 +1307,10 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
switch( cmd ) { switch( cmd ) {
case cmdHELP: case cmdHELP:
for(i=0; cmds[i].name; i++ ) { for(i=0; cmds[i].name; i++ ) {
if( sign_mode && !cmds[i].signmode ) if( cmds[i].need_sk && !sec_keyblock )
; ; /* skip if we do not have the secret key */
else if( cmds[i].need_sk && !sec_keyblock ) else if( cmds[i].desc )
; /* skip if we do not have the secret key */ tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) );
else if( cmds[i].desc )
tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) );
} }
break; break;
@ -1381,12 +1370,11 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
break; break;
} }
} }
if( !sign_uids( keyblock, locusr, &modified,
(cmd == cmdLSIGN) || (cmd == cmdNRLSIGN), sign_uids( keyblock, locusr, &modified,
(cmd == cmdNRSIGN) || (cmd==cmdNRLSIGN), (cmd == cmdLSIGN) || (cmd == cmdNRLSIGN),
(cmd == cmdTSIGN)) (cmd == cmdNRSIGN) || (cmd==cmdNRLSIGN),
&& sign_mode ) (cmd == cmdTSIGN));
goto do_cmd_save;
break; break;
case cmdDEBUG: case cmdDEBUG:
@ -1598,7 +1586,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
case cmdUPDPREF: case cmdUPDPREF:
{ {
PKT_user_id *temp=keygen_get_std_prefs(); PKT_user_id *temp=keygen_get_std_prefs();
tty_printf(_("Current preference list:\n")); tty_printf(_("Set preference list to:\n"));
show_prefs(temp,1); show_prefs(temp,1);
m_free(temp); m_free(temp);
} }
@ -1661,7 +1649,6 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands,
} }
/* fall thru */ /* fall thru */
case cmdSAVE: case cmdSAVE:
do_cmd_save:
if( modified || sec_modified ) { if( modified || sec_modified ) {
if( modified ) { if( modified ) {
rc = keydb_update_keyblock (kdbhd, keyblock); rc = keydb_update_keyblock (kdbhd, keyblock);

View File

@ -1,6 +1,6 @@
/* main.h /* main.h
* Copyright (C) 1998, 1999, 2000, 2001, 2002, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
* 2003 Free Software Foundation, Inc. * 2004 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -142,8 +142,8 @@ int check_key_signature2( KBNODE root, KBNODE node, PKT_public_key *check_pk,
int delete_keys( STRLIST names, int secret, int allow_both ); int delete_keys( STRLIST names, int secret, int allow_both );
/*-- keyedit.c --*/ /*-- keyedit.c --*/
void keyedit_menu( const char *username, STRLIST locusr, STRLIST cmds, void keyedit_menu( const char *username, STRLIST locusr,
int sign_mode ); STRLIST commands, int quiet, int seckey_check );
void show_basic_key_info (KBNODE keyblock); void show_basic_key_info (KBNODE keyblock);
/*-- keygen.c --*/ /*-- keygen.c --*/