xref: /dragonfly/lib/libc/gen/readpassphrase.3 (revision b40e316c)
1.\"	$OpenBSD: readpassphrase.3,v 1.7 2001/12/15 15:37:51 millert 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: 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.2 2003/06/17 04:26:42 dillon Exp $
30.\"
31.Dd December 7, 2001
32.Dt READPASSPHRASE 3
33.Os
34.Sh NAME
35.Nm readpassphrase
36.Nd get a passphrase from the user
37.Sh SYNOPSIS
38.In readpassphrase.h
39.Ft "char *"
40.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags"
41.Sh DESCRIPTION
42The
43.Fn readpassphrase
44function displays a prompt to, and reads in a passphrase from,
45.Pa /dev/tty .
46If this file is inaccessible
47and the
48.Dv RPP_REQUIRE_TTY
49flag is not set,
50.Fn readpassphrase
51displays the prompt on the standard error output and reads from the standard
52input.
53In this case it is generally not possible to turn off echo.
54.Pp
55Up to
56.Fa bufsiz
57\- 1 characters (one is for the
58.Dv NUL )
59are read into the provided buffer
60.Fa buf .
61Any additional
62characters and the terminating newline (or return) character are discarded.
63.Pp
64The
65.Fn readpassphrase
66function
67takes the following optional
68.Fa flags :
69.Pp
70.Bl -tag -width ".Dv RPP_REQUIRE_TTY" -compact
71.It Dv RPP_ECHO_OFF
72turn off echo (default behavior)
73.It Dv RPP_ECHO_ON
74leave echo on
75.It Dv RPP_REQUIRE_TTY
76fail if there is no tty
77.It Dv RPP_FORCELOWER
78force input to lower case
79.It Dv RPP_FORCEUPPER
80force input to upper case
81.It Dv RPP_SEVENBIT
82strip the high bit from input
83.El
84.Pp
85The calling process should zero the passphrase as soon as possible to
86avoid leaving the cleartext passphrase visible in the process's address
87space.
88.Sh RETURN VALUES
89Upon successful completion,
90.Fn readpassphrase
91returns a pointer to the null-terminated passphrase.
92If an error is encountered, the terminal state is restored and
93a
94.Dv NULL
95pointer is returned.
96.Sh ERRORS
97.Bl -tag -width Er
98.It Bq Er EINTR
99The
100.Fn readpassphrase
101function was interrupted by a signal.
102.It Bq Er EINVAL
103The
104.Fa bufsiz
105argument was zero.
106.It Bq Er EIO
107The process is a member of a background process attempting to read
108from its controlling terminal, the process is ignoring or blocking
109the
110.Dv SIGTTIN
111signal or the process group is orphaned.
112.It Bq Er EMFILE
113The process has already reached its limit for open file descriptors.
114.It Bq Er ENFILE
115The system file table is full.
116.It Bq Er ENOTTY
117There is no controlling terminal and the
118.Dv RPP_REQUIRE_TTY
119flag was specified.
120.El
121.Sh EXAMPLES
122The following code fragment will read a passphrase from
123.Pa /dev/tty
124into the buffer
125.Fa passbuf .
126.Bd -literal -offset indent
127char passbuf[1024];
128
129\&...
130
131if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
132    RPP_REQUIRE_TTY) == NULL)
133	errx(1, "unable to read passphrase");
134
135if (compare(transform(passbuf), epass) != 0)
136	errx(1, "bad passphrase");
137
138\&...
139
140memset(passbuf, 0, sizeof(passbuf));
141.Ed
142.Sh SIGNALS
143The
144.Fn readpassphrase
145function
146will catch the following signals:
147.Pp
148.Bl -tag -compact
149.It Dv SIGINT
150.It Dv SIGHUP
151.It Dv SIGQUIT
152.It Dv SIGTERM
153.It Dv SIGTSTP
154.It Dv SIGTTIN
155.It Dv SIGTTOU
156.El
157.Pp
158When one of the above signals is intercepted, terminal echo will
159be restored if it had previously been turned off.
160If a signal handler was installed for the signal when
161.Fn readpassphrase
162was called that handler is then executed.
163If no handler was previously installed for the signal then the
164default action is taken as per
165.Xr sigaction 2 .
166.Pp
167The
168.Dv SIGTSTP , SIGTTIN ,
169and
170.Dv SIGTTOU
171signals (stop signal generated from keyboard or due to terminal I/O
172from a background process) are treated specially.
173When the process is resumed after it has been stopped,
174.Fn readpassphrase
175will reprint the prompt and the user may then enter a passphrase.
176.Sh FILES
177.Bl -tag -width ".Pa /dev/tty" -compact
178.It Pa /dev/tty
179.El
180.Sh SEE ALSO
181.Xr sigaction 2 ,
182.Xr getpass 3
183.Sh STANDARDS
184The
185.Fn readpassphrase
186function is an
187extension and should not be used if portability is desired.
188.Sh HISTORY
189The
190.Fn readpassphrase
191function first appeared in
192.Ox 2.9 .
193