.I tag
.IR attr ...
.br
+.B getattr
+.I tag
+.I attr
+.br
.B lock
.I qtag
.br
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
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)
fpr = GH_DONE(h, 0);
if (memcmp(fpr, buf, ch->hashsz) != 0)
die(EXIT_FAILURE, "key fingerprint mismatch");
+ doclose(&f);
return (0);
}
{ "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" },