1 .\" $OpenBSD: readpassphrase.3,v 1.17 2007/05/31 19:19:28 jmc Exp $
3 .\" Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 .\" Sponsored in part by the Defense Advanced Research Projects
18 .\" Agency (DARPA) and Air Force Research Laboratory, Air Force
19 .\" Materiel Command, USAF, under agreement number F39502-99-1-0512.
28 .Nd get a passphrase from the user
32 .Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
36 function displays a prompt to, and reads in a passphrase from,
38 If this file is inaccessible
43 displays the prompt on the standard error output and reads from the standard
45 In this case it is generally not possible to turn off echo.
49 \- 1 characters (one is for the
51 are read into the provided buffer
54 characters and the terminating newline (or return) character are discarded.
59 takes the following optional
62 .Bl -tag -width ".Dv RPP_REQUIRE_TTY" -compact
64 turn off echo (default behavior)
67 .It Dv RPP_REQUIRE_TTY
68 fail if there is no tty
70 force input to lower case
72 force input to upper case
74 strip the high bit from input
76 force read of passphrase from stdin
79 The calling process should zero the passphrase as soon as possible to
80 avoid leaving the cleartext passphrase visible in the process's address
83 Upon successful completion,
85 returns a pointer to the NUL-terminated passphrase.
86 If an error is encountered, the terminal state is restored and
91 .Bl -tag -width ".Pa /dev/tty" -compact
95 The following code fragment will read a passphrase from
99 .Bd -literal -offset indent
104 if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
105 RPP_REQUIRE_TTY) == NULL)
106 errx(1, "unable to read passphrase");
108 if (compare(transform(passbuf), epass) != 0)
109 errx(1, "bad passphrase");
113 memset(passbuf, 0, sizeof(passbuf));
120 function was interrupted by a signal.
126 The process is a member of a background process attempting to read
127 from its controlling terminal, the process is ignoring or blocking
130 signal, or the process group is orphaned.
132 The process has already reached its limit for open file descriptors.
134 The system file table is full.
136 There is no controlling terminal and the
144 will catch the following signals:
145 .Bd -literal -offset indent
146 SIGALRM SIGHUP SIGINT
147 SIGPIPE SIGQUIT SIGTERM
148 SIGTSTP SIGTTIN SIGTTOU
151 When one of the above signals is intercepted, terminal echo will
152 be restored if it had previously been turned off.
153 If a signal handler was installed for the signal when
155 was called, that handler is then executed.
156 If no handler was previously installed for the signal then the
157 default action is taken as per
161 .Dv SIGTSTP , SIGTTIN
164 signals (stop signals generated from keyboard or due to terminal I/O
165 from a background process) are treated specially.
166 When the process is resumed after it has been stopped,
168 will reprint the prompt and the user may then enter a passphrase.
176 extension and should not be used if portability is desired.
180 function first appeared in
183 was introduced in OS X 10.12.