3 * $Id: pixie-client.c,v 1.1 1999/12/22 15:58:41 mdw Exp $
5 * Simple passphrase pixie client (Unix-specific)
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
32 * $Log: pixie-client.c,v $
33 * Revision 1.1 1999/12/22 15:58:41 mdw
34 * Passphrase pixie support.
38 /*----- Header files ------------------------------------------------------*/
45 #include <sys/types.h>
50 #include <sys/socket.h>
53 #include <mLib/dstr.h>
54 #include <mLib/fdflags.h>
57 #include "passphrase.h"
60 /*----- Main code ---------------------------------------------------------*/
62 /* --- @pixie_open@ --- *
64 * Arguments: @const char *sock@ = path to pixie socket
66 * Returns: Less than zero if it failed, or file descriptor.
68 * Use: Opens a connection to a passphrase pixie.
71 int pixie_open(const char *sock
)
73 struct sockaddr_un
*sun
;
77 /* --- Open the connection --- */
79 if ((fd
= socket(PF_UNIX
, SOCK_STREAM
, 0)) < 0)
81 sun
= pixie_address(sock
, &sz
);
82 if (connect(fd
, (struct sockaddr
*)sun
, sz
))
87 /* --- Tidy up if things went wrong --- */
96 /* --- @pixie_read@ --- *
98 * Arguments: @int fd@ = connection to passphrase pixie
99 * @const char *tag@ = pointer to tag string
100 * @unsigned mode@ = reading mode
101 * @char *buf@ = pointer to destination buffer
102 * @size_t sz@ = size of the buffer
104 * Returns: Zero if all went well, nonzero if the read fails.
106 * Use: Reads a passphrase from the pixie.
109 int pixie_read(int fd
, const char *tag
, unsigned mode
, char *buf
, size_t sz
)
114 /* --- Send the request --- */
116 dstr_putf(&d
, "%s %s\n", mode
== PMODE_READ ?
"PASS" : "VERIFY", tag
);
117 write(fd
, d
.buf
, d
.len
);
120 /* --- Sort out the result --- */
123 pixie_fdline(fd
, buf
, sz
);
125 if ((q
= str_getword(&p
)) == 0)
127 if (strcmp(q
, "INFO") == 0)
129 else if (strcmp(q
, "OK") != 0)
132 /* --- Return the final answer --- */
135 memmove(buf
, p
, strlen(p
) + 1);
141 /* --- @pixie_cancel@ --- *
143 * Arguments: @int fd@ = pixie file descriptor
144 * @const char *tag@ = pointer to tag string
148 * Use: Cancels a passphrase if it turns out to be bogus.
151 void pixie_cancel(int fd
, const char *tag
)
157 /* --- Send the request --- */
159 dstr_putf(&d
, "FLUSH %s\n", tag
);
160 write(fd
, d
.buf
, d
.len
);
163 /* --- Sort out the result --- */
166 pixie_fdline(fd
, buf
, sizeof(buf
));
168 if ((q
= str_getword(&p
)) != 0 && strcmp(q
, "INFO") == 0)
172 /*----- That's all, folks -------------------------------------------------*/