1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-10 13:04:23 +01:00

Enhanced delkey command and other stuff for gpgme

This commit is contained in:
Werner Koch 2001-01-23 13:56:30 +00:00
parent 227d0f17de
commit 4ae64383cd
5 changed files with 61 additions and 10 deletions

View File

@ -413,6 +413,12 @@ Remove key from the public keyring
Remove key from the secret and public keyring
</para></listitem></varlistentry>
<varlistentry>
<term>--delete-secret-and-public-key &ParmName;</term>
<listitem><para>
Same as --delete-key, but if a secret key exists, it will be removed first.
</para></listitem></varlistentry>
<varlistentry>
<term>--gen-revoke</term>
<listitem><para>

View File

@ -1,3 +1,9 @@
2001-01-22 Werner Koch <wk@gnupg.org>
* g10.c: New command --delete-secret-and-public-key.
* delkey.c (delete_key): Add new arg allow_both.
(do_delete_key): Move most stuff from above to this new function.
2001-01-12 Werner Koch <wk@gnupg.org>
* passphrase.c (passphrase_to_dek): Use MD5 when IDEA is installed

View File

@ -43,9 +43,11 @@
/****************
* Delete a public or secret key from a keyring.
* r_sec_avail will be set if a secret key is available and the public
* key can't be deleted for that reason.
*/
int
delete_key( const char *username, int secret )
static int
do_delete_key( const char *username, int secret, int *r_sec_avail )
{
int rc = 0;
KBNODE keyblock = NULL;
@ -57,6 +59,7 @@ delete_key( const char *username, int secret )
int okay=0;
int yes;
*r_sec_avail = 0;
/* search the userid */
rc = secret? find_secret_keyblock_byname( &kbpos, username )
: find_keyblock_byname( &kbpos, username );
@ -90,12 +93,8 @@ delete_key( const char *username, int secret )
keyid_from_pk( pk, keyid );
rc = seckey_available( keyid );
if( !rc ) {
log_error(_(
"there is a secret key for this public key!\n"));
log_info(_(
"use option \"--delete-secret-key\" to delete it first.\n"));
write_status_text( STATUS_DELETE_PROBLEM, "2" );
rc = -1;
*r_sec_avail = 1;
rc = -1;
}
else if( rc != G10ERR_NO_SECKEY ) {
log_error("%s: get secret key: %s\n", username, g10_errstr(rc) );
@ -161,3 +160,29 @@ delete_key( const char *username, int secret )
return rc;
}
/****************
* Delete a public or secret key from a keyring.
*/
int
delete_key( const char *username, int secret, int allow_both )
{
int rc, avail;
rc = do_delete_key (username, secret, &avail );
if ( rc && avail ) {
assert (secret);
if ( allow_both ) {
rc = do_delete_key (username, 1, &avail );
if ( !rc )
rc = do_delete_key (username, 0, &avail );
}
else {
log_error(_(
"there is a secret key for this public key!\n"));
log_info(_(
"use option \"--delete-secret-key\" to delete it first.\n"));
write_status_text( STATUS_DELETE_PROBLEM, "2" );
}
}
return rc;
}

View File

@ -76,6 +76,7 @@ enum cmd_and_opt_values { aNull = 0,
aEditKey,
aDeleteKey,
aDeleteSecretKey,
aDeleteSecretAndPublicKey,
aKMode,
aKModeC,
aImport,
@ -395,6 +396,7 @@ static ARGPARSE_OPTS opts[] = {
{ oTryAllSecrets, "try-all-secrets", 0, "@" },
{ oEnableSpecialFilenames, "enable-special-filenames", 0, "@" },
{ oNoExpensiveTrustChecks, "no-expensive-trust-checks", 0, "@" },
{ aDeleteSecretAndPublicKey, "delete-secret-and-public-key",256, "@" },
{ oEmu3DESS2KBug, "emulate-3des-s2k-bug", 0, "@"},
{ oEmuMDEncodeBug, "emulate-md-encode-bug", 0, "@"},
{0} };
@ -754,6 +756,10 @@ main( int argc, char **argv )
case aExportSecretSub: set_cmd( &cmd, aExportSecretSub); break;
case aDeleteSecretKey: set_cmd( &cmd, aDeleteSecretKey);
greeting=1; break;
case aDeleteSecretAndPublicKey:
set_cmd( &cmd, aDeleteSecretAndPublicKey);
greeting=1;
break;
case aDeleteKey: set_cmd( &cmd, aDeleteKey); greeting=1; break;
case aDetachedSign: detached_sig = 1; set_cmd( &cmd, aSign ); break;
@ -1280,10 +1286,18 @@ main( int argc, char **argv )
if( argc != 1 )
wrong_args(_("--delete-key user-id"));
username = make_username( fname );
if( (rc = delete_key(username, cmd==aDeleteSecretKey)) )
if( (rc = delete_key(username, cmd==aDeleteSecretKey, 0)) )
log_error("%s: delete key failed: %s\n", username, g10_errstr(rc) );
m_free(username);
break;
case aDeleteSecretAndPublicKey:
if( argc != 1 )
wrong_args(_("--delete-secret-and-public-key user-id"));
username = make_username( fname );
if( (rc = delete_key(username, 0, 1)) )
log_error("%s: delete key failed: %s\n", username, g10_errstr(rc));
m_free(username);
break;
case aCheckKeys:

View File

@ -85,7 +85,7 @@ int check_key_signature2( KBNODE root, KBNODE node,
int *is_selfsig, u32 *r_expiredate, int *r_expired );
/*-- delkey.c --*/
int delete_key( const char *username, int secure );
int delete_key( const char *username, int secret, int allow_both );
/*-- keyedit.c --*/
void keyedit_menu( const char *username, STRLIST locusr, STRLIST cmds,