1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-10 21:38:50 +01:00

gpg: New debug flag "keydb".

* g10/options.h (DBG_KEYDB_VALUE): New.
* g10/gpg.c (debug_flags): Add it.
* g10/keydb.c: Replace all DBG_LOOKUP by DBG_KEYDB.
* g10/keyring.c: Ditto.
* g10/call-keyboxd.c: Ditto.
--

Using "lookup" also for key search debugging was not a good idea.
This uses a separate flag for the latter.
This commit is contained in:
Werner Koch 2024-08-09 09:31:54 +02:00
parent 7d82fca43d
commit 8735b87411
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 28 additions and 23 deletions

View File

@ -1,5 +1,5 @@
/* call-keyboxd.c - Access to the keyboxd storage server /* call-keyboxd.c - Access to the keyboxd storage server
* Copyright (C) 2019 g10 Code GmbH * Copyright (C) 2019, 2024 g10 Code GmbH
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -717,7 +717,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
if (DBG_CLOCK) if (DBG_CLOCK)
log_clock ("%s enter", __func__); log_clock ("%s enter", __func__);
if (DBG_LOOKUP) if (DBG_KEYDB)
{ {
log_debug ("%s: %zu search descriptions:\n", __func__, ndesc); log_debug ("%s: %zu search descriptions:\n", __func__, ndesc);
for (i = 0; i < ndesc; i ++) for (i = 0; i < ndesc; i ++)
@ -880,7 +880,7 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
{ {
hd->kbl->search_result = iobuf_temp_with_content (buffer, len); hd->kbl->search_result = iobuf_temp_with_content (buffer, len);
xfree (buffer); xfree (buffer);
if (DBG_LOOKUP && hd->last_ubid_valid) if (DBG_KEYDB && hd->last_ubid_valid)
log_printhex (hd->last_ubid, 20, "found UBID (%d,%d):", log_printhex (hd->last_ubid, 20, "found UBID (%d,%d):",
hd->last_uid_no, hd->last_pk_no); hd->last_uid_no, hd->last_pk_no);
} }

View File

@ -1035,6 +1035,7 @@ static struct debug_flags_s debug_flags [] =
{ DBG_CLOCK_VALUE , "clock" }, { DBG_CLOCK_VALUE , "clock" },
{ DBG_LOOKUP_VALUE , "lookup" }, { DBG_LOOKUP_VALUE , "lookup" },
{ DBG_EXTPROG_VALUE, "extprog" }, { DBG_EXTPROG_VALUE, "extprog" },
{ DBG_KEYDB_VALUE, "keydb" },
{ 0, NULL } { 0, NULL }
}; };

View File

@ -1,6 +1,7 @@
/* keydb.c - key database dispatcher /* keydb.c - key database dispatcher
* Copyright (C) 2001-2013 Free Software Foundation, Inc. * Copyright (C) 2001-2013 Free Software Foundation, Inc.
* Copyright (C) 2001-2015 Werner Koch * Copyright (C) 2001-2015 Werner Koch
* Copyright (C) 2019,2024 g10 Code GmbH
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *
@ -16,6 +17,7 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses/>. * along with this program; if not, see <https://www.gnu.org/licenses/>.
* SPDX-License-Identifier: GPL-3.0-or-later
*/ */
#include <config.h> #include <config.h>
@ -1818,7 +1820,7 @@ internal_keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
while ((rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF) while ((rc == -1 || gpg_err_code (rc) == GPG_ERR_EOF)
&& hd->current >= 0 && hd->current < hd->used) && hd->current >= 0 && hd->current < hd->used)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: searching %s (resource %d of %d)\n", log_debug ("%s: searching %s (resource %d of %d)\n",
__func__, __func__,
hd->active[hd->current].type == KEYDB_RESOURCE_TYPE_KEYRING hd->active[hd->current].type == KEYDB_RESOURCE_TYPE_KEYRING
@ -1845,7 +1847,7 @@ internal_keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
break; break;
} }
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: searched %s (resource %d of %d) => %s\n", log_debug ("%s: searched %s (resource %d of %d) => %s\n",
__func__, __func__,
hd->active[hd->current].type == KEYDB_RESOURCE_TYPE_KEYRING hd->active[hd->current].type == KEYDB_RESOURCE_TYPE_KEYRING

View File

