1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-04-17 15:44:34 +02:00

* main.h, import.c (import_one): Optionally return the fingerprint of

the key being imported.  (import_keys_internal, import_keys_stream,
import): Change all callers.
This commit is contained in:
David Shaw 2006-03-14 02:23:00 +00:00
parent 7e3ba27aef
commit 671ec45001
4 changed files with 43 additions and 26 deletions

View File

@ -1,3 +1,10 @@
2006-03-13 David Shaw <dshaw@jabberwocky.com>
* main.h, import.c (import_one): Optionally return the fingerprint
of the key being imported.
(import_keys_internal, import_keys_stream, import): Change all
callers.
2006-03-12 David Shaw <dshaw@jabberwocky.com> 2006-03-12 David Shaw <dshaw@jabberwocky.com>
* sig-check.c (signature_check2): Print the backsig warning when * sig-check.c (signature_check2): Print the backsig warning when

View File

@ -1,6 +1,6 @@
/* import.c - import a key into our key storage. /* import.c - import a key into our key storage.
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
* 2005 Free Software Foundation, Inc. * 2006 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -60,12 +60,13 @@ struct stats_s {
}; };
static int import( IOBUF inp, const char* fname, static int import( IOBUF inp, const char* fname,struct stats_s *stats,
struct stats_s *stats, unsigned int options ); unsigned char **fpr,size_t *fpr_len,unsigned int options );
static int read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root ); static int read_block( IOBUF a, PACKET **pending_pkt, KBNODE *ret_root );
static void revocation_present(KBNODE keyblock); static void revocation_present(KBNODE keyblock);
static int import_one( const char *fname, KBNODE keyblock, static int import_one(const char *fname, KBNODE keyblock,struct stats_s *stats,
struct stats_s *stats, unsigned int options); unsigned char **fpr,size_t *fpr_len,
unsigned int options);
static int import_secret_one( const char *fname, KBNODE keyblock, static int import_secret_one( const char *fname, KBNODE keyblock,
struct stats_s *stats, unsigned int options); struct stats_s *stats, unsigned int options);
static int import_revoke_cert( const char *fname, KBNODE node, static int import_revoke_cert( const char *fname, KBNODE node,
@ -163,7 +164,8 @@ import_release_stats_handle (void *p)
*/ */
static int static int
import_keys_internal( IOBUF inp, char **fnames, int nnames, import_keys_internal( IOBUF inp, char **fnames, int nnames,
void *stats_handle, unsigned int options ) void *stats_handle, unsigned char **fpr, size_t *fpr_len,
unsigned int options )
{ {
int i, rc = 0; int i, rc = 0;
struct stats_s *stats = stats_handle; struct stats_s *stats = stats_handle;
@ -172,7 +174,7 @@ import_keys_internal( IOBUF inp, char **fnames, int nnames,
stats = import_new_stats_handle (); stats = import_new_stats_handle ();
if (inp) { if (inp) {
rc = import( inp, "[stream]", stats, options); rc = import( inp, "[stream]", stats, fpr, fpr_len, options);
} }
else { else {
if( !fnames && !nnames ) if( !fnames && !nnames )
@ -191,8 +193,9 @@ import_keys_internal( IOBUF inp, char **fnames, int nnames,
} }
if( !inp2 ) if( !inp2 )
log_error(_("can't open `%s': %s\n"), fname, strerror(errno) ); log_error(_("can't open `%s': %s\n"), fname, strerror(errno) );
else { else
rc = import( inp2, fname, stats, options ); {
rc = import( inp2, fname, stats, fpr, fpr_len, options );
iobuf_close(inp2); iobuf_close(inp2);
/* Must invalidate that ugly cache to actually close it. */ /* Must invalidate that ugly cache to actually close it. */
iobuf_ioctl (NULL, 2, 0, (char*)fname); iobuf_ioctl (NULL, 2, 0, (char*)fname);
@ -225,18 +228,19 @@ void
import_keys( char **fnames, int nnames, import_keys( char **fnames, int nnames,
void *stats_handle, unsigned int options ) void *stats_handle, unsigned int options )
{ {
import_keys_internal( NULL, fnames, nnames, stats_handle, options); import_keys_internal(NULL,fnames,nnames,stats_handle,NULL,NULL,options);
} }
int int
import_keys_stream( IOBUF inp, void *stats_handle, unsigned int options ) import_keys_stream( IOBUF inp, void *stats_handle,
unsigned char **fpr, size_t *fpr_len,unsigned int options )
{ {
return import_keys_internal( inp, NULL, 0, stats_handle, options); return import_keys_internal(inp,NULL,0,stats_handle,fpr,fpr_len,options);
} }
static int static int
import( IOBUF inp, const char* fname, import( IOBUF inp, const char* fname,struct stats_s *stats,
struct stats_s *stats, unsigned int options ) unsigned char **fpr,size_t *fpr_len,unsigned int options )
{ {
PACKET *pending_pkt = NULL; PACKET *pending_pkt = NULL;
KBNODE keyblock; KBNODE keyblock;
@ -252,7 +256,7 @@ import( IOBUF inp, const char* fname,
while( !(rc = read_block( inp, &pending_pkt, &keyblock) )) { while( !(rc = read_block( inp, &pending_pkt, &keyblock) )) {
if( keyblock->pkt->pkttype == PKT_PUBLIC_KEY ) if( keyblock->pkt->pkttype == PKT_PUBLIC_KEY )
rc = import_one( fname, keyblock, stats, options ); rc = import_one( fname, keyblock, stats, fpr, fpr_len, options );
else if( keyblock->pkt->pkttype == PKT_SECRET_KEY ) else if( keyblock->pkt->pkttype == PKT_SECRET_KEY )
rc = import_secret_one( fname, keyblock, stats, options ); rc = import_secret_one( fname, keyblock, stats, options );
else if( keyblock->pkt->pkttype == PKT_SIGNATURE else if( keyblock->pkt->pkttype == PKT_SIGNATURE
@ -673,8 +677,8 @@ check_prefs(KBNODE keyblock)
* which called g10. * which called g10.
*/ */
static int static int
import_one( const char *fname, KBNODE keyblock, import_one( const char *fname, KBNODE keyblock, struct stats_s *stats,
struct stats_s *stats, unsigned int options ) unsigned char **fpr,size_t *fpr_len,unsigned int options )
{ {
PKT_public_key *pk; PKT_public_key *pk;
PKT_public_key *pk_orig; PKT_public_key *pk_orig;
@ -692,6 +696,10 @@ import_one( const char *fname, KBNODE keyblock,
BUG(); BUG();
pk = node->pkt->pkt.public_key; pk = node->pkt->pkt.public_key;
if(fpr)
*fpr=fingerprint_from_pk(pk,NULL,fpr_len);
keyid_from_pk( pk, keyid ); keyid_from_pk( pk, keyid );
uidnode = find_next_kbnode( keyblock, PKT_USER_ID ); uidnode = find_next_kbnode( keyblock, PKT_USER_ID );
@ -1146,7 +1154,8 @@ import_secret_one( const char *fname, KBNODE keyblock,
KBNODE pub_keyblock=sec_to_pub_keyblock(keyblock); KBNODE pub_keyblock=sec_to_pub_keyblock(keyblock);
if(pub_keyblock) if(pub_keyblock)
{ {
import_one(fname,pub_keyblock,stats,opt.import_options); import_one(fname,pub_keyblock,stats,
NULL,NULL,opt.import_options);
release_kbnode(pub_keyblock); release_kbnode(pub_keyblock);
} }
} }

View File

@ -1457,7 +1457,7 @@ keyserver_spawn(enum ks_action action,STRLIST list,KEYDB_SEARCH_DESC *desc,
way to do this could be to continue parsing this way to do this could be to continue parsing this
line-by-line and make a temp iobuf for each key. */ line-by-line and make a temp iobuf for each key. */
import_keys_stream(spawn->fromchild,stats_handle, import_keys_stream(spawn->fromchild,stats_handle,NULL,NULL,
opt.keyserver_options.import_options); opt.keyserver_options.import_options);
import_print_stats(stats_handle); import_print_stats(stats_handle);
@ -1995,7 +1995,8 @@ keyserver_import_cert(const char *name)
/* CERTs are always in binary format */ /* CERTs are always in binary format */
opt.no_armor=1; opt.no_armor=1;
rc=import_keys_stream(key,NULL,opt.keyserver_options.import_options); rc=import_keys_stream(key,NULL,NULL,NULL,
opt.keyserver_options.import_options);
opt.no_armor=armor_status; opt.no_armor=armor_status;

View File

@ -210,8 +210,8 @@ MPI encode_md_value( int pubkey_algo, MD_HANDLE md,
int parse_import_options(char *str,unsigned int *options,int noisy); int parse_import_options(char *str,unsigned int *options,int noisy);
void import_keys( char **fnames, int nnames, void import_keys( char **fnames, int nnames,
void *stats_hd, unsigned int options ); void *stats_hd, unsigned int options );
int import_keys_stream( IOBUF inp, int import_keys_stream( IOBUF inp,void *stats_hd,unsigned char **fpr,
void *stats_hd, unsigned int options ); size_t *fpr_len,unsigned int options );
void *import_new_stats_handle (void); void *import_new_stats_handle (void);
void import_release_stats_handle (void *p); void import_release_stats_handle (void *p);
void import_print_stats (void *hd); void import_print_stats (void *hd);