[svn] GnuPG - r3932 - trunk/g10

svn author dshaw cvs at cvs.gnupg.org
Sat Nov 12 05:53:04 CET 2005


Author: dshaw
Date: 2005-11-12 05:53:03 +0100 (Sat, 12 Nov 2005)
New Revision: 3932

Modified:
   trunk/g10/ChangeLog
   trunk/g10/import.c
   trunk/g10/options.h
   trunk/g10/parse-packet.c
   trunk/g10/trustdb.c
   trunk/g10/trustdb.h
Log:
* trustdb.h, trustdb.c (clean_key): New function to handle key
cleaning from one convenient place.

* options.h, import.c (parse_import_options, clean_sigs_from_all_uids,
import_one): Reduce clean options to two: clean and minimize.

* parse-packet.c (setup_user_id): Remove.  (parse_user_id,
parse_attribute): Just use xmalloc_clear instead.


Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/ChangeLog	2005-11-12 04:53:03 UTC (rev 3932)
@@ -1,5 +1,15 @@
 2005-11-11  David Shaw  <dshaw at jabberwocky.com>
 
+	* trustdb.h, trustdb.c (clean_key): New function to handle key
+	cleaning from one convenient place.
+
+	* options.h, import.c (parse_import_options,
+	clean_sigs_from_all_uids, import_one): Reduce clean options to
+	two: clean and minimize.
+
+	* parse-packet.c (setup_user_id): Remove.
+	(parse_user_id, parse_attribute): Just use xmalloc_clear instead.
+
 	* trustdb.c (clean_uid_from_key, clean_uids_from_key):
 	Significantly simpler implementation.
 

Modified: trunk/g10/import.c
===================================================================
--- trunk/g10/import.c	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/import.c	2005-11-12 04:53:03 UTC (rev 3932)
@@ -101,15 +101,14 @@
        N_("create a public key when importing a secret key")},
       {"merge-only",IMPORT_MERGE_ONLY,NULL,
        N_("only accept updates to existing keys")},
-      {"import-clean",IMPORT_CLEAN_SIGS|IMPORT_CLEAN_UIDS,NULL,
-       N_("all import-clean-* options from above")},
-      {"import-clean-sigs",IMPORT_CLEAN_SIGS,NULL,
-       N_("remove unusable signatures after import")},
-      {"import-clean-uids",IMPORT_CLEAN_UIDS,NULL,
-       N_("remove unusable user IDs after import")},
-      {"import-minimal",
-       IMPORT_MINIMAL|IMPORT_CLEAN_SIGS|IMPORT_CLEAN_UIDS,NULL,
+      {"import-clean",IMPORT_CLEAN,NULL,
+       N_("remove unusable user IDs and signatures after import")},
+      {"import-clean-sigs",0,NULL,NULL},
+      {"import-clean-uids",0,NULL,NULL},
+      {"import-minimal",IMPORT_MINIMAL|IMPORT_CLEAN,NULL,
        N_("remove unusable user IDs and all signatures after import")},
+      /* Alias */
+      {"import-minimize",IMPORT_MINIMAL|IMPORT_CLEAN,NULL,NULL},
       /* Aliases for backward compatibility */
       {"allow-local-sigs",IMPORT_LOCAL_SIGS,NULL,NULL},
       {"repair-hkp-subkey-bug",IMPORT_REPAIR_PKS_SUBKEY_BUG,NULL,NULL},
@@ -669,20 +668,6 @@
     }
 }
 
-static int
-clean_sigs_from_all_uids(KBNODE keyblock,int self_only)
-{
-  KBNODE uidnode;
-  int deleted=0;
-
-  for(uidnode=keyblock->next;uidnode;uidnode=uidnode->next)
-    if(uidnode->pkt->pkttype==PKT_USER_ID)
-      deleted+=clean_sigs_from_uid(keyblock,uidnode,opt.verbose,self_only);
-
-  return deleted;
-}
-
-
 /****************
  * Try to import one keyblock.	Return an error only in serious cases, but
  * never for an invalid keyblock.  It uses log_error to increase the
@@ -748,12 +733,9 @@
        that we have to clean later.  This has no practical impact on
        the end result, but does result in less logging which might
        confuse the user. */
