~ubuntu-branches/ubuntu/oneiric/gnupg2/oneiric-updates

« back to all changes in this revision

Viewing changes to g10/trustdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* trustdb.c
2
 
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003
3
 
 *                                             Free Software Foundation, Inc.
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
 
3
 *               2007 Free Software Foundation, Inc.
4
4
 *
5
5
 * This file is part of GnuPG.
6
6
 *
7
7
 * GnuPG is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * the Free Software Foundation; either version 3 of the License, or
10
10
 * (at your option) any later version.
11
11
 *
12
12
 * GnuPG is distributed in the hope that it will be useful,
15
15
 * GNU General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program; if not, write to the Free Software
19
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
18
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20
19
 */
21
20
 
22
21
#include <config.h>
27
26
 
28
27
#ifndef DISABLE_REGEX
29
28
#include <sys/types.h>
30
 
#ifdef USE_GNU_REGEX
31
 
#include "_regex.h"
32
 
#else
33
29
#include <regex.h>
34
 
#endif
35
30
#endif /* !DISABLE_REGEX */
36
31
 
37
32
#include "gpg.h"
38
 
#include "errors.h"
 
33
#include "status.h"
39
34
#include "iobuf.h"
40
35
#include "keydb.h"
41
 
#include "memory.h"
42
36
#include "util.h"
43
37
#include "options.h"
44
38
#include "packet.h"
99
93
{
100
94
  struct key_item *k;
101
95
  
102
 
  k = xcalloc (1,sizeof *k);
 
96
  k = xmalloc_clear (sizeof *k);
103
97
  return k;
104
98
}
105
99
 
129
123
{
130
124
  struct key_item **tbl;
131
125
 
132
 
  tbl = xcalloc (1,1024 * sizeof *tbl);
 
126
  tbl = xmalloc_clear (1024 * sizeof *tbl);
133
127
  return tbl;
134
128
}
135
129
 
206
200
 * FIXME: Should be replaced by a function to add those keys to the trustdb.
207
201
 */
208
202
void
209
 
register_trusted_key( const char *string )
 
203
register_trusted_keyid(u32 *keyid)
210
204
{
211
 
  KEYDB_SEARCH_DESC desc;
212
205
  struct key_item *k;
213
206
 
214
 
  if (classify_user_id (string, &desc) != KEYDB_SEARCH_MODE_LONG_KID ) {
215
 
    log_error(_("`%s' is not a valid long keyID\n"), string );
216
 
    return;
217
 
  }
218
 
 
219
207
  k = new_key_item ();
220
 
  k->kid[0] = desc.u.kid[0];
221
 
  k->kid[1] = desc.u.kid[1];
 
208
  k->kid[0] = keyid[0];
 
209
  k->kid[1] = keyid[1];
222
210
  k->next = user_utk_list;
223
211
  user_utk_list = k;
224
212
}
225
213
 
 
214
void
 
215
register_trusted_key( const char *string )
 
216
{
 
217
  KEYDB_SEARCH_DESC desc;
 
218
 
 
219
  if (classify_user_id (string, &desc) != KEYDB_SEARCH_MODE_LONG_KID )
 
220
    {
 
221
      log_error(_("`%s' is not a valid long keyID\n"), string );
 
222
      return;
 
223
    }
 
224
 
 
225
  register_trusted_keyid(desc.u.kid);
 
226
}
 
227
 
226
228
/*
227
229
 * Helper to add a key to the global list of ultimately trusted keys.
228
230
 * Retruns: true = inserted, false = already in in list.
247
249
  k->next = utk_list;
248
250
  utk_list = k;
249
251
  if( opt.verbose > 1 )
250
 
    log_info(_("key %08lX: accepted as trusted key\n"), (ulong)kid[1]);
 
252
    log_info(_("key %s: accepted as trusted key\n"), keystr(kid));
251
253
  return 1;
252
254
}
253
255
 
285
287
            fprlen = (!fpr[16] && !fpr[17] && !fpr[18] && !fpr[19])? 16:20;
286
288
            keyid_from_fingerprint (fpr, fprlen, kid);
287
289
            if (!add_utk (kid))
288
 
                log_info(_("key %08lX occurs more than once in the trustdb\n"),
289
 
                            (ulong)kid[1]);
 
290
              log_info(_("key %s occurs more than once in the trustdb\n"),
 
291
                       keystr(kid));
290
292
        }
291
293
    }
292
294
 
299
301
 
300
302
          memset (&pk, 0, sizeof pk);
301
303
          rc = get_pubkey (&pk, k->kid);
302
 
          if (rc) {
303
 
            log_info(_("key %08lX: no public key for trusted key - skipped\n"),
304
 
                     (ulong)k->kid[1] );
305
 
          }
306
 
          else {
307
 
            update_ownertrust (&pk,
308
 
                               ((get_ownertrust (&pk) & ~TRUST_MASK)
309
 
                                | TRUST_ULTIMATE ));
310
 
            release_public_key_parts (&pk);
311
 
          }
312
 
          log_info (_("key %08lX marked as ultimately trusted\n"),
313
 
                    (ulong)k->kid[1]);
 
304
          if (rc)
 
305
            log_info(_("key %s: no public key for trusted key - skipped\n"),
 
306
                     keystr(k->kid));
 
307
          else
 
308
            {
 
309
              update_ownertrust (&pk,
 
310
                                 ((get_ownertrust (&pk) & ~TRUST_MASK)
 
311
                                  | TRUST_ULTIMATE ));
 
312
              release_public_key_parts (&pk);
 
313
            }
 
314
 
 
315
          log_info (_("key %s marked as ultimately trusted\n"),keystr(k->kid));
314
316
        }
315
317
    }
316
318
 
317
 
 
318
319
  /* release the helper table table */
319
320
  release_key_items (user_utk_list);
320
321
  user_utk_list = NULL;
336
337
  if (rc)
337
338
    {
338
339
      log_error(_("trust record %lu, req type %d: read failed: %s\n"),
339
 
                recno, rec->rectype, gpg_strerror (rc) );
 
340
                recno, rec->rectype, g10_errstr(rc) );
340
341
      tdbio_invalid();
341
342
    }
342
343
  if (rectype != rec->rectype)
357
358
  if (rc)
358
359
    {
359
360
      log_error(_("trust record %lu, type %d: write failed: %s\n"),
360
 
                            rec->recnum, rec->rectype, gpg_strerror (rc) );
 
361
                            rec->recnum, rec->rectype, g10_errstr(rc) );
361
362
      tdbio_invalid();
362
363
    }
363
364
}
371
372
    int rc = tdbio_sync ();
372
373
    if(rc)
