1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

gpg: Add property "fpr" for use by --export-filter.

* g10/export.c (push_export_filters): New.
(pop_export_filters): New.
(export_pubkey_buffer): Add args prefix and prefixlen.  Adjust
callers.
* g10/import.c (impex_filter_getval): Add property "fpr".
* g10/main.h (struct impex_filter_parm_s): Add field hexfpr.
--

The push and pop feature will help us to use the export filter
internally in gpg.  Same for the export_pubkey_buffer change.

GnuPG-bug-id: 4856
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2020-03-13 13:17:51 +01:00
parent 90fb4a69d2
commit 32493ce50a
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
7 changed files with 71 additions and 2 deletions

View File

@ -2471,6 +2471,10 @@ The available properties are:
created. The second is the same but given as an ISO string, created. The second is the same but given as an ISO string,
e.g. "2016-08-17". (drop-subkey) e.g. "2016-08-17". (drop-subkey)
@item fpr
The hexified fingerprint of the current subkey or primary key.
(drop-subkey)
@item primary @item primary
Boolean indicating whether the user id is the primary one. (keep-uid) Boolean indicating whether the user id is the primary one. (keep-uid)

View File

@ -73,6 +73,17 @@ static recsel_expr_t export_keep_uid;
static recsel_expr_t export_drop_subkey; static recsel_expr_t export_drop_subkey;
/* An object used for a linked list to implement the
* push_export_filter/pop_export_filters functions. */
struct export_filter_attic_s
{
struct export_filter_attic_s *next;
recsel_expr_t export_keep_uid;
recsel_expr_t export_drop_subkey;
};
static struct export_filter_attic_s *export_filter_attic;
/* Local prototypes. */ /* Local prototypes. */
static int do_export (ctrl_t ctrl, strlist_t users, int secret, static int do_export (ctrl_t ctrl, strlist_t users, int secret,
@ -198,6 +209,41 @@ parse_and_set_export_filter (const char *string)
} }
/* Push the current export filters onto a stack so that new export
* filters can be defined which will be active until the next
* pop_export_filters or another push_export_filters. */
void
push_export_filters (void)
{
struct export_filter_attic_s *item;
item = xcalloc (1, sizeof *item);
item->export_keep_uid = export_keep_uid;
export_keep_uid = NULL;
item->export_drop_subkey = export_drop_subkey;
export_drop_subkey = NULL;
item->next = export_filter_attic;
export_filter_attic = item;
}
/* Revert the last push_export_filters. */
void
pop_export_filters (void)
{
struct export_filter_attic_s *item;
item = export_filter_attic;
if (!item)
BUG (); /* No corresponding push. */
export_filter_attic = item->next;
cleanup_export_globals ();
export_keep_uid = item->export_keep_uid;
export_drop_subkey = item->export_drop_subkey;
}
/* Create a new export stats object initialized to zero. On error /* Create a new export stats object initialized to zero. On error
returns NULL and sets ERRNO. */ returns NULL and sets ERRNO. */
export_stats_t export_stats_t
@ -292,10 +338,12 @@ export_secsubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
/* /*
* Export a single key into a memory buffer. STATS is either an * Export a single key into a memory buffer. STATS is either an
* export stats object for update or NULL. * export stats object for update or NULL. If PREFIX is not NULL
* PREFIXLEN bytes from PREFIX are prepended to the R_DATA.
*/ */
gpg_error_t gpg_error_t
export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options, export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
const void *prefix, size_t prefixlen,
export_stats_t stats, export_stats_t stats,
kbnode_t *r_keyblock, void **r_data, size_t *r_datalen) kbnode_t *r_keyblock, void **r_data, size_t *r_datalen)
{ {
@ -313,6 +361,8 @@ export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
return gpg_error_from_syserror (); return gpg_error_from_syserror ();
iobuf = iobuf_temp (); iobuf = iobuf_temp ();
if (prefix && prefixlen)
iobuf_write (iobuf, prefix, prefixlen);
err = do_export_stream (ctrl, iobuf, helplist, 0, r_keyblock, options, err = do_export_stream (ctrl, iobuf, helplist, 0, r_keyblock, options,
stats, &any); stats, &any);
if (!err && !any) if (!err && !any)

View File

@ -715,12 +715,15 @@ gpg_dirmngr_get_pka (ctrl_t ctrl, const char *userid,
gpg_error_t gpg_error_t
export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options, export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
const void *prefix, size_t prefixlen,
export_stats_t stats, export_stats_t stats,
kbnode_t *r_keyblock, void **r_data, size_t *r_datalen) kbnode_t *r_keyblock, void **r_data, size_t *r_datalen)
{ {
(void)ctrl; (void)ctrl;
(void)keyspec; (void)keyspec;
(void)options; (void)options;
(void)prefix;
(void)prefixlen;
(void)stats; (void)stats;
*r_keyblock = NULL; *r_keyblock = NULL;

View File

@ -1478,6 +1478,11 @@ impex_filter_getval (void *cookie, const char *propname)
(pk->pubkey_usage & PUBKEY_USAGE_UNKNOWN)?"?":""); (pk->pubkey_usage & PUBKEY_USAGE_UNKNOWN)?"?":"");
result = numbuf; result = numbuf;
} }
else if (!strcmp (propname, "fpr"))
{
hexfingerprint (pk, parm->hexfpr, sizeof parm->hexfpr);
result = parm->hexfpr;
}
else else
result = NULL; result = NULL;
} }

