~ubuntu-branches/ubuntu/hardy/gnupg/hardy-updates

« back to all changes in this revision

Viewing changes to g10/import.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-12-16 16:57:39 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051216165739-v0m2d1you6hd8jho
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 *
17
17
 * You should have received a copy of the GNU General Public License
18
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
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
 
20
 * USA.
20
21
 */
21
22
 
22
23
#include <config.h>
54
55
    ulong secret_dups;
55
56
    ulong skipped_new_keys;
56
57
    ulong not_imported;
 
58
    ulong n_sigs_cleaned;
 
59
    ulong n_uids_cleaned;
57
60
};
58
61
 
59
62
 
93
96
      {"fast-import",IMPORT_FAST,NULL},
94
97
      {"convert-sk-to-pk",IMPORT_SK2PK,NULL},
95
98
      {"merge-only",IMPORT_MERGE_ONLY,NULL},
96
 
      {"import-unusable-sigs",IMPORT_UNUSABLE_SIGS,NULL},
 
99
      {"import-clean",IMPORT_CLEAN_SIGS|IMPORT_CLEAN_UIDS,NULL},
 
100
      {"import-clean-sigs",IMPORT_CLEAN_SIGS,NULL},
 
101
      {"import-clean-uids",IMPORT_CLEAN_UIDS,NULL},
97
102
      /* Aliases for backward compatibility */
98
103
      {"allow-local-sigs",IMPORT_LOCAL_SIGS,NULL},
99
104
      {"repair-hkp-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG,NULL},
 
105
      /* dummy */
 
106
      {"import-unusable-sigs",0,NULL},
100
107
      {NULL,0,NULL}
101
108
    };
102
109
 
300
307
            log_info(_(" secret keys unchanged: %lu\n"), stats->secret_dups );
301
308
        if( stats->not_imported )
302
309
            log_info(_("          not imported: %lu\n"), stats->not_imported );
 
310
        if( stats->n_sigs_cleaned)
 
311
            log_info(_("    signatures cleaned: %lu\n"),stats->n_sigs_cleaned);
 
312
        if( stats->n_uids_cleaned)
 
313
            log_info(_("      user IDs cleaned: %lu\n"),stats->n_uids_cleaned);
303
314
    }
304
315
 
305
316
    if( is_status_enabled() ) {
647
658
    }
648
659
}
649
660
 
 
661
static int
 
662
clean_sigs_from_all_uids(KBNODE keyblock)
 
663
{
 
664
  KBNODE uidnode;
 
665
  int deleted=0;
 
666
 
 
667
  for(uidnode=keyblock->next;uidnode;uidnode=uidnode->next)
 
668
    if(uidnode->pkt->pkttype==PKT_USER_ID)
 
669
      deleted+=clean_sigs_from_uid(keyblock,uidnode,opt.verbose);
 
670
 
 
671
  return deleted;
 
672
}
 
673
 
 
674
 
650
675
/****************
651
676
 * Try to import one keyblock.  Return an error only in serious cases, but
652
677
 * never for an invalid keyblock.  It uses log_error to increase the
706
731
            return 0;
707
732
    }
708
733
 
 
734
    /* Clean the key that we're about to import, to cut down on things
 
735
       that we have to clean later.  This has no practical impact on
 
736
       the end result, but does result in less logging which might
 
737
       confuse the user. */
 
738
    if(options&IMPORT_CLEAN_SIGS)
 
739
      clean_sigs_from_all_uids(keyblock);
 
740
 
 
741
    if(options&IMPORT_CLEAN_UIDS)
 
742
      clean_uids_from_key(keyblock,opt.verbose);
 
743
 
709
744
    clear_kbnode_flags( keyblock );
710
745
 
711
746
    if((options&IMPORT_REPAIR_PKS_SUBKEY_BUG) && fix_pks_corruption(keyblock)
806
841
    }
