1 .\" $OpenBSD: readpassphrase.3,v 1.7 2001/12/15 15:37:51 millert Exp $
3 .\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\" derived from this software without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
20 .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 .\" $FreeBSD: src/lib/libc/gen/readpassphrase.3,v 1.4.2.3 2003/03/15 15:11:05 trhodes Exp $
29 .\" $DragonFly: src/lib/libc/gen/readpassphrase.3,v 1.5 2008/04/15 08:11:50 swildner Exp $
36 .Nd get a passphrase from the user
43 .Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
47 function displays a prompt to, and reads in a passphrase from,
49 If this file is inaccessible
54 displays the prompt on the standard error output and reads from the standard
56 In this case it is generally not possible to turn off echo.
60 \- 1 characters (one is for the
62 are read into the provided buffer
65 characters and the terminating newline (or return) character are discarded.
70 takes the following optional
73 .Bl -tag -width ".Dv RPP_REQUIRE_TTY" -compact
75 turn off echo (default behavior)
78 .It Dv RPP_REQUIRE_TTY
79 fail if there is no tty
81 force input to lower case
83 force input to upper case
85 strip the high bit from input
88 The calling process should zero the passphrase as soon as possible to
89 avoid leaving the cleartext passphrase visible in the process's address
92 Upon successful completion,
94 returns a pointer to the null-terminated passphrase.
95 If an error is encountered, the terminal state is restored and
100 .Bl -tag -width ".Pa /dev/tty" -compact
104 The following code fragment will read a passphrase from
108 .Bd -literal -offset indent
113 if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
114 RPP_REQUIRE_TTY) == NULL)
115 errx(1, "unable to read passphrase");
117 if (compare(transform(passbuf), epass) != 0)
118 errx(1, "bad passphrase");
122 memset(passbuf, 0, sizeof(passbuf));
129 function was interrupted by a signal.
135 The process is a member of a background process attempting to read
136 from its controlling terminal, the process is ignoring or blocking
139 signal or the process group is orphaned.
141 The process has already reached its limit for open file descriptors.
143 The system file table is full.
145 There is no controlling terminal and the
153 will catch the following signals:
165 When one of the above signals is intercepted, terminal echo will
166 be restored if it had previously been turned off.
167 If a signal handler was installed for the signal when
169 was called that handler is then executed.
170 If no handler was previously installed for the signal then the
171 default action is taken as per
175 .Dv SIGTSTP , SIGTTIN ,
178 signals (stop signal generated from keyboard or due to terminal I/O
179 from a background process) are treated specially.
180 When the process is resumed after it has been stopped,
182 will reprint the prompt and the user may then enter a passphrase.
190 extension and should not be used if portability is desired.
194 function first appeared in