From bd5517b9e2c72bada1ec7e506bca03b613402de1 Mon Sep 17 00:00:00 2001 From: David Shaw Date: Wed, 9 Jan 2002 19:59:26 +0000 Subject: [PATCH] Move idea_cipher_warn to misc.c so gpgv.c doesn't need a stub Remove get_temp_dir (it's in exec.c now) Allow --delete-key (now --delete-keys, though --delete-key still works) to delete multiple keys in one go. This applies to --delete-secret-key(s) and --delete-secret-and-public-key(s) as well --- g10/ChangeLog | 13 +++++++ g10/delkey.c | 41 +++++++++++++--------- g10/g10.c | 95 ++++++++++++--------------------------------------- g10/gpgv.c | 3 -- g10/main.h | 5 ++- g10/misc.c | 15 ++++++++ 6 files changed, 77 insertions(+), 95 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index c4ff17743..5ae14b4f8 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,16 @@ +2002-01-09 David Shaw + + * g10.c, misc.c, gpgv.c: move idea_cipher_warn to misc.c so gpgv.c + doesn't need a stub for it any longer. + + * g10.c (get_temp_dir), main.h: no longer used (it's in exec.c now) + + * g10.c (main), delkey.c (delete_keys), main.h : Allow + --delete-key (now --delete-keys, though --delete-key still works, + of course) to delete multiple keys in one go. This applies to + --delete-secret-key(s) and --delete-secret-and-public-key(s) as + well. + 2001-01-09 Timo Schulz * encode.c (encode_crypt_files): Now it behaves like verify_files. diff --git a/g10/delkey.c b/g10/delkey.c index 593e195c6..0b51ea899 100644 --- a/g10/delkey.c +++ b/g10/delkey.c @@ -168,24 +168,33 @@ do_delete_key( const char *username, int secret, int *r_sec_avail ) * Delete a public or secret key from a keyring. */ int -delete_key( const char *username, int secret, int allow_both ) +delete_keys( STRLIST names, int secret, int allow_both ) { int rc, avail; - rc = do_delete_key (username, secret, &avail ); - if ( rc && avail ) { - 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" ); - } + for(;names;names=names->next) { + rc = do_delete_key (names->d, secret, &avail ); + if ( rc && avail ) { + if ( allow_both ) { + rc = do_delete_key (names->d, 1, &avail ); + if ( !rc ) + rc = do_delete_key (names->d, 0, &avail ); + } + else { + log_error(_( + "there is a secret key for public key \"%s\"!\n"),names->d); + log_info(_( + "use option \"--delete-secret-keys\" to delete it first.\n")); + write_status_text( STATUS_DELETE_PROBLEM, "2" ); + return rc; + } + } + + if(rc) { + log_error("%s: delete key failed: %s\n", names->d, g10_errstr(rc) ); + return rc; + } } - return rc; + + return 0; } diff --git a/g10/g10.c b/g10/g10.c index ac685fd73..66f72f867 100644 --- a/g10/g10.c +++ b/g10/g10.c @@ -82,9 +82,9 @@ enum cmd_and_opt_values { aNull = 0, aNRSignKey, aListPackets, aEditKey, - aDeleteKey, - aDeleteSecretKey, - aDeleteSecretAndPublicKey, + aDeleteKeys, + aDeleteSecretKeys, + aDeleteSecretAndPublicKeys, aKMode, aKModeC, aImport, @@ -282,9 +282,9 @@ static ARGPARSE_OPTS opts[] = { { oFingerprint, "fingerprint", 256, N_("list keys and fingerprints")}, { aListSecretKeys, "list-secret-keys", 256, N_("list secret keys")}, { aKeygen, "gen-key", 256, N_("generate a new key pair")}, - { aDeleteKey, "delete-key",256, N_("remove key from the public keyring")}, - { aDeleteSecretKey, "delete-secret-key",256, - N_("remove key from the secret keyring")}, + { aDeleteKeys,"delete-keys",256,N_("remove keys from the public keyring")}, + { aDeleteSecretKeys, "delete-secret-keys",256, + N_("remove keys from the secret keyring")}, { aSignKey, "sign-key" ,256, N_("sign a key")}, { aLSignKey, "lsign-key" ,256, N_("sign a key locally")}, { aNRSignKey, "nrsign-key" ,256, N_("sign a key non-revocably")}, @@ -499,7 +499,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, "@" }, + { aDeleteSecretAndPublicKeys, "delete-secret-and-public-keys",256, "@" }, { aRebuildKeydbCaches, "rebuild-keydb-caches", 256, "@"}, { oPreservePermissions, "preserve-permissions", 0, "@"}, { oPreferenceList, "preference-list", 2, "@"}, @@ -888,13 +888,13 @@ main( int argc, char **argv ) case aListSigs: set_cmd( &cmd, aListSigs); break; case aExportSecret: set_cmd( &cmd, aExportSecret); break; case aExportSecretSub: set_cmd( &cmd, aExportSecretSub); break; - case aDeleteSecretKey: set_cmd( &cmd, aDeleteSecretKey); + case aDeleteSecretKeys: set_cmd( &cmd, aDeleteSecretKeys); greeting=1; break; - case aDeleteSecretAndPublicKey: - set_cmd( &cmd, aDeleteSecretAndPublicKey); + case aDeleteSecretAndPublicKeys: + set_cmd( &cmd, aDeleteSecretAndPublicKeys); greeting=1; break; - case aDeleteKey: set_cmd( &cmd, aDeleteKey); greeting=1; break; + case aDeleteKeys: set_cmd( &cmd, aDeleteKeys); greeting=1; break; case aDetachedSign: detached_sig = 1; set_cmd( &cmd, aSign ); break; case aSym: set_cmd( &cmd, aSym); break; @@ -1652,26 +1652,18 @@ main( int argc, char **argv ) m_free(username); break; - case aDeleteSecretKey: - if( argc != 1 ) - wrong_args(_("--delete-secret-key user-id")); - case aDeleteKey: - if( argc != 1 ) - wrong_args(_("--delete-key user-id")); - username = make_username( fname ); - if( (rc = delete_key(username, cmd==aDeleteSecretKey, 0)) ) - log_error("%s: delete key failed: %s\n", username, g10_errstr(rc) ); - m_free(username); + case aDeleteKeys: + case aDeleteSecretKeys: + case aDeleteSecretAndPublicKeys: + sl = NULL; + /* I'm adding these in reverse order as add_to_strlist2 + reverses them again, and it's easier to understand in the + proper order :) */ + for( ; argc; argc-- ) + add_to_strlist2( &sl, argv[argc-1], utf8_strings ); + delete_keys(sl,cmd==aDeleteSecretKeys,cmd==aDeleteSecretAndPublicKeys); + free_strlist(sl); 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: opt.check_sigs = 1; @@ -2232,46 +2224,3 @@ check_policy_url( const char *s ) } return 0; } - -/* Special warning for the IDEA cipher */ -void -idea_cipher_warn(int show) -{ - static int warned=0; - - if(!warned || show) - { - log_info(_("the IDEA cipher plugin is not present\n")); - log_info(_("please see http://www.gnupg.org/why-not-idea.html " - "for more information\n")); - warned=1; - } -} - -const char * -get_temp_dir(void) -{ - char *tmp; - -#ifndef __MINGW32__ - /* Don't allow to be setuid when we are going to create temporary - files or directories - yes, this is a bit paranoid */ - if (getuid() != geteuid() ) - BUG (); -#endif - - if(opt.temp_dir) - return opt.temp_dir; - - if((tmp=getenv("TMPDIR"))) - return tmp; - - if((tmp=getenv("TMP"))) - return tmp; - -#ifdef __riscos__ - return ""; -#else - return "/tmp"; -#endif -} diff --git a/g10/gpgv.c b/g10/gpgv.c index 87a77447e..7a220f331 100644 --- a/g10/gpgv.c +++ b/g10/gpgv.c @@ -300,9 +300,6 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo, return NULL; } -/* Stub: no decrypting, so no IDEA needed */ -void idea_cipher_warn( int show ) {} - /* Stub to avoid linking to photoid.c */ void show_photo(const struct user_attribute *attr,PKT_public_key *pk) {} diff --git a/g10/main.h b/g10/main.h index b262056b0..c1cb2fbee 100644 --- a/g10/main.h +++ b/g10/main.h @@ -48,8 +48,6 @@ extern int g10_errors_seen; void print_pubkey_algo_note( int algo ); void print_cipher_algo_note( int algo ); void print_digest_algo_note( int algo ); -void idea_cipher_warn( int show ); -const char *get_temp_dir(void); /*-- armor.c --*/ char *make_radix64_string( const byte *data, size_t len ); @@ -68,6 +66,7 @@ int openpgp_pk_test_algo( int algo, unsigned int usage_flags ); int openpgp_pk_algo_usage ( int algo ); int openpgp_md_test_algo( int algo ); int check_permissions(const char *path,int extension,int checkonly); +void idea_cipher_warn( int show ); /*-- helptext.c --*/ void display_online_help( const char *keyword ); @@ -94,7 +93,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 secret, int allow_both ); +int delete_keys( STRLIST names, int secret, int allow_both ); /*-- keyedit.c --*/ void keyedit_menu( const char *username, STRLIST locusr, STRLIST cmds, diff --git a/g10/misc.c b/g10/misc.c index acbd78d88..76070b1be 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -423,3 +423,18 @@ check_permissions(const char *path,int extension,int checkonly) return 0; } + +/* Special warning for the IDEA cipher */ +void +idea_cipher_warn(int show) +{ + static int warned=0; + + if(!warned || show) + { + log_info(_("the IDEA cipher plugin is not present\n")); + log_info(_("please see http://www.gnupg.org/why-not-idea.html " + "for more information\n")); + warned=1; + } +}