373
374
      {
374
 
        log_error (_("trustdb: sync failed: %s\n"), gpg_strerror (rc) );
 
375
        log_error (_("trustdb: sync failed: %s\n"), g10_errstr(rc) );
375
376
        g10_exit(2);
376
377
      }
377
378
}
381
382
{
382
383
  switch(opt.trust_model)
383
384
    {
384
 
    case TM_PGP:     return "PGP";
385
 
    case TM_CLASSIC: return "classic";
386
 
    case TM_ALWAYS:  return "always";
387
 
    default:         return "unknown";
 
385
    case TM_CLASSIC:  return "classic";
 
386
    case TM_PGP:      return "PGP";
 
387
    case TM_EXTERNAL: return "external";
 
388
    case TM_ALWAYS:   return "always";
 
389
    case TM_DIRECT:   return "direct";
 
390
    default:          return "unknown";
388
391
    }
389
392
}
390
393
 
400
403
    if( trustdb_args.init )
401
404
        return 0;
402
405
    trustdb_args.level = level;
403
 
    trustdb_args.dbname = dbname? xstrdup (dbname): NULL;
 
406
    trustdb_args.dbname = dbname? xstrdup(dbname): NULL;
404
407
    return 0;
405
408
}
406
409
 
407
410
void
408
411
init_trustdb()
409
412
{
410
 
  int rc=0;
411
413
  int level = trustdb_args.level;
412
414
  const char* dbname = trustdb_args.dbname;
413
415
 
416
418
 
417
419
  trustdb_args.init = 1;
418
420
 
419
 
  if ( !level || level==1)
 
421
  if(level==0 || level==1)
420
422
    {
421
 
      rc = tdbio_set_dbname( dbname, !!level );
422
 
      if( !rc )
423
 
        {
424
 
          if( !level )
425
 
            return;
426
 
          
427
 
          /* verify that our own keys are in the trustDB
428
 
           * or move them to the trustdb. */
429
 
          verify_own_keys();
430
 
          
431
 
          /* should we check whether there is no other ultimately trusted
432
 
           * key in the database? */
433
 
        }
 
423
      int rc = tdbio_set_dbname( dbname, !!level );
 
424
      if( rc )
 
425
        log_fatal("can't init trustdb: %s\n", g10_errstr(rc) );
434
426
    }
435
427
  else
436
428
    BUG();
437
 
  if( rc )
438
 
    log_fatal("can't init trustdb: %s\n", gpg_strerror (rc) );
439
429
 
440
430
  if(opt.trust_model==TM_AUTO)
441
431
    {
444
434
      opt.trust_model=tdbio_read_model();
445
435
 
446
436
      /* Sanity check this ;) */
447
 
      if(opt.trust_model!=TM_PGP && opt.trust_model!=TM_CLASSIC)
 
437
      if(opt.trust_model!=TM_CLASSIC
 
438
         && opt.trust_model!=TM_PGP
 
439
         && opt.trust_model!=TM_EXTERNAL)
448
440
        {
449
441
          log_info(_("unable to use unknown trust model (%d) - "
450
442
                     "assuming %s trust model\n"),opt.trust_model,"PGP");
455
447
        log_info(_("using %s trust model\n"),trust_model_string());
456
448
    }
457
449
 
458
 
  if((opt.trust_model==TM_PGP || opt.trust_model==TM_CLASSIC)
459
 
     && !tdbio_db_matches_options())
460
 
    pending_check_trustdb=1;
 
450
  if(opt.trust_model==TM_PGP || opt.trust_model==TM_CLASSIC)
 
451
    {
 
452
      /* Verify the list of ultimately trusted keys and move the
 
453
         --trusted-keys list there as well. */
 
454
      if(level==1)
 
455
        verify_own_keys();
 
456
 
 
457
      if(!tdbio_db_matches_options())
 
458
        pending_check_trustdb=1;
 
459
    }
461
460
}
462
461
 
463
462
 
464
 
 
465
 
 
466
463
/***********************************************
467
464
 *************  Print helpers   ****************
468
465
 ***********************************************/
487
484
    }
488
485
}
489
486
 
 
487
/* NOTE TO TRANSLATOR: these strings are similar to those in
 
488
   trust_value_to_string(), but are a fixed length.  This is needed to
 
489
   make attractive information listings where columns line up
 
490
   properly.  The value "10" should be the length of the strings you
 
491
   choose to translate to.  This is the length in printable columns.
 
492
   It gets passed to atoi() so everything after the number is
 
493
   essentially a comment and need not be translated.  Either key and
 
494
   uid are both NULL, or neither are NULL. */
 
495
const char *
 
496
uid_trust_string_fixed(PKT_public_key *key,PKT_user_id *uid)
 
497
{
 
498
  if(!key && !uid)
 
499
    return _("10 translator see trustdb.c:uid_trust_string_fixed");
 
500
  else if(uid->is_revoked || (key && key->is_revoked))
 
501
    return                         _("[ revoked]");
 
502
  else if(uid->is_expired)
 
503
    return                         _("[ expired]");
 
504
  else if(key)
 
505
    switch(get_validity(key,uid)&TRUST_MASK)
 
506
      {
 
507
      case TRUST_UNKNOWN:   return _("[ unknown]");
 
508
      case TRUST_EXPIRED:   return _("[ expired]");
 
509
      case TRUST_UNDEFINED: return _("[  undef ]");
 
510
      case TRUST_MARGINAL:  return _("[marginal]");
 
511
      case TRUST_FULLY:     return _("[  full  ]");
 
512
      case TRUST_ULTIMATE:  return _("[ultimate]");
 
513
      }
 
514
 
 
515
  return "err";
 
516
}
 
517
 
490
518
/* The strings here are similar to those in
491
519
   pkclist.c:do_edit_ownertrust() */
492
520
const char *
555
583
      validate_keys (0);
556
584
    }
557
585
  else
558
 
    log_info (_("no need for a trustdb check with \"%s\" trust model\n"),
 
586
    log_info (_("no need for a trustdb check with `%s' trust model\n"),
559
587
              trust_model_string());
560
588
}
561
589
 
570
598
  if(opt.trust_model==TM_PGP || opt.trust_model==TM_CLASSIC)
571
599
    validate_keys (1);
572
600
  else
573
 
    log_info (_("no need for a trustdb update with \"%s\" trust model\n"),
 
601
    log_info (_("no need for a trustdb update with `%s' trust model\n"),
574
602
              trust_model_string());
575
603
}
576
604
 
591
619
  return pending_check_trustdb;
592
620
}
593
621
 
 
622
/* If the trustdb is dirty, and we're interactive, update it.
 
623
   Otherwise, check it unless no-auto-check-trustdb is set. */
 
