See ChangeLog: Mon Sep 6 19:59:08 CEST 1999 Werner Koch
[gnupg.git] / g10 / pkclist.c
index 6dff742..fab2f13 100644 (file)
@@ -68,6 +68,33 @@ print_fpr( PKT_public_key *pk )
     tty_printf("\n");
 }
 
+static void
+fpr_info( PKT_public_key *pk )
+{
+    byte array[MAX_FINGERPRINT_LEN], *p;
+    size_t i, n;
+    FILE *fp = log_stream();
+
+    fingerprint_from_pk( pk, array, &n );
+    p = array;
+    log_info(_("Fingerprint:"));
+    if( n == 20 ) {
+       for(i=0; i < n ; i++, i++, p += 2 ) {
+           if( i == 10 )
+               putc(' ', fp);
+           fprintf(fp, " %02X%02X", *p, p[1] );
+       }
+    }
+    else {
+       for(i=0; i < n ; i++, p++ ) {
+           if( i && !(i%8) )
+               putc(' ', fp);
+           fprintf(fp, " %02X", *p );
+       }
+    }
+    putc('\n', fp );
+}
+
 
 
 static void
@@ -453,7 +480,8 @@ do_we_trust_pre( PKT_public_key *pk, int trustlevel )
         */
     }
     else if( opt.always_trust && !rc ) {
-       log_info(_("WARNING: Using untrusted key!\n"));
+       if( !opt.quiet )
+           log_info(_("WARNING: Using untrusted key!\n"));
        rc = 1;
     }
     return rc;
@@ -475,7 +503,8 @@ check_signatures_trust( PKT_signature *sig )
 
 
     if( opt.always_trust ) {
-       log_info(_("WARNING: Using untrusted key!\n"));
+       if( !opt.quiet )
+           log_info(_("WARNING: Using untrusted key!\n"));
        return 0;
     }
 
@@ -523,6 +552,7 @@ check_signatures_trust( PKT_signature *sig )
 
       case TRUST_EXPIRED:
        log_info(_("Note: This key has expired!\n"));
+       fpr_info( pk );
        break;
 
       case TRUST_UNDEFINED:
@@ -533,6 +563,7 @@ check_signatures_trust( PKT_signature *sig )
            log_info(_(
            "         There is no indication that the "
                                    "signature belongs to the owner.\n" ));
+           fpr_info( pk );
        }
        else {
            int quit;
@@ -560,6 +591,7 @@ check_signatures_trust( PKT_signature *sig )
        log_info(_(
         "         It is not certain that the signature belongs to the owner.\n"
                 ));
+       fpr_info( pk );
        break;
 
       case TRUST_FULLY:
@@ -719,11 +751,18 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
                tty_printf(_("No such user ID.\n"));
            else if( !(rc=check_pubkey_algo2(pk->pubkey_algo, use)) ) {
                if( have_def_rec ) {
-                   PK_LIST r = m_alloc( sizeof *r );
-                   r->pk = pk; pk = NULL;
-                   r->next = pk_list;
-                   r->mark = 0;
-                   pk_list = r;
+                   if (key_present_in_pk_list(pk_list, pk) == 0) {
+                       free_public_key(pk); pk = NULL;
+                       log_info(_("skipped: public key "
+                                  "already set as default recipient\n") );
+                   }
+                   else {
+                       PK_LIST r = m_alloc( sizeof *r );
+                       r->pk = pk; pk = NULL;
+                       r->next = pk_list;
+                       r->mark = 0;
+                       pk_list = r;
+                   }
                    any_recipients = 1;
                    break;
                }
@@ -739,13 +778,22 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
                        tty_printf(_("Public key is disabled.\n") );
                    }
                    else if( do_we_trust_pre( pk, trustlevel ) ) {
-                       PK_LIST r;
-
-                       r = m_alloc( sizeof *r );
-                       r->pk = pk; pk = NULL;
-                       r->next = pk_list;
-                       r->mark = 0;
-                       pk_list = r;
+                       /* Skip the actual key if the key is already present
+                        * in the list */
+                       if (key_present_in_pk_list(pk_list, pk) == 0) {
+                           free_public_key(pk); pk = NULL;
+                           log_info(_("skipped: public key "
+                                      "already set with --encrypt-to\n") );
+                       }
+                       else {
+                           PK_LIST r;
+
+                           r = m_alloc( sizeof *r );
+                           r->pk = pk; pk = NULL;
+                           r->next = pk_list;
+                           r->mark = 0;
+                           pk_list = r;
+                       }
                        any_recipients = 1;
                        break;
                    }
@@ -765,7 +813,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
        pk->pubkey_usage = use;
        rc = get_pubkey_byname( NULL, pk, def_rec, NULL );
        if( rc )
-           log_error(_("unknown default recipient `s'\n"), def_rec );
+           log_error(_("unknown default recipient `%s'\n"), def_rec );
        else if( !(rc=check_pubkey_algo2(pk->pubkey_algo, use)) ) {
            PK_LIST r = m_alloc( sizeof *r );
            r->pk = pk; pk = NULL;