]> granicus.if.org Git - neomutt/commitdiff
Make mutt compatible with GnuPG's latest features. As requested by
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 28 Mar 2001 14:38:11 +0000 (14:38 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 28 Mar 2001 14:38:11 +0000 (14:38 +0000)
Werner Koch.

gnupgparse.c
pgpkey.c
pgplib.c
pgplib.h
pgppacket.c

index 407ace65e88b04565ac356de7131a6907df5f5aa..a7263b83927a97db5e1abd40b27bf0ba7d735173 100644 (file)
@@ -119,6 +119,7 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k)
   int field = 0, is_uid = 0;
   char *pend, *p;
   int trust = 0;
+  int flags = 0;
 
   *is_subkey = 0;
   if (!*buf)
@@ -160,19 +161,18 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k)
       }
       case 2:                  /* trust info */
       {
-
        dprint (2, (debugfile, "trust info: %s\n", p));
        
        switch (*p)
        {                               /* look only at the first letter */
          case 'e':
-           k->flags |= KEYFLAG_EXPIRED;
+           flags |= KEYFLAG_EXPIRED;
            break;
          case 'r':
-           k->flags |= KEYFLAG_REVOKED;
+           flags |= KEYFLAG_REVOKED;
            break;
          case 'd':
-           k->flags |= KEYFLAG_DISABLED;
+           flags |= KEYFLAG_DISABLED;
            break;
          case 'n':
            trust = 1;
@@ -187,6 +187,10 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k)
            trust = 3;
            break;
        }
+
+        if (!is_uid && !(*is_subkey && option (OPTPGPIGNORESUB)))
+         k->flags |= flags;
+
        break;
       }
       case 3:                  /* key length  */
@@ -263,6 +267,7 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k)
        fix_uid (p);
        uid->addr = safe_strdup (p);
        uid->trust = trust;
+       uid->flags |= flags;
        uid->parent = k;
        uid->next = k->address;
        k->address = uid;
@@ -276,6 +281,8 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k)
       }
       case 11:                 /* signature class  */
         break;
+      case 12:                 /* key capabilities */
+        break;
       default:
         break;
     }
@@ -341,6 +348,7 @@ pgp_key_t *pgp_get_candidates (pgp_ring_t keyring, LIST * hints)
   mutt_wait_filter (thepid);
 
   close (devnull);
+  
   return db;
 }
 
index b8aab925f6d59aee32e72518ed33517c78372109..838ed7b8578996e80608c197fac35b89074956d6 100644 (file)
--- a/pgpkey.c
+++ b/pgpkey.c
@@ -129,7 +129,7 @@ static const char *pgp_entry_fmt (char *dest,
   pgp_entry_t *entry;
   pgp_uid_t *uid;
   pgp_key_t *key, *pkey;
-  int kflags;
+  int kflags = 0;
   int optional = (flags & M_FORMAT_OPTIONAL);
 
   entry = (pgp_entry_t *) data;
@@ -138,13 +138,10 @@ static const char *pgp_entry_fmt (char *dest,
   pkey  = pgp_principal_key (key);
 
   if (isupper (op))
-  {
     key = pkey;
-    kflags = pkey->flags;
-  }
-  else
-    /* a subkey inherits the principal key's usage restrictions. */
-    kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS);
+
+  kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS)
+    | uid->flags;
   
   switch (tolower (op))
   {
@@ -304,8 +301,8 @@ static int _pgp_compare_address (const void *a, const void *b)
   if ((r = mutt_strcasecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
   else
-    return (mutt_strcasecmp (pgp_keyid ((*s)->parent),
-                            pgp_keyid ((*t)->parent)) > 0);
+    return (mutt_strcasecmp (_pgp_keyid ((*s)->parent),
+                            _pgp_keyid ((*t)->parent)) > 0);
 }
 
 static int pgp_compare_address (const void *a, const void *b)
@@ -323,8 +320,8 @@ static int _pgp_compare_keyid (const void *a, const void *b)
   pgp_uid_t **s = (pgp_uid_t **) a;
   pgp_uid_t **t = (pgp_uid_t **) b;
 
-  if ((r = mutt_strcasecmp (pgp_keyid ((*s)->parent), 
-                           pgp_keyid ((*t)->parent))))
+  if ((r = mutt_strcasecmp (_pgp_keyid ((*s)->parent), 
+                           _pgp_keyid ((*t)->parent))))
     return r > 0;
   else
     return (mutt_strcasecmp ((*s)->addr, (*t)->addr)) > 0;
@@ -371,8 +368,8 @@ static int _pgp_compare_trust (const void *a, const void *b)
     return r < 0;
   if ((r = mutt_strcasecmp ((*s)->addr, (*t)->addr)))
     return r > 0;
-  return (mutt_strcasecmp (pgp_keyid ((*s)->parent), 
-                          pgp_keyid ((*t)->parent))) > 0;
+  return (mutt_strcasecmp (_pgp_keyid ((*s)->parent), 
+                          _pgp_keyid ((*t)->parent))) > 0;
 }
 
 static int pgp_compare_trust (const void *a, const void *b)
@@ -381,6 +378,47 @@ static int pgp_compare_trust (const void *a, const void *b)
                                       : _pgp_compare_trust (a, b));
 }
 
