chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0044-gpg-Make-export-options-work-with-export-secret-keys.patch
1 From: Werner Koch <wk@gnupg.org>
2 Date: Wed, 1 Mar 2017 14:41:47 +0100
3 Subject: gpg: Make --export-options work with --export-secret-keys.
4
5 * g10/export.c (export_seckeys): Add arg OPTIONS and pass it to
6 do_export.
7 (export_secsubkeys): Ditto.
8 * g10/gpg.c (main): Pass opt.export_options to export_seckeys and
9 export_secsubkeys
10 --
11
12 Back in the old days we did not used the export options for secret
13 keys export because of a lot of duplicated code and that the old
14 secring.gpg was anyway smaller that the pubring.gpg.  With 2.1 it was
15 pretty easy to enable it.
16
17 Reported-by: Peter Lebbing
18 GnuPG-bug-id: 2973
19 (cherry picked from commit 891ab23411b7f20ef37d8bde81d9857b083235df)
20 ---
21  doc/gpg.texi |  7 ++++---
22  g10/export.c | 31 ++++++++++++++++---------------
23  g10/gpg.c    |  4 ++--
24  g10/main.h   |  6 ++++--
25  4 files changed, 26 insertions(+), 22 deletions(-)
26
27 diff --git a/doc/gpg.texi b/doc/gpg.texi
28 index b79b783..3b82b44 100644
29 --- a/doc/gpg.texi
30 +++ b/doc/gpg.texi
31 @@ -1824,7 +1824,8 @@ are available for all keyserver types, some common options are:
32    used with HKP keyservers.
33  
34    @item auto-key-retrieve
35 -  This is the same as the option @option{auto-key-retrieve}.
36 +  This is an obsolete alias for the option @option{auto-key-retrieve}.
37 +  Please do not use it; it will be removed in future versions..
38  
39    @item honor-keyserver-url
40    When using @option{--refresh-keys}, if the key in question has a preferred
41 @@ -2371,8 +2372,8 @@ The available properties are:
42  @item --export-options @code{parameters}
43  @opindex export-options
44  This is a space or comma delimited string that gives options for
45 -exporting keys. Options can be prepended with a `no-' to give the
46 -opposite meaning. The options are:
47 +exporting keys.  Options can be prepended with a `no-' to give the
48 +opposite meaning.  The options are:
49  
50  @table @asis
51  
52 diff --git a/g10/export.c b/g10/export.c
53 index 8668126..207f994 100644
54 --- a/g10/export.c
55 +++ b/g10/export.c
56 @@ -247,16 +247,17 @@ export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
57  /*
58   * Export secret keys (to stdout or to --output FILE).
59   *
60 - * Depending on opt.armor the output is armored.  If USERS is NULL,
61 - * all secret keys will be exported.  STATS is either an export stats
62 - * object for update or NULL.
63 + * Depending on opt.armor the output is armored.  OPTIONS are defined
64 + * in main.h.  If USERS is NULL, all secret keys will be exported.
65 + * STATS is either an export stats object for update or NULL.
66   *
67   * This function is the core of "gpg --export-secret-keys".
68   */
69  int
70 -export_seckeys (ctrl_t ctrl, strlist_t users, export_stats_t stats)
71 +export_seckeys (ctrl_t ctrl, strlist_t users, unsigned int options,
72 +                export_stats_t stats)
73  {
74 -  return do_export (ctrl, users, 1, 0, stats);
75 +  return do_export (ctrl, users, 1, options, stats);
76  }
77  
78  
79 @@ -264,16 +265,18 @@ export_seckeys (ctrl_t ctrl, strlist_t users, export_stats_t stats)
80   * Export secret sub keys (to stdout or to --output FILE).
81   *
82   * This is the same as export_seckeys but replaces the primary key by
83 - * a stub key.  Depending on opt.armor the output is armored.  If
84 - * USERS is NULL, all secret subkeys will be exported.  STATS is
85 - * either an export stats object for update or NULL.
86 + * a stub key.  Depending on opt.armor the output is armored.  OPTIONS
87 + * are defined in main.h.  If USERS is NULL, all secret subkeys will
88 + * be exported.  STATS is either an export stats object for update or
89 + * NULL.
90   *
91   * This function is the core of "gpg --export-secret-subkeys".
92   */
93  int
94 -export_secsubkeys (ctrl_t ctrl, strlist_t users, export_stats_t stats)
95 +export_secsubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
96 +                   export_stats_t stats)
97  {
98 -  return do_export (ctrl, users, 2, 0, stats);
99 +  return do_export (ctrl, users, 2, options, stats);
100  }
101  
102  
103 @@ -1969,11 +1972,9 @@ do_export_stream (ctrl_t ctrl, iobuf_t out, strlist_t users, int secret,
104          }
105  
106        /* Always do the cleaning on the public key part if requested.
107 -         Note that we don't yet set this option if we are exporting
108 -         secret keys.  Note that both export-clean and export-minimal
109 -         only apply to UID sigs (0x10, 0x11, 0x12, and 0x13).  A
110 -         designated revocation is never stripped, even with
111 -         export-minimal set.  */
112 +       * Note that both export-clean and export-minimal only apply to
113 +       * UID sigs (0x10, 0x11, 0x12, and 0x13).  A designated
114 +       * revocation is never stripped, even with export-minimal set.  */
115        if ((options & EXPORT_CLEAN))
116          clean_key (keyblock, opt.verbose, (options&EXPORT_MINIMAL), NULL, NULL);
117  
118 diff --git a/g10/gpg.c b/g10/gpg.c
119 index 2a4a0ad..5a880fd 100644
120 --- a/g10/gpg.c
121 +++ b/g10/gpg.c
122 @@ -4546,7 +4546,7 @@ main (int argc, char **argv)
123             add_to_strlist2( &sl, *argv, utf8_strings );
124          {
125            export_stats_t stats = export_new_stats ();
126 -          export_seckeys (ctrl, sl, stats);
127 +          export_seckeys (ctrl, sl, opt.export_options, stats);
128            export_print_stats (stats);
129            export_release_stats (stats);
130          }
131 @@ -4559,7 +4559,7 @@ main (int argc, char **argv)
132             add_to_strlist2( &sl, *argv, utf8_strings );
133          {
134            export_stats_t stats = export_new_stats ();
135 -          export_secsubkeys (ctrl, sl, stats);
136 +          export_secsubkeys (ctrl, sl, opt.export_options, stats);
137            export_print_stats (stats);
138            export_release_stats (stats);
139          }
140 diff --git a/g10/main.h b/g10/main.h
141 index 5ed501b..6837e98 100644
142 --- a/g10/main.h
143 +++ b/g10/main.h
144 @@ -397,8 +397,10 @@ gpg_error_t parse_and_set_export_filter (const char *string);
145  
146  int export_pubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
147                      export_stats_t stats);
148 -int export_seckeys (ctrl_t ctrl, strlist_t users, export_stats_t stats);
149 -int export_secsubkeys (ctrl_t ctrl, strlist_t users, export_stats_t stats);
150 +int export_seckeys (ctrl_t ctrl, strlist_t users, unsigned int options,
151 +                    export_stats_t stats);
152 +int export_secsubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
153 +                       export_stats_t stats);
154  
155  gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
156                                    unsigned int options,