[git] GnuPG - branch, master, updated. gnupg-2.1.19-90-g0526c99

by Werner Koch cvs at cvs.gnupg.org
Wed Mar 29 10:09:41 CEST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  0526c99164d3531b5ec763ffc672407eb24b2296 (commit)
       via  f5b565a5b8de3f2a3d98bc1a655e18333aee223b (commit)
       via  5b3523d3e055158cb9beb2c4a8419df52c764a18 (commit)
      from  b20780658ebb1e1245db18c04db3e815399cf706 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0526c99164d3531b5ec763ffc672407eb24b2296
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Mar 29 10:02:40 2017 +0200

    gpg: Change parse_packet to take a context.
    
    * g10/packet.h (struct parse_packet_ctx_s): New.
    (parse_packet_ctx_t): New type.
    (init_parse_packet): New macro.
    * g10/parse-packet.c (parse_packet, dbg_parse_packet): Change to take
    a parse context.  Change all callers to provide a context instead of
    directly supplying the input stream.
    (search_packet, dbg_search_packet): Ditto.
    (copy_all_packets, dbg_copy_all_packets): Init an use a parse context.
    (copy_some_packets, dbg_copy_some_packets): Ditto.
    (skip_some_packets, dbg_skip_some_packets): Ditto.
    --
    
    We will need this change to handle ring packets inside the parser.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/import.c b/g10/import.c