+static int pgp_id_is_valid (pgp_uid_t *uid)
+{
+  pgp_key_t *pk = pgp_principal_key (uid->parent);
+
+  if (uid->parent->flags & KEYFLAG_CANTUSE)
+    return 0;
+  if (pk->flags & KEYFLAG_CANTUSE)
+    return 0;
+  if (uid->flags & KEYFLAG_CANTUSE)
+    return 0;
+  if ((uid->trust & 0x03) < 3)
+    return 0;
+  /* else */
+  return 1;
+}
+
+
+#define PGP_KV_VALID  1
+#define PGP_KV_ADDR   2
+#define PGP_KV_STRING 4
+
+#define PGP_KV_MATCH (PGP_KV_ADDR|PGP_KV_STRING)
+
+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 (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;
+}
+
 static pgp_key_t *pgp_select_key (pgp_key_t *keys,
                                  ADDRESS * p, const char *s)
 {
@@ -396,28 +434,27 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys,
   pgp_uid_t *a;
   int (*f) (const void *, const void *);
 
-  for (i = 0, kp = keys; kp; kp = kp->next)
-  {
-    if (!option (OPTPGPSHOWUNUSABLE) && (kp->flags & KEYFLAG_CANTUSE))
-      continue;
-    
-    for (a = kp->address; a; i++, a = a->next)
-      ;
-  }
-
-  if (i == 0)
-    return NULL;
-
-  keymax = i;
-  KeyTable = safe_malloc (sizeof (pgp_key_t *) * i);
+  keymax = 5;
+  KeyTable = safe_malloc (sizeof (pgp_key_t *) * keymax);
 
   for (i = 0, kp = keys; kp; kp = kp->next)
   {
     if (!option (OPTPGPSHOWUNUSABLE) && (kp->flags & KEYFLAG_CANTUSE))
       continue;
        
-    for (a = kp->address; a; i++, a = a->next)
-      KeyTable[i] = a;
+    for (a = kp->address; a; a = a->next)
+    {
+      if (!option (OPTPGPSHOWUNUSABLE) && (a->flags & KEYFLAG_CANTUSE))
+       continue;
+      
+      if (i == keymax)
+      {
+       keymax += 5;
+       safe_realloc ((void **) &KeyTable, sizeof (pgp_key_t *) * keymax);
+      }
+      
+      KeyTable[i++] = a;
+    }
   }
 
   switch (PgpSortKeys & SORT_MASK)
@@ -450,7 +487,7 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys,
   strcat (helpstr, buf);       /* __STRCAT_CHECKED__ */
 
   menu = mutt_new_menu ();
-  menu->max = keymax;
+  menu->max = i;
   menu->make_entry = pgp_entry;
   menu->menu = MENU_PGP;
   menu->help = helpstr;
@@ -537,25 +574,27 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys,
       }
       
       if (option (OPTPGPCHECKTRUST) &&
-         (KeyTable[menu->current]->trust & 0x03) < 3)
+         !pgp_id_is_valid (KeyTable[menu->current]))
       {
        char *s = "";
        char buff[LONG_STRING];
-
-       switch (KeyTable[menu->current]->trust & 0x03)
+       
+       if (KeyTable[menu->current]->flags & KEYFLAG_CANTUSE)
+         s = N_("This ID is expired/disabled/revoked");
+       else switch (KeyTable[menu->current]->trust & 0x03)
        {
-       case 0:
-         s = N_("This ID's trust level is undefined.");
-         break;
-       case 1:
-         s = N_("This ID is not trusted.");
-         break;
-       case 2:
-         s = N_("This ID is only marginally trusted.");
-         break;
+         case 0:
+           s = N_("This ID's trust level is undefined.");
+           break;
+         case 1:
+           s = N_("This ID is not trusted.");
+           break;
+         case 2:
+           s = N_("This ID is only marginally trusted.");
+           break;
        }
 
-       snprintf (buff, sizeof (buff), _("%s Do you really want to use it?"),
+       snprintf (buff, sizeof (buff), _("%s Do you really want to use the key?"),
                  _(s));
 
        if (mutt_yesorno (buff, 0) != 1)
@@ -739,12 +778,12 @@ pgp_key_t *pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring)
   ADDRESS *r, *p;
   LIST *hints = NULL;
   int weak = 0;
-  int weak_association, kflags;
+  int weak_association;
   int match;
-  pgp_uid_t *q;
-  pgp_key_t *keys, *k, *kn, *pk;
+  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);
@@ -777,41 +816,27 @@ pgp_key_t *pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring)
       continue;
     }
 
