aboutsummaryrefslogtreecommitdiffstats
path: root/g10/import.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/import.c')
-rw-r--r--g10/import.c64
1 files changed, 41 insertions, 23 deletions
diff --git a/g10/import.c b/g10/import.c
index 491609d0a..8010fa521 100644
--- a/g10/import.c
+++ b/g10/import.c
@@ -97,7 +97,7 @@ struct import_filter_s import_filter;
static int import (ctrl_t ctrl,
IOBUF inp, const char* fname, struct import_stats_s *stats,
unsigned char **fpr, size_t *fpr_len, unsigned int options,
- import_screener_t screener, void *screener_arg);
+ import_screener_t screener, void *screener_arg, int origin);
static int read_block (IOBUF a, int with_meta,
PACKET **pending_pkt, kbnode_t *ret_root, int *r_v3keys);
static void revocation_present (ctrl_t ctrl, kbnode_t keyblock);
@@ -106,7 +106,8 @@ static int import_one (ctrl_t ctrl,
struct import_stats_s *stats,
unsigned char **fpr, size_t *fpr_len,
unsigned int options, int from_sk, int silent,
- import_screener_t screener, void *screener_arg);
+ import_screener_t screener, void *screener_arg,
+ int origin);
static int import_secret_one (ctrl_t ctrl, kbnode_t keyblock,
struct import_stats_s *stats, int batch,
unsigned int options, int for_migration,
@@ -430,7 +431,8 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames,
import_stats_t stats_handle,
unsigned char **fpr, size_t *fpr_len,
unsigned int options,
- import_screener_t screener, void *screener_arg)
+ import_screener_t screener, void *screener_arg,
+ int origin)
{
int i;
int rc = 0;
@@ -442,7 +444,7 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames,
if (inp)
{
rc = import (ctrl, inp, "[stream]", stats, fpr, fpr_len, options,
- screener, screener_arg);
+ screener, screener_arg, origin);
}
else
{
@@ -467,7 +469,7 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames,
else
{
rc = import (ctrl, inp2, fname, stats, fpr, fpr_len, options,
- screener, screener_arg);
+ screener, screener_arg, origin);
iobuf_close (inp2);
/* Must invalidate that ugly cache to actually close it. */
iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname);
@@ -501,28 +503,20 @@ import_keys_internal (ctrl_t ctrl, iobuf_t inp, char **fnames, int nnames,
void
import_keys (ctrl_t ctrl, char **fnames, int nnames,
- import_stats_t stats_handle, unsigned int options )
+ import_stats_t stats_handle, unsigned int options, int origin)
{
import_keys_internal (ctrl, NULL, fnames, nnames, stats_handle,
- NULL, NULL, options, NULL, NULL);
-}
-
-int
-import_keys_stream (ctrl_t ctrl, IOBUF inp, import_stats_t stats_handle,
- unsigned char **fpr, size_t *fpr_len, unsigned int options)
-{
- return import_keys_internal (ctrl, inp, NULL, 0, stats_handle,
- fpr, fpr_len, options, NULL, NULL);
+ NULL, NULL, options, NULL, NULL, origin);
}
-/* Variant of import_keys_stream reading from an estream_t. */
int
import_keys_es_stream (ctrl_t ctrl, estream_t fp,
import_stats_t stats_handle,
unsigned char **fpr, size_t *fpr_len,
unsigned int options,
- import_screener_t screener, void *screener_arg)
+ import_screener_t screener, void *screener_arg,
+ int origin)
{
int rc;
iobuf_t inp;
@@ -537,7 +531,7 @@ import_keys_es_stream (ctrl_t ctrl, estream_t fp,
rc = import_keys_internal (ctrl, inp, NULL, 0, stats_handle,
fpr, fpr_len, options,
- screener, screener_arg);
+ screener, screener_arg, origin);
iobuf_close (inp);
return rc;
@@ -547,7 +541,7 @@ import_keys_es_stream (ctrl_t ctrl, estream_t fp,
static int
import (ctrl_t ctrl, IOBUF inp, const char* fname,struct import_stats_s *stats,
unsigned char **fpr,size_t *fpr_len, unsigned int options,
- import_screener_t screener, void *screener_arg)
+ import_screener_t screener, void *screener_arg, int origin)
{
PACKET *pending_pkt = NULL;
kbnode_t keyblock = NULL; /* Need to initialize because gcc can't
@@ -575,7 +569,7 @@ import (ctrl_t ctrl, IOBUF inp, const char* fname,struct import_stats_s *stats,
if (keyblock->pkt->pkttype == PKT_PUBLIC_KEY)
rc = import_one (ctrl, keyblock,
stats, fpr, fpr_len, options, 0, 0,
- screener, screener_arg);
+ screener, screener_arg, origin);
else if (keyblock->pkt->pkttype == PKT_SECRET_KEY)
rc = import_secret_one (ctrl, keyblock, stats,
opt.batch, options, 0,
@@ -1384,19 +1378,32 @@ apply_drop_sig_filter (ctrl_t ctrl, kbnode_t keyblock, recsel_expr_t selector)
}
+/* Apply meta data to KEYBLOCK. This sets the origin of the key to
+ * ORIGIN. If MERGE is true KEYBLOCK has been updated and the meta
+ * data is merged and not simply inserted. */
+static gpg_error_t
+apply_meta_data (kbnode_t keyblock, int merge, int origin)
+{
+
+ return 0;
+}
+
+
/*
* 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 internal errorcount, so that invalid input can be detected by
* programs which called gpg. If SILENT is no messages are printed -
- * even most error messages are suppressed.
+ * even most error messages are suppressed. ORIGIN is the origin of
+ * the key (0 for unknown).
*/
static int
import_one (ctrl_t ctrl,
kbnode_t keyblock, struct import_stats_s *stats,
unsigned char **fpr, size_t *fpr_len, unsigned int options,
int from_sk, int silent,
- import_screener_t screener, void *screener_arg)
+ import_screener_t screener, void *screener_arg,
+ int origin)
{
PKT_public_key *pk;
PKT_public_key *pk_orig = NULL;
@@ -1614,6 +1621,17 @@ import_one (ctrl_t ctrl,
if (opt.verbose > 1 )
log_info (_("writing to '%s'\n"), keydb_get_resource_name (hd) );
+ /* Unless we are in restore mode apply meta data to the
+ * keyblock. Note that this will never change the first packet
+ * and thus the address of KEYBLOCK won't change. */
+ if ( !(options & IMPORT_RESTORE) )
+ {
+ rc = apply_meta_data (keyblock, 0, origin);
+ log_error ("apply_meta_data failed: %s\n", gpg_strerror (rc));
+ keydb_release (hd);
+ return GPG_ERR_GENERAL;
+ }
+
rc = keydb_insert_keyblock (hd, keyblock );
if (rc)
log_error (_("error writing keyring '%s': %s\n"),
@@ -2286,7 +2304,7 @@ import_secret_one (ctrl_t ctrl, kbnode_t keyblock,
the secret keys. FIXME? */
import_one (ctrl, pub_keyblock, stats,
NULL, NULL, options, 1, for_migration,
- screener, screener_arg);
+ screener, screener_arg, 0);
/* Fixme: We should check for an invalid keyblock and
cancel the secret key import in this case. */