[git] GnuPG - branch, master, updated. gnupg-2.1.15-61-g0a4a03e

by Werner Koch cvs at cvs.gnupg.org
Mon Sep 5 10:00:08 CEST 2016


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  0a4a03e5310946b0866a0f6a34031eda7a240162 (commit)
       via  959cd8903fd012e63dbb156db56708dd3934b5df (commit)
       via  c8e0d37f4152d1341ef562a190fce93a0386a759 (commit)
      from  f9e49c80e706a27d5e30d4b3237ff26367a67130 (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 0a4a03e5310946b0866a0f6a34031eda7a240162
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 5 09:51:16 2016 +0200

    gpg: New export filter drop-subkey.
    
    * g10/import.c (impex_filter_getval): Add properties for key packets.
    * g10/export.c (export_drop_subkey): New var.
    (cleanup_export_globals): Release that var.
    (parse_and_set_export_filter): Add filter "drop-subkey".
    (apply_drop_subkey_filter): New.
    (do_export_stream): Run that filter.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/doc/gpg.texi b/doc/gpg.texi
index 901d1ee..8864a0a 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -2254,6 +2254,10 @@ The available filter types are:
   This filter will keep a user id packet and its dependent packets in
   the keyblock if the expression evaluates to true.
 
+  @item drop-subkey
+  This filter drops the selected subkeys.
+  Currently only implemented for --export-filter.
+
   @item drop-sig
   This filter drops the selected key signatures on user ids.
   Self-signatures are not consideres.
@@ -2276,9 +2280,23 @@ The available properties are:
   The addr-spec part of a user id with mailbox or the empty string.
   (keep-uid)
 
+  @item key_algo
+  A number with the public key algorithm of a key or subkey packet.
+  (drop-subkey)
+
+  @item key_created
+  @itemx key_created_d
+  The first is the timestamp a public key or subkey packet was
+  created.  The second is the same but given as an ISO string,
+  e.g. "2016-08-17". (drop-subkey)
+
   @item primary
   Boolean indicating whether the user id is the primary one.  (keep-uid)
 
+  @item secret
+  Boolean indicating whether a key or subkey is a secret one.
+  drop-subkey)
+
   @item sig_created
   @itemx sig_created_d
   The first is the timestamp a signature packet was created.  The
diff --git a/g10/export.c b/g10/export.c
index e0699db..78cb85f 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -62,11 +62,13 @@ struct export_stats_s
 
 /* A global variable to store the selector created from
  * --export-filter keep-uid=EXPR.
+ * --export-filter drop-subkey=EXPR.
  *
  * FIXME: We should put this into the CTRL object but that requires a
  * lot more changes right now.
  */
 static recsel_expr_t export_keep_uid;
+static recsel_expr_t export_drop_subkey;
 
 
 
@@ -88,6 +90,8 @@ cleanup_export_globals (void)
 {
   recsel_release (export_keep_uid);
   export_keep_uid = NULL;
+  recsel_release (export_drop_subkey);
+  export_drop_subkey = NULL;
 }
 
 
@@ -142,6 +146,14 @@ parse_export_options(char *str,unsigned int *options,int noisy)
  *                - uid  :: The entire user ID.
  *                - mbox :: The mail box part of the user ID.
  *                - primary :: Evaluate to true for the primary user ID.
+ *
+ *  - drop-subkey :: If the expression evaluates to true for a subkey
+ *                packet that subkey and all it dependencies will be
+ *                remove from the keyblock.  The expression may use these
+ *                variables:
+ *
+ *                - secret   :: 1 for a secret subkey, else 0.
+ *                - key_algo :: Public key algorithm id
  */
 gpg_error_t
 parse_and_set_export_filter (const char *string)
@@ -153,6 +165,8 @@ parse_and_set_export_filter (const char *string)
 
   if (!strncmp (string, "keep-uid=", 9))
     err = recsel_parse_expr (&export_keep_uid, string+9);
+  else if (!strncmp (string, "drop-subkey=", 12))
+    err = recsel_parse_expr (&export_drop_subkey, string+12);
   else
     err = gpg_error (GPG_ERR_INV_NAME);
 
@@ -1329,6 +1343,38 @@ apply_keep_uid_filter (kbnode_t keyblock, recsel_expr_t selector)
 }
 
 