-    if(options&IMPORT_CLEAN_SIGS)
-      clean_sigs_from_all_uids(keyblock,options&IMPORT_MINIMAL);
+    if(options&IMPORT_CLEAN)
+      clean_key(keyblock,opt.verbose,options&IMPORT_MINIMAL,NULL,NULL);
 
-    if(options&IMPORT_CLEAN_UIDS)
-      clean_uids_from_key(keyblock,opt.verbose);
-
     clear_kbnode_flags( keyblock );
 
     if((options&IMPORT_REPAIR_PKS_SUBKEY_BUG) && fix_pks_corruption(keyblock)
@@ -901,13 +883,10 @@
 	    goto leave;
 	  }
 
-	if(options&IMPORT_CLEAN_SIGS)
-	  n_sigs_cleaned=clean_sigs_from_all_uids(keyblock_orig,
-						  options&IMPORT_MINIMAL);
+	if(options&IMPORT_CLEAN)
+	  clean_key(keyblock_orig,opt.verbose,options&IMPORT_MINIMAL,
+		    &n_uids_cleaned,&n_sigs_cleaned);
 
-        if(options&IMPORT_CLEAN_UIDS)
-	  n_uids_cleaned=clean_uids_from_key(keyblock_orig,opt.verbose);
-
 	if( n_uids || n_sigs || n_subk || n_sigs_cleaned || n_uids_cleaned) {
 	    mod_key = 1;
 	    /* keyblock_orig has been updated; write */

Modified: trunk/g10/options.h
===================================================================
--- trunk/g10/options.h	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/options.h	2005-11-12 04:53:03 UTC (rev 3932)
@@ -266,8 +266,7 @@
 #define IMPORT_SK2PK                     (1<<3)
 #define IMPORT_MERGE_ONLY                (1<<4)
 #define IMPORT_MINIMAL                   (1<<5)
-#define IMPORT_CLEAN_SIGS                (1<<6)
-#define IMPORT_CLEAN_UIDS                (1<<7)
+#define IMPORT_CLEAN                     (1<<6)
 
 #define EXPORT_LOCAL_SIGS                (1<<0)
 #define EXPORT_ATTRIBUTES                (1<<1)

Modified: trunk/g10/parse-packet.c
===================================================================
--- trunk/g10/parse-packet.c	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/parse-packet.c	2005-11-12 04:53:03 UTC (rev 3932)
@@ -1966,33 +1966,16 @@
   return count;
 }
 