@ -691,14 +691,14 @@ prepare_search (KEYRING_HANDLE hd)
we can easily use search_next. */ we can easily use search_next. */
if (gpg_err_code (hd->current.error) == GPG_ERR_LEGACY_KEY) if (gpg_err_code (hd->current.error) == GPG_ERR_LEGACY_KEY)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: last error was GPG_ERR_LEGACY_KEY, clearing\n", log_debug ("%s: last error was GPG_ERR_LEGACY_KEY, clearing\n",
__func__); __func__);
hd->current.error = 0; hd->current.error = 0;
} }
else else
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: returning last error: %s\n", log_debug ("%s: returning last error: %s\n",
__func__, gpg_strerror (hd->current.error)); __func__, gpg_strerror (hd->current.error));
return hd->current.error; /* still in error state */ return hd->current.error; /* still in error state */
@ -708,7 +708,7 @@ prepare_search (KEYRING_HANDLE hd)
if (hd->current.kr && !hd->current.eof) { if (hd->current.kr && !hd->current.eof) {
if ( !hd->current.iobuf ) if ( !hd->current.iobuf )
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: missing iobuf!\n", __func__); log_debug ("%s: missing iobuf!\n", __func__);
return GPG_ERR_GENERAL; /* Position invalid after a modify. */ return GPG_ERR_GENERAL; /* Position invalid after a modify. */
} }
@ -717,7 +717,7 @@ prepare_search (KEYRING_HANDLE hd)
if (!hd->current.kr && hd->current.eof) if (!hd->current.kr && hd->current.eof)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: EOF!\n", __func__); log_debug ("%s: EOF!\n", __func__);
return -1; /* still EOF */ return -1; /* still EOF */
} }
@ -725,7 +725,7 @@ prepare_search (KEYRING_HANDLE hd)
if (!hd->current.kr) { /* start search with first keyring */ if (!hd->current.kr) { /* start search with first keyring */
hd->current.kr = hd->resource; hd->current.kr = hd->resource;
if (!hd->current.kr) { if (!hd->current.kr) {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: keyring not available!\n", __func__); log_debug ("%s: keyring not available!\n", __func__);
hd->current.eof = 1; hd->current.eof = 1;
return -1; /* keyring not available */ return -1; /* keyring not available */
@ -733,7 +733,7 @@ prepare_search (KEYRING_HANDLE hd)
log_assert (!hd->current.iobuf); log_assert (!hd->current.iobuf);
} }
else { /* EOF */ else { /* EOF */
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: EOF\n", __func__); log_debug ("%s: EOF\n", __func__);
iobuf_close (hd->current.iobuf); iobuf_close (hd->current.iobuf);
hd->current.iobuf = NULL; hd->current.iobuf = NULL;
@ -1018,14 +1018,14 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
} }
} }
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: need_uid = %d; need_words = %d; need_keyid = %d; need_fpr = %d; any_skip = %d\n", log_debug ("%s: need_uid = %d; need_words = %d; need_keyid = %d; need_fpr = %d; any_skip = %d\n",
__func__, need_uid, need_words, need_keyid, need_fpr, any_skip); __func__, need_uid, need_words, need_keyid, need_fpr, any_skip);
rc = prepare_search (hd); rc = prepare_search (hd);
if (rc) if (rc)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: prepare_search failed: %s (%d)\n", log_debug ("%s: prepare_search failed: %s (%d)\n",
__func__, gpg_strerror (rc), gpg_err_code (rc)); __func__, gpg_strerror (rc), gpg_err_code (rc));
return rc; return rc;
@ -1034,12 +1034,12 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
use_key_present_hash = !!key_present_hash; use_key_present_hash = !!key_present_hash;
if (!use_key_present_hash) if (!use_key_present_hash)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: no offset table.\n", __func__); log_debug ("%s: no offset table.\n", __func__);
} }
else if (!key_present_hash_ready) else if (!key_present_hash_ready)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: initializing offset table. (need_keyid: %d => 1)\n", log_debug ("%s: initializing offset table. (need_keyid: %d => 1)\n",
__func__, need_keyid); __func__, need_keyid);
need_keyid = 1; need_keyid = 1;
@ -1048,13 +1048,13 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
{ {
struct key_present *oi; struct key_present *oi;
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: look up by long key id, checking cache\n", __func__); log_debug ("%s: look up by long key id, checking cache\n", __func__);
oi = key_present_hash_lookup (key_present_hash, desc[0].u.kid); oi = key_present_hash_lookup (key_present_hash, desc[0].u.kid);
if (!oi) if (!oi)
{ /* We know that we don't have this key */ { /* We know that we don't have this key */
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: cache says not present\n", __func__); log_debug ("%s: cache says not present\n", __func__);
hd->found.kr = NULL; hd->found.kr = NULL;
hd->current.eof = 1; hd->current.eof = 1;
@ -1099,7 +1099,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
pk_no = uid_no = 0; pk_no = uid_no = 0;
initial_skip = 1; /* skip until we see the start of a keyblock */ initial_skip = 1; /* skip until we see the start of a keyblock */
scanned_from_start = iobuf_tell (hd->current.iobuf) == 0; scanned_from_start = iobuf_tell (hd->current.iobuf) == 0;
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: %ssearching from start of resource.\n", log_debug ("%s: %ssearching from start of resource.\n",
__func__, scanned_from_start ? "" : "not "); __func__, scanned_from_start ? "" : "not ");
init_parse_packet (&parsectx, hd->current.iobuf); init_parse_packet (&parsectx, hd->current.iobuf);
@ -1218,7 +1218,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
if (rc) if (rc)
goto real_found; goto real_found;
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: packet starting at offset %lld matched descriptor %zu\n" log_debug ("%s: packet starting at offset %lld matched descriptor %zu\n"
, __func__, (long long)offset, n); , __func__, (long long)offset, n);
@ -1231,7 +1231,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
if (desc[n].skipfnc if (desc[n].skipfnc
&& desc[n].skipfnc (desc[n].skipfncvalue, aki, uid_no)) && desc[n].skipfnc (desc[n].skipfncvalue, aki, uid_no))
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: skipping match: desc %zd's skip function returned TRUE\n", log_debug ("%s: skipping match: desc %zd's skip function returned TRUE\n",
__func__, n); __func__, n);
break; break;
@ -1244,7 +1244,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
real_found: real_found:
if (!rc) if (!rc)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: returning success\n", __func__); log_debug ("%s: returning success\n", __func__);
hd->found.offset = main_offset; hd->found.offset = main_offset;
hd->found.kr = hd->current.kr; hd->found.kr = hd->current.kr;
@ -1253,7 +1253,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
} }
else if (rc == -1) else if (rc == -1)
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: no matches (EOF)\n", __func__); log_debug ("%s: no matches (EOF)\n", __func__);
hd->current.eof = 1; hd->current.eof = 1;
@ -1287,7 +1287,7 @@ keyring_search (KEYRING_HANDLE hd, KEYDB_SEARCH_DESC *desc,
} }
else else
{ {
if (DBG_LOOKUP) if (DBG_KEYDB)
log_debug ("%s: error encountered during search: %s (%d)\n", log_debug ("%s: error encountered during search: %s (%d)\n",
__func__, gpg_strerror (rc), rc); __func__, gpg_strerror (rc), rc);
hd->current.error = rc; hd->current.error = rc;

View File

@ -365,6 +365,7 @@ struct {
#define DBG_CLOCK_VALUE 4096 #define DBG_CLOCK_VALUE 4096
#define DBG_LOOKUP_VALUE 8192 /* debug the key lookup */ #define DBG_LOOKUP_VALUE 8192 /* debug the key lookup */
#define DBG_EXTPROG_VALUE 16384 /* debug external program calls */ #define DBG_EXTPROG_VALUE 16384 /* debug external program calls */
#define DBG_KEYDB_VALUE 32768 /* debug keydb and keyboxd searches. */
/* Tests for the debugging flags. */ /* Tests for the debugging flags. */
#define DBG_PACKET (opt.debug & DBG_PACKET_VALUE) #define DBG_PACKET (opt.debug & DBG_PACKET_VALUE)
@ -378,6 +379,7 @@ struct {
#define DBG_CLOCK (opt.debug & DBG_CLOCK_VALUE) #define DBG_CLOCK (opt.debug & DBG_CLOCK_VALUE)
#define DBG_LOOKUP (opt.debug & DBG_LOOKUP_VALUE) #define DBG_LOOKUP (opt.debug & DBG_LOOKUP_VALUE)
#define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE) #define DBG_EXTPROG (opt.debug & DBG_EXTPROG_VALUE)
#define DBG_KEYDB (opt.debug & DBG_KEYDB_VALUE)
/* FIXME: We need to check why we did not put this into opt. */ /* FIXME: We need to check why we did not put this into opt. */
#define DBG_MEMORY memory_debug_mode #define DBG_MEMORY memory_debug_mode