624
void
 
625
trustdb_check_or_update(void)
 
626
{
 
627
  if(trustdb_pending_check())
 
628
    {
 
629
      if(opt.interactive)
 
630
        update_trustdb();
 
631
      else if(!opt.no_auto_check_trustdb)
 
632
        check_trustdb();
 
633
    }
 
634
}
 
635
 
594
636
void
595
637
read_trust_options(byte *trust_model,ulong *created,ulong *nextcheck,
596
638
                   byte *marginals,byte *completes,byte *cert_depth)
615
657
    *cert_depth=opts.r.ver.cert_depth;
616
658
}
617
659
 
618
 
 
619
 
 
620
660
/***********************************************
621
661
 ***********  Ownertrust et al. ****************
622
662
 ***********************************************/
633
673
  if (rc) 
634
674
    {
635
675
      log_error ("trustdb: searching trust record failed: %s\n",
636
 
                 gpg_strerror (rc));
 
676
                 g10_errstr (rc));
637
677
      return rc; 
638
678
    }
639
679
      
641
681
    {
642
682
      log_error ("trustdb: record %lu is not a trust record\n",
643
683
                 rec->recnum);
644
 
      return GPG_ERR_TRUSTDB; 
 
684
      return G10ERR_TRUSTDB; 
645
685
    }      
646
686
  
647
687
  return 0;
786
826
  TRUSTREC rec;
787
827
  int rc;
788
828
 
789
 
  pk = xcalloc (1,sizeof *pk);
 
829
  pk = xmalloc_clear (sizeof *pk);
790
830
  rc = get_pubkey (pk, kid);
791
831
  if (rc)
792
832
    {
793
 
      log_error (_("public key %08lX not found: %s\n"),
794
 
                 (ulong)kid[1], gpg_strerror (rc) );
 
833
      log_error(_("public key %s not found: %s\n"),keystr(kid),g10_errstr(rc));
795
834
      return;
796
835
    }
797
836
 
799
838
  if (!rc)
800
839
    {
801
840
      if (DBG_TRUST)
802
 
        log_debug ("key %08lX: update min_ownertrust from %u to %u\n",
803
 
                   (ulong)kid[1],(unsigned int)rec.r.trust.min_ownertrust,
 
841
        log_debug ("key %08lX%08lX: update min_ownertrust from %u to %u\n",
 
842
                   (ulong)kid[0],(ulong)kid[1],
 
843
                   (unsigned int)rec.r.trust.min_ownertrust,
804
844
                   new_trust );
805
845
      if (rec.r.trust.min_ownertrust != new_trust)
806
846
        {
927
967
}
928
968
 
929
969
 
930
 
/* reset validity for all user IDs.  Caller must sync. */
931
 
static int
932
 
clear_validity (PKT_public_key *pk)
933
 
{
934
 
  TRUSTREC trec, vrec;
935
 
  int rc;
936
 
  ulong recno;
937
 
  int any = 0;
938
 
  
939
 
  rc = read_trust_record (pk, &trec);
940
 
  if (rc && rc != -1)
941
 
    {
942
 
      tdbio_invalid ();
943
 
      return 0;
944
 
    }
945
 
  if (rc == -1) /* no record yet - no need to clear it then ;-) */
946
 
    return 0;
947
 
 
948
 
  /* Clear minimum ownertrust, if any */
949
 
  if(trec.r.trust.min_ownertrust)
950
 
    {
951
 
      trec.r.trust.min_ownertrust=0;
952
 
      write_record(&trec);
953
 
    }
954
 
 
955
 
  recno = trec.r.trust.validlist;
956
 
  while (recno)
957
 
    {
958
 
      read_record (recno, &vrec, RECTYPE_VALID);
959
 
      if ((vrec.r.valid.validity & TRUST_MASK)
960
 
          || vrec.r.valid.marginal_count || vrec.r.valid.full_count)
961
 
        {
962
 
          vrec.r.valid.validity &= ~TRUST_MASK;
963
 
          vrec.r.valid.marginal_count = vrec.r.valid.full_count = 0;
964
 
          write_record (&vrec);
965
 
          any = 1;
966
 
        }
967
 
      recno = vrec.r.valid.next;
968
 
    }
969
 
 
970
 
  return any;
971
 
}
972
 
 
973
970
/***********************************************
974
971
 *********  Query trustdb values  **************
975
972
 ***********************************************/
1010
1007
   return disabled;
1011
1008
}
1012
1009
 
1013
 
/*
1014
 
 * Return the validity information for PK.  If the namehash is not
1015
 
 * NULL, the validity of the corresponsing user ID is returned,
1016
 
 * otherwise, a reasonable value for the entire key is returned. 
1017
 
 */
1018
 
unsigned int
1019
 
get_validity (PKT_public_key *pk, PKT_user_id *uid)
 
1010
void
 
1011
check_trustdb_stale(void)
1020
1012
{
1021
 
  static int did_nextcheck;
1022
 
  TRUSTREC trec, vrec;
1023
 
  int rc;
1024
 
  ulong recno;
1025
 
  unsigned int validity;
1026
 
  u32 kid[2];
1027
 
  PKT_public_key *main_pk;
1028
 
 
1029
 
  if(uid)
1030
 
    namehash_from_uid(uid);
 
1013
  static int did_nextcheck=0;
1031
1014
 
1032
1015
  init_trustdb ();
1033
1016
  if (!did_nextcheck
1051
1034
            }
1052
1035
        }
1053
1036
    }
 
1037
}
 
1038
 
 
1039
/*
 
1040
 * Return the validity information for PK.  If the namehash is not
 
1041
 * NULL, the validity of the corresponsing user ID is returned,
 
1042
 * otherwise, a reasonable value for the entire key is returned. 
 
1043
 */
 
1044
unsigned int
 
1045
get_validity (PKT_public_key *pk, PKT_user_id *uid)
 
