X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/75b1b62430734fba729675f563138817bc853a60..95959d1099b58690f2d490d22bfbbfc678380964:/pixie-client.c diff --git a/pixie-client.c b/pixie-client.c index 5b7c0dc..f1b8678 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.2 2000/06/17 11:49:37 mdw Exp $ * * Simple passphrase pixie client (Unix-specific) * @@ -30,6 +30,10 @@ /*----- Revision history --------------------------------------------------* * * $Log: pixie-client.c,v $ + * Revision 1.2 2000/06/17 11:49:37 mdw + * New pixie protocol allowing application to request passphrases and send + * them to the pixie. + * * Revision 1.1 1999/12/22 15:58:41 mdw * Passphrase pixie support. * @@ -101,7 +105,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 +131,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 +145,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