/*
- * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
- * Copyright (c) 1998,1999 Thomas Roessler <roessler@does-not-exist.org>
+ * Copyright (C) 1996-7,2007 Michael R. Elkins <me@mutt.org>
+ * Copyright (c) 1998-2003 Thomas Roessler <roessler@does-not-exist.org>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General Public
kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS)
| uid->flags;
-
+
switch (ascii_tolower (op))
{
case '[':
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;
return 0;
if (pk->flags & KEYFLAG_CANTUSE)
return 0;
-
+
return 1;
}
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;
}
unusable = 1;
continue;
}
-
+
if (i == keymax)
{
keymax += 5;
safe_realloc (&KeyTable, sizeof (pgp_uid_t *) * keymax);
}
-
+
KeyTable[i++] = a;
}
}
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;
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))
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");
}
if ((fp = safe_fopen (tempfile, "w")) == NULL)
{
- fclose (devnull);
+ safe_fclose (&devnull);
mutt_perror _("Can't create temporary file");
break;
}
{
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)));
/* 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])))
FREE (&KeyTable);
set_option (OPTNEEDREDRAW);
-
+
return (kp);
}
struct pgp_cache *l = NULL;
mutt_clear_error ();
-
+
resp[0] = 0;
if (whatfor)
{
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;
}
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;
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);
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;
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)
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));
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)
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);
}
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.
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;
continue;
match = 0;
-
+
for (a = k->address; a; a = a->next)
{
dprint (5, (debugfile, "pgp_getkeybystr: matching \"%s\" against key %s, \"%s\": ",
break;
}
}
-
+
if (match)
{
*last = pgp_principal_key (k);
{
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 */