X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/069c185c6386ddd0a43d3cd4bed99c69884afbfe..578a86d91941a0f722b87973d88e84ec2cf9a608:/pixie-client.c diff --git a/pixie-client.c b/pixie-client.c index 5b7c0dc..1597426 100644 --- a/pixie-client.c +++ b/pixie-client.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: pixie-client.c,v 1.1 1999/12/22 15:58:41 mdw Exp $ + * $Id: pixie-client.c,v 1.3 2004/04/08 01:36:15 mdw Exp $ * * Simple passphrase pixie client (Unix-specific) * @@ -27,14 +27,6 @@ * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: pixie-client.c,v $ - * Revision 1.1 1999/12/22 15:58:41 mdw - * Passphrase pixie support. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -101,7 +93,8 @@ fail_0: * @char *buf@ = pointer to destination buffer * @size_t sz@ = size of the buffer * - * Returns: Zero if all went well, nonzero if the read fails. + * Returns: Zero if all went well, @-1@ if the read fails, @+1@ to + * request the passphrase from the user. * * Use: Reads a passphrase from the pixie. */ @@ -126,6 +119,8 @@ again: return (-1); if (strcmp(q, "INFO") == 0) goto again; + else if (strcmp(q, "MISSING") == 0) + return (+1); else if (strcmp(q, "OK") != 0) return (-1); @@ -138,6 +133,46 @@ again: return (0); } +/* --- @pixie_set@ --- * + * + * Arguments: @int fd@ = pixie file descriptor + * @const char *tag@ = pointer to tag string + * @const char *phrase@ = pointer to passphrase string + * + * Returns: --- + * + * Use: Sends a passphrase to the passphrase pixie. + */ + +void pixie_set(int fd, const char *tag, const char *phrase) +{ + dstr d = DSTR_INIT; + char buf[16]; + size_t sz = strlen(phrase); + char nl = '\n'; + char *p, *q; + + /* --- Send the request --- * + * + * I didn't want to copy it out of the caller's buffer. @writev@ may + * produce a copy, too, so I didn't do that either. + */ + + dstr_putf(&d, "SET %s -- ", tag); + write(fd, d.buf, d.len); + write(fd, phrase, sz); + write(fd, &nl, 1); + dstr_destroy(&d); + + /* --- Pick up the pieces --- */ + +again: + pixie_fdline(fd, buf, sizeof(buf)); + p = buf; + if ((q = str_getword(&p)) != 0 && strcmp(q, "INFO") == 0) + goto again; +} + /* --- @pixie_cancel@ --- * * * Arguments: @int fd@ = pixie file descriptor