+/*
+ * Apply the drop-subkey filter to the keyblock.  The deleted nodes are
+ * marked and thus the caller should call commit_kbnode afterwards.
+ * KEYBLOCK must not have any blocks marked as deleted.
+ */
+static void
+apply_drop_subkey_filter (kbnode_t keyblock, recsel_expr_t selector)
+{
+  kbnode_t node;
+
+  for (node = keyblock->next; node; node = node->next )
+    {
+      if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY
+          || node->pkt->pkttype == PKT_SECRET_SUBKEY)
+        {
+          if (recsel_select (selector, impex_filter_getval, node))
+            {
+              log_debug ("drop-subkey: deleting a key\n");
+              /* The subkey packet and all following packets up to the
+               * next subkey.  */
+              delete_kbnode (node);
+              for (; node->next
+                     && node->next->pkt->pkttype != PKT_PUBLIC_SUBKEY
+                     && node->next->pkt->pkttype != PKT_SECRET_SUBKEY ;
+                   node = node->next)
+                delete_kbnode (node->next);
+	    }
+        }
+    }
+}
+
+
 /* Print DANE or PKA records for all user IDs in KEYBLOCK to OUT.  The
  * data for the record is taken from (DATA,DATELEN).  PK is the public
  * key packet with the primary key. */
@@ -1922,6 +1968,13 @@ do_export_stream (ctrl_t ctrl, iobuf_t out, strlist_t users, int secret,
           commit_kbnode (&keyblock);
         }
 
+      if (export_drop_subkey)
+        {
+          commit_kbnode (&keyblock);
+          apply_drop_subkey_filter (keyblock, export_drop_subkey);
+          commit_kbnode (&keyblock);
+        }
+
       /* And write it. */
       err = do_export_one_keyblock (ctrl, keyblock, keyid,
                                     out_help? out_help : out,
diff --git a/g10/import.c b/g10/import.c
index 14abd2b..f32a3da 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -1157,6 +1157,35 @@ impex_filter_getval (void *cookie, const char *propname)
       else
         result = NULL;
     }
+  else if (node->pkt->pkttype == PKT_PUBLIC_KEY
+           || node->pkt->pkttype == PKT_SECRET_KEY
+           || node->pkt->pkttype == PKT_PUBLIC_SUBKEY
+           || node->pkt->pkttype == PKT_SECRET_SUBKEY)
+    {
+      PKT_public_key *pk = node->pkt->pkt.public_key;
+
+      if (!strcmp (propname, "secret"))
+        {
+          result = (node->pkt->pkttype == PKT_SECRET_KEY
+                    || node->pkt->pkttype == PKT_SECRET_SUBKEY)? "1":"0";
+        }
+      else if (!strcmp (propname, "key_algo"))
+        {
+          snprintf (numbuf, sizeof numbuf, "%d", pk->pubkey_algo);
+          result = numbuf;
+        }
+      if (!strcmp (propname, "key_created"))
+        {
+          snprintf (numbuf, sizeof numbuf, "%lu", (ulong)pk->timestamp);
+          result = numbuf;
+        }
+      else if (!strcmp (propname, "key_created_d"))
+        {
+          result = datestr_from_pk (pk);
+        }
+      else
+        result = NULL;
+    }
   else
     result = NULL;
 

commit 959cd8903fd012e63dbb156db56708dd3934b5df
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 5 09:49:06 2016 +0200

    common: Add string operator gt,ge,le,lt to recsel.
    
    * common/recsel.c (recsel_parse_expr): Add them.
    (recsel_dump): Print them.
    (recsel_select): Evaluate them.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/recsel.c b/common/recsel.c
index 5dc685f..866861b 100644
--- a/common/recsel.c
+++ b/common/recsel.c
@@ -48,7 +48,11 @@ typedef enum
     SELECT_LE,
     SELECT_GE,
     SELECT_LT,
-    SELECT_GT
+    SELECT_GT,
+    SELECT_STRLE, /* String is less or equal.  */
+    SELECT_STRGE,
+    SELECT_STRLT,
+    SELECT_STRGT
   } select_op_t;
 
 
@@ -347,6 +351,26 @@ recsel_parse_expr (recsel_expr_t *selector, const char *expression)
       se->op = SELECT_ISTRUE;
       s += 2;
     }
