1 .\" $NetBSD: readpassphrase.3,v 1.12 2009/02/16 20:55:22 christos Exp $
2 .\" $OpenBSD: readpassphrase.3,v 1.3 2001/08/06 10:42:25 mpech Exp $
4 .\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
5 .\" All rights reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. The name of the author may not be used to endorse or promote products
16 .\" derived from this software without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24 .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27 .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 .Nd get a passphrase from the user
38 .Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
42 function displays a prompt to, and reads in a passphrase from,
44 If this file is inaccessible
49 displays the prompt on the standard error output and reads from the standard
51 In this case it is generally not possible to turn off echo.
55 - 1 characters (one is for the NUL) are read into the provided buffer
58 characters and the terminating newline (or return) character are discarded.
61 takes the following optional
64 .Bd -literal -offset indent -compact
65 RPP_ECHO_OFF turn off echo (default behavior)
66 RPP_ECHO_ON leave echo on
67 RPP_REQUIRE_TTY fail if there is no tty
68 RPP_FORCELOWER force input to lower case
69 RPP_FORCEUPPER force input to upper case
70 RPP_SEVENBIT strip the high bit from input
73 The calling process should zero the passphrase as soon as possible to
74 avoid leaving the cleartext passphrase visible in the process's address
79 returns a pointer to the null-terminated passphrase.
86 returns a null pointer.
88 .Bl -tag -width /dev/tty -compact
92 The following code fragment will read a passphrase from
96 .Bd -literal -offset indent
101 if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
102 RPP_REQUIRE_TTY) == NULL)
103 errx(1, "unable to read passphrase");
105 if (compare(transform(passbuf), epass) != 0)
106 errx(1, "bad passphrase");
110 memset(passbuf, 0, sizeof(passbuf));
117 function first appeared in