mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-09 12:54:23 +01:00
* import.c (collapse_uids): Significant speedup for de-duping user
IDs.
This commit is contained in:
parent
d1a13319bb
commit
8bc8b9d932
@ -1,3 +1,8 @@
|
|||||||
|
2007-09-02 David Shaw <dshaw@jabberwocky.com>
|
||||||
|
|
||||||
|
* import.c (collapse_uids): Significant speedup for de-duping user
|
||||||
|
IDs.
|
||||||
|
|
||||||
2007-08-24 Werner Koch <wk@g10code.com>
|
2007-08-24 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
* keyring.c (keyring_register_filename): Use same_file_p.
|
* keyring.c (keyring_register_filename): Use same_file_p.
|
||||||
|
138
g10/import.c
138
g10/import.c
@ -1644,90 +1644,102 @@ delete_inv_parts( const char *fname, KBNODE keyblock,
|
|||||||
* It may happen that the imported keyblock has duplicated user IDs.
|
* It may happen that the imported keyblock has duplicated user IDs.
|
||||||
* We check this here and collapse those user IDs together with their
|
* We check this here and collapse those user IDs together with their
|
||||||
* sigs into one.
|
* sigs into one.
|
||||||
* Returns: True if the keyblock hash changed.
|
* Returns: True if the keyblock has changed.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
collapse_uids( KBNODE *keyblock )
|
collapse_uids( KBNODE *keyblock )
|
||||||
{
|
{
|
||||||
KBNODE n, n2;
|
KBNODE uid1;
|
||||||
int in_uid;
|
|
||||||
int any=0;
|
int any=0;
|
||||||
|
|
||||||
restart:
|
for(uid1=*keyblock;uid1;uid1=uid1->next)
|
||||||
for( n = *keyblock; n; n = n->next ) {
|
{
|
||||||
if( n->pkt->pkttype != PKT_USER_ID )
|
KBNODE uid2;
|
||||||
|
|
||||||
|
if(uid1->pkt->pkttype!=PKT_USER_ID)
|
||||||
continue;
|
continue;
|
||||||
for( n2 = n->next; n2; n2 = n2->next ) {
|
|
||||||
if( n2->pkt->pkttype == PKT_USER_ID
|
|
||||||
&& !cmp_user_ids( n->pkt->pkt.user_id,
|
|
||||||
n2->pkt->pkt.user_id ) ) {
|
|
||||||
/* found a duplicate */
|
|
||||||
any = 1;
|
|
||||||
if( !n2->next
|
|
||||||
|| n2->next->pkt->pkttype == PKT_USER_ID
|
|
||||||
|| n2->next->pkt->pkttype == PKT_PUBLIC_SUBKEY
|
|
||||||
|| n2->next->pkt->pkttype == PKT_SECRET_SUBKEY ) {
|
|
||||||
/* no more signatures: delete the user ID
|
|
||||||
* and start over */
|
|
||||||
remove_kbnode( keyblock, n2 );
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* The simple approach: Move one signature and
|
|
||||||
* then start over to delete the next one :-( */
|
|
||||||
move_kbnode( keyblock, n2->next, n->next );
|
|
||||||
}
|
|
||||||
goto restart;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if( !any )
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
restart_sig:
|
for(uid2=uid1->next;uid2;uid2=uid2->next)
|
||||||
/* now we may have duplicate signatures on one user ID: fix this */
|
{
|
||||||
for( in_uid = 0, n = *keyblock; n; n = n->next ) {
|
if(uid2->pkt->pkttype!=PKT_USER_ID)
|
||||||
if( n->pkt->pkttype == PKT_USER_ID )
|
continue;
|
||||||
in_uid = 1;
|
|
||||||
else if( n->pkt->pkttype == PKT_PUBLIC_SUBKEY
|
if(cmp_user_ids(uid1->pkt->pkt.user_id,
|
||||||
|| n->pkt->pkttype == PKT_SECRET_SUBKEY )
|
uid2->pkt->pkt.user_id)==0)
|
||||||
in_uid = 0;
|
{
|
||||||
else if( in_uid ) {
|
/* We have a duplicated uid */
|
||||||
n2 = n;
|
KBNODE sig1,last;
|
||||||
do {
|
|
||||||
KBNODE ncmp = NULL;
|
any=1;
|
||||||
for( ; n2; n2 = n2->next ) {
|
|
||||||
if( n2->pkt->pkttype == PKT_USER_ID
|
/* Now take uid2's signatures, and attach them to
|
||||||
|| n2->pkt->pkttype == PKT_PUBLIC_SUBKEY
|
uid1 */
|
||||||
|| n2->pkt->pkttype == PKT_SECRET_SUBKEY )
|
for(last=uid2;last->next;last=last->next)
|
||||||
|
{
|
||||||
|
if(last->next->pkt->pkttype==PKT_USER_ID
|
||||||
|
|| last->next->pkt->pkttype==PKT_PUBLIC_SUBKEY
|
||||||
|
|| last->next->pkt->pkttype==PKT_SECRET_SUBKEY)
|
||||||
break;
|
break;
|
||||||
if( n2->pkt->pkttype != PKT_SIGNATURE )
|
}
|
||||||
;
|
|
||||||
else if( !ncmp )
|
/* Snip out uid2 */
|
||||||
ncmp = n2;
|
(find_prev_kbnode(*keyblock,uid2,0))->next=last->next;
|
||||||
else if( !cmp_signatures( ncmp->pkt->pkt.signature,
|
|
||||||
n2->pkt->pkt.signature )) {
|
/* Now put uid2 in place as part of uid1 */
|
||||||
remove_kbnode( keyblock, n2 );
|
last->next=uid1->next;
|
||||||
goto restart_sig;
|
uid1->next=uid2;
|
||||||
|
remove_kbnode(keyblock,uid2);
|
||||||
|
|
||||||
|
/* Now dedupe uid1 */
|
||||||
|
for(sig1=uid1->next;sig1;sig1=sig1->next)
|
||||||
|
{
|
||||||
|
KBNODE sig2;
|
||||||
|
|
||||||
|
if(sig1->pkt->pkttype==PKT_USER_ID
|
||||||
|
|| sig1->pkt->pkttype==PKT_PUBLIC_SUBKEY
|
||||||
|
|| sig1->pkt->pkttype==PKT_SECRET_SUBKEY)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(sig1->pkt->pkttype!=PKT_SIGNATURE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for(sig2=sig1->next,last=sig1;sig2;last=sig2,sig2=sig2->next)
|
||||||
|
{
|
||||||
|
if(sig2->pkt->pkttype==PKT_USER_ID
|
||||||
|
|| sig2->pkt->pkttype==PKT_PUBLIC_SUBKEY
|
||||||
|
|| sig2->pkt->pkttype==PKT_SECRET_SUBKEY)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(sig2->pkt->pkttype!=PKT_SIGNATURE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(cmp_signatures(sig1->pkt->pkt.signature,
|
||||||
|
sig2->pkt->pkt.signature)==0)
|
||||||
|
{
|
||||||
|
/* We have a match, so delete the second
|
||||||
|
signature */
|
||||||
|
remove_kbnode(&uid1,sig2);
|
||||||
|
sig2=last;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n2 = ncmp? ncmp->next : NULL;
|
|
||||||
} while( n2 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!opt.quiet)
|
if(any && !opt.quiet)
|
||||||
{
|
{
|
||||||
const char *key="???";
|
const char *key="???";
|
||||||
|
|
||||||
if( (n = find_kbnode( *keyblock, PKT_PUBLIC_KEY )) )
|
if( (uid1=find_kbnode( *keyblock, PKT_PUBLIC_KEY )) )
|
||||||
key=keystr_from_pk(n->pkt->pkt.public_key);
|
key=keystr_from_pk(uid1->pkt->pkt.public_key);
|
||||||
else if( (n = find_kbnode( *keyblock, PKT_SECRET_KEY )) )
|
else if( (uid1 = find_kbnode( *keyblock, PKT_SECRET_KEY )) )
|
||||||
key=keystr_from_sk(n->pkt->pkt.secret_key);
|
key=keystr_from_sk(uid1->pkt->pkt.secret_key);
|
||||||
|
|
||||||
log_info(_("key %s: duplicated user ID detected - merged\n"),key);
|
log_info(_("key %s: duplicated user ID detected - merged\n"),key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for a 0x20 revocation from a revocation key that is not
|
/* Check for a 0x20 revocation from a revocation key that is not
|
||||||
|
Loading…
x
Reference in New Issue
Block a user