3 * Reading of passphrases (Unix-specific)
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/dstr.h>
39 #include "passphrase.h"
42 /*----- Static variables --------------------------------------------------*/
45 static unsigned flags = 0;
49 /*----- Main code ---------------------------------------------------------*/
51 /* --- @passphrase_connect@ ---
53 * Arguments: @const char *sock@ = socket name to connect to, or null for
56 * Returns: Zero if OK, nonzero if it failed
58 * Use: Attempts to connect to the passphrase pixie.
61 int passphrase_connect(const char *sock)
65 if ((fd = pixie_open(sock)) < 0) {
73 static int pconn(void)
79 return (passphrase_connect(0));
82 /* --- @passphrase_read@ --- *
84 * Arguments: @const char *tag@ = pointer to passphrase tag string
85 * @unsigned mode@ = reading mode
86 * @char *buf@ = pointer to destination buffer
87 * @size_t sz@ = size of destination buffer
89 * Returns: Zero if successful, nonzero on failure.
91 * Use: Reads a passphrase from the user, using some system-specific
92 * secure mechanism. The mechanism may keep a cache of
93 * passphrases, so the user may not necessarily be prompted.
96 int passphrase_read(const char *tag, unsigned mode, char *buf, size_t sz)
101 /* --- Try talking to the pixie --- */
104 rc = pixie_read(fd, tag, mode, buf, sz);
114 /* --- Read from the terminal --- */
116 dstr_putf(&d, "%s %s: ",
117 mode == PMODE_READ ? "Passphrase" : "New passphrase",
119 if (pixie_getpass(d.buf, buf, sz))
121 if (mode == PMODE_VERIFY) {
124 dstr_putf(&d, "Verify passphrase %s: ", tag);
125 if (pixie_getpass(d.buf, b, sizeof(b)) || strcmp(b, buf) != 0) {
126 memset(b, 0, sizeof(b));
132 /* --- If the pixie is interested, tell it the new passphrase --- */
135 pixie_set(fd, tag, buf);
138 /* --- Tidy up after a failure --- */
146 /* --- @passphrase_cancel@ --- *
148 * Arguments: @const char *tag@ = pointer to passphrase tag string
152 * Use: Attempts to make the passphrase cache forget about a
153 * particular passphrase. This may be useful if the passphrase
154 * turns out to be wrong, or if the user is attempting to change
158 void passphrase_cancel(const char *tag)
161 pixie_cancel(fd, tag);
164 /*----- That's all, folks -------------------------------------------------*/