1046
{
 
1047
  TRUSTREC trec, vrec;
 
1048
  int rc;
 
1049
  ulong recno;
 
1050
  unsigned int validity;
 
1051
  u32 kid[2];
 
1052
  PKT_public_key *main_pk;
 
1053
 
 
1054
  if(uid)
 
1055
    namehash_from_uid(uid);
 
1056
 
 
1057
  init_trustdb ();
 
1058
  check_trustdb_stale();
1054
1059
 
1055
1060
  keyid_from_pk (pk, kid);
1056
1061
  if (pk->main_keyid[0] != kid[0] || pk->main_keyid[1] != kid[1])
1057
1062
    { /* this is a subkey - get the mainkey */
1058
 
      main_pk = xcalloc (1,sizeof *main_pk);
 
1063
      main_pk = xmalloc_clear (sizeof *main_pk);
1059
1064
      rc = get_pubkey (main_pk, pk->main_keyid);
1060
1065
      if (rc)
1061
1066
        {
1062
 
          log_error ("error getting main key %08lX of subkey %08lX: %s\n",
1063
 
                     (ulong)pk->main_keyid[1], (ulong)kid[1], gpg_strerror (rc));
 
1067
          char *tempkeystr=xstrdup(keystr(pk->main_keyid));
 
1068
          log_error ("error getting main key %s of subkey %s: %s\n",
 
1069
                     tempkeystr, keystr(kid), g10_errstr(rc));
 
1070
          xfree(tempkeystr);
1064
1071
          validity = TRUST_UNKNOWN; 
1065
1072
          goto leave;
1066
1073
        }
1068
1075
  else
1069
1076
    main_pk = pk;
1070
1077
 
 
1078
  if(opt.trust_model==TM_DIRECT)
 
1079
    {
 
1080
      /* Note that this happens BEFORE any user ID stuff is checked.
 
1081
         The direct trust model applies to keys as a whole. */
 
1082
      validity=get_ownertrust(main_pk);
 
1083
      goto leave;
 
1084
    }
 
1085
 
1071
1086
  rc = read_trust_record (main_pk, &trec);
1072
1087
  if (rc && rc != -1)
1073
1088
    {
1249
1264
  int rc;
1250
1265
  int ot;
1251
1266
 
1252
 
  pk = xcalloc (1,sizeof *pk);
 
1267
  pk = xmalloc_clear (sizeof *pk);
1253
1268
  rc = get_pubkey (pk, kid);
1254
1269
  if (rc)
1255
1270
    {
1256
 
      log_error (_("public key %08lX not found: %s\n"),
1257
 
                 (ulong)kid[1], gpg_strerror (rc) );
 
1271
      log_error (_("public key %s not found: %s\n"),
 
1272
                 keystr(kid), g10_errstr(rc) );
1258
1273
      return TRUST_UNKNOWN;
1259
1274
    }
1260
1275
 
1261
1276
  if(opt.force_ownertrust)
1262
1277
    {
1263
 
      log_info("force trust for key %08lX%08lX to %s\n",
1264
 
               (ulong)kid[0],(ulong)kid[1],
1265
 
               trust_value_to_string(opt.force_ownertrust));
 
1278
      log_info("force trust for key %s to %s\n",
 
1279
               keystr(kid),trust_value_to_string(opt.force_ownertrust));
1266
1280
      update_ownertrust(pk,opt.force_ownertrust);
1267
1281
      ot=opt.force_ownertrust;
1268
1282
    }
1390
1404
 * To do this, we first revmove all signatures which are not valid and
1391
1405
 * from the remain ones we look for the latest one.  If this is not a
1392
1406
 * certification revocation signature we mark the signature by setting
1393
 
 * node flag bit 8.  Note that flag bits 9 and 10 are used for internal
1394
 
 * purposes.  
 
1407
 * node flag bit 8.  Revocations are marked with flag 11, and sigs
 
1408
 * from unavailable keys are marked with flag 12.  Note that flag bits
 
1409
 * 9 and 10 are used for internal purposes.
1395
1410
 */
1396
1411
static void
1397
1412
mark_usable_uid_certs (KBNODE keyblock, KBNODE uidnode,
1404
1419
  /* first check all signatures */
1405
1420
  for (node=uidnode->next; node; node = node->next)
1406
1421
    {
1407
 
      node->flag &= ~(1<<8 | 1<<9 | 1<<10);
 
1422
      int rc;
 
1423
 
 
1424
      node->flag &= ~(1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<12);
1408
1425
      if (node->pkt->pkttype == PKT_USER_ID
1409
1426
          || node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
1410
1427
        break; /* ready */
1411
1428
      if (node->pkt->pkttype != PKT_SIGNATURE)
1412
1429
        continue;
1413
 
      
1414
1430
      sig = node->pkt->pkt.signature;
1415
 
      if (sig->keyid[0] == main_kid[0] && sig->keyid[1] == main_kid[1])
1416
 
        continue; /* ignore self-signatures */
 
1431
      if (main_kid
 
1432
          && sig->keyid[0] == main_kid[0] && sig->keyid[1] == main_kid[1])
 
1433
        continue; /* ignore self-signatures if we pass in a main_kid */
1417
1434
      if (!IS_UID_SIG(sig) && !IS_UID_REV(sig))
1418
1435
        continue; /* we only look at these signature classes */
1419
 
      if (!is_in_klist (klist, sig))
 
1436
      if(sig->sig_class>=0x11 && sig->sig_class<=0x13 &&
 
1437
         sig->sig_class-0x10<opt.min_cert_level)
 
1438
        continue; /* treat anything under our min_cert_level as an
 
1439
                     invalid signature */
 
1440
      if (klist && !is_in_klist (klist, sig))
1420
1441
        continue;  /* no need to check it then */
1421
 
      if (check_key_signature (keyblock, node, NULL))
1422
 
        continue; /* ignore invalid signatures */
 
1442
      if ((rc=check_key_signature (keyblock, node, NULL)))
 
1443
        {
 
1444
          /* we ignore anything that won't verify, but tag the
 
1445
             no_pubkey case */
 
1446
          if(rc==G10ERR_NO_PUBKEY)
 
1447
            node->flag |= 1<<12;
 
1448
          continue;
 
1449
        }
1423
1450
      node->flag |= 1<<9;
1424
1451
    }      
1425
1452
  /* reset the remaining flags */
1426
1453
  for (; node; node = node->next)
1427
 
      node->flag &= ~(1<<8 | 1<<9 | 1 << 10);
 
1454
      node->flag &= ~(1<<8 | 1<<9 | 1<<10 | 1<<11 | 1<<12);
1428
1455
 
1429
1456
  /* kbnode flag usage: bit 9 is here set for signatures to consider,
1430
1457
   * bit 10 will be set by the loop to keep track of keyIDs already
1431
 
   * processed, bit 8 will be set for the usable signatures */
 
1458
   * processed, bit 8 will be set for the usable signatures, and bit
 
1459
   * 11 will be set for usable revocations. */
1432
1460
 
1433
1461
  /* for each cert figure out the latest valid one */
1434
1462
  for (node=uidnode->next; node; node = node->next)
1436
1464
      KBNODE n, signode;
1437
1465
      u32 kid[2];
1438
1466
      u32 sigdate;
1439
 
      
 
1467
 
1440
1468
      if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
1441
1469
        break;
1442
1470
      if ( !(node->flag & (1<<9)) )
1448
1476
      signode = node;
1449
1477
      sigdate = sig->timestamp;
1450
1478
      kid[0] = sig->keyid[0]; kid[1] = sig->keyid[1];
 
1479
 
 
1480
      /* Now find the latest and greatest signature */
1451
1481
      for (n=uidnode->next; n; n = n->next)
1452
1482
        {
1453
1483
          if (n->pkt->pkttype == PKT_PUBLIC_SUBKEY)
1510
1540
              sigdate = sig->timestamp;
1511
1541
            }
1512
1542
        }
 
1543
 
1513
1544
      sig = signode->pkt->pkt.signature;
1514
1545
      if (IS_UID_SIG (sig))
1515
1546
        { /* this seems to be a usable one which is not revoked. 
1528
1559
          if (expire==0 || expire > curtime )
1529
1560
            {
1530
1561
              signode->flag |= (1<<8); /* yeah, found a good cert */
1531
 
              if (expire && expire < *next_expire)
 
1562
              if (next_expire && expire && expire < *next_expire)
1532
1563
                *next_expire = expire;
1533
1564
            }
1534
1565
        }
1535
 
    }
1536
 
}
 
1566
      else
 
1567
        signode->flag |= (1<<11);
 
1568
    }
 
