* keydb.h, keyring.c (keyring_search), trustdb.c (search_skipfnc): Expand
authorDavid Shaw <dshaw@jabberwocky.com>
Tue, 23 Sep 2003 23:14:03 +0000 (23:14 +0000)
committerDavid Shaw <dshaw@jabberwocky.com>
Tue, 23 Sep 2003 23:14:03 +0000 (23:14 +0000)
the skipfnc to include a pointer to the user ID that matched.

* getkey.c (skip_disabled): Rename to skip_unusable, and add checks for
expired or revoked user IDs.

g10/ChangeLog
g10/getkey.c
g10/keydb.h
g10/keyring.c
g10/trustdb.c

index 6bf4c7d..fbbf81f 100644 (file)
@@ -1,3 +1,12 @@
+2003-09-23  David Shaw  <dshaw@jabberwocky.com>
+
+       * keydb.h, keyring.c (keyring_search), trustdb.c (search_skipfnc):
+       Expand the skipfnc to include a pointer to the user ID that
+       matched.
+
+       * getkey.c (skip_disabled): Rename to skip_unusable, and add
+       checks for expired or revoked user IDs.
+
 2003-09-22  David Shaw  <dshaw@jabberwocky.com>
 
        * g10.c (main): Deprecate --default-comment in favor of
index e2d2f34..5e4ca44 100644 (file)
@@ -726,24 +726,44 @@ classify_user_id( const char *name, KEYDB_SEARCH_DESC *desc )
 
 
 static int
-skip_disabled(void *dummy,u32 *keyid)
+skip_unusable(void *dummy,u32 *keyid,PKT_user_id *uid)
 {
-  int rc,disabled=0;
-  PKT_public_key *pk=m_alloc_clear(sizeof(PKT_public_key));
+  int unusable=0;
+  KBNODE keyblock;
 
-  rc = get_pubkey(pk, keyid);
-  if(rc)
+  keyblock=get_pubkeyblock(keyid);
+  if(!keyblock)
     {
-      log_error("error checking disabled status of %08lX: %s\n",
-               (ulong)keyid[1],g10_errstr(rc));
+      log_error("error checking usability status of %08lX\n",(ulong)keyid[1]);
       goto leave;
     }
-  disabled=pk_is_disabled(pk);
+
+  /* Is the user ID in question revoked/expired? */
+  if(uid)
+    {
+      KBNODE node;
+
+      for(node=keyblock;node;node=node->next)
+       {
+         if(node->pkt->pkttype==PKT_USER_ID)
+           {
+             if(cmp_user_ids(uid,node->pkt->pkt.user_id)==0
+                && (node->pkt->pkt.user_id->is_revoked
+                    || node->pkt->pkt.user_id->is_expired))
+               {
+                 unusable=1;
+                 break;
+               }
+           }
+       }
+    }
+
+  if(!unusable)
+    unusable=pk_is_disabled(keyblock->pkt->pkt.public_key);
 
  leave:
-  free_public_key(pk);
-  return disabled;
+  release_kbnode(keyblock);
+  return unusable;
 }
 
 /****************
@@ -758,7 +778,7 @@ skip_disabled(void *dummy,u32 *keyid)
 static int
 key_byname( GETKEY_CTX *retctx, STRLIST namelist,
            PKT_public_key *pk, PKT_secret_key *sk,
-           int secmode, int include_disabled,
+           int secmode, int include_unusable,
             KBNODE *ret_kb, KEYDB_HANDLE *ret_kdbhd )
 {
     int rc = 0;
@@ -790,13 +810,13 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
            m_free (ctx);
            return G10ERR_INV_USER_ID;
        }
-       if(!include_disabled
+       if(!include_unusable
           && ctx->items[n].mode!=KEYDB_SEARCH_MODE_SHORT_KID
           && ctx->items[n].mode!=KEYDB_SEARCH_MODE_LONG_KID
           && ctx->items[n].mode!=KEYDB_SEARCH_MODE_FPR16
           && ctx->items[n].mode!=KEYDB_SEARCH_MODE_FPR20
           && ctx->items[n].mode!=KEYDB_SEARCH_MODE_FPR)
-         ctx->items[n].skipfnc=skip_disabled;
+         ctx->items[n].skipfnc=skip_unusable;
     }
 
     ctx->kr_handle = keydb_new (secmode);
@@ -847,14 +867,14 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
 int
 get_pubkey_byname (PKT_public_key *pk,
                   const char *name, KBNODE *ret_keyblock,
-                   KEYDB_HANDLE *ret_kdbhd, int include_disabled ) 
+                   KEYDB_HANDLE *ret_kdbhd, int include_unusable )
 {
     int rc;
     STRLIST namelist = NULL;
 
     add_to_strlist( &namelist, name );
     rc = key_byname( NULL, namelist, pk, NULL, 0,
-                    include_disabled, ret_keyblock, ret_kdbhd);
+                    include_unusable, ret_keyblock, ret_kdbhd);
     free_strlist( namelist );
     return rc;
 }
index 7be5e7f..216add2 100644 (file)
@@ -131,7 +131,7 @@ typedef enum {
 
 struct keydb_search_desc {
     KeydbSearchMode mode;
-    int (*skipfnc)(void *,u32*);
+    int (*skipfnc)(void *,u32*,PKT_user_id*);
     void *skipfncvalue;
     union {
         const char *name;
@@ -201,7 +201,7 @@ int get_pubkey_fast ( PKT_public_key *pk, u32 *keyid );
 KBNODE get_pubkeyblock( u32 *keyid );
 int get_pubkey_byname( PKT_public_key *pk,  const char *name,
                        KBNODE *ret_keyblock, KEYDB_HANDLE *ret_kdbhd,
-                      int include_disabled );
+                      int include_unusable );
 int get_pubkey_bynames( GETKEY_CTX *rx, PKT_public_key *pk,
                        STRLIST names, KBNODE *ret_keyblock );
 int get_pubkey_next( GETKEY_CTX ctx, PKT_public_key *pk, KBNODE *ret_keyblock );
index a18cbba..8004e37 100644 (file)
@@ -1083,7 +1083,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
       for (n=any_skip?0:ndesc; n < ndesc; n++) 
         {
           if (desc[n].skipfnc
-              && desc[n].skipfnc (desc[n].skipfncvalue, aki))
+              && desc[n].skipfnc (desc[n].skipfncvalue, aki, uid))
             break;
         }
       if (n == ndesc)
index 289af8d..9e152a9 100644 (file)
@@ -1714,7 +1714,7 @@ validate_one_keyblock (KBNODE kb, struct key_item *klist,
 
 
 static int
-search_skipfnc (void *opaque, u32 *kid)
+search_skipfnc (void *opaque, u32 *kid, PKT_user_id *dummy)
 {
   return test_key_hash_table ((KeyHashTable)opaque, kid);
 }