Imported Upstream version 2.1.13
[platform/upstream/gpg2.git] / g10 / trust.c
index c8a1c2c..8790754 100644 (file)
@@ -23,7 +23,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <assert.h>
 
 #include "gpg.h"
 #include "keydb.h"
@@ -33,6 +32,7 @@
 #include "main.h"
 #include "i18n.h"
 #include "trustdb.h"
+#include "host2net.h"
 
 
 /* Return true if key is disabled.  Note that this is usually used via
@@ -131,7 +131,7 @@ string_to_trust_value (const char *str)
 
 
 const char *
-uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid)
+uid_trust_string_fixed (ctrl_t ctrl, PKT_public_key *key, PKT_user_id *uid)
 {
   if (!key && !uid)
     {
@@ -151,11 +151,12 @@ uid_trust_string_fixed (PKT_public_key *key, PKT_user_id *uid)
     return                         _("[ expired]");
   else if(key)
     {
-      switch (get_validity(key,uid)&TRUST_MASK)
+      switch (get_validity (ctrl, key, uid, NULL, 0) & TRUST_MASK)
         {
         case TRUST_UNKNOWN:   return _("[ unknown]");
         case TRUST_EXPIRED:   return _("[ expired]");
         case TRUST_UNDEFINED: return _("[  undef ]");
+        case TRUST_NEVER:     return _("[  never ]");
         case TRUST_MARGINAL:  return _("[marginal]");
         case TRUST_FULLY:     return _("[  full  ]");
         case TRUST_ULTIMATE:  return _("[ultimate]");
@@ -274,30 +275,35 @@ revalidation_mark (void)
 
 
 void
-check_trustdb_stale (void)
+check_trustdb_stale (ctrl_t ctrl)
 {
 #ifndef NO_TRUST_MODELS
-  tdb_check_trustdb_stale ();
+  tdb_check_trustdb_stale (ctrl);
+#else
+  (void)ctrl;
 #endif
 }
 
 
 void
-check_or_update_trustdb (void)
+check_or_update_trustdb (ctrl_t ctrl)
 {
 #ifndef NO_TRUST_MODELS
-  tdb_check_or_update ();
+  tdb_check_or_update (ctrl);
+#else
+  (void)ctrl;
 #endif
 }
 
 
 /*
  * Return the validity information for PK.  If the namehash is not
- * NULL, the validity of the corresponsing user ID is returned,
+ * NULL, the validity of the corresponding user ID is returned,
  * otherwise, a reasonable value for the entire key is returned.
  */
 unsigned int
-get_validity (PKT_public_key *pk, PKT_user_id *uid)
+get_validity (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *uid,
+              PKT_signature *sig, int may_ask)
 {
   int rc;
   unsigned int validity;
@@ -317,7 +323,7 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid)
         {
          char *tempkeystr = xstrdup (keystr (pk->main_keyid));
           log_error ("error getting main key %s of subkey %s: %s\n",
-                     tempkeystr, keystr (kid), g10_errstr (rc));
+                     tempkeystr, keystr (kid), gpg_strerror (rc));
          xfree (tempkeystr);
           validity = TRUST_UNKNOWN;
           goto leave;
@@ -329,7 +335,7 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid)
 #ifdef NO_TRUST_MODELS
   validity = TRUST_UNKNOWN;
 #else
-  validity = tdb_get_validity_core (pk, uid, main_pk);
+  validity = tdb_get_validity_core (ctrl, pk, uid, main_pk, sig, may_ask);
 #endif
 
  leave:
@@ -351,14 +357,14 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid)
 
 
 int
-get_validity_info (PKT_public_key *pk, PKT_user_id *uid)
+get_validity_info (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *uid)
 {
   int trustlevel;
 
   if (!pk)
     return '?';  /* Just in case a NULL PK is passed.  */
 
-  trustlevel = get_validity (pk, uid);
+  trustlevel = get_validity (ctrl, pk, uid, NULL, 0);
   if ((trustlevel & TRUST_FLAG_REVOKED))
     return 'r';
   return trust_letter (trustlevel);
@@ -366,14 +372,14 @@ get_validity_info (PKT_public_key *pk, PKT_user_id *uid)
 
 
 const char *
-get_validity_string (PKT_public_key *pk, PKT_user_id *uid)
+get_validity_string (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *uid)
 {
   int trustlevel;
 
   if (!pk)
     return "err";  /* Just in case a NULL PK is passed.  */
 
-  trustlevel = get_validity (pk, uid);
+  trustlevel = get_validity (ctrl, pk, uid, NULL, 0);
   if ((trustlevel & TRUST_FLAG_REVOKED))
     return _("revoked");
   return trust_value_to_string (trustlevel);
@@ -536,7 +542,7 @@ mark_usable_uid_certs (kbnode_t keyblock, kbnode_t uidnode,
           u32 expire;
 
           p = parse_sig_subpkt (sig->hashed, SIGSUBPKT_SIG_EXPIRE, NULL );
-          expire = p? sig->timestamp + buffer_to_u32(p) : 0;
+          expire = p? sig->timestamp + buf32_to_u32(p) : 0;
 
           if (expire==0 || expire > curtime )
             {
@@ -559,7 +565,7 @@ clean_sigs_from_uid (kbnode_t keyblock, kbnode_t uidnode,
   kbnode_t node;
   u32 keyid[2];
 
-  assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
+  log_assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
 
   keyid_from_pk (keyblock->pkt->pkt.public_key, keyid);
 
@@ -639,7 +645,7 @@ clean_sigs_from_uid (kbnode_t keyblock, kbnode_t uidnode,
    compacted.  To "compact" a user ID, we simply remove ALL signatures
    except the self-sig that caused the user ID to be remove-worthy.
    We don't actually remove the user ID packet itself since it might
-   be ressurected in a later merge.  Note that this function requires
+   be resurrected in a later merge.  Note that this function requires
    that the caller has already done a merge_keys_and_selfsig().
 
    TODO: change the import code to allow importing a uid with only a
@@ -652,8 +658,8 @@ clean_uid_from_key (kbnode_t keyblock, kbnode_t uidnode, int noisy)
   PKT_user_id *uid = uidnode->pkt->pkt.user_id;
   int deleted = 0;
 
-  assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
-  assert (uidnode->pkt->pkttype==PKT_USER_ID);
+  log_assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
+  log_assert (uidnode->pkt->pkttype==PKT_USER_ID);
 
   /* Skip valid user IDs, compacted user IDs, and non-self-signed user
      IDs if --allow-non-selfsigned-uid is set. */
@@ -702,10 +708,10 @@ void
 clean_one_uid (kbnode_t keyblock, kbnode_t uidnode, int noisy, int self_only,
                int *uids_cleaned, int *sigs_cleaned)
 {
-  int dummy;
+  int dummy = 0;
 
-  assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
-  assert (uidnode->pkt->pkttype==PKT_USER_ID);
+  log_assert (keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
+  log_assert (uidnode->pkt->pkttype==PKT_USER_ID);
 
   if (!uids_cleaned)
     uids_cleaned = &dummy;