X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/14d553d6c309b5e3a1ce3fdd344a706a89e6c3cc..f52f2db067dc1388b16ab00ddb53e26a381a6e3e:/passphrase.c diff --git a/passphrase.c b/passphrase.c index d27b9a4..8bbbb9d 100644 --- a/passphrase.c +++ b/passphrase.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: passphrase.c,v 1.5 2002/01/13 13:41:37 mdw Exp $ + * $Id$ * * Reading of passphrases (Unix-specific) * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,40 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: passphrase.c,v $ - * Revision 1.5 2002/01/13 13:41:37 mdw - * Fix stupidity in passphrase verification. - * - * 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 @@ -72,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 @@ -155,7 +142,7 @@ int passphrase_read(const char *tag, unsigned mode, char *buf, size_t sz) fail: dstr_destroy(&d); memset(buf, 0, sz); - return (-1); + return (-1); } /* --- @passphrase_cancel@ --- *