+  else if (!strncmp (s, "-le", 3))
+    {
+      se->op = SELECT_STRLE;
+      s += 3;
+    }
+  else if (!strncmp (s, "-ge", 3))
+    {
+      se->op = SELECT_STRGE;
+      s += 3;
+    }
+  else if (!strncmp (s, "-lt", 3))
+    {
+      se->op = SELECT_STRLT;
+      s += 3;
+    }
+  else if (!strncmp (s, "-gt", 3))
+    {
+      se->op = SELECT_STRGT;
+      s += 3;
+    }
   else
     {
       log_error ("invalid operator in expression\n");
@@ -467,7 +491,12 @@ recsel_dump (recsel_expr_t selector)
                  se->op == SELECT_LT?      "< ":
                  se->op == SELECT_LE?      "<=":
                  se->op == SELECT_GT?      "> ":
-                 se->op == SELECT_GE?      ">=":"[oops]",
+                 se->op == SELECT_GE?      ">=":
+                 se->op == SELECT_STRLT?   "-lt":
+                 se->op == SELECT_STRLE?   "-le":
+                 se->op == SELECT_STRGT?   "-gt":
+                 se->op == SELECT_STRGE?   "-ge":
+                 /**/                      "[oops]",
                  se->value);
     }
   log_debug ("--- End selectors ---\n");
@@ -541,6 +570,30 @@ recsel_select (recsel_expr_t selector,
             case SELECT_LE:
               result = (numvalue <= se->numvalue);
               break;
+            case SELECT_STRGT:
+              if (se->xcase)
+                result = strcmp (value, se->value) > 0;
+              else
+                result = strcasecmp (value, se->value) > 0;
+              break;
+            case SELECT_STRGE:
+              if (se->xcase)
+                result = strcmp (value, se->value) >= 0;
+              else
+                result = strcasecmp (value, se->value) >= 0;
+              break;
+            case SELECT_STRLT:
+              if (se->xcase)
+                result = strcmp (value, se->value) < 0;
+              else
+                result = strcasecmp (value, se->value) < 0;
+              break;
+            case SELECT_STRLE:
+              if (se->xcase)
+                result = strcmp (value, se->value) <= 0;
+              else
+                result = strcasecmp (value, se->value) <= 0;
+              break;
             }
         }
 
diff --git a/common/t-recsel.c b/common/t-recsel.c
index fe2a7b9..faddc97 100644
--- a/common/t-recsel.c
+++ b/common/t-recsel.c
@@ -171,6 +171,8 @@ test_2_getval (void *cookie, const char *name)
     return "    ";
   else if (!strcmp (name, "letters"))
     return "abcde";
+  else if (!strcmp (name, "str1"))
+    return "aaa";
   else
     return cookie;
 }
@@ -264,6 +266,37 @@ run_test_2 (void)
 
 
   FREEEXPR();