View File

@ -1806,7 +1806,7 @@ keyserver_put (ctrl_t ctrl, strlist_t keyspecs)
err = export_pubkey_buffer (ctrl, kspec->d, err = export_pubkey_buffer (ctrl, kspec->d,
opt.keyserver_options.export_options, opt.keyserver_options.export_options,
NULL, NULL, 0, NULL,
&keyblock, &data, &datalen); &keyblock, &data, &datalen);
if (err) if (err)
log_error (_("skipped \"%s\": %s\n"), kspec->d, gpg_strerror (err)); log_error (_("skipped \"%s\": %s\n"), kspec->d, gpg_strerror (err));

View File

@ -390,6 +390,7 @@ struct impex_filter_parm_s
{ {
ctrl_t ctrl; ctrl_t ctrl;
kbnode_t node; kbnode_t node;
char hexfpr[2*MAX_FINGERPRINT_LEN + 1];
}; };
const char *impex_filter_getval (void *cookie, const char *propname); const char *impex_filter_getval (void *cookie, const char *propname);
@ -413,6 +414,8 @@ void export_print_stats (export_stats_t stats);
int parse_export_options(char *str,unsigned int *options,int noisy); int parse_export_options(char *str,unsigned int *options,int noisy);
gpg_error_t parse_and_set_export_filter (const char *string); gpg_error_t parse_and_set_export_filter (const char *string);
void push_export_filters (void);
void pop_export_filters (void);
int exact_subkey_match_p (KEYDB_SEARCH_DESC *desc, kbnode_t node); int exact_subkey_match_p (KEYDB_SEARCH_DESC *desc, kbnode_t node);
@ -425,6 +428,7 @@ int export_secsubkeys (ctrl_t ctrl, strlist_t users, unsigned int options,
gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, gpg_error_t export_pubkey_buffer (ctrl_t ctrl, const char *keyspec,
unsigned int options, unsigned int options,
const void *prefix, size_t prefixlen,
export_stats_t stats, export_stats_t stats,
kbnode_t *r_keyblock, kbnode_t *r_keyblock,
void **r_data, size_t *r_datalen); void **r_data, size_t *r_datalen);

View File

@ -471,12 +471,15 @@ gpg_dirmngr_get_pka (ctrl_t ctrl, const char *userid,
gpg_error_t gpg_error_t
export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options, export_pubkey_buffer (ctrl_t ctrl, const char *keyspec, unsigned int options,
const void *prefix, size_t prefixlen,
export_stats_t stats, export_stats_t stats,
kbnode_t *r_keyblock, void **r_data, size_t *r_datalen) kbnode_t *r_keyblock, void **r_data, size_t *r_datalen)
{ {
(void)ctrl; (void)ctrl;
(void)keyspec; (void)keyspec;
(void)options; (void)options;
(void)prefix;
(void)prefixlen;
(void)stats; (void)stats;
*r_keyblock = NULL; *r_keyblock = NULL;