1569
}
 
1570
 
 
1571
static int
 
1572
clean_sigs_from_uid(KBNODE keyblock,KBNODE uidnode,int noisy,int self_only)
 
1573
{
 
1574
  int deleted=0;
 
1575
  KBNODE node;
 
1576
  u32 keyid[2];
 
1577
 
 
1578
  assert(keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
 
1579
 
 
1580
  keyid_from_pk(keyblock->pkt->pkt.public_key,keyid);
 
1581
 
 
1582
  /* Passing in a 0 for current time here means that we'll never weed
 
1583
     out an expired sig.  This is correct behavior since we want to
 
1584
     keep the most recent expired sig in a series. */
 
1585
  mark_usable_uid_certs(keyblock,uidnode,NULL,NULL,0,NULL);
 
1586
 
 
1587
  /* What we want to do here is remove signatures that are not
 
1588
     considered as part of the trust calculations.  Thus, all invalid
 
1589
     signatures are out, as are any signatures that aren't the last of
 
1590
     a series of uid sigs or revocations It breaks down like this:
 
1591
     coming out of mark_usable_uid_certs, if a sig is unflagged, it is
 
1592
     not even a candidate.  If a sig has flag 9 or 10, that means it
 
1593
     was selected as a candidate and vetted.  If a sig has flag 8 it
 
1594
     is a usable signature.  If a sig has flag 11 it is a usable
 
1595
     revocation.  If a sig has flag 12 it was issued by an unavailable
 
1596
     key.  "Usable" here means the most recent valid
 
1597
     signature/revocation in a series from a particular signer.
 
1598
 
 
1599
     Delete everything that isn't a usable uid sig (which might be
 
1600
     expired), a usable revocation, or a sig from an unavailable
 
1601
     key. */
 
1602
 
 
1603
  for(node=uidnode->next;
 
1604
      node && node->pkt->pkttype==PKT_SIGNATURE;
 
1605
      node=node->next)
 
1606
    {
 
1607
      int keep=self_only?(node->pkt->pkt.signature->keyid[0]==keyid[0]
 
1608
                          && node->pkt->pkt.signature->keyid[1]==keyid[1]):1;
 
1609
 
 
1610
      /* Keep usable uid sigs ... */
 
1611
      if((node->flag & (1<<8)) && keep)
 
1612
        continue;
 
1613
 
 
1614
      /* ... and usable revocations... */
 
1615
      if((node->flag & (1<<11)) && keep)
 
1616
        continue;
 
1617
 
 
1618
      /* ... and sigs from unavailable keys. */
 
1619
      /* disabled for now since more people seem to want sigs from
 
1620
         unavailable keys removed altogether.  */
 
1621
      /*
 
1622
        if(node->flag & (1<<12))
 
1623
        continue;
 
1624
      */
 
1625
 
 
1626
      /* Everything else we delete */
 
1627
 
 
1628
      /* At this point, if 12 is set, the signing key was unavailable.
 
1629
         If 9 or 10 is set, it's superceded.  Otherwise, it's
 
1630
         invalid. */
 
1631
 
 
1632
      if(noisy)
 
1633
        log_info("removing signature from key %s on user ID \"%s\": %s\n",
 
1634
                 keystr(node->pkt->pkt.signature->keyid),
 
1635
                 uidnode->pkt->pkt.user_id->name,
 
1636
                 node->flag&(1<<12)?"key unavailable":
 
1637
                 node->flag&(1<<9)?"signature superceded":"invalid signature");
 
1638
 
 
1639
      delete_kbnode(node);
 
1640
      deleted++;
 
1641
    }
 
1642
    
 
1643
  return deleted;
 
1644
}
 
1645
 
 
1646
/* This is substantially easier than clean_sigs_from_uid since we just
 
1647
   have to establish if the uid has a valid self-sig, is not revoked,
 
1648
   and is not expired.  Note that this does not take into account
 
1649
   whether the uid has a trust path to it - just whether the keyholder
 
1650
   themselves has certified the uid.  Returns true if the uid was
 
1651
   compacted.  To "compact" a user ID, we simply remove ALL signatures
 
1652
   except the self-sig that caused the user ID to be remove-worthy.
 
1653
   We don't actually remove the user ID packet itself since it might
 
1654
   be ressurected in a later merge.  Note that this function requires
 
1655
   that the caller has already done a merge_keys_and_selfsig().
 
1656
 
 
1657
   TODO: change the import code to allow importing a uid with only a
 
1658
   revocation if the uid already exists on the keyring. */
 
1659
 
 
1660
static int
 
1661
clean_uid_from_key(KBNODE keyblock,KBNODE uidnode,int noisy)
 
1662
{
 
1663
  KBNODE node;
 
1664
  PKT_user_id *uid=uidnode->pkt->pkt.user_id;
 
1665
  int deleted=0;
 
1666
 
 
1667
  assert(keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
 
1668
  assert(uidnode->pkt->pkttype==PKT_USER_ID);
 
1669
 
 
1670
  /* Skip valid user IDs, compacted user IDs, and non-self-signed user
 
1671
     IDs if --allow-non-selfsigned-uid is set. */
 
1672
  if(uid->created || uid->flags.compacted
 
1673
     || (!uid->is_expired && !uid->is_revoked
 
1674
         && opt.allow_non_selfsigned_uid))
 
1675
    return 0;
 
1676
 
 
1677
  for(node=uidnode->next;
 
1678
      node && node->pkt->pkttype==PKT_SIGNATURE;
 
1679
      node=node->next)
 
1680
    if(!node->pkt->pkt.signature->flags.chosen_selfsig)
 
1681
      {
 
1682
        delete_kbnode(node);
 
1683
        deleted=1;
 
1684
        uidnode->pkt->pkt.user_id->flags.compacted=1;
 
1685
      }
 
1686
 
 
1687
  if(noisy)
 
1688
    {
 
1689
      const char *reason;
 
1690
      char *user=utf8_to_native(uid->name,uid->len,0);
 
1691
 
 
1692
      if(uid->is_revoked)
 
1693
        reason=_("revoked");
 
1694
      else if(uid->is_expired)
 
1695
        reason=_("expired");
 
1696
      else
 
1697
        reason=_("invalid");
 
1698
 
 
1699
      log_info("compacting user ID \"%s\" on key %s: %s\n",
 
1700
               user,keystr_from_pk(keyblock->pkt->pkt.public_key),
 
1701
               reason);
 
1702
 
 
1703
      xfree(user);
 
1704
    }
 
1705
 
 
1706
  return deleted;
 
1707
}
 
1708
 
 
1709
/* Needs to be called after a merge_keys_and_selfsig() */
 
1710
void
 
1711
clean_one_uid(KBNODE keyblock,KBNODE uidnode,int noisy,int self_only,
 
1712
              int *uids_cleaned,int *sigs_cleaned)
 
1713
{
 
1714
  int dummy;
 
1715
 
 
1716
  assert(keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
 
1717
  assert(uidnode->pkt->pkttype==PKT_USER_ID);
 
1718
 
 
1719
  if(!uids_cleaned)
 
1720
    uids_cleaned=&dummy;
 
1721
 
 
1722
  if(!sigs_cleaned)
 
1723
    sigs_cleaned=&dummy;
 
1724
 
 
1725
  /* Do clean_uid_from_key first since if it fires off, we don't
 
1726
     have to bother with the other */
 
1727
  *uids_cleaned+=clean_uid_from_key(keyblock,uidnode,noisy);
 
1728
  if(!uidnode->pkt->pkt.user_id->flags.compacted)
 
1729
    *sigs_cleaned+=clean_sigs_from_uid(keyblock,uidnode,noisy,self_only);
 
1730
}
 
1731
 
 
1732
void
 
1733
clean_key(KBNODE keyblock,int noisy,int self_only,
 
1734
          int *uids_cleaned,int *sigs_cleaned)
 
1735
{
 
1736
  KBNODE uidnode;
 
1737
 
 
1738
  merge_keys_and_selfsig(keyblock);
 
1739
 
 
1740
  for(uidnode=keyblock->next;
 
1741
      uidnode && uidnode->pkt->pkttype!=PKT_PUBLIC_SUBKEY;
 
1742
      uidnode=uidnode->next)
 
1743
    if(uidnode->pkt->pkttype==PKT_USER_ID)
 
1744
      clean_one_uid(keyblock,uidnode,noisy,self_only,
 
1745
                    uids_cleaned,sigs_cleaned);
 
1746
}
 
1747
 
 
1748
/* Returns a sanitized copy of the regexp (which might be "", but not
 
1749
   NULL). */
 
1750
#ifndef DISABLE_REGEX
 
1751
static char *
 
1752
sanitize_regexp(const char *old)
 
1753
{
 
1754
  size_t start=0,len=strlen(old),idx=0;
 
1755
  int escaped=0,standard_bracket=0;
 
1756
  char *new=xmalloc((len*2)+1); /* enough to \-escape everything if we
 
1757
                                   have to */
 
1758
 
 
1759
  /* There are basically two commonly-used regexps here.  GPG and most
 
1760
     versions of PGP use "<[^>]+[@.]example\.com>$" and PGP (9)
 
1761
     command line uses "example.com" (i.e. whatever the user specfies,
 
1762
     and we can't expect users know to use "\." instead of ".").  So
 
1763
     here are the rules: we're allowed to start with "<[^>]+[@.]" and
 
1764
     end with ">$" or start and end with nothing.  In between, the
 
1765
     only legal regex character is ".", and everything else gets
 
1766
     escaped.  Part of the gotcha here is that some regex packages
 
1767
     allow more than RFC-4880 requires.  For example, 4880 has no "{}"
 
1768
     operator, but GNU regex does.  Commenting removes these operators
 
1769
     from consideration.  A possible future enhancement is to use
 
1770
     commenting to effectively back off a given regex to the Henry
 
1771
     Spencer syntax in 4880. -dshaw */
 
1772
 
 
1773
  /* Are we bracketed between "<[^>]+[@.]" and ">$" ? */
 
1774
  if(len>=12 && strncmp(old,"<[^>]+[@.]",10)==0
 
1775
     && old[len-2]=='>' && old[len-1]=='$')
 
1776
    {
 
1777
      strcpy(new,"<[^>]+[@.]");
 
1778
      idx=strlen(new);
 
1779
      standard_bracket=1;
 
1780
      start+=10;
 
1781
      len-=2;
 
1782
    }
 
1783
 
 
1784
  /* Walk the remaining characters and ensure that everything that is
 
1785
     left is not an operational regex character. */
 
1786
  for(;start<len;start++)
 
1787
    {
 
1788
      if(!escaped && old[start]=='\\')
 
1789
        escaped=1;
 
1790
      else if(!escaped && old[start]!='.')
 
1791
        new[idx++]='\\';
 
1792
      else
 
1793
        escaped=0;
 
1794
 
 
1795
      new[idx++]=old[start];
 
1796
    }
 
1797
 
 
1798
  new[idx]='\0';
 
1799
 
 
1800
  /* Note that the (sub)string we look at might end with a bare "\".
 
1801
     If it does, leave it that way.  If the regexp actually ended with
 
1802
     ">$", then it was escaping the ">" and is fine.  If the regexp
 
1803
     actually ended with the bare "\", then it's an illegal regexp and
 
1804
     regcomp should kick it out. */
 
1805
 
 
1806
  if(standard_bracket)
 
1807
    strcat(new,">$");
 
1808
 
 
1809
  return new;
 
1810
}
 
1811
#endif /*!DISABLE_REGEX*/
1537
1812
 
1538
1813
/* Used by validate_one_keyblock to confirm a regexp within a trust
1539
1814
   signature.  Returns 1 for match, and 0 for no match or regex
1545
1820
  /* When DISABLE_REGEX is defined, assume all regexps do not
1546
1821
     match. */
1547
1822
  return 0;
1548
 
#elif defined(__riscos__)
1549
 
  return riscos_check_regexp(expr, string, DBG_TRUST);
1550
1823
#else
1551
1824
  int ret;
1552
 
  regex_t pat;
1553
 
 
1554
 
  if(regcomp(&pat,expr,REG_ICASE|REG_NOSUB|REG_EXTENDED)!=0)
1555
 
    return 0;
1556
 
 
1557
 
  ret=regexec(&pat,string,0,NULL,0);
1558
 
 
1559
 
  regfree(&pat);
 
1825
  char *regexp;
 
1826
 
 
1827
  regexp=sanitize_regexp(expr);
 
1828
 
 
1829
#ifdef __riscos__
 
1830
  ret=riscos_check_regexp(expr, string, DBG_TRUST);
 
1831
#else
 
1832
  {
 
1833
    regex_t pat;
 
1834
 
 
1835
    ret=regcomp(&pat,regexp,REG_ICASE|REG_NOSUB|REG_EXTENDED);
 
1836
    if(ret==0)
 
1837
      {
 
1838
        ret=regexec(&pat,string,0,NULL,0);
 
1839
        regfree(&pat);
 
1840
        ret=(ret==0);
 
1841
      }
 
1842
  }
 
1843
#endif
1560
1844
 
1561
1845
  if(DBG_TRUST)
1562
 
    log_debug("regexp \"%s\" on \"%s\": %s\n",expr,string,ret==0?"YES":"NO");
1563
 
 
1564
 
  return (ret==0);
 
1846
    log_debug("regexp `%s' (`%s') on `%s': %s\n",
 
1847
              regexp,expr,string,ret==0?"YES":"NO");
 
1848
 
 
1849
  xfree(regexp);
 
1850
 
 
1851
  return ret;
1565
1852
#endif
1566
1853
}
1567
1854
 
1717
2004
 
1718
2005
 
1719
2006
static int
1720
 
search_skipfnc (void *opaque, u32 *kid)
 
2007
search_skipfnc (void *opaque, u32 *kid, PKT_user_id *dummy)
1721
2008
{
1722
2009
  return test_key_hash_table ((KeyHashTable)opaque, kid);
1723
2010
}
1747
2034
  rc = keydb_search_reset (hd);
1748
2035
  if (rc)
1749
2036
    {
1750
 
      log_error ("keydb_search_reset failed: %s\n", gpg_strerror (rc));
 
2037
      log_error ("keydb_search_reset failed: %s\n", g10_errstr(rc));
1751
2038
      xfree (keys);
1752
2039
      return NULL;
1753
2040
    }
1764
2051
    }
1765
2052
  if (rc)
1766
2053
    {
1767
 
      log_error ("keydb_search_first failed: %s\n", gpg_strerror (rc));
 
2054
      log_error ("keydb_search_first failed: %s\n", g10_errstr(rc));
1768
2055
      xfree (keys);
1769
2056
      return NULL;
1770
2057
    }
1777
2064
      rc = keydb_get_keyblock (hd, &keyblock);
1778
2065
      if (rc) 
1779
2066
        {
1780
 
          log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
 
2067
          log_error ("keydb_get_keyblock failed: %s\n", g10_errstr(rc));
1781
2068
          xfree (keys);
1782
2069
          return NULL;
1783
2070
        }
1833
2120
  while ( !(rc = keydb_search (hd, &desc, 1)) );
1834
2121
  if (rc && rc != -1) 
1835
2122
    {
1836
 
      log_error ("keydb_search_next failed: %s\n", gpg_strerror (rc));
 
2123
      log_error ("keydb_search_next failed: %s\n", g10_errstr(rc));
1837
2124
      xfree (keys);
1838
2125
      return NULL;
1839
2126
    }
1844
2131
 
1845
2132
/* Caller must sync */
1846
2133
static void
1847
 
reset_trust_records (KEYDB_HANDLE hd, KeyHashTable exclude)
 
2134
reset_trust_records(void)
1848
2135
{
1849
 
  int rc;
1850
 
  KBNODE keyblock = NULL;
1851
 
  KEYDB_SEARCH_DESC desc;
 
2136
  TRUSTREC rec;
 
2137
  ulong recnum;
1852
2138
  int count = 0, nreset = 0;
1853
 
  
1854
 
  rc = keydb_search_reset (hd);
1855
 
  if (rc)
1856
 
    {
1857
 
      log_error ("keydb_search_reset failed: %s\n", gpg_strerror (rc));
1858
 
      return;
1859
 
    }
1860
 
 
1861
 
  memset (&desc, 0, sizeof desc);
1862
 
  desc.mode = KEYDB_SEARCH_MODE_FIRST;
1863
 
  if(exclude)
1864
 
    {
1865
 
      desc.skipfnc = search_skipfnc;
1866
 
      desc.skipfncvalue = exclude;
1867
 
    }
1868
 
  rc = keydb_search (hd, &desc, 1);
1869
 
  if (rc && rc != -1 )
1870
 
    log_error ("keydb_search_first failed: %s\n", gpg_strerror (rc));
1871
 
  else if (!rc)
1872
 
    {
1873
 
      desc.mode = KEYDB_SEARCH_MODE_NEXT; /* change mode */
1874
 
      do
1875
 
        {
1876
 
          rc = keydb_get_keyblock (hd, &keyblock);
1877
 
          if (rc) 
1878
 
            {
1879
 
              log_error ("keydb_get_keyblock failed: %s\n", gpg_strerror (rc));
1880
 
              break;
1881
 
            }
1882
 
          count++;
1883
 
 
1884
 
          if (keyblock->pkt->pkttype == PKT_PUBLIC_KEY) /* paranoid assertion*/
1885
 
            {
1886
 
              nreset += clear_validity (keyblock->pkt->pkt.public_key);
1887
 
              release_kbnode (keyblock);
1888
 
            } 
1889
 
        }
1890
 
      while ( !(rc = keydb_search (hd, &desc, 1)) );
1891
 
      if (rc && rc != -1) 
1892
 
        log_error ("keydb_search_next failed: %s\n", gpg_strerror (rc));
1893
 
    }
 
2139
 
 
2140
  for (recnum=1; !tdbio_read_record (recnum, &rec, 0); recnum++ ) 
 
2141
    {
 
2142
      if(rec.rectype==RECTYPE_TRUST)
 
2143
        {
 
2144
          count++;
 
2145
          if(rec.r.trust.min_ownertrust)
 
2146
            {
 
2147
              rec.r.trust.min_ownertrust=0;
 
2148
              write_record(&rec);
 
2149
            }
 
2150
 
 
2151
        }
 
2152
      else if(rec.rectype==RECTYPE_VALID
 
2153
              && ((rec.r.valid.validity&TRUST_MASK)
 
2154
                  || rec.r.valid.marginal_count
 
2155
                  || rec.r.valid.full_count))
 
2156
        {
 
2157
          rec.r.valid.validity &= ~TRUST_MASK;
 
2158
          rec.r.valid.marginal_count=rec.r.valid.full_count=0;
 
2159
          nreset++;
 
2160
          write_record(&rec);
 
2161
        }
 
2162
 
 
2163
    }
 
2164
 
1894
2165
  if (opt.verbose)
1895
2166
    log_info (_("%d keys processed (%d validity counts cleared)\n"),
1896
 
              count, nreset);
 
2167
              count, nreset);
1897
2168
}
1898
2169
 
