Uprating of the passphrase pixie.
[u/mdw/catacomb] / passphrase.c
index a8dacc2..410b7af 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: passphrase.c,v 1.4 2001/04/19 18:26:01 mdw Exp $
+ * $Id$
  *
  * Reading of passphrases (Unix-specific)
  *
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: passphrase.c,v $
- * Revision 1.4  2001/04/19 18:26:01  mdw
- * Re-request broken passphrases.
- *
- * Revision 1.3  2000/12/06 20:33:27  mdw
- * Make flags be macros rather than enumerations, to ensure that they're
- * unsigned.
- *
- * 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:20  mdw
- * Portable interface to reading passphrases.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <errno.h>
@@ -69,28 +50,37 @@ static unsigned flags = 0;
 
 /*----- Main code ---------------------------------------------------------*/
 
-/* --- @pconn@ --- *
+/* --- @passphrase_connect@ ---
  *
- * Arguments:  ---
+ * Arguments:  @const char *sock@ = socket name to connect to, or null for
+ *             default
  *
  * Returns:    Zero if OK, nonzero if it failed
  *
  * Use:                Attempts to connect to the passphrase pixie.
  */
 
-static int pconn(void)
+int passphrase_connect(const char *sock)
 {
   if (fd != -1)
-    return (0);
-  if (flags & f_fail)
-    return (-1);
-  if ((fd = pixie_open(0)) < 0) {
+    close(fd);
+  if ((fd = pixie_open(sock)) < 0) {
     flags |= f_fail;
     return (-1);
   }
+  flags &= ~f_fail;
   return (0);
 }
 
+static int pconn(void)
+{
+  if (fd != -1)
+    return (0);
+  if (flags & f_fail)
+    return (-1);
+  return (passphrase_connect(0));
+}
+
 /* --- @passphrase_read@ --- *
  *
  * Arguments:  @const char *tag@ = pointer to passphrase tag string
@@ -125,7 +115,6 @@ int passphrase_read(const char *tag, unsigned mode, char *buf, size_t sz)
 
   /* --- Read from the terminal --- */
 
-again:
   dstr_putf(&d, "%s %s: ",
            mode == PMODE_READ ? "Passphrase" : "New passphrase",
            tag);
@@ -135,9 +124,9 @@ again:
     char b[1024];
     DRESET(&d);
     dstr_putf(&d, "Verify passphrase %s: ", tag);
-    if (pixie_getpass(d.buf, b, sizeof(b)) ||
-       strcmp(b, buf) != 0) {
+    if (pixie_getpass(d.buf, b, sizeof(b)) || strcmp(b, buf) != 0) {
       memset(b, 0, sizeof(b));
+      goto fail;
     }
   }
   dstr_destroy(&d);