aboutsummaryrefslogtreecommitdiffstats
path: root/g10/call-keyboxd.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2020-09-24 08:27:19 +0000
committerWerner Koch <[email protected]>2020-09-24 08:37:42 +0000
commit25ad3c22d79d06c16a5fc652b0a6e3ffd99ad2b6 (patch)
tree055829e80850bdec48fcbce915ff9e4de8280021 /g10/call-keyboxd.c
parentkeyboxd: Fix UDPATE keyblob SQL statement (diff)
downloadgnupg-25ad3c22d79d06c16a5fc652b0a6e3ffd99ad2b6.tar.gz
gnupg-25ad3c22d79d06c16a5fc652b0a6e3ffd99ad2b6.zip
keyboxd: Implement multiple search descriptions.
* kbx/kbx-client-util.c (kbx_client_data_simple): New. * kbx/backend-sqlite.c (struct be_sqlite_local_s): Add field descidx. (be_sqlite_search): Use that. * g10/call-keyboxd.c (keydb_search): Implement multi mode. -- With that change the keyboxd is at par with the keybox code. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/call-keyboxd.c')
-rw-r--r--g10/call-keyboxd.c186
1 files changed, 103 insertions, 83 deletions
diff --git a/g10/call-keyboxd.c b/g10/call-keyboxd.c
index b54dbffc4..bb9901ab9 100644
--- a/g10/call-keyboxd.c
+++ b/g10/call-keyboxd.c
@@ -702,95 +702,115 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
err = gpg_error (GPG_ERR_INV_ARG);
goto leave;
}
-
- /* FIXME: Implement --multi */
- switch (desc->mode)
- {
- case KEYDB_SEARCH_MODE_EXACT:
- snprintf (line, sizeof line, "SEARCH --openpgp -- =%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_SUBSTR:
- snprintf (line, sizeof line, "SEARCH --openpgp -- *%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_MAIL:
- snprintf (line, sizeof line, "SEARCH --openpgp -- <%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_MAILSUB:
- snprintf (line, sizeof line, "SEARCH --openpgp -- @%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_MAILEND:
- snprintf (line, sizeof line, "SEARCH --openpgp -- .%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_WORDS:
- snprintf (line, sizeof line, "SEARCH --openpgp -- +%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_SHORT_KID:
- snprintf (line, sizeof line, "SEARCH --openpgp -- 0x%08lX",
- (ulong)desc->u.kid[1]);
- break;
-
- case KEYDB_SEARCH_MODE_LONG_KID:
- snprintf (line, sizeof line, "SEARCH --openpgp -- 0x%08lX%08lX",
- (ulong)desc->u.kid[0], (ulong)desc->u.kid[1]);
- break;
-
- case KEYDB_SEARCH_MODE_FPR:
- {
- unsigned char hexfpr[MAX_FINGERPRINT_LEN * 2 + 1];
- log_assert (desc[0].fprlen <= MAX_FINGERPRINT_LEN);
- bin2hex (desc[0].u.fpr, desc[0].fprlen, hexfpr);
- snprintf (line, sizeof line, "SEARCH --openpgp -- 0x%s", hexfpr);
- }
- break;
-
- case KEYDB_SEARCH_MODE_ISSUER:
- snprintf (line, sizeof line, "SEARCH --openpgp -- #/%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_ISSUER_SN:
- case KEYDB_SEARCH_MODE_SN:
- snprintf (line, sizeof line, "SEARCH --openpgp -- #%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_SUBJECT:
- snprintf (line, sizeof line, "SEARCH --openpgp -- /%s", desc[0].u.name);
- break;
-
- case KEYDB_SEARCH_MODE_KEYGRIP:
+ for (i = 0; i < ndesc; i++)
+ if (desc->mode == KEYDB_SEARCH_MODE_FIRST)
{
- unsigned char hexgrip[KEYGRIP_LEN * 2 + 1];
- bin2hex (desc[0].u.grip, KEYGRIP_LEN, hexgrip);
- snprintf (line, sizeof line, "SEARCH --openpgp -- &%s", hexgrip);
+ /* If any description has mode FIRST, this item trumps all
+ * other descriptions. */
+ snprintf (line, sizeof line, "SEARCH --openpgp");
+ goto do_search;
}
- break;
- case KEYDB_SEARCH_MODE_UBID:
- {
- unsigned char hexubid[UBID_LEN * 2 + 1];
- bin2hex (desc[0].u.ubid, UBID_LEN, hexubid);
- snprintf (line, sizeof line, "SEARCH --openpgp -- ^%s", hexubid);
- }
- break;
-
- case KEYDB_SEARCH_MODE_FIRST:
- snprintf (line, sizeof line, "SEARCH --openpgp");
- break;
+ for ( ; ndesc; desc++, ndesc--)
+ {
+ const char *more = ndesc > 1 ? "--openpgp --more" : "--openpgp";
- case KEYDB_SEARCH_MODE_NEXT:
- log_debug ("%s: mode next - we should not get to here!\n", __func__);
- snprintf (line, sizeof line, "NEXT");
- break;
+ switch (desc->mode)
+ {
+ case KEYDB_SEARCH_MODE_EXACT:
+ snprintf (line, sizeof line, "SEARCH %s -- =%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_SUBSTR:
+ snprintf (line, sizeof line, "SEARCH %s -- *%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_MAIL:
+ snprintf (line, sizeof line, "SEARCH %s -- <%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_MAILSUB:
+ snprintf (line, sizeof line, "SEARCH %s -- @%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_MAILEND:
+ snprintf (line, sizeof line, "SEARCH %s -- .%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_WORDS:
+ snprintf (line, sizeof line, "SEARCH %s -- +%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_SHORT_KID:
+ snprintf (line, sizeof line, "SEARCH %s -- 0x%08lX", more,
+ (ulong)desc->u.kid[1]);
+ break;
+
+ case KEYDB_SEARCH_MODE_LONG_KID:
+ snprintf (line, sizeof line, "SEARCH %s -- 0x%08lX%08lX", more,
+ (ulong)desc->u.kid[0], (ulong)desc->u.kid[1]);
+ break;
+
+ case KEYDB_SEARCH_MODE_FPR:
+ {
+ unsigned char hexfpr[MAX_FINGERPRINT_LEN * 2 + 1];
+ log_assert (desc->fprlen <= MAX_FINGERPRINT_LEN);
+ bin2hex (desc->u.fpr, desc->fprlen, hexfpr);
+ snprintf (line, sizeof line, "SEARCH %s -- 0x%s", more, hexfpr);
+ }
+ break;
+
+ case KEYDB_SEARCH_MODE_ISSUER:
+ snprintf (line, sizeof line, "SEARCH %s -- #/%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_ISSUER_SN:
+ case KEYDB_SEARCH_MODE_SN:
+ snprintf (line, sizeof line, "SEARCH %s -- #%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_SUBJECT:
+ snprintf (line, sizeof line, "SEARCH %s -- /%s", more, desc->u.name);
+ break;
+
+ case KEYDB_SEARCH_MODE_KEYGRIP:
+ {
+ unsigned char hexgrip[KEYGRIP_LEN * 2 + 1];
+ bin2hex (desc->u.grip, KEYGRIP_LEN, hexgrip);
+ snprintf (line, sizeof line, "SEARCH %s -- &%s", more, hexgrip);
+ }
+ break;
+
+ case KEYDB_SEARCH_MODE_UBID:
+ {
+ unsigned char hexubid[UBID_LEN * 2 + 1];
+ bin2hex (desc->u.ubid, UBID_LEN, hexubid);
+ snprintf (line, sizeof line, "SEARCH %s -- ^%s", more, hexubid);
+ }
+ break;
+
+ case KEYDB_SEARCH_MODE_NEXT:
+ log_debug ("%s: mode next - we should not get to here!\n", __func__);
+ snprintf (line, sizeof line, "NEXT");
+ break;
+
+ case KEYDB_SEARCH_MODE_FIRST:
+ log_debug ("%s: mode first - we should not get to here!\n", __func__);
+ /*fallthru*/
+ default:
+ err = gpg_error (GPG_ERR_INV_ARG);
+ goto leave;
+ }
- default:
- err = gpg_error (GPG_ERR_INV_ARG);
- goto leave;
+ if (ndesc > 1)
+ {
+ err = kbx_client_data_simple (hd->kbl->kcd, line);
+ if (err)
+ goto leave;
+ }
}
+ while (ndesc);
+
do_search:
hd->last_ubid_valid = 0;