1899
2170
/*
1932
2203
  KEYDB_HANDLE kdb = NULL;
1933
2204
  KBNODE node;
1934
2205
  int depth;
1935
 
  int key_count;
1936
2206
  int ot_unknown, ot_undefined, ot_never, ot_marginal, ot_full, ot_ultimate;
1937
2207
  KeyHashTable stored,used,full_trust;
1938
2208
  u32 start_time, next_expire;
1939
2209
 
 
2210
  /* Make sure we have all sigs cached.  TODO: This is going to
 
2211
     require some architectual re-thinking, as it is agonizingly slow.
 
2212
     Perhaps combine this with reset_trust_records(), or only check
 
2213
     the caches on keys that are actually involved in the web of
 
2214
     trust. */
 
2215
  keydb_rebuild_caches(0);
 
2216
 
1940
2217
  start_time = make_timestamp ();
1941
2218
  next_expire = 0xffffffff; /* set next expire to the year 2106 */
1942
2219
  stored = new_key_hash_table ();
1943
2220
  used = new_key_hash_table ();
1944
2221
  full_trust = new_key_hash_table ();
 
2222
 
 
2223
  kdb = keydb_new (0);
 
2224
  reset_trust_records();
 
2225
 
1945
2226
  /* Fixme: Instead of always building a UTK list, we could just build it
1946
2227
   * here when needed */
1947
2228
  if (!utk_list)
1948
2229
    {
1949
 
      log_info (_("no ultimately trusted keys found\n"));
 
2230
      if (!opt.quiet)
 
2231
        log_info (_("no ultimately trusted keys found\n"));
1950
2232
      goto leave;
1951
2233
    }
1952
2234
 
1953
 
  kdb = keydb_new (0);
1954
 
 
1955
 
  reset_trust_records (kdb,NULL);
1956
 
 
1957
2235
  /* mark all UTKs as used and fully_trusted and set validity to
1958
2236
     ultimate */
1959
2237
  for (k=utk_list; k; k = k->next)
1965
2243
      if (!keyblock)
1966
2244
        {
1967
2245
          log_error (_("public key of ultimately"
1968
 
                       " trusted key %08lX not found\n"), (ulong)k->kid[1]);
 
2246
                       " trusted key %s not found\n"), keystr(k->kid));
1969
2247
          continue;
1970
2248
        }
1971
2249
      mark_keyblock_seen (used, keyblock);
1992
2270
 
1993
2271
  for (depth=0; depth < opt.max_cert_depth; depth++)
1994
2272
    {
 
2273
      int valids=0,key_count;
1995
2274
      /* See whether we should assign ownertrust values to the keys in
1996
 
         utk_list.  */
 
2275
         klist.  */
1997
2276
      ot_unknown = ot_undefined = ot_never = 0;
1998
2277
      ot_marginal = ot_full = ot_ultimate = 0;
1999
2278
      for (k=klist; k; k = k->next)
2027
2306
          if(k->ownertrust<min)
2028
2307
            {
2029
2308
              if(DBG_TRUST)
2030
 
                log_debug("key %08lX: "
2031
 
                          "overriding ownertrust \"%s\" with \"%s\"\n",
2032
 
                          (ulong)k->kid[1],
 
2309
                log_debug("key %08lX%08lX:"
 
2310
                          " overriding ownertrust `%s' with `%s'\n",
 
2311
                          (ulong)k->kid[0],(ulong)k->kid[1],
2033
2312
                          trust_value_to_string(k->ownertrust),
2034
2313
                          trust_value_to_string(min));
2035
2314
 
2048
2327
            ot_full++;
2049
2328
          else if (k->ownertrust == TRUST_ULTIMATE)
2050
2329
            ot_ultimate++;
 
2330
 
 
2331
          valids++;
2051
2332
        }
2052
2333
 
2053
2334
      /* Find all keys which are signed by a key in kdlist */
2056
2337
      if (!keys) 
2057
2338
        {
2058
2339
          log_error ("validate_key_list failed\n");
2059
 
          rc = GPG_ERR_GENERAL;
 
2340
          rc = G10ERR_GENERAL;
2060
2341
          goto leave;
2061
2342
        }
2062
2343
 
2070
2351
      for (kar=keys; kar->keyblock; kar++)
2071
2352
          store_validation_status (depth, kar->keyblock, stored);
2072
2353
 
2073
 
      log_info (_("checking at depth %d valid=%d"
2074
 
                  " ot(-/q/n/m/f/u)=%d/%d/%d/%d/%d/%d\n"), 
2075
 
                depth, key_count, ot_unknown, ot_undefined,
 
2354
      log_info (_("depth: %d  valid: %3d  signed: %3d"
 
2355
                  "  trust: %d-, %dq, %dn, %dm, %df, %du\n"), 
 
2356
                depth, valids, key_count, ot_unknown, ot_undefined,
2076
2357
                ot_never, ot_marginal, ot_full, ot_ultimate ); 
2077
2358
 
2078
2359
      /* Build a new kdlist from all fully valid keys in KEYS */
2110
2391
                        kar->keyblock->pkt->pkt.public_key->trust_value;
2111
2392
                      if(kar->keyblock->pkt->pkt.public_key->trust_regexp)
2112
2393
                        k->trust_regexp=
2113
 
                          xstrdup (kar->keyblock->pkt->
 
2394
                          xstrdup(kar->keyblock->pkt->
2114
2395
                                   pkt.public_key->trust_regexp);
2115
2396
                      k->next = klist;
2116
2397
                      klist = k;
2146
2427
      if(tdbio_update_version_record()!=0)
2147
2428
        {
2148
2429
          log_error(_("unable to update trustdb version record: "
2149
 
                      "write failed: %s\n"), gpg_strerror (rc));
 
2430
                      "write failed: %s\n"), g10_errstr(rc));
2150
2431
          tdbio_invalid();
2151
2432
        }
2152
2433