xref: /freebsd/lib/libc/gen/readpassphrase.3 (revision 8fa113e5fc65fe6abc757f0089f477a87ee4d185)
1.\"	$OpenBSD: readpassphrase.3,v 1.3 2001/08/06 10:42:25 mpech Exp $
2.\"
3.\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com>
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
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.
16.\"
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.
27.\"
28.\" $FreeBSD$
29.\"
30.Dd November 20, 2000
31.Dt READPASSPHRASE 3
32.Os
33.Sh NAME
34.Nm readpassphrase
35.Nd get a passphrase from the user
36.Sh SYNOPSIS
37.In readpassphrase.h
38.Ft "char *"
39.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
40.Sh DESCRIPTION
41The
42.Fn readpassphrase
43function displays a prompt to, and reads in a passphrase from,
44.Pa /dev/tty .
45If this file is inaccessible
46and the
47.Dv RPP_REQUIRE_TTY
48flag is not set,
49.Fn readpassphrase
50displays the prompt on the standard error output and reads from the standard
51input.
52In this case it is generally not possible to turn off echo.
53.Pp
54Up to
55.Fa bufsiz
56\- 1 characters (one is for the
57.Dv NUL )
58are read into the provided buffer
59.Fa buf .
60Any additional
61characters and the terminating newline (or return) character are discarded.
62.Pp
63.Fn readpassphrase
64takes the following optional
65.Fa flags :
66.Pp
67.Bl -tag -width ".Dv RPP_REQUIRE_TTY" -compact
68.It Dv RPP_ECHO_OFF
69turn off echo (default behavior)
70.It Dv RPP_ECHO_ON
71leave echo on
72.It Dv RPP_REQUIRE_TTY
73fail if there is no tty
74.It Dv RPP_FORCELOWER
75force input to lower case
76.It Dv RPP_FORCEUPPER
77force input to upper case
78.It Dv RPP_SEVENBIT
79strip the high bit from input
80.El
81.Pp
82The calling process should zero the passphrase as soon as possible to
83avoid leaving the cleartext passphrase visible in the process's address
84space.
85.Sh RETURN VALUES
86On success,
87.Fn readpassphrase
88returns a pointer to the null-terminated passphrase.
89If the
90.Dv RPP_REQUIRE_TTY
91flag is set and
92.Pa /dev/tty
93is inaccessible,
94.Fn readpassphrase
95returns a
96.Dv NULL
97pointer.
98.Sh EXAMPLES
99The following code fragment will read a passphrase from
100.Pa /dev/tty
101into the buffer
102.Fa passbuf .
103.Bd -literal -offset indent
104char passbuf[1024];
105
106\&...
107
108if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
109    RPP_REQUIRE_TTY) == NULL)
110	errx(1, "unable to read passphrase");
111
112if (compare(transform(passbuf), epass) != 0)
113	errx(1, "bad passphrase");
114
115\&...
116
117memset(passbuf, 0, sizeof(passbuf));
118.Ed
119.Sh FILES
120.Bl -tag -width ".Pa /dev/tty" -compact
121.It Pa /dev/tty
122.El
123.Sh SEE ALSO
124.Xr getpass 3
125.Sh HISTORY
126The
127.Fn readpassphrase
128function first appeared in
129.Ox 2.9 .
130