-    pk = pgp_principal_key (k);
-    kflags = k->flags | pk->flags;
-    
-    q = k->address;
     weak_association = 1;
     match = 0;
 
-    for (; q; q = q->next)
+    for (q = k->address; q; q = q->next)
     {
       r = rfc822_parse_adrlist (NULL, q->addr);
 
-
       for (p = r; p && weak_association; p = p->next)
       {
-       if ((p->mailbox && a->mailbox &&
-            mutt_strcasecmp (p->mailbox, a->mailbox) == 0) ||
-           (a->personal && p->personal &&
-            mutt_strcasecmp (a->personal, p->personal) == 0))
-       {
+       int validity = pgp_id_matches_addr (a, p, q);
+       if (validity & PGP_KV_MATCH)
          match = 1;
-
-         if (((q->trust & 0x03) == 3) &&
-             (!(kflags & KEYFLAG_CANTUSE)) &&
-             (p->mailbox && a->mailbox &&
-              !mutt_strcasecmp (p->mailbox, a->mailbox)))
-         {
-           weak_association = 0;
-         }
-       }
+       if ((validity & PGP_KV_ADDR) && (validity & PGP_KV_VALID))
+         weak_association = 0;
       }
+
       rfc822_free_address (&r);
     }
 
     if (match && weak_association)
-       weak = 1;
+      weak = 1;
     
     if (match)
     {
index dc1fca0f05c1f0d21cd81b17810f1a7a54f241e4..ec7af9b97706c9a17cc3f60e7d543f040e37a46a 100644 (file)
--- a/pgplib.c
+++ b/pgplib.c
@@ -141,6 +141,7 @@ pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t *parent)
   {
     *lp = safe_calloc (1, sizeof (pgp_uid_t));
     (*lp)->trust  = up->trust;
+    (*lp)->flags  = up->flags;
     (*lp)->addr   = safe_strdup (up->addr);
     (*lp)->parent = parent;
     lp = &(*lp)->next;
index 55ce4050cd7a0eeaeaf1209bff81f2cdc9443baa..b89b951f820faf3895f996476361078a5488851a 100644 (file)
--- a/pgplib.h
+++ b/pgplib.h
@@ -58,6 +58,7 @@ typedef struct pgp_uid
 {
   char *addr;
   short trust;
+  int flags;
   struct pgp_keyinfo *parent;
   struct pgp_uid *next;
 }
index 1e6b8576538f94baabf880a66ccfb04087c045b0..caec05c3de25e74f8bf40ea72cf316f2b98f76ba 100644 (file)
@@ -220,6 +220,6 @@ bail:
 void pgp_release_packet (void)
 {
   plen = 0;
-  safe_free (&pbuf);
+  safe_free ((void **) &pbuf);
 }