+  ADDEXPR ("str1 -gt aa");
+  if (!recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+  FREEEXPR();
+  ADDEXPR ("str1 -gt aaa");
+  if (recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+  FREEEXPR();
+  ADDEXPR ("str1 -ge aaa");
+  if (!recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+  FREEEXPR();
+  ADDEXPR ("str1 -lt aab");
+  if (!recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+  FREEEXPR();
+  ADDEXPR ("str1 -le aaa");
+  if (!recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+
+  FREEEXPR();
+  ADDEXPR ("-c str1 -lt AAB");
+  if (recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+  FREEEXPR();
+  ADDEXPR ("str1 -lt AAB");
+  if (!recsel_select (se, test_2_getval, NULL))
+    fail (0, 0);
+
+
+  FREEEXPR();
   ADDEXPR ("uid -n");
   if (!recsel_select (se, test_2_getval, NULL))
     fail (0, 0);
diff --git a/doc/gpg.texi b/doc/gpg.texi
index 68b21b6..901d1ee 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -3500,12 +3500,24 @@ The supported operators (@var{op}) are:
   @item  <
   The numerical value of the field must be LT than the value.
 
-  @item  >=
+  @item  >
   The numerical value of the field must be GT than the value.
 
   @item  >=
   The numerical value of the field must be GE than the value.
 
+  @item  -le
+  The string value of the field must be less or equal than the value.
+
+  @item  -lt
+  The string value of the field must be less than the value.
+
+  @item  -gt
+  The string value of the field must be greater than the value.
+
+  @item  -ge
+  The string value of the field must be greater or equal than the value.
+
   @item  -n
   True if value is not empty (no value allowed).
 

commit c8e0d37f4152d1341ef562a190fce93a0386a759
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 5 08:31:25 2016 +0200

    gpg: Use a common filter_getval for import and export.
    
    * g10/import.c (filter_getval): Rename to ...
    (impex_filter_getval): this.  Make global.
    (apply_keep_uid_filter, apply_drop_sig_filter): Adjust.
    * g10/export.c (filter_getval): Remove.
    (apply_drop_sig_filter): Use impex_filter_getval.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/export.c b/g10/export.c
index 8c15868..e0699db 100644
--- a/g10/export.c
+++ b/g10/export.c
@@ -1293,37 +1293,6 @@ write_keyblock_to_output (kbnode_t keyblock, int with_armor,
 }
 
 
-/* Helper for apply_keep_uid_filter.  */
-static const char *
-filter_getval (void *cookie, const char *propname)
-{
-  kbnode_t node = cookie;
-  const char *result;
-
-  if (node->pkt->pkttype == PKT_USER_ID)
-    {
-      if (!strcmp (propname, "uid"))
-        result = node->pkt->pkt.user_id->name;
-      else if (!strcmp (propname, "mbox"))
-        {
-          if (!node->pkt->pkt.user_id->mbox)
-            {
-              node->pkt->pkt.user_id->mbox
-                = mailbox_from_userid (node->pkt->pkt.user_id->name);
-            }
-          return node->pkt->pkt.user_id->mbox;
-        }
-      else if (!strcmp (propname, "primary"))
-        result = node->pkt->pkt.user_id->is_primary? "1":"0";
-      else
-        result = NULL;
-    }
-  else
-    result = NULL;
-
-  return result;
-}
-
 /*
  * Apply the keep-uid filter to the keyblock.  The deleted nodes are
  * marked and thus the caller should call commit_kbnode afterwards.
@@ -1338,7 +1307,7 @@ apply_keep_uid_filter (kbnode_t keyblock, recsel_expr_t selector)
     {
       if (node->pkt->pkttype == PKT_USER_ID)
         {
-          if (!recsel_select (selector, filter_getval, node))
+          if (!recsel_select (selector, impex_filter_getval, node))
             {
               /* log_debug ("keep-uid: deleting '%s'\n", */
               /*            node->pkt->pkt.user_id->name); */
diff --git a/g10/import.c b/g10/import.c
index f7cb923..14abd2b 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -1103,9 +1103,9 @@ check_prefs (ctrl_t ctrl, kbnode_t keyblock)
 }
 
 
-/* Helper for apply_keep_uid_filter and apply_drop_sig_filter.  */
-static const char *
-filter_getval (void *cookie, const char *propname)
+/* Helper for apply_*_filter in im,port.c and export.c.  */
+const char *
+impex_filter_getval (void *cookie, const char *propname)
 {
   /* FIXME: Malloc our static buffers and access them via the cookie.  */
   kbnode_t node = cookie;
@@ -1178,7 +1178,7 @@ apply_keep_uid_filter (kbnode_t keyblock, recsel_expr_t selector)
     {
       if (node->pkt->pkttype == PKT_USER_ID)
         {
-          if (!recsel_select (selector, filter_getval, node))
+          if (!recsel_select (selector, impex_filter_getval, node))
             {
 
               /* log_debug ("keep-uid: deleting '%s'\n", */
@@ -1237,7 +1237,7 @@ apply_drop_sig_filter (kbnode_t keyblock, recsel_expr_t selector)
 
       if (IS_UID_SIG(sig) || IS_UID_REV(sig))
         {
-          if (recsel_select (selector, filter_getval, node))
+          if (recsel_select (selector, impex_filter_getval, node))
             delete_kbnode (node);
         }
     }
diff --git a/g10/main.h b/g10/main.h
index 340f3b3..b1563d2 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -368,6 +368,7 @@ gpg_error_t import_old_secring (ctrl_t ctrl, const char *fname);
 import_stats_t import_new_stats_handle (void);
 void import_release_stats_handle (import_stats_t hd);
 void import_print_stats (import_stats_t hd);
+const char *impex_filter_getval (void *cookie, const char *propname);
 gpg_error_t transfer_secret_keys (ctrl_t ctrl, struct import_stats_s *stats,
                                   kbnode_t sec_keyblock, int batch, int force);
 

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

Summary of changes:
 common/recsel.c   | 57 ++++++++++++++++++++++++++++++++++--
 common/t-recsel.c | 33 +++++++++++++++++++++
 doc/gpg.texi      | 32 ++++++++++++++++++++-
 g10/export.c      | 86 ++++++++++++++++++++++++++++++++++---------------------
 g10/import.c      | 39 +++++++++++++++++++++----
 g10/main.h        |  1 +
 6 files changed, 208 insertions(+), 40 deletions(-)


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




More information about the Gnupg-commits mailing list