From e9be047b35e12f353e313f60677d80f1e86c73af Mon Sep 17 00:00:00 2001 From: mdw Date: Tue, 27 Sep 2005 11:32:59 +0000 Subject: [PATCH] key getattr --- key.1 | 11 +++++++++++ keyutil.c | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/key.1 b/key.1 index 6aa3520..459a0b3 100644 --- a/key.1 +++ b/key.1 @@ -98,6 +98,10 @@ is one of: .I tag .IR attr ... .br +.B getattr +.I tag +.I attr +.br .B lock .I qtag .br @@ -836,6 +840,13 @@ An attribute can be deleted by assigning it an empty value. Although the keyring file format is capable of representing an attribute with an empty value as distinct from a nonexistant attribute, this interface does not allow empty attributes to be set. +.SS "getattr" +Fetches a single attribute of a key. The key whose attribute is to be +read is given by its +.IR tag . +The attribute's value is written to standard output followed by a +newline. If the key or attribute is absent, a message is written to +standard error and the program exits nonzero. .SS "comment" Sets, deletes or changes the comment attached to a key. The first argument is a key tag or keyid which names the key to be modified; the diff --git a/keyutil.c b/keyutil.c index 1d4bbca..9881dc7 100644 --- a/keyutil.c +++ b/keyutil.c @@ -1609,6 +1609,29 @@ static int cmd_setattr(int argc, char *argv[]) return (0); } +/* --- @cmd_getattr@ --- */ + +static int cmd_getattr(int argc, char *argv[]) +{ + key_file f; + key *k; + dstr d = DSTR_INIT; + const char *p; + + if (argc != 3) + die(EXIT_FAILURE, "Usage: getattr TAG ATTR"); + doopen(&f, KOPEN_READ); + if ((k = key_bytag(&f, argv[1])) == 0) + die(EXIT_FAILURE, "key `%s' not found", argv[1]); + key_fulltag(k, &d); + if ((p = key_getattr(&f, k, argv[2])) == 0) + die(EXIT_FAILURE, "no attribute `%s' for key `%s'", argv[2], d.buf); + puts(p); + dstr_destroy(&d); + doclose(&f); + return (0); +} + /* --- @cmd_finger@ --- */ static void fingerprint(key *k, const gchash *ch, const key_filter *kf) @@ -1784,6 +1807,7 @@ static int cmd_verify(int argc, char *argv[]) fpr = GH_DONE(h, 0); if (memcmp(fpr, buf, ch->hashsz) != 0) die(EXIT_FAILURE, "key fingerprint mismatch"); + doclose(&f); return (0); } @@ -2057,6 +2081,7 @@ Options:\n\ { "expire", cmd_expire, "expire TAG..." }, { "delete", cmd_delete, "delete TAG..." }, { "setattr", cmd_setattr, "setattr TAG ATTR..." }, + { "getattr", cmd_getattr, "getattr TAG ATTR" }, { "comment", cmd_comment, "comment TAG [COMMENT]" }, { "lock", cmd_lock, "lock QTAG" }, { "unlock", cmd_unlock, "unlock QTAG" }, -- 2.11.0