-static void setup_user_id(PACKET *packet)
-{
-  packet->pkt.user_id->ref = 1;
-  packet->pkt.user_id->attribs = NULL;
-  packet->pkt.user_id->attrib_data = NULL;
-  packet->pkt.user_id->attrib_len = 0;
-  packet->pkt.user_id->is_primary = 0;
-  packet->pkt.user_id->is_revoked = 0;
-  packet->pkt.user_id->is_expired = 0;
-  packet->pkt.user_id->expiredate = 0;
-  packet->pkt.user_id->created = 0;
-  packet->pkt.user_id->help_key_usage = 0;
-  packet->pkt.user_id->help_key_expire = 0;
-  packet->pkt.user_id->prefs = NULL;
-  packet->pkt.user_id->namehash = NULL;
-}
 
 static int
 parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
 {
     byte *p;
 
-    packet->pkt.user_id = xmalloc(sizeof *packet->pkt.user_id  + pktlen);
+    packet->pkt.user_id = xmalloc_clear(sizeof *packet->pkt.user_id + pktlen);
     packet->pkt.user_id->len = pktlen;
+    packet->pkt.user_id->ref=1;
 
-    setup_user_id(packet);
-
     p = packet->pkt.user_id->name;
     for( ; pktlen; pktlen--, p++ )
 	*p = iobuf_get_noeof(inp);
@@ -2052,13 +2035,12 @@
     byte *p;
 
 #define EXTRA_UID_NAME_SPACE 71
-    packet->pkt.user_id = xmalloc(sizeof *packet->pkt.user_id
-                                  + EXTRA_UID_NAME_SPACE);
-
-    setup_user_id(packet);
-
+    packet->pkt.user_id = xmalloc_clear(sizeof *packet->pkt.user_id
+					+ EXTRA_UID_NAME_SPACE);
+    packet->pkt.user_id->ref=1;
     packet->pkt.user_id->attrib_data = xmalloc(pktlen);
     packet->pkt.user_id->attrib_len = pktlen;
+
     p = packet->pkt.user_id->attrib_data;
     for( ; pktlen; pktlen--, p++ )
 	*p = iobuf_get_noeof(inp);

Modified: trunk/g10/trustdb.c
===================================================================
--- trunk/g10/trustdb.c	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/trustdb.c	2005-11-12 04:53:03 UTC (rev 3932)
@@ -1668,24 +1668,28 @@
 {
   KBNODE node;
   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);
 
-  /* Skip valid user IDs, and non-self-signed user IDs if
-     --allow-non-selfsigned-uid is set. */
-  if(uid->created || (!uid->is_expired && !uid->is_revoked
-		      && opt.allow_non_selfsigned_uid))
+  /* Skip valid user IDs, compacted user IDs, and non-self-signed user
+     IDs if --allow-non-selfsigned-uid is set. */
+  if(uid->created || uid->flags.compacted
+     || (!uid->is_expired && !uid->is_revoked
+	 && opt.allow_non_selfsigned_uid))
     return 0;
 
   for(node=uidnode->next;
       node && node->pkt->pkttype==PKT_SIGNATURE;
       node=node->next)
     if(!node->pkt->pkt.signature->flags.chosen_selfsig)
-      delete_kbnode(node);
+      {
+	delete_kbnode(node);
+	deleted=1;
+	uidnode->pkt->pkt.user_id->flags.compacted=1;
+      }
 
-  uid->flags.compacted=1;
-
   if(noisy)
     {
       const char *reason;
@@ -1705,7 +1709,7 @@
       xfree(user);
     }
 
-  return 1;
+  return deleted;
 }
 
 int
@@ -1725,6 +1729,34 @@
   return deleted;
 }
 
+void
+clean_key(KBNODE keyblock,int noisy,int self_only,
+	  int *uids_cleaned,int *sigs_cleaned)
+{
+  KBNODE uidnode;
+  int dummy;
+
+  if(!uids_cleaned)
+    uids_cleaned=&dummy;
+
+  if(!sigs_cleaned)
+    sigs_cleaned=&dummy;
+
+  merge_keys_and_selfsig(keyblock);
+
+  for(uidnode=keyblock->next;
+      uidnode && uidnode->pkt->pkttype!=PKT_PUBLIC_SUBKEY;
+      uidnode=uidnode->next)
+    if(uidnode->pkt->pkttype==PKT_USER_ID)
+      {
+	/* Do clean_uid_from_key first since if it fires off, we don't
+	   have to bother with the other */
+	*uids_cleaned+=clean_uid_from_key(keyblock,uidnode,noisy);
+	if(!uidnode->pkt->pkt.user_id->flags.compacted)
+	  *sigs_cleaned+=clean_sigs_from_uid(keyblock,uidnode,noisy,self_only);
+      }
+}
+
 /* Used by validate_one_keyblock to confirm a regexp within a trust
    signature.  Returns 1 for match, and 0 for no match or regex
    error. */

Modified: trunk/g10/trustdb.h
===================================================================
--- trunk/g10/trustdb.h	2005-11-12 03:48:02 UTC (rev 3931)
+++ trunk/g10/trustdb.h	2005-11-12 04:53:03 UTC (rev 3932)
@@ -84,6 +84,8 @@
 
 int clean_sigs_from_uid(KBNODE keyblock,KBNODE uidnode,int noisy,int self_only);
 int clean_uids_from_key(KBNODE keyblock,int noisy);
+void clean_key(KBNODE keyblock,int noisy,int self_only,
+	       int *uids_cleaned,int *sigs_cleaned);
 
 /*-- tdbdump.c --*/
 void list_trustdb(const char *username);




More information about the Gnupg-commits mailing list