index ea7a92f..9aa6c8b 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -762,6 +762,7 @@ static int
 read_block( IOBUF a, PACKET **pending_pkt, kbnode_t *ret_root, int *r_v3keys)
 {
   int rc;
+  struct parse_packet_ctx_s parsectx;
   PACKET *pkt;
   kbnode_t root = NULL;
   int in_cert, in_v3key;
@@ -779,8 +780,9 @@ read_block( IOBUF a, PACKET **pending_pkt, kbnode_t *ret_root, int *r_v3keys)
 
   pkt = xmalloc (sizeof *pkt);
   init_packet (pkt);
+  init_parse_packet (&parsectx, a);
   in_v3key = 0;
-  while ((rc=parse_packet(a, pkt)) != -1)
+  while ((rc=parse_packet (&parsectx, pkt)) != -1)
     {
       if (rc && (gpg_err_code (rc) == GPG_ERR_LEGACY_KEY
                  && (pkt->pkttype == PKT_PUBLIC_KEY
diff --git a/g10/keydb.c b/g10/keydb.c
index 27dacf2..c0bc9f5 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -1156,6 +1156,7 @@ parse_keyblock_image (iobuf_t iobuf, int pk_no, int uid_no,
                       const u32 *sigstatus, kbnode_t *r_keyblock)
 {
   gpg_error_t err;
+  struct parse_packet_ctx_s parsectx;
   PACKET *pkt;
   kbnode_t keyblock = NULL;
   kbnode_t node, *tail;
@@ -1169,12 +1170,13 @@ parse_keyblock_image (iobuf_t iobuf, int pk_no, int uid_no,
   if (!pkt)
     return gpg_error_from_syserror ();
   init_packet (pkt);
+  init_parse_packet (&parsectx, iobuf);
   save_mode = set_packet_list_mode (0);
   in_cert = 0;
   n_sigs = 0;
   tail = NULL;
   pk_count = uid_count = 0;
-  while ((err = parse_packet (iobuf, pkt)) != -1)
+  while ((err = parse_packet (&parsectx, pkt)) != -1)
     {
       if (gpg_err_code (err) == GPG_ERR_UNKNOWN_PACKET)
         {
diff --git a/g10/keyedit.c b/g10/keyedit.c
index 9a7fe13..76d1889 100644
--- a/g10/keyedit.c
+++ b/g10/keyedit.c
@@ -2431,6 +2431,7 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
 	    char *fname;
 	    PACKET *pkt;
 	    IOBUF a;
+            struct parse_packet_ctx_s parsectx;
 
             if (!*arg_string)
 	      {
@@ -2464,7 +2465,8 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr,
 	    /* Parse and check that file.  */
 	    pkt = xmalloc (sizeof *pkt);
 	    init_packet (pkt);
-	    err = parse_packet (a, pkt);
+            init_parse_packet (&parsectx, a);
+	    err = parse_packet (&parsectx, pkt);
 	    iobuf_close (a);
 	    iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char *) fname);
 	    if (!err && pkt->pkttype != PKT_SECRET_KEY
diff --git a/g10/keyring.c b/g10/keyring.c
index 31f60f9..e4fc111 100644
--- a/g10/keyring.c
+++ b/g10/keyring.c
@@ -378,6 +378,7 @@ int
 keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
 {
     PACKET *pkt;
+    struct parse_packet_ctx_s parsectx;
     int rc;
     KBNODE keyblock = NULL, node, lastnode;
     IOBUF a;
@@ -407,10 +408,11 @@ keyring_get_keyblock (KEYRING_HANDLE hd, KBNODE *ret_kb)
 
     pkt = xmalloc (sizeof *pkt);
     init_packet (pkt);
+    init_parse_packet (&parsectx, a);
     hd->found.n_packets = 0;;
     lastnode = NULL;
     save_mode = set_packet_list_mode(0);
-    while ((rc=parse_packet (a, pkt)) != -1) {
+    while ((rc=parse_packet (&parsectx, pkt)) != -1) {
         hd->found.n_packets++;
         if (gpg_err_code (rc) == GPG_ERR_UNKNOWN_PACKET) {
 	    free_packet (pkt);
@@ -985,6 +987,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
 {
   int rc;
   PACKET pkt;
+  struct parse_packet_ctx_s parsectx;
   int save_mode;
   off_t offset, main_offset;
   size_t n;
@@ -1120,12 +1123,13 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
   if (DBG_LOOKUP)
     log_debug ("%s: %ssearching from start of resource.\n",
                __func__, scanned_from_start ? "" : "not ");
+  init_parse_packet (&parsectx, hd->current.iobuf);
   while (1)
     {
       byte afp[MAX_FINGERPRINT_LEN];
       size_t an;
 
-      rc = search_packet (hd->current.iobuf, &pkt, &offset, need_uid);
+      rc = search_packet (&parsectx, &pkt, &offset, need_uid);
       if (ignore_legacy && gpg_err_code (rc) == GPG_ERR_LEGACY_KEY)
         {
           free_packet (&pkt);
diff --git a/g10/mainproc.c b/g10/mainproc.c
index 4c5dce1..30d9b18 100644
--- a/g10/mainproc.c
+++ b/g10/mainproc.c
@@ -1330,6 +1330,7 @@ static int
 do_proc_packets (ctrl_t ctrl, CTX c, iobuf_t a)
 {
   PACKET *pkt;
+  struct parse_packet_ctx_s parsectx;
   int rc = 0;
   int any_data = 0;
   int newpkt;
@@ -1341,7 +1342,8 @@ do_proc_packets (ctrl_t ctrl, CTX c, iobuf_t a)
   pkt = xmalloc( sizeof *pkt );
   c->iobuf = a;
   init_packet(pkt);
-  while ((rc=parse_packet(a, pkt)) != -1)
+  init_parse_packet (&parsectx, a);
+  while ((rc=parse_packet (&parsectx, pkt)) != -1)
     {
       any_data = 1;
       if (rc)
diff --git a/g10/packet.h b/g10/packet.h
index efccc76..ffa1fe9 100644
--- a/g10/packet.h
+++ b/g10/packet.h
@@ -592,12 +592,26 @@ int list_packets( iobuf_t a );
 */
 int set_packet_list_mode( int mode );
 
+
+/* A context used with parse_packet.  */
+struct parse_packet_ctx_s
+{
+  iobuf_t inp; /* The input stream with the packets.  */
+};
+typedef struct parse_packet_ctx_s *parse_packet_ctx_t;
+
+#define init_parse_packet(a,i) do { (a)->inp = (i);    \
+    /**/                       } while (0)
+
+
+
 #if DEBUG_PARSE_PACKET
 /* There are debug functions and should not be used directly.  */
-int dbg_search_packet( iobuf_t inp, PACKET *pkt, off_t *retpos, int with_uid,
+int dbg_search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
+                       off_t *retpos, int with_uid,
                        const char* file, int lineno  );
-int dbg_parse_packet( iobuf_t inp, PACKET *ret_pkt,
-                      const char* file, int lineno );
+int dbg_parse_packet (parse_packet_ctx_t ctx, PACKET *ret_pkt,
+                      const char *file, int lineno);
 int dbg_copy_all_packets( iobuf_t inp, iobuf_t out,
                           const char* file, int lineno  );
 int dbg_copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff,
@@ -616,51 +630,53 @@ int dbg_skip_some_packets( iobuf_t inp, unsigned n,
              dbg_skip_some_packets((a),(b), __FILE__, __LINE__ )
 #else
 /* Return the next valid OpenPGP packet in *PKT.  (This function will
-   skip any packets whose type is 0.)
-
-   Returns 0 on success, -1 if EOF is reached, and an error code
-   otherwise.  In the case of an error, the packet in *PKT may be
-   partially constructed.  As such, even if there is an error, it is
-   necessary to free *PKT to avoid a resource leak.  To detect what
-   has been allocated, clear *PKT before calling this function.  */
-int parse_packet( iobuf_t inp, PACKET *pkt);
+ * skip any packets whose type is 0.)  CTX must have been setup prior to
+ * calling this function.
+ *
+ * Returns 0 on success, -1 if EOF is reached, and an error code
+ * otherwise.  In the case of an error, the packet in *PKT may be
+ * partially constructed.  As such, even if there is an error, it is
+ * necessary to free *PKT to avoid a resource leak.  To detect what
+ * has been allocated, clear *PKT before calling this function.  */
+int parse_packet (parse_packet_ctx_t ctx, PACKET *pkt);
 
 /* Return the first OpenPGP packet in *PKT that contains a key (either
-   a public subkey, a public key, a secret subkey or a secret key) or,
-   if WITH_UID is set, a user id.
-
-   Saves the position in the pipeline of the start of the returned
-   packet (according to iobuf_tell) in RETPOS, if it is not NULL.
-
-   The return semantics are the same as parse_packet.  */
-int search_packet( iobuf_t inp, PACKET *pkt, off_t *retpos, int with_uid );
+ * a public subkey, a public key, a secret subkey or a secret key) or,
+ * if WITH_UID is set, a user id.
+ *
+ * Saves the position in the pipeline of the start of the returned
+ * packet (according to iobuf_tell) in RETPOS, if it is not NULL.
+ *
+ * The return semantics are the same as parse_packet.  */
+int search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
+                   off_t *retpos, int with_uid);
 
 /* Copy all packets (except invalid packets, i.e., those with a type
-   of 0) from INP to OUT until either an error occurs or EOF is
-   reached.
-
-   Returns -1 when end of file is reached or an error code, if an
-   error occurred.  (Note: this function never returns 0, because it
-   effectively keeps going until it gets an EOF.)  */
-int copy_all_packets( iobuf_t inp, iobuf_t out );
+ * of 0) from INP to OUT until either an error occurs or EOF is
+ * reached.
+ *
+ * Returns -1 when end of file is reached or an error code, if an
+ * error occurred.  (Note: this function never returns 0, because it
+ * effectively keeps going until it gets an EOF.)  */
+int copy_all_packets (iobuf_t inp, iobuf_t out );
 
 /* Like copy_all_packets, but stops at the first packet that starts at
-   or after STOPOFF (as indicated by iobuf_tell).
-
-   Example: if STOPOFF is 100, the first packet in INP goes from 0 to
-   110 and the next packet starts at offset 111, then the packet
-   starting at offset 0 will be completely processed (even though it
-   extends beyond STOPOFF) and the packet starting at offset 111 will
-   not be processed at all.  */
-int copy_some_packets( iobuf_t inp, iobuf_t out, off_t stopoff );
+ * or after STOPOFF (as indicated by iobuf_tell).
+ *
+ * Example: if STOPOFF is 100, the first packet in INP goes from
+ * 0 to 110 and the next packet starts at offset 111, then the packet
+ * starting at offset 0 will be completely processed (even though it
+ * extends beyond STOPOFF) and the packet starting at offset 111 will
+ * not be processed at all.  */
+int copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff);
 
 /* Skips the next N packets from INP.
-
-   If parsing a packet returns an error code, then the function stops
-   immediately and returns the error code.  Note: in the case of an
-   error, this function does not indicate how many packets were
-   successfully processed.  */
-int skip_some_packets( iobuf_t inp, unsigned n );
+ *
+ * If parsing a packet returns an error code, then the function stops
+ * immediately and returns the error code.  Note: in the case of an
+ * error, this function does not indicate how many packets were
+ * successfully processed.  */
+int skip_some_packets (iobuf_t inp, unsigned int n);
 #endif
 
 /* Parse a signature packet and store it in *SIG.
diff --git a/g10/parse-packet.c b/g10/parse-packet.c
index 06b286b..7766a45 100644
--- a/g10/parse-packet.c
+++ b/g10/parse-packet.c
@@ -48,7 +48,7 @@ static int mpi_print_mode;
 static int list_mode;
 static estream_t listfp;
 
-static int parse (IOBUF inp, PACKET * pkt, int onlykeypkts,
+static int parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts,
 		  off_t * retpos, int *skip, IOBUF out, int do_skip
 #ifdef DEBUG_PARSE_PACKET
 		  , const char *dbg_w, const char *dbg_f, int dbg_l
@@ -263,26 +263,27 @@ unknown_pubkey_warning (int algo)
 
 #ifdef DEBUG_PARSE_PACKET
 int
-dbg_parse_packet (IOBUF inp, PACKET *pkt, const char *dbg_f, int dbg_l)
+dbg_parse_packet (parse_packet_ctx_t ctx, PACKET *pkt,
+                  const char *dbg_f, int dbg_l)
 {
   int skip, rc;
 
   do
     {
-      rc = parse (inp, pkt, 0, NULL, &skip, NULL, 0, "parse", dbg_f, dbg_l);
+      rc = parse (ctx, pkt, 0, NULL, &skip, NULL, 0, "parse", dbg_f, dbg_l);
     }
   while (skip && ! rc);
   return rc;
 }
 #else /*!DEBUG_PARSE_PACKET*/
 int
-parse_packet (IOBUF inp, PACKET * pkt)
+parse_packet (parse_packet_ctx_t ctx, PACKET *pkt)
 {
   int skip, rc;
 
   do
     {
-      rc = parse (inp, pkt, 0, NULL, &skip, NULL, 0);
+      rc = parse (ctx, pkt, 0, NULL, &skip, NULL, 0);
     }
   while (skip && ! rc);
   return rc;
@@ -296,29 +297,30 @@ parse_packet (IOBUF inp, PACKET * pkt)
  */
 #ifdef DEBUG_PARSE_PACKET
 int
-dbg_search_packet (IOBUF inp, PACKET * pkt, off_t * retpos, int with_uid,
+dbg_search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
+                   off_t * retpos, int with_uid,
 		   const char *dbg_f, int dbg_l)
 {
   int skip, rc;
 
   do
     {
-      rc =
-	parse (inp, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0, "search",
-	       dbg_f, dbg_l);
+      rc = parse (ctx, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0, "search",
+                  dbg_f, dbg_l);
     }
   while (skip && ! rc);
   return rc;
 }
 #else /*!DEBUG_PARSE_PACKET*/
 int
-search_packet (IOBUF inp, PACKET * pkt, off_t * retpos, int with_uid)
+search_packet (parse_packet_ctx_t ctx, PACKET *pkt,
+               off_t * retpos, int with_uid)
 {
   int skip, rc;
 
   do
     {
-      rc = parse (inp, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0);
+      rc = parse (ctx, pkt, with_uid ? 2 : 1, retpos, &skip, NULL, 0);
     }
   while (skip && ! rc);
   return rc;
@@ -331,38 +333,45 @@ search_packet (IOBUF inp, PACKET * pkt, off_t * retpos, int with_uid)
  */
 #ifdef DEBUG_PARSE_PACKET
 int
-dbg_copy_all_packets (IOBUF inp, IOBUF out, const char *dbg_f, int dbg_l)
+dbg_copy_all_packets (iobuf_t inp, iobuf_t out, const char *dbg_f, int dbg_l)
 {
   PACKET pkt;
+  struct parse_packet_ctx_s parsectx;
   int skip, rc = 0;
 
   if (! out)
     log_bug ("copy_all_packets: OUT may not be NULL.\n");
 
+  init_parse_packet (&parsectx, inp);
+
   do
     {
       init_packet (&pkt);
     }
   while (!
 	 (rc =
-	  parse (inp, &pkt, 0, NULL, &skip, out, 0, "copy", dbg_f, dbg_l)));
+	  parse (&parsectx, &pkt, 0, NULL, &skip, out, 0, "copy",
+                 dbg_f, dbg_l)));
   return rc;
 }
 #else /*!DEBUG_PARSE_PACKET*/
 int
-copy_all_packets (IOBUF inp, IOBUF out)
+copy_all_packets (iobuf_t inp, iobuf_t out)
 {
   PACKET pkt;
+  struct parse_packet_ctx_s parsectx;
   int skip, rc = 0;
 
   if (! out)
     log_bug ("copy_all_packets: OUT may not be NULL.\n");
 
+  init_parse_packet (&parsectx, inp);
+
   do
     {
       init_packet (&pkt);
     }
-  while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0)));
+  while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0)));
   return rc;
 }
 #endif /*!DEBUG_PARSE_PACKET*/
@@ -375,34 +384,44 @@ copy_all_packets (IOBUF inp, IOBUF out)
  */
 #ifdef DEBUG_PARSE_PACKET
 int
-dbg_copy_some_packets (IOBUF inp, IOBUF out, off_t stopoff,
+dbg_copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff,
 		       const char *dbg_f, int dbg_l)
 {
+  int rc = 0;
   PACKET pkt;
-  int skip, rc = 0;
+  int skip;
+  struct parse_packet_ctx_s parsectx;
+
+  init_parse_packet (&parsectx, inp);
+
   do
     {
       if (iobuf_tell (inp) >= stopoff)
 	return 0;
       init_packet (&pkt);
     }
-  while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0,
+  while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0,
 		       "some", dbg_f, dbg_l)));
   return rc;
 }
 #else /*!DEBUG_PARSE_PACKET*/
 int
-copy_some_packets (IOBUF inp, IOBUF out, off_t stopoff)
+copy_some_packets (iobuf_t inp, iobuf_t out, off_t stopoff)
 {
+  int rc = 0;
   PACKET pkt;
-  int skip, rc = 0;
+  struct parse_packet_ctx_s parsectx;
+  int skip;
+
+  init_parse_packet (&parsectx, inp);
+
   do
     {
       if (iobuf_tell (inp) >= stopoff)
 	return 0;
       init_packet (&pkt);
     }
-  while (!(rc = parse (inp, &pkt, 0, NULL, &skip, out, 0)));
+  while (!(rc = parse (&parsectx, &pkt, 0, NULL, &skip, out, 0)));
   return rc;
 }
 #endif /*!DEBUG_PARSE_PACKET*/
@@ -413,29 +432,38 @@ copy_some_packets (IOBUF inp, IOBUF out, off_t stopoff)
  */
 #ifdef DEBUG_PARSE_PACKET
 int
-dbg_skip_some_packets (IOBUF inp, unsigned n, const char *dbg_f, int dbg_l)
+dbg_skip_some_packets (iobuf_t inp, unsigned n, const char *dbg_f, int dbg_l)
 {
-  int skip, rc = 0;
+  int rc = 0;
+  int skip;
   PACKET pkt;
+  struct parse_packet_ctx_s parsectx;
+
+  init_parse_packet (&parsectx, inp);
 
   for (; n && !rc; n--)
     {
       init_packet (&pkt);
-      rc = parse (inp, &pkt, 0, NULL, &skip, NULL, 1, "skip", dbg_f, dbg_l);
+      rc = parse (&parsectx, &pkt, 0, NULL, &skip, NULL, 1, "skip",
+                  dbg_f, dbg_l);
     }
   return rc;
 }
 #else /*!DEBUG_PARSE_PACKET*/
 int
-skip_some_packets (IOBUF inp, unsigned n)
+skip_some_packets (iobuf_t inp, unsigned int n)
 {
-  int skip, rc = 0;
+  int rc = 0;
+  int skip;
   PACKET pkt;
+  struct parse_packet_ctx_s parsectx;
+
+  init_parse_packet (&parsectx, inp);
 
   for (; n && !rc; n--)
     {
       init_packet (&pkt);
-      rc = parse (inp, &pkt, 0, NULL, &skip, NULL, 1);
+      rc = parse (&parsectx, &pkt, 0, NULL, &skip, NULL, 1);
     }
   return rc;
 }
@@ -466,18 +494,20 @@ skip_some_packets (IOBUF inp, unsigned n)
    Note: ONLYKEYPKTS and DO_SKIP are only respected if OUT is NULL,
    i.e., the packets are not simply being copied.
 
-   If RETPOS is not NULL, then the position of INP (as returned by
-   iobuf_tell) is saved there before any data is read from INP.
+   If RETPOS is not NULL, then the position of CTX->INP (as returned by
+   iobuf_tell) is saved there before any data is read from CTX->INP.
   */
 static int
-parse (IOBUF inp, PACKET * pkt, int onlykeypkts, off_t * retpos,
+parse (parse_packet_ctx_t ctx, PACKET *pkt, int onlykeypkts, off_t * retpos,
        int *skip, IOBUF out, int do_skip
 #ifdef DEBUG_PARSE_PACKET
        , const char *dbg_w, const char *dbg_f, int dbg_l
 #endif
        )
 {
-  int rc = 0, c, ctb, pkttype, lenbytes;
+  int rc = 0;
+  iobuf_t inp;
+  int c, ctb, pkttype, lenbytes;
   unsigned long pktlen;
   byte hdr[8];
   int hdrlen;
@@ -486,6 +516,8 @@ parse (IOBUF inp, PACKET * pkt, int onlykeypkts, off_t * retpos,
   off_t pos;
 
   *skip = 0;
+  inp = ctx->inp;
+
   log_assert (!pkt->pkt.generic);
   if (retpos || list_mode)
     {

commit f5b565a5b8de3f2a3d98bc1a655e18333aee223b
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Mar 29 08:44:52 2017 +0200

    gpg: Export ring trust packets in backup mode.
    
    * g10/export.c (write_keyblock_to_output): Export ring trust packets.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/export.c b/g10/export.c
index a7aecd6..5b0c81d 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -1282,8 +1282,11 @@ write_keyblock_to_output (kbnode_t keyblock, int with_armor,
 
   for (node = keyblock; node; node = node->next)
     {
-      if (is_deleted_kbnode (node) || node->pkt->pkttype == PKT_RING_TRUST)
+      if (is_deleted_kbnode (node))
         continue;
+      if (node->pkt->pkttype == PKT_RING_TRUST && !(options & EXPORT_BACKUP))
+        continue;
+
       if (!pk && (node->pkt->pkttype == PKT_PUBLIC_KEY
                   || node->pkt->pkttype == PKT_SECRET_KEY))
         pk = node->pkt->pkt.public_key;

commit 5b3523d3e055158cb9beb2c4a8419df52c764a18
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Mar 29 08:43:04 2017 +0200

    indent: Re-indent parts of build-packet.c
    
    --

diff --git a/g10/build-packet.c b/g10/build-packet.c
index c81c1ab..512e55c 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -85,93 +85,101 @@ ctb_pkttype (int ctb)
 int
 build_packet( IOBUF out, PACKET *pkt )
 {
-    int new_ctb=0, rc=0, ctb;
-    int pkttype;
+  int rc = 0;
+  int new_ctb = 0;
+  int ctb, pkttype;
 
-    if( DBG_PACKET )
-	log_debug("build_packet() type=%d\n", pkt->pkttype );
-    log_assert( pkt->pkt.generic );
+  if (DBG_PACKET)
+    log_debug ("build_packet() type=%d\n", pkt->pkttype);
+  log_assert (pkt->pkt.generic);
 
-    switch ((pkttype = pkt->pkttype))
-      {
-      case PKT_PUBLIC_KEY:
-        if (pkt->pkt.public_key->seckey_info)
-          pkttype = PKT_SECRET_KEY;
-        break;
-      case PKT_PUBLIC_SUBKEY:
-        if (pkt->pkt.public_key->seckey_info)
-          pkttype = PKT_SECRET_SUBKEY;
-        break;
-      case PKT_PLAINTEXT: new_ctb = pkt->pkt.plaintext->new_ctb; break;
-      case PKT_ENCRYPTED:
-      case PKT_ENCRYPTED_MDC: new_ctb = pkt->pkt.encrypted->new_ctb; break;
-      case PKT_COMPRESSED:new_ctb = pkt->pkt.compressed->new_ctb; break;
-      case PKT_USER_ID:
-	if( pkt->pkt.user_id->attrib_data )
-	  pkttype = PKT_ATTRIBUTE;
-	break;
-      default: break;
-      }
+  switch ((pkttype = pkt->pkttype))
+    {
+    case PKT_PUBLIC_KEY:
+      if (pkt->pkt.public_key->seckey_info)
+        pkttype = PKT_SECRET_KEY;
+      break;
+    case PKT_PUBLIC_SUBKEY:
+      if (pkt->pkt.public_key->seckey_info)
+        pkttype = PKT_SECRET_SUBKEY;
+      break;
+    case PKT_PLAINTEXT:
+      new_ctb = pkt->pkt.plaintext->new_ctb;
+      break;
+    case PKT_ENCRYPTED:
+    case PKT_ENCRYPTED_MDC:
+      new_ctb = pkt->pkt.encrypted->new_ctb;
+      break;
+    case PKT_COMPRESSED:
+      new_ctb = pkt->pkt.compressed->new_ctb;
+      break;
+    case PKT_USER_ID:
+      if (pkt->pkt.user_id->attrib_data)
+        pkttype = PKT_ATTRIBUTE;
+      break;
+    default:
+      break;
+    }
 
-    if( new_ctb || pkttype > 15 ) /* new format */
-	ctb = 0xc0 | (pkttype & 0x3f);
-    else
-	ctb = 0x80 | ((pkttype & 15)<<2);
-    switch( pkttype )
-      {
-      case PKT_ATTRIBUTE:
-      case PKT_USER_ID:
-	rc = do_user_id( out, ctb, pkt->pkt.user_id );
-	break;
-      case PKT_OLD_COMMENT:
-      case PKT_COMMENT:
-	/*
-	  Ignore these.  Theoretically, this will never be called as
-	  we have no way to output comment packets any longer, but
-	  just in case there is some code path that would end up
-	  outputting a comment that was written before comments were
-	  dropped (in the public key?) this is a no-op.
-	*/
-	break;
-      case PKT_PUBLIC_SUBKEY:
-      case PKT_PUBLIC_KEY:
-      case PKT_SECRET_SUBKEY:
-      case PKT_SECRET_KEY:
-	rc = do_key (out, ctb, pkt->pkt.public_key);
-	break;
-      case PKT_SYMKEY_ENC:
-	rc = do_symkey_enc( out, ctb, pkt->pkt.symkey_enc );
-	break;
-      case PKT_PUBKEY_ENC:
-	rc = do_pubkey_enc( out, ctb, pkt->pkt.pubkey_enc );
-	break;
-      case PKT_PLAINTEXT:
-	rc = do_plaintext( out, ctb, pkt->pkt.plaintext );
-	break;
-      case PKT_ENCRYPTED:
-	rc = do_encrypted( out, ctb, pkt->pkt.encrypted );
-	break;
-      case PKT_ENCRYPTED_MDC:
-	rc = do_encrypted_mdc( out, ctb, pkt->pkt.encrypted );
-	break;
-      case PKT_COMPRESSED:
-	rc = do_compressed( out, ctb, pkt->pkt.compressed );
-	break;
-      case PKT_SIGNATURE:
-	rc = do_signature( out, ctb, pkt->pkt.signature );
-	break;
-      case PKT_ONEPASS_SIG:
-	rc = do_onepass_sig( out, ctb, pkt->pkt.onepass_sig );
-	break;
-      case PKT_RING_TRUST:
-	break; /* ignore it (keyring.c does write it directly)*/
-      case PKT_MDC: /* we write it directly, so we should never see it here. */
-      default:
-	log_bug("invalid packet type in build_packet()\n");
-	break;
-      }
+  if (new_ctb || pkttype > 15) /* new format */
+    ctb = (0xc0 | (pkttype & 0x3f));
+  else
+    ctb = (0x80 | ((pkttype & 15)<<2));
+  switch (pkttype)
+    {
+    case PKT_ATTRIBUTE:
+    case PKT_USER_ID:
+      rc = do_user_id (out, ctb, pkt->pkt.user_id);
+      break;
+    case PKT_OLD_COMMENT:
+    case PKT_COMMENT:
+      /* Ignore these.  Theoretically, this will never be called as we
+       * have no way to output comment packets any longer, but just in
+       * case there is some code path that would end up outputting a
+       * comment that was written before comments were dropped (in the
+       * public key?) this is a no-op. 	*/
+      break;
+    case PKT_PUBLIC_SUBKEY:
+    case PKT_PUBLIC_KEY:
+    case PKT_SECRET_SUBKEY:
+    case PKT_SECRET_KEY:
+      rc = do_key (out, ctb, pkt->pkt.public_key);
+      break;
+    case PKT_SYMKEY_ENC:
+      rc = do_symkey_enc (out, ctb, pkt->pkt.symkey_enc);
+      break;
+    case PKT_PUBKEY_ENC:
+      rc = do_pubkey_enc (out, ctb, pkt->pkt.pubkey_enc);
+      break;
+    case PKT_PLAINTEXT:
+      rc = do_plaintext (out, ctb, pkt->pkt.plaintext);
+      break;
+    case PKT_ENCRYPTED:
+      rc = do_encrypted (out, ctb, pkt->pkt.encrypted);
+      break;
+    case PKT_ENCRYPTED_MDC:
+      rc = do_encrypted_mdc (out, ctb, pkt->pkt.encrypted);
+      break;
+    case PKT_COMPRESSED:
+      rc = do_compressed (out, ctb, pkt->pkt.compressed);
+      break;
+    case PKT_SIGNATURE:
+      rc = do_signature (out, ctb, pkt->pkt.signature);
+      break;
+    case PKT_ONEPASS_SIG:
+      rc = do_onepass_sig (out, ctb, pkt->pkt.onepass_sig);
+      break;
+    case PKT_RING_TRUST:
+      /* Ignore it (keyring.c does write it directly)  */
+      break;
+    case PKT_MDC:
+      /* We write it directly, so we should never see it here. */
+    default:
+      log_bug ("invalid packet type in build_packet()\n");
+      break;
+    }
 
-    return rc;
+  return rc;
 }
 
 
@@ -262,34 +270,35 @@ gpg_mpi_write_nohdr (iobuf_t out, gcry_mpi_t a)
 u32
 calc_packet_length( PACKET *pkt )
 {
-    u32 n=0;
-    int new_ctb = 0;
-
-    log_assert (pkt->pkt.generic);
-    switch( pkt->pkttype ) {
-      case PKT_PLAINTEXT:
-	n = calc_plaintext( pkt->pkt.plaintext );
-	new_ctb = pkt->pkt.plaintext->new_ctb;
-	break;
-      case PKT_ATTRIBUTE:
-      case PKT_USER_ID:
-      case PKT_COMMENT:
-      case PKT_PUBLIC_KEY:
-      case PKT_SECRET_KEY:
-      case PKT_SYMKEY_ENC:
-      case PKT_PUBKEY_ENC:
-      case PKT_ENCRYPTED:
-      case PKT_SIGNATURE:
-      case PKT_ONEPASS_SIG:
-      case PKT_RING_TRUST:
-      case PKT_COMPRESSED:
-      default:
-	log_bug("invalid packet type in calc_packet_length()");
-	break;
+  u32 n = 0;
+  int new_ctb = 0;
+
+  log_assert (pkt->pkt.generic);
+  switch (pkt->pkttype)
+    {
+    case PKT_PLAINTEXT:
+      n = calc_plaintext (pkt->pkt.plaintext);
+      new_ctb = pkt->pkt.plaintext->new_ctb;
+      break;
+    case PKT_ATTRIBUTE:
+    case PKT_USER_ID:
+    case PKT_COMMENT:
+    case PKT_PUBLIC_KEY:
+    case PKT_SECRET_KEY:
+    case PKT_SYMKEY_ENC:
+    case PKT_PUBKEY_ENC:
+    case PKT_ENCRYPTED:
+    case PKT_SIGNATURE:
+    case PKT_ONEPASS_SIG:
+    case PKT_RING_TRUST:
+    case PKT_COMPRESSED:
+    default:
+      log_bug ("invalid packet type in calc_packet_length()");
+      break;
     }
 
-    n += calc_header_length(n, new_ctb);
-    return n;
+  n += calc_header_length (n, new_ctb);
+  return n;
 }
 
 
@@ -312,10 +321,10 @@ write_fake_data (IOBUF out, gcry_mpi_t a)
 
 
 /* Serialize the user id (RFC 4880, Section 5.11) or the user
-   attribute UID (Section 5.12) and write it to OUT.
-
-   CTB is the serialization's CTB.  It specifies the header format and
-   the packet's type.  The header length must not be set.  */
+ * attribute UID (Section 5.12) and write it to OUT.
+ *
+ * CTB is the serialization's CTB.  It specifies the header format and
+ * the packet's type.  The header length must not be set.  */
 static int
 do_user_id( IOBUF out, int ctb, PKT_user_id *uid )
 {
@@ -339,17 +348,17 @@ do_user_id( IOBUF out, int ctb, PKT_user_id *uid )
 
 
 /* Serialize the key (RFC 4880, Section 5.5) described by PK and write
-   it to OUT.
-
-   This function serializes both primary keys and subkeys with or
-   without a secret part.
-
-   CTB is the serialization's CTB.  It specifies the header format and
-   the packet's type.  The header length must not be set.
-
-   PK->VERSION specifies the serialization format.  A value of 0 means
-   to use the default version.  Currently, only version 4 packets are
-   supported.
+ * it to OUT.
+ *
+ * This function serializes both primary keys and subkeys with or
+ * without a secret part.
+ *
+ * CTB is the serialization's CTB.  It specifies the header format and
+ * the packet's type.  The header length must not be set.
+ *
+ * PK->VERSION specifies the serialization format.  A value of 0 means
+ * to use the default version.  Currently, only version 4 packets are
+ * supported.
  */
 static int
 do_key (iobuf_t out, int ctb, PKT_public_key *pk)
@@ -496,36 +505,33 @@ do_key (iobuf_t out, int ctb, PKT_public_key *pk)
   return err;
 }
 
-/* Serialize the symmetric-key encrypted session key packet (RFC 4880,
-   5.3) described by ENC and write it to OUT.
 
-   CTB is the serialization's CTB.  It specifies the header format and
-   the packet's type.  The header length must not be set.  */
+/* Serialize the symmetric-key encrypted session key packet (RFC 4880,
+ * 5.3) described by ENC and write it to OUT.
+ *
+ * CTB is the serialization's CTB.  It specifies the header format and
+ * the packet's type.  The header length must not be set.  */
 static int
 do_symkey_enc( IOBUF out, int ctb, PKT_symkey_enc *enc )
 {
-    int rc = 0;
-    IOBUF a = iobuf_temp();
+  int rc = 0;
+  IOBUF a = iobuf_temp();
 
-    log_assert (ctb_pkttype (ctb) == PKT_SYMKEY_ENC);
+  log_assert (ctb_pkttype (ctb) == PKT_SYMKEY_ENC);
 
-    /* The only acceptable version.  */
-    log_assert( enc->version == 4 );
+  /* The only acceptable version.  */
+  log_assert( enc->version == 4 );
 
-    /* RFC 4880, Section 3.7.  */
-    switch( enc->s2k.mode )
-      {
-      /* Simple S2K.  */
-      case 0:
-      /* Salted S2K.  */
-      case 1:
-      /* Iterated and salted S2K.  */
-      case 3:
-        /* Reasonable values.  */
-        break;
+  /* RFC 4880, Section 3.7.  */
+  switch (enc->s2k.mode)
+    {
+    case 0: /* Simple S2K.  */
+    case 1: /* Salted S2K.  */
+    case 3: /* Iterated and salted S2K.  */
+      break; /* Reasonable values.  */
 
-      default:
-        log_bug("do_symkey_enc: s2k=%d\n", enc->s2k.mode );
+    default:
+      log_bug ("do_symkey_enc: s2k=%d\n", enc->s2k.mode);
     }
     iobuf_put( a, enc->version );
     iobuf_put( a, enc->cipher_algo );

-----------------------------------------------------------------------

Summary of changes:
 g10/build-packet.c | 298 +++++++++++++++++++++++++++--------------------------
 g10/export.c       |   5 +-
 g10/import.c       |   4 +-
 g10/keydb.c        |   4 +-
 g10/keyedit.c      |   4 +-
 g10/keyring.c      |   8 +-
 g10/mainproc.c     |   4 +-
 g10/packet.h       |  96 ++++++++++-------
 g10/parse-packet.c |  94 +++++++++++------
 9 files changed, 293 insertions(+), 224 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list