mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-01 16:33:02 +01:00
fixed a stupid C error
This commit is contained in:
parent
ed17c7afd0
commit
59334400a1
1
THANKS
1
THANKS
@ -127,6 +127,7 @@ Michael Sobolev mss@despair.transas.com
|
||||
Michael Tokarev mjt@tls.msk.ru
|
||||
Nicolas Graner Nicolas.Graner@cri.u-psud.fr
|
||||
Mike McEwan mike@lotusland.demon.co.uk
|
||||
Neal H Walfield neal@cs.uml.edu
|
||||
NIIBE Yutaka gniibe@chroot.org
|
||||
Niklas Hernaeus
|
||||
Nimrod Zimerman zimerman@forfree.at
|
||||
|
@ -1,3 +1,13 @@
|
||||
2001-09-07 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* hkp.c (hkp_import): Use log_error. Bug reported by Neal H
|
||||
Walfield.
|
||||
|
||||
* getkey.c (classify_user_id2): Change args to take the desc union
|
||||
direct. It was a stupid idea to pass the individual fields of an
|
||||
union to this function. Changed all callers.
|
||||
(classify_user_id): Ditto and allow to pass NULL as the description.
|
||||
|
||||
2001-09-06 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* getkey.c (fixup_uidnode): Features flag is now a bit vector.
|
||||
|
@ -63,13 +63,7 @@ do_delete_key( const char *username, int secret, int *r_sec_avail )
|
||||
*r_sec_avail = 0;
|
||||
|
||||
/* search the userid */
|
||||
memset (&desc, 0, sizeof desc);
|
||||
desc.mode = classify_user_id (username,
|
||||
desc.u.kid,
|
||||
desc.u.fpr,
|
||||
&desc.u.name,
|
||||
NULL);
|
||||
|
||||
classify_user_id (username, &desc);
|
||||
rc = desc.mode? keydb_search (hd, &desc, 1):G10ERR_INV_USER_ID;
|
||||
if (rc) {
|
||||
log_error (_("key `%s' not found: %s\n"), username, g10_errstr (rc));
|
||||
|
@ -143,9 +143,7 @@ do_export_stream( IOBUF out, STRLIST users, int secret, int onlyrfc, int *any )
|
||||
else {
|
||||
KEYDB_SEARCH_DESC desc;
|
||||
|
||||
memset (&desc, 0, sizeof desc);
|
||||
desc.mode = classify_user_id (sl->d, desc.u.kid, desc.u.fpr,
|
||||
&desc.u.name, NULL);
|
||||
classify_user_id (sl->d, &desc);
|
||||
rc = desc.mode? keydb_search (kdbhd, &desc, 1):G10ERR_INV_USER_ID;
|
||||
if( rc ) {
|
||||
log_error (_("key `%s' not found: %s\n"),
|
||||
|
111
g10/getkey.c
111
g10/getkey.c
@ -543,8 +543,6 @@ hextobyte( const byte *s )
|
||||
* 21 = Unified fingerprint :fpr:pk_algo:
|
||||
* (We don't use pk_algo yet)
|
||||
*
|
||||
* if fprint is not NULL, it should be an array of at least 20 bytes.
|
||||
*
|
||||
* Rules used:
|
||||
* - If the username starts with 8,9,16 or 17 hex-digits (the first one
|
||||
* must be in the range 0..9), this is considered a keyid; depending
|
||||
@ -570,16 +568,20 @@ hextobyte( const byte *s )
|
||||
*/
|
||||
|
||||
static int
|
||||
classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
const char **retstr, size_t *retlen, int *force_exact )
|
||||
classify_user_id2( const char *name,
|
||||
KEYDB_SEARCH_DESC *desc,
|
||||
int *force_exact )
|
||||
{
|
||||
const char * s;
|
||||
int mode = 0;
|
||||
int hexprefix = 0;
|
||||
int hexlength;
|
||||
const char *s;
|
||||
int hexprefix = 0;
|
||||
int hexlength;
|
||||
int mode = 0;
|
||||
|
||||
/* clear the structure so that the mode field is set to zero unless
|
||||
* we set it to the correct value right at the end of this function */
|
||||
memset (desc, 0, sizeof *desc);
|
||||
*force_exact = 0;
|
||||
/* skip leading spaces. FIXME: what is with leading spaces? */
|
||||
/* skip leading spaces. Fixme: what is with trailing spaces? */
|
||||
for(s = name; *s && isspace(*s); s++ )
|
||||
;
|
||||
|
||||
@ -590,39 +592,43 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
case '.': /* an email address, compare from end */
|
||||
mode = KEYDB_SEARCH_MODE_MAILEND;
|
||||
s++;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '<': /* an email address */
|
||||
mode = KEYDB_SEARCH_MODE_MAIL;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '@': /* part of an email address */
|
||||
mode = KEYDB_SEARCH_MODE_MAILSUB;
|
||||
s++;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '=': /* exact compare */
|
||||
mode = KEYDB_SEARCH_MODE_EXACT;
|
||||
s++;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '*': /* case insensitive substring search */
|
||||
mode = KEYDB_SEARCH_MODE_SUBSTR;
|
||||
s++;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '+': /* compare individual words */
|
||||
mode = KEYDB_SEARCH_MODE_WORDS;
|
||||
s++;
|
||||
desc->u.name = s;
|
||||
break;
|
||||
|
||||
case '#': /* local user id */
|
||||
mode = KEYDB_SEARCH_MODE_TDBIDX;
|
||||
s++;
|
||||
if (keyid) {
|
||||
if (keyid_from_lid(strtoul(s, NULL, 10), keyid))
|
||||
keyid[0] = keyid[1] = 0;
|
||||
}
|
||||
if (keyid_from_lid(strtoul(s, NULL, 10), desc->u.kid))
|
||||
desc->u.kid[0] = desc->u.kid[1] = 0;
|
||||
break;
|
||||
|
||||
case ':': /*Unified fingerprint */
|
||||
@ -639,12 +645,10 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
}
|
||||
if (i != 32 && i != 40)
|
||||
return 0; /* invalid length of fpr*/
|
||||
if (fprint) {
|
||||
for (i=0,si=s; si < se; i++, si +=2)
|
||||
fprint[i] = hextobyte(si);
|
||||
for ( ; i < 20; i++)
|
||||
fprint[i]= 0;
|
||||
}
|
||||
for (i=0,si=s; si < se; i++, si +=2)
|
||||
desc->u.fpr[i] = hextobyte(si);
|
||||
for ( ; i < 20; i++)
|
||||
desc->u.fpr[i]= 0;
|
||||
s = se + 1;
|
||||
mode = KEYDB_SEARCH_MODE_FPR;
|
||||
}
|
||||
@ -678,10 +682,8 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
/* short keyid */
|
||||
if (hexlength == 9)
|
||||
s++;
|
||||
if (keyid) {
|
||||
keyid[0] = 0;
|
||||
keyid[1] = strtoul( s, NULL, 16 );
|
||||
}
|
||||
desc->u.kid[0] = 0;
|
||||
desc->u.kid[1] = strtoul( s, NULL, 16 );
|
||||
mode = KEYDB_SEARCH_MODE_SHORT_KID;
|
||||
}
|
||||
else if (hexlength == 16
|
||||
@ -691,8 +693,8 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
if (hexlength == 17)
|
||||
s++;
|
||||
mem2str(buf, s, 9 );
|
||||
keyid[0] = strtoul( buf, NULL, 16 );
|
||||
keyid[1] = strtoul( s+8, NULL, 16 );
|
||||
desc->u.kid[0] = strtoul( buf, NULL, 16 );
|
||||
desc->u.kid[1] = strtoul( s+8, NULL, 16 );
|
||||
mode = KEYDB_SEARCH_MODE_LONG_KID;
|
||||
}
|
||||
else if (hexlength == 32 || (!hexprefix && hexlength == 33
|
||||
@ -701,15 +703,13 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
int i;
|
||||
if (hexlength == 33)
|
||||
s++;
|
||||
if (fprint) {
|
||||
memset(fprint+16, 0, 4);
|
||||
for (i=0; i < 16; i++, s+=2) {
|
||||
int c = hextobyte(s);
|
||||
if (c == -1)
|
||||
return 0;
|
||||
fprint[i] = c;
|
||||
}
|
||||
}
|
||||
memset(desc->u.fpr+16, 0, 4);
|
||||
for (i=0; i < 16; i++, s+=2) {
|
||||
int c = hextobyte(s);
|
||||
if (c == -1)
|
||||
return 0;
|
||||
desc->u.fpr[i] = c;
|
||||
}
|
||||
mode = KEYDB_SEARCH_MODE_FPR16;
|
||||
}
|
||||
else if (hexlength == 40 || (!hexprefix && hexlength == 41
|
||||
@ -718,14 +718,12 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
int i;
|
||||
if (hexlength == 41)
|
||||
s++;
|
||||
if (fprint) {
|
||||
for (i=0; i < 20; i++, s+=2) {
|
||||
int c = hextobyte(s);
|
||||
if (c == -1)
|
||||
return 0;
|
||||
fprint[i] = c;
|
||||
}
|
||||
}
|
||||
for (i=0; i < 20; i++, s+=2) {
|
||||
int c = hextobyte(s);
|
||||
if (c == -1)
|
||||
return 0;
|
||||
desc->u.fpr[i] = c;
|
||||
}
|
||||
mode = KEYDB_SEARCH_MODE_FPR20;
|
||||
}
|
||||
else {
|
||||
@ -733,24 +731,24 @@ classify_user_id2( const char *name, u32 *keyid, byte *fprint,
|
||||
return 0; /* and a wrong length */
|
||||
|
||||
*force_exact = 0;
|
||||
desc->u.name = s;
|
||||
mode = KEYDB_SEARCH_MODE_SUBSTR; /* default mode */
|
||||
}
|
||||
}
|
||||
|
||||
if( retstr )
|
||||
*retstr = s;
|
||||
if( retlen )
|
||||
*retlen = strlen(s);
|
||||
|
||||
desc->mode = mode;
|
||||
return mode;
|
||||
}
|
||||
|
||||
int
|
||||
classify_user_id( const char *name, u32 *keyid, byte *fprint,
|
||||
const char **retstr, size_t *retlen )
|
||||
classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc)
|
||||
{
|
||||
int dummy;
|
||||
return classify_user_id2 (name, keyid, fprint, retstr, retlen, &dummy);
|
||||
KEYDB_SEARCH_DESC dummy_desc;
|
||||
|
||||
if (!desc)
|
||||
desc = &dummy_desc;
|
||||
return classify_user_id2 (name, desc, &dummy);
|
||||
}
|
||||
|
||||
/****************
|
||||
@ -789,17 +787,12 @@ key_byname( GETKEY_CTX *retctx, STRLIST namelist,
|
||||
ctx->nitems = n;
|
||||
|
||||
for(n=0, r=namelist; r; r = r->next, n++ ) {
|
||||
int mode = classify_user_id2 ( r->d,
|
||||
ctx->items[n].u.kid,
|
||||
ctx->items[n].u.fpr,
|
||||
&ctx->items[n].u.name,
|
||||
NULL, &exact );
|
||||
classify_user_id2 (r->d, &ctx->items[n], &exact);
|
||||
|
||||
if ( exact )
|
||||
if (exact)
|
||||
ctx->exact = 1;
|
||||
ctx->items[n].mode = mode;
|
||||
if( !ctx->items[n].mode ) {
|
||||
m_free( ctx );
|
||||
if (!ctx->items[n].mode) {
|
||||
m_free (ctx);
|
||||
return G10ERR_INV_USER_ID;
|
||||
}
|
||||
}
|
||||
|
12
g10/hkp.c
12
g10/hkp.c
@ -104,17 +104,19 @@ hkp_import( STRLIST users )
|
||||
}
|
||||
|
||||
for( ; users; users = users->next ) {
|
||||
u32 kid[2];
|
||||
int type = classify_user_id( users->d, kid, NULL, NULL, NULL );
|
||||
if( type != 10 && type != 11 ) {
|
||||
log_info(_("%s: not a valid key ID\n"), users->d );
|
||||
KEYDB_SEARCH_DESC desc;
|
||||
|
||||
classify_user_id (users->d, &desc);
|
||||
if( desc.mode != KEYDB_SEARCH_MODE_SHORT_KID
|
||||
&& desc.mode != KEYDB_SEARCH_MODE_LONG_KID ) {
|
||||
log_error (_("%s: not a valid key ID\n"), users->d );
|
||||
continue;
|
||||
}
|
||||
/* because the function may use log_info in some situations, the
|
||||
* errorcounter ist not increaed and the program will return
|
||||
* with success - which is not good when this function is used.
|
||||
*/
|
||||
if( hkp_ask_import( kid ) )
|
||||
if( hkp_ask_import( desc.u.kid ) )
|
||||
log_inc_errorcount();
|
||||
}
|
||||
return 0;
|
||||
|
@ -177,8 +177,7 @@ void set_next_passphrase( const char *s );
|
||||
char *get_last_passphrase(void);
|
||||
|
||||
/*-- getkey.c --*/
|
||||
int classify_user_id( const char *name, u32 *keyid, byte *fprint,
|
||||
const char **retstr, size_t *retlen );
|
||||
int classify_user_id( const char *name, KEYDB_SEARCH_DESC *desc);
|
||||
void cache_public_key( PKT_public_key *pk );
|
||||
void getkey_disable_caches(void);
|
||||
int get_pubkey( PKT_public_key *pk, u32 *keyid );
|
||||
|
@ -945,6 +945,8 @@ ask_expire_interval(void)
|
||||
/* print the date when the key expires */
|
||||
tty_printf(_("Key expires at %s\n"),
|
||||
asctimestamp((ulong)(curtime + interval) ) );
|
||||
/* FIXME: This check yields warning on alhas:
|
||||
write a configure check and to this check here only for 32 bit machines */
|
||||
if( (time_t)((ulong)(curtime+interval)) < 0 )
|
||||
tty_printf(_("Your system can't display dates beyond 2038.\n"
|
||||
"However, it will be correctly handled up to 2106.\n"));
|
||||
|
@ -104,12 +104,7 @@ gen_revoke( const char *uname )
|
||||
* We don't want the whole getkey stuff here but the entire keyblock
|
||||
*/
|
||||
kdbhd = keydb_new (1);
|
||||
memset (&desc, 0, sizeof desc);
|
||||
desc.mode = classify_user_id (uname,
|
||||
desc.u.kid,
|
||||
desc.u.fpr,
|
||||
&desc.u.name,
|
||||
NULL);
|
||||
classify_user_id (uname, &desc);
|
||||
rc = desc.mode? keydb_search (kdbhd, &desc, 1) : G10ERR_INV_USER_ID;
|
||||
if (rc) {
|
||||
log_error (_("secret key `%s' not found: %s\n"),
|
||||
|
@ -467,20 +467,20 @@ lid_from_keyid_no_sdir( u32 *keyid )
|
||||
void
|
||||
register_trusted_key( const char *string )
|
||||
{
|
||||
u32 keyid[2];
|
||||
KEYDB_SEARCH_DESC desc;
|
||||
struct keyid_list *r;
|
||||
|
||||
if( classify_user_id( string, keyid, NULL, NULL, NULL ) != 11 ) {
|
||||
log_error(_("'%s' is not a valid long keyID\n"), string );
|
||||
if (classify_user_id (string, &desc) != KEYDB_SEARCH_MODE_LONG_KID ) {
|
||||
log_error(_("`%s' is not a valid long keyID\n"), string );
|
||||
return;
|
||||
}
|
||||
|
||||
for( r = trusted_key_list; r; r = r->next )
|
||||
if( r->keyid[0] == keyid[0] && r->keyid[1] == keyid[1] )
|
||||
if( r->keyid[0] == desc.u.kid[0] && r->keyid[1] == desc.u.kid[1] )
|
||||
return;
|
||||
r = m_alloc( sizeof *r );
|
||||
r->keyid[0] = keyid[0];
|
||||
r->keyid[1] = keyid[1];
|
||||
r->keyid[0] = desc.u.kid[0];
|
||||
r->keyid[1] = desc.u.kid[1];
|
||||
r->next = trusted_key_list;
|
||||
trusted_key_list = r;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user