X-Git-Url: https://git.llucax.com/software/mutt-debian.git/blobdiff_plain/14c29200cb58d3c4a0830265f2433849781858d0..e0fe492429aa15be0fe92b431b66506f2906c892:/pgpkey.c?ds=sidebyside diff --git a/pgpkey.c b/pgpkey.c index 90e7c6e..04bca9f 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -1,6 +1,6 @@ /* - * Copyright (C) 1996,1997 Michael R. Elkins - * Copyright (c) 1998,1999 Thomas Roessler + * Copyright (C) 1996-7,2007 Michael R. Elkins + * Copyright (c) 1998-2003 Thomas Roessler * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General Public @@ -147,7 +147,7 @@ static const char *pgp_entry_fmt (char *dest, kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags; - + switch (ascii_tolower (op)) { case '[': @@ -283,12 +283,12 @@ static const char *pgp_entry_fmt (char *dest, mutt_FormatString (dest, destlen, col, elsestring, mutt_attach_fmt, data, 0); return (src); } - + static void pgp_entry (char *s, size_t l, MUTTMENU * menu, int num) { pgp_uid_t **KeyTable = (pgp_uid_t **) menu->data; pgp_entry_t entry; - + entry.uid = KeyTable[num]; entry.num = num + 1; @@ -390,7 +390,7 @@ static int pgp_key_is_valid (pgp_key_t k) return 0; if (pk->flags & KEYFLAG_CANTUSE) return 0; - + return 1; } @@ -422,21 +422,21 @@ static int pgp_id_is_valid (pgp_uid_t *uid) static int pgp_id_matches_addr (ADDRESS *addr, ADDRESS *u_addr, pgp_uid_t *uid) { int rv = 0; - + if (pgp_id_is_valid (uid)) rv |= PGP_KV_VALID; if (pgp_id_is_strong (uid)) rv |= PGP_KV_STRONGID; - + if (addr->mailbox && u_addr->mailbox && mutt_strcasecmp (addr->mailbox, u_addr->mailbox) == 0) rv |= PGP_KV_ADDR; - + if (addr->personal && u_addr->personal && mutt_strcasecmp (addr->personal, u_addr->personal) == 0) rv |= PGP_KV_STRING; - + return rv; } @@ -475,13 +475,13 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, unusable = 1; continue; } - + if (i == keymax) { keymax += 5; safe_realloc (&KeyTable, sizeof (pgp_uid_t *) * keymax); } - + KeyTable[i++] = a; } } @@ -522,10 +522,9 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, mutt_make_help (buf, sizeof (buf), _("Help"), MENU_PGP, OP_HELP); strcat (helpstr, buf); /* __STRCAT_CHECKED__ */ - menu = mutt_new_menu (); + menu = mutt_new_menu (MENU_PGP); menu->max = i; menu->make_entry = pgp_entry; - menu->menu = MENU_PGP; menu->help = helpstr; menu->data = KeyTable; @@ -533,14 +532,14 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, snprintf (buf, sizeof (buf), _("PGP keys matching <%s>."), p->mailbox); else snprintf (buf, sizeof (buf), _("PGP keys matching \"%s\"."), s); - - + + menu->title = buf; kp = NULL; mutt_clear_error (); - + while (!done) { switch (mutt_menuLoop (menu)) @@ -548,7 +547,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, case OP_VERIFY_KEY: - mutt_mktemp (tempfile); + mutt_mktemp (tempfile, sizeof (tempfile)); if ((devnull = fopen ("/dev/null", "w")) == NULL) /* __FOPEN_CHECKED__ */ { mutt_perror _("Can't open /dev/null"); @@ -556,7 +555,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, } if ((fp = safe_fopen (tempfile, "w")) == NULL) { - fclose (devnull); + safe_fclose (&devnull); mutt_perror _("Can't create temporary file"); break; } @@ -570,13 +569,13 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, { mutt_perror _("Can't create filter"); unlink (tempfile); - fclose (fp); - fclose (devnull); + safe_fclose (&fp); + safe_fclose (&devnull); } mutt_wait_filter (thepid); - fclose (fp); - fclose (devnull); + safe_fclose (&fp); + safe_fclose (&devnull); mutt_clear_error (); snprintf (cmd, sizeof (cmd), _("Key ID: 0x%s"), pgp_keyid (pgp_principal_key (KeyTable[menu->current]->parent))); @@ -594,14 +593,14 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, /* XXX make error reporting more verbose */ - + if (option (OPTPGPCHECKTRUST)) if (!pgp_key_is_valid (KeyTable[menu->current]->parent)) { mutt_error _("This key can't be used: expired/disabled/revoked."); break; } - + if (option (OPTPGPCHECKTRUST) && (!pgp_id_is_valid (KeyTable[menu->current]) || !pgp_id_is_strong (KeyTable[menu->current]))) @@ -654,7 +653,7 @@ static pgp_key_t pgp_select_key (pgp_key_t keys, FREE (&KeyTable); set_option (OPTNEEDREDRAW); - + return (kp); } @@ -666,7 +665,7 @@ pgp_key_t pgp_ask_for_key (char *tag, char *whatfor, struct pgp_cache *l = NULL; mutt_clear_error (); - + resp[0] = 0; if (whatfor) { @@ -728,10 +727,10 @@ BODY *pgp_make_key_attachment (char *tempf) snprintf (tmp, sizeof (tmp), "0x%s", pgp_keyid (pgp_principal_key (key))); pgp_free_key (&key); - + if (!tempf) { - mutt_mktemp (tempfb); + mutt_mktemp (tempfb, sizeof (tempfb)); tempf = tempfb; } @@ -744,7 +743,7 @@ BODY *pgp_make_key_attachment (char *tempf) if ((devnull = fopen ("/dev/null", "w")) == NULL) /* __FOPEN_CHECKED__ */ { mutt_perror _("Can't open /dev/null"); - fclose (tempfp); + safe_fclose (&tempfp); if (tempf == tempfb) unlink (tempf); return NULL; @@ -752,22 +751,22 @@ BODY *pgp_make_key_attachment (char *tempf) mutt_message _("Invoking PGP..."); - + if ((thepid = pgp_invoke_export (NULL, NULL, NULL, -1, fileno (tempfp), fileno (devnull), tmp)) == -1) { mutt_perror _("Can't create filter"); unlink (tempf); - fclose (tempfp); - fclose (devnull); + safe_fclose (&tempfp); + safe_fclose (&devnull); return NULL; } mutt_wait_filter (thepid); - fclose (tempfp); - fclose (devnull); + safe_fclose (&tempfp); + safe_fclose (&devnull); att = mutt_new_body (); att->filename = safe_strdup (tempf); @@ -818,12 +817,7 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) ADDRESS *r, *p; LIST *hints = NULL; - int weak = 0; - int invalid = 0; int multi = 0; - int this_key_has_strong; - int this_key_has_weak; - int this_key_has_invalid; int match; pgp_key_t keys, k, kn; @@ -831,7 +825,7 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) pgp_key_t matches = NULL; pgp_key_t *last = &matches; pgp_uid_t *q; - + if (a && a->mailbox) hints = pgp_add_string_to_hints (hints, a->mailbox); if (a && a->personal) @@ -841,10 +835,10 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) keys = pgp_get_candidates (keyring, hints); mutt_free_list (&hints); - + if (!keys) return NULL; - + dprint (5, (debugfile, "pgp_getkeybyaddr: looking for %s <%s>.", a->personal, a->mailbox)); @@ -863,9 +857,6 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) continue; } - this_key_has_weak = 0; /* weak but valid match */ - this_key_has_invalid = 0; /* invalid match */ - this_key_has_strong = 0; /* strong and valid match */ match = 0; /* any match */ for (q = k->address; q; q = q->next) @@ -886,23 +877,12 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) if (the_valid_key && the_valid_key != k) multi = 1; the_valid_key = k; - this_key_has_strong = 1; } - else if ((validity & PGP_KV_MATCH) && !(validity & PGP_KV_VALID)) - this_key_has_invalid = 1; - else if ((validity & PGP_KV_MATCH) - && (!(validity & PGP_KV_STRONGID) || !(validity & PGP_KV_ADDR))) - this_key_has_weak = 1; } rfc822_free_address (&r); } - if (match && !this_key_has_strong && this_key_has_invalid) - invalid = 1; - if (match && !this_key_has_strong && this_key_has_weak) - weak = 1; - if (match) { *last = pgp_principal_key (k); @@ -912,11 +892,10 @@ pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) } pgp_free_key (&keys); - + if (matches) { - if (the_valid_key && !multi /* && !weak - && !(invalid && option (OPTPGPSHOWUNUSABLE)) */) + if (the_valid_key && !multi) { /* * There was precisely one strong match on a valid ID. @@ -952,17 +931,20 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) pgp_key_t k, kn; pgp_uid_t *a; short match; + size_t l; + + if ((l = mutt_strlen (p)) && p[l-1] == '!') + p[l-1] = 0; mutt_message (_("Looking for keys matching \"%s\"..."), p); - + hints = pgp_add_string_to_hints (hints, p); keys = pgp_get_candidates (keyring, hints); mutt_free_list (&hints); if (!keys) - return NULL; - - + goto out; + for (k = keys; k; k = kn) { kn = k->next; @@ -970,7 +952,7 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) continue; match = 0; - + for (a = k->address; a; a = a->next) { dprint (5, (debugfile, "pgp_getkeybystr: matching \"%s\" against key %s, \"%s\": ", @@ -986,7 +968,7 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) break; } } - + if (match) { *last = pgp_principal_key (k); @@ -1001,14 +983,17 @@ pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) { if ((k = pgp_select_key (matches, NULL, p))) pgp_remove_key (&matches, k); - + pgp_free_key (&matches); + if (!p[l-1]) + p[l-1] = '!'; return k; } +out: + if (!p[l-1]) + p[l-1] = '!'; return NULL; } - - #endif /* CRYPT_BACKEND_CLASSIC_PGP */