From f1b73d2ff308f27a35948360885aa8e227427460 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 26 Oct 2019 15:40:19 +0100 Subject: [PATCH] key/key-misc.c (key_bytag): Accept `tag:', `id:' and `type:' prefixes. Further to the fix 079836cc4d21b355c8b58a4624ef85df0ac6c21a, allow the user to attach a disambiguating prefix to the label. Using the colon is safe here, since it's obviously not acceptable in a hex id, and `key_chkident' rejects colons in tag and type strings. --- key/key-misc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/key/key-misc.c b/key/key-misc.c index b10879ac..0afad76e 100644 --- a/key/key-misc.c +++ b/key/key-misc.c @@ -160,14 +160,29 @@ key *key_bytag(key_file *f, const char *tag) time_t t = time(0); char *p; uint32 id; - key_ref *kr = sym_find(&f->bytag, tag, -1, 0, 0); + enum { GUESS = -1, TAG, ID, TYPE }; int lookup; + key_ref *kr; key *k; - if (kr && !(KEY_EXPIRED(t, kr->k->exp) && KEY_EXPIRED(t, kr->k->del))) + if (STRNCMP(tag, ==, "tag:", 4)) { lookup = TAG; tag += 4; } + else if (STRNCMP(tag, ==, "id:", 3)) { lookup = ID; tag += 3; } + else if (STRNCMP(tag, ==, "type:", 5)) { lookup = TYPE; tag += 5; } + else lookup = GUESS; + + if ((lookup == GUESS || lookup == TAG) && + (kr = sym_find(&f->bytag, tag, -1, 0, 0)) != 0 && + !(KEY_EXPIRED(t, kr->k->exp) && KEY_EXPIRED(t, kr->k->del))) return (kr->k); - id = strtoul(tag, &p, 16); - if (!*p && (k = key_byid(f, id)) != 0) return (k); - return (key_bytype(f, tag)); + + if (lookup == GUESS || lookup == ID) { + id = strtoul(tag, &p, 16); + if (!*p && (k = key_byid(f, id)) != 0) return (k); + } + + if ((lookup == GUESS || lookup == TYPE) && (k = key_bytype(f, tag)) != 0) + return (k); + + return (0); } /* --- @key_qtag@ --- * -- 2.11.0