mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpg: Replace -1 by GPG_ERR_NOT_FOUND in tdbio.c
* g10/tdbio.c (lookup_hashtable): Return GPG_ERR_NOT_FOUND. * g10/tdbdump.c (import_ownertrust): Test for GPG_ERR_NOT_FOUND. * g10/trustdb.c (read_trust_record): Ditto. (tdb_get_ownertrust, tdb_get_min_ownertrust): Ditto. (tdb_update_ownertrust, update_min_ownertrust): Ditto. (tdb_clear_ownertrusts, update_validity): Ditto. (tdb_cache_disabled_value): Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
f170240ef7
commit
a4a15195c2
@ -204,7 +204,7 @@ import_ownertrust( const char *fname )
|
||||
any = 1;
|
||||
}
|
||||
}
|
||||
else if( rc == -1 ) { /* not found: insert */
|
||||
else if (gpg_err_code (rc) == GPG_ERR_NOT_FOUND) { /* insert */
|
||||
log_info("inserting ownertrust of %u\n", otrust );
|
||||
memset (&rec, 0, sizeof rec);
|
||||
rec.recnum = tdbio_new_recnum ();
|
||||
|
21
g10/tdbio.c
21
g10/tdbio.c
@ -1245,10 +1245,9 @@ drop_from_hashtable (ulong table, byte *key, int keylen, ulong recnum)
|
||||
* the result in REC. The return value of CMP() should be True if the
|
||||
* record is the desired one.
|
||||
*
|
||||
* Return: -1 if not found, 0 if found or another error code.
|
||||
* FIXME: Use GPG_ERR_NOT_FOUND instead of -1.
|
||||
* Return: 0 if found, GPG_ERR_NOT_FOUND, or another error code.
|
||||
*/
|
||||
static int
|
||||
static gpg_error_t
|
||||
lookup_hashtable (ulong table, const byte *key, size_t keylen,
|
||||
int (*cmpfnc)(const void*, const TRUSTREC *),
|
||||
const void *cmpdata, TRUSTREC *rec )
|
||||
@ -1271,7 +1270,7 @@ lookup_hashtable (ulong table, const byte *key, size_t keylen,
|
||||
|
||||
item = rec->r.htbl.item[msb % ITEMS_PER_HTBL_RECORD];
|
||||
if (!item)
|
||||
return -1; /* Not found. */
|
||||
return gpg_error (GPG_ERR_NOT_FOUND);
|
||||
|
||||
rc = tdbio_read_record (item, rec, 0);
|
||||
if (rc)
|
||||
@ -1327,14 +1326,14 @@ lookup_hashtable (ulong table, const byte *key, size_t keylen,
|
||||
}
|
||||
}
|
||||
else
|
||||
return -1; /* not found */
|
||||
return gpg_error (GPG_ERR_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
if ((*cmpfnc)(cmpdata, rec))
|
||||
return 0; /* really found */
|
||||
|
||||
return -1; /* no: not found */
|
||||
return gpg_error (GPG_ERR_NOT_FOUND); /* no: not found */
|
||||
}
|
||||
|
||||
|
||||
@ -1805,10 +1804,9 @@ cmp_trec_fpr ( const void *fpr, const TRUSTREC *rec )
|
||||
* Given a 20 byte FINGERPRINT search its trust record and return
|
||||
* that at REC.
|
||||
*
|
||||
* Return: -1 if not found, 0 if found or another error code.
|
||||
* FIXME: Use GPG_ERR_NOT_FOUND instead of -1.
|
||||
* Return: 0 if found, GPG_ERR_NOT_FOUND, or another error code.
|
||||
*/
|
||||
int
|
||||
gpg_error_t
|
||||
tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec)
|
||||
{
|
||||
int rc;
|
||||
@ -1824,10 +1822,9 @@ tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec)
|
||||
* Given a primary public key object PK search its trust record and
|
||||
* return that at REC.
|
||||
*
|
||||
* Return: -1 if not found, 0 if found or another error code.
|
||||
* FIXME: Use GPG_ERR_NOT_FOUND instead of -1.
|
||||
* Return: 0 if found, GPG_ERR_NOT_FOUND, or another error code.
|
||||
*/
|
||||
int
|
||||
gpg_error_t
|
||||
tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec)
|
||||
{
|
||||
byte fingerprint[MAX_FINGERPRINT_LEN];
|
||||
|
@ -109,8 +109,8 @@ int tdbio_end_transaction(void);
|
||||
int tdbio_cancel_transaction(void);
|
||||
int tdbio_delete_record( ulong recnum );
|
||||
ulong tdbio_new_recnum(void);
|
||||
int tdbio_search_trust_byfpr(const byte *fingerprint, TRUSTREC *rec );
|
||||
int tdbio_search_trust_bypk(PKT_public_key *pk, TRUSTREC *rec );
|
||||
gpg_error_t tdbio_search_trust_byfpr (const byte *fingerprint, TRUSTREC *rec);
|
||||
gpg_error_t tdbio_search_trust_bypk (PKT_public_key *pk, TRUSTREC *rec);
|
||||
|
||||
void tdbio_how_to_fix (void);
|
||||
void tdbio_invalid(void);
|
||||
|
102
g10/trustdb.c
102
g10/trustdb.c
@ -598,10 +598,9 @@ read_trust_record (PKT_public_key *pk, TRUSTREC *rec)
|
||||
|
||||
init_trustdb();
|
||||
rc = tdbio_search_trust_bypk (pk, rec);
|
||||
if (rc == -1)
|
||||
return -1; /* no record yet */
|
||||
if (rc)
|
||||
{
|
||||
if (gpg_err_code (rc) != GPG_ERR_NOT_FOUND)
|
||||
log_error ("trustdb: searching trust record failed: %s\n",
|
||||
gpg_strerror (rc));
|
||||
return rc;
|
||||
@ -625,18 +624,18 @@ unsigned int
|
||||
tdb_get_ownertrust ( PKT_public_key *pk)
|
||||
{
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
|
||||
if (trustdb_args.no_trustdb && opt.trust_model == TM_ALWAYS)
|
||||
return TRUST_UNKNOWN;
|
||||
|
||||
rc = read_trust_record (pk, &rec);
|
||||
if (rc == -1)
|
||||
err = read_trust_record (pk, &rec);
|
||||
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
return TRUST_UNKNOWN; /* no record yet */
|
||||
if (rc)
|
||||
if (err)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
return rc; /* actually never reached */
|
||||
return TRUST_UNKNOWN; /* actually never reached */
|
||||
}
|
||||
|
||||
return rec.r.trust.ownertrust;
|
||||
@ -647,18 +646,18 @@ unsigned int
|
||||
tdb_get_min_ownertrust (PKT_public_key *pk)
|
||||
{
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
|
||||
if (trustdb_args.no_trustdb && opt.trust_model == TM_ALWAYS)
|
||||
return TRUST_UNKNOWN;
|
||||
|
||||
rc = read_trust_record (pk, &rec);
|
||||
if (rc == -1)
|
||||
err = read_trust_record (pk, &rec);
|
||||
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
return TRUST_UNKNOWN; /* no record yet */
|
||||
if (rc)
|
||||
if (err)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
return rc; /* actually never reached */
|
||||
return TRUST_UNKNOWN; /* actually never reached */
|
||||
}
|
||||
|
||||
return rec.r.trust.min_ownertrust;
|
||||
@ -673,13 +672,13 @@ void
|
||||
tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust )
|
||||
{
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
|
||||
if (trustdb_args.no_trustdb && opt.trust_model == TM_ALWAYS)
|
||||
return;
|
||||
|
||||
rc = read_trust_record (pk, &rec);
|
||||
if (!rc)
|
||||
err = read_trust_record (pk, &rec);
|
||||
if (!err)
|
||||
{
|
||||
if (DBG_TRUST)
|
||||
log_debug ("update ownertrust from %u to %u\n",
|
||||
@ -692,7 +691,7 @@ tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust )
|
||||
do_sync ();
|
||||
}
|
||||
}
|
||||
else if (rc == -1)
|
||||
else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
{ /* no record yet - create a new one */
|
||||
size_t dummy;
|
||||
|
||||
@ -707,7 +706,7 @@ tdb_update_ownertrust (PKT_public_key *pk, unsigned int new_trust )
|
||||
write_record (&rec);
|
||||
tdb_revalidation_mark ();
|
||||
do_sync ();
|
||||
rc = 0;
|
||||
err = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -720,21 +719,22 @@ update_min_ownertrust (u32 *kid, unsigned int new_trust )
|
||||
{
|
||||
PKT_public_key *pk;
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
|
||||
if (trustdb_args.no_trustdb && opt.trust_model == TM_ALWAYS)
|
||||
return;
|
||||
|
||||
pk = xmalloc_clear (sizeof *pk);
|
||||
rc = get_pubkey (pk, kid);
|
||||
if (rc)
|
||||
err = get_pubkey (pk, kid);
|
||||
if (err)
|
||||
{
|
||||
log_error(_("public key %s not found: %s\n"),keystr(kid),gpg_strerror (rc));
|
||||
log_error (_("public key %s not found: %s\n"),
|
||||
keystr (kid), gpg_strerror (err));
|
||||
return;
|
||||
}
|
||||
|
||||
rc = read_trust_record (pk, &rec);
|
||||
if (!rc)
|
||||
err = read_trust_record (pk, &rec);
|
||||
if (!err)
|
||||
{
|
||||
if (DBG_TRUST)
|
||||
log_debug ("key %08lX%08lX: update min_ownertrust from %u to %u\n",
|
||||
@ -749,7 +749,7 @@ update_min_ownertrust (u32 *kid, unsigned int new_trust )
|
||||
do_sync ();
|
||||
}
|
||||
}
|
||||
else if (rc == -1)
|
||||
else if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
{ /* no record yet - create a new one */
|
||||
size_t dummy;
|
||||
|
||||
@ -764,7 +764,7 @@ update_min_ownertrust (u32 *kid, unsigned int new_trust )
|
||||
write_record (&rec);
|
||||
tdb_revalidation_mark ();
|
||||
do_sync ();
|
||||
rc = 0;
|
||||
err = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -773,21 +773,24 @@ update_min_ownertrust (u32 *kid, unsigned int new_trust )
|
||||
}
|
||||
|
||||
|
||||
/* Clear the ownertrust and min_ownertrust values. Return true if a
|
||||
change actually happened. */
|
||||
/*
|
||||
* Clear the ownertrust and min_ownertrust values.
|
||||
*
|
||||
* Return: True if a change actually happened.
|
||||
*/
|
||||
int
|
||||
tdb_clear_ownertrusts (PKT_public_key *pk)
|
||||
{
|
||||
TRUSTREC rec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
|
||||
init_trustdb ();
|
||||
|
||||
if (trustdb_args.no_trustdb && opt.trust_model == TM_ALWAYS)
|
||||
return 0;
|
||||
|
||||
rc = read_trust_record (pk, &rec);
|
||||
if (!rc)
|
||||
err = read_trust_record (pk, &rec);
|
||||
if (!err)
|
||||
{
|
||||
if (DBG_TRUST)
|
||||
{
|
||||
@ -806,7 +809,7 @@ tdb_clear_ownertrusts (PKT_public_key *pk)
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (rc != -1)
|
||||
else if (gpg_err_code (err) != GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
}
|
||||
@ -821,22 +824,23 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid,
|
||||
int depth, int validity)
|
||||
{
|
||||
TRUSTREC trec, vrec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
ulong recno;
|
||||
|
||||
namehash_from_uid(uid);
|
||||
|
||||
rc = read_trust_record (pk, &trec);
|
||||
if (rc && rc != -1)
|
||||
err = read_trust_record (pk, &trec);
|
||||
if (err && gpg_err_code (err) != GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
return;
|
||||
}
|
||||
if (rc == -1) /* no record yet - create a new one */
|
||||
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
/* No record yet - create a new one. */
|
||||
size_t dummy;
|
||||
|
||||
rc = 0;
|
||||
err = 0;
|
||||
memset (&trec, 0, sizeof trec);
|
||||
trec.recnum = tdbio_new_recnum ();
|
||||
trec.rectype = RECTYPE_TRUST;
|
||||
@ -881,7 +885,7 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid,
|
||||
int
|
||||
tdb_cache_disabled_value (PKT_public_key *pk)
|
||||
{
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
TRUSTREC trec;
|
||||
int disabled = 0;
|
||||
|
||||
@ -893,16 +897,19 @@ tdb_cache_disabled_value (PKT_public_key *pk)
|
||||
if (trustdb_args.no_trustdb)
|
||||
return 0; /* No trustdb => not disabled. */
|
||||
|
||||
rc = read_trust_record (pk, &trec);
|
||||
if (rc && rc != -1)
|
||||
err = read_trust_record (pk, &trec);
|
||||
if (err && gpg_err_code (err) != GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
goto leave;
|
||||
}
|
||||
if (rc == -1) /* no record found, so assume not disabled */
|
||||
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
/* No record found, so assume not disabled. */
|
||||
goto leave;
|
||||
}
|
||||
|
||||
if (trec.r.trust.ownertrust & TRUST_FLAG_DISABLED)
|
||||
if ((trec.r.trust.ownertrust & TRUST_FLAG_DISABLED))
|
||||
disabled = 1;
|
||||
|
||||
/* Cache it for later so we don't need to look at the trustdb every
|
||||
@ -960,7 +967,7 @@ tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
|
||||
PKT_public_key *main_pk)
|
||||
{
|
||||
TRUSTREC trec, vrec;
|
||||
int rc;
|
||||
gpg_error_t err;
|
||||
ulong recno;
|
||||
unsigned int validity;
|
||||
|
||||
@ -983,19 +990,20 @@ tdb_get_validity_core (PKT_public_key *pk, PKT_user_id *uid,
|
||||
goto leave;
|
||||
}
|
||||
|
||||
rc = read_trust_record (main_pk, &trec);
|
||||
if (rc && rc != -1)
|
||||
err = read_trust_record (main_pk, &trec);
|
||||
if (err && gpg_err_code (err) != GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
tdbio_invalid ();
|
||||
return 0;
|
||||
}
|
||||
if (rc == -1) /* no record found */
|
||||
if (gpg_err_code (err) == GPG_ERR_NOT_FOUND)
|
||||
{
|
||||
/* No record found. */
|
||||
validity = TRUST_UNKNOWN;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* loop over all user IDs */
|
||||
/* Loop over all user IDs */
|
||||
recno = trec.r.trust.validlist;
|
||||
validity = 0;
|
||||
while (recno)
|
||||
@ -1057,7 +1065,7 @@ get_validity_counts (PKT_public_key *pk, PKT_user_id *uid)
|
||||
|
||||
init_trustdb ();
|
||||
|
||||
if(read_trust_record (pk, &trec)!=0)
|
||||
if(read_trust_record (pk, &trec))
|
||||
return;
|
||||
|
||||
/* loop over all user IDs */
|
||||
|
Loading…
x
Reference in New Issue
Block a user