xref: /openbsd-src/lib/libc/gen/getpass.3 (revision 3a3fbb3f2e2521ab7c4a56b7ff7462ebd9095ec5)
1.\"	$OpenBSD: getpass.3,v 1.9 2001/12/07 23:56:09 millert Exp $
2.\"
3.\" Copyright (c) 1989, 1991, 1993
4.\"	The Regents of the University of California.  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. All advertising materials mentioning features or use of this software
15.\"    must display the following acknowledgement:
16.\"	This product includes software developed by the University of
17.\"	California, Berkeley and its contributors.
18.\" 4. Neither the name of the University nor the names of its contributors
19.\"    may be used to endorse or promote products derived from this software
20.\"    without specific prior written permission.
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE.
33.\"
34.Dd December 7, 2001
35.Dt GETPASS 3
36.Os
37.Sh NAME
38.Nm getpass
39.Nd get a password
40.Sh SYNOPSIS
41.Fd #include <pwd.h>
42.Fd #include <unistd.h>
43.Ft char *
44.Fn getpass "const char *prompt"
45.Sh DESCRIPTION
46The
47.Fn getpass
48function displays a prompt to, and reads in a password from,
49.Pa /dev/tty .
50If this file is not accessible,
51.Fn getpass
52displays the prompt on the standard error output and reads from the standard
53input.
54.Pp
55The password may be up to
56.Dv _PASSWORD_LEN
57(currently 128, as defined in the
58.Aq Pa pwd.h
59include file)
60characters in length.
61Any additional
62characters and the terminating newline character are discarded.
63.Pp
64.Fn getpass
65turns off character echoing while reading the password.
66.Pp
67The calling process should zero the password as soon as possible to
68avoid leaving the cleartext password visible in the process's address
69space.
70.Sh RETURN VALUES
71Upon successful completion,
72.Fn getpass
73returns a pointer to a null-terminated string of at most
74.Dv _PASSWORD_LEN
75characters.
76If an error is encountered, the terminal state is restored and
77a null pointer is returned.
78.Sh ERRORS
79.Bl -tag -width Er
80.It Bq Er EINTR
81The
82.Fn getpass
83function was interrupted by a signal.
84.It Bq Er EIO
85The process is a member of a background process attempting to read
86from its controlling terminal, the process is ignoring or blocking
87the SIGTTIN signal or the process group is orphaned.
88.It Bq Er EMFILE
89The process has already reached its limit for open file descriptors.
90.It Bq Er ENFILE
91The system file table is full.
92.El
93.Sh FILES
94.Bl -tag -width /dev/tty -compact
95.It Pa /dev/tty
96.El
97.Sh SEE ALSO
98.Xr crypt 3 ,
99.Xr readpassphrase 3
100.Sh STANDARDS
101Historically,
102.Bx
103versions of
104.Fn getpass
105have accepted a password on the standard input if
106.Pa /dev/tty
107is unavailable.
108This contradicts
109.St -xpg4.2
110but the
111.Ox
112implementation is conformant in all other respects.
113.Sh HISTORY
114A
115.Fn getpass
116function appeared in
117.At v7 .
118.Sh BUGS
119The
120.Fn getpass
121function leaves its result in an internal static object and returns
122a pointer to that object.
123Subsequent calls to
124.Fn getpass
125will modify the same object.
126