/* -*-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)
*
/*----- 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.
*
* @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.
*/
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);
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