807
842
    else { /* merge */
808
843
        KEYDB_HANDLE hd;
809
 
        int n_uids, n_sigs, n_subk;
 
844
        int n_uids, n_sigs, n_subk, n_sigs_cleaned, n_uids_cleaned;
810
845
 
811
846
        /* Compare the original against the new key; just to be sure nothing
812
847
         * weird is going on */
847
882
        /* and try to merge the block */
848
883
        clear_kbnode_flags( keyblock_orig );
849
884
        clear_kbnode_flags( keyblock );
850
 
        n_uids = n_sigs = n_subk = 0;
 
885
        n_uids = n_sigs = n_subk = n_sigs_cleaned = n_uids_cleaned = 0;
851
886
        rc = merge_blocks( fname, keyblock_orig, keyblock,
852
 
                                keyid, &n_uids, &n_sigs, &n_subk );
853
 
        if( rc ) {
 
887
                           keyid, &n_uids, &n_sigs, &n_subk );
 
888
        if( rc )
 
889
          {
854
890
            keydb_release (hd);
855
891
            goto leave;
856
 
        }
857
 
        if( n_uids || n_sigs || n_subk ) {
 
892
          }
 
893
 
 
894
        if(options&IMPORT_CLEAN_SIGS)
 
895
          n_sigs_cleaned=clean_sigs_from_all_uids(keyblock_orig);
 
896
 
 
897
        if(options&IMPORT_CLEAN_UIDS)
 
898
          n_uids_cleaned=clean_uids_from_key(keyblock_orig,opt.verbose);
 
899
 
 
900
        if( n_uids || n_sigs || n_subk || n_sigs_cleaned || n_uids_cleaned) {
858
901
            mod_key = 1;
859
902
            /* keyblock_orig has been updated; write */
860
903
            rc = keydb_update_keyblock (hd, keyblock_orig);
886
929
                else if( n_subk )
887
930
                  log_info( _("key %s: \"%s\" %d new subkeys\n"),
888
931
                            keystr(keyid), p, n_subk );
 
932
                if(n_sigs_cleaned==1)
 
933
                  log_info(_("key %s: \"%s\" %d signature cleaned\n"),
 
934
                           keystr(keyid),p,n_sigs_cleaned);
 
935
                else if(n_sigs_cleaned)
 
936
                  log_info(_("key %s: \"%s\" %d signatures cleaned\n"),
 
937
                           keystr(keyid),p,n_sigs_cleaned);
 
938
                if(n_uids_cleaned==1)
 
939
                  log_info(_("key %s: \"%s\" %d user ID cleaned\n"),
 
940
                           keystr(keyid),p,n_uids_cleaned);
 
941
                else if(n_uids_cleaned)
 
942
                  log_info(_("key %s: \"%s\" %d user IDs cleaned\n"),
 
943
                           keystr(keyid),p,n_uids_cleaned);
889
944
                m_free(p);
890
945
              }
891
946
 
892
947
            stats->n_uids +=n_uids;
893
948
            stats->n_sigs +=n_sigs;
894
949
            stats->n_subk +=n_subk;
 
950
            stats->n_sigs_cleaned +=n_sigs_cleaned;
 
951
            stats->n_uids_cleaned +=n_uids_cleaned;
895
952
 
896
953
            if (is_status_enabled ()) 
897
954
                 print_import_ok (pk, NULL,
1289
1346
        sig = n->pkt->pkt.signature;
1290
1347
        if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] ) {
1291
1348
 
1292
 
          /* This just caches the sigs for later use.  That way we
1293
 
             import a fully-cached key which speeds things up. */
1294
 
          if(!opt.no_sig_cache)
1295
 
            check_key_signature(keyblock,n,NULL);
 
1349
            /* This just caches the sigs for later use.  That way we
 
1350
               import a fully-cached key which speeds things up. */
 
1351
            if(!opt.no_sig_cache)
 
1352
              check_key_signature(keyblock,n,NULL);
1296
1353
 
1297
 
            if( (sig->sig_class&~3) == 0x10 ) {
 
1354
            if( IS_UID_SIG(sig) || IS_UID_REV(sig) )
 
1355
              {
1298
1356
                KBNODE unode = find_prev_kbnode( keyblock, n, PKT_USER_ID );
1299
1357
                if( !unode )
1300
1358
                  {
1324
1382
                  else
1325
1383
                    unode->flag |= 1; /* mark that signature checked */
1326
1384
                }
1327
 
            }
 
1385
              }
1328
1386
            else if( sig->sig_class == 0x18 ) {
1329
1387
              /* Note that this works based solely on the timestamps
1330
1388
                 like the rest of gpg.  If the standard gets
1555
1613
                       node->pkt->pkt.signature->sig_class);
1556
1614
            delete_kbnode(node);
1557
1615
          }
1558
 
        else if(node->pkt->pkttype==PKT_SIGNATURE
1559
 
                && IS_UID_SIG(node->pkt->pkt.signature)
1560
 
                && node->pkt->pkt.signature->flags.expired
1561
 
                && (node->pkt->pkt.signature->keyid[0]!=keyid[0]
1562
 
                    || node->pkt->pkt.signature->keyid[1]!=keyid[1])
1563
 
                && !(options&IMPORT_UNUSABLE_SIGS))
1564
 
          {
1565
 
            /* Note that we haven't necessarily checked this sig for
1566
 
               validity.  We strip it anyway since if it was valid, it
1567
 
               would be expired.  If it wasn't valid, it either would
1568
 
               be expired if it was valid, or was altered to the point
1569
 
               that it looked expired (and so doesn't matter terribly
1570
 
               much if it is expired or not). */
1571
 
            if(opt.verbose)
1572
 
              {
1573
 
                char *kid=m_strdup(keystr(keyid));
1574
 
                log_info(_("key %s: expired signature from key %s -"
1575
 
                           " skipped\n"),kid,
1576
 
                         keystr(node->pkt->pkt.signature->keyid));
1577
 
                m_free(kid);
1578
 
              }
1579
 
 
1580
 
            delete_kbnode(node);
1581
 
          }
1582
1616
        else if( (node->flag & 4) ) /* marked for deletion */
1583
1617
          delete_kbnode( node );
1584
1618
    }