]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/getpass.3
All pages: Replace the 4th argument to .TH by "Linux man-pages (unreleased)"
[thirdparty/man-pages.git] / man3 / getpass.3
CommitLineData
fea681da
MK
1.\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
2.\"
e4a74ca8 3.\" SPDX-License-Identifier: GPL-2.0-or-later
fea681da 4.\"
7bd6328f 5.TH GETPASS 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
fea681da
MK
6.SH NAME
7getpass \- get a password
42009080
AC
8.SH LIBRARY
9Standard C library
10.RI ( libc ", " \-lc )
fea681da 11.SH SYNOPSIS
4653ec6e 12.nf
fea681da 13.B #include <unistd.h>
68e4db0a 14.PP
b73ce084 15.BI "char *getpass(const char *" prompt );
4653ec6e 16.fi
68e4db0a 17.PP
d39ad78f 18.RS -4
2df50e3d
MK
19Feature Test Macro Requirements for glibc (see
20.BR feature_test_macros (7)):
d39ad78f 21.RE
68e4db0a 22.PP
2df50e3d 23.BR getpass ():
2df50e3d 24.nf
9d2adbae 25 Since glibc 2.2.2:
5c10d2c5 26 _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
9d2adbae
MK
27 || /* Glibc since 2.19: */ _DEFAULT_SOURCE
28 || /* Glibc <= 2.19: */ _BSD_SOURCE
29 Before glibc 2.2.2:
30 none
2df50e3d 31.fi
fea681da 32.SH DESCRIPTION
c13182ef
MK
33This function is obsolete.
34Do not use it.
63bed6ae
MK
35If you want to read input without terminal echoing enabled,
36see the description of the
37.I ECHO
38flag in
39.BR termios (3).
fea681da
MK
40.PP
41The
42.BR getpass ()
43function opens
44.I /dev/tty
45(the controlling terminal of the process), outputs the string
46.IR prompt ,
47turns off echoing, reads one line (the "password"),
48restores the terminal state and closes
49.I /dev/tty
50again.
47297adb 51.SH RETURN VALUE
fea681da 52The function
e511ffb6 53.BR getpass ()
cd4995f5 54returns a pointer to a static buffer containing (the first
2f0af33b
MK
55.B PASS_MAX
56bytes of) the password without the trailing
d1a71985 57newline, terminated by a null byte (\(aq\e0\(aq).
fea681da
MK
58This buffer may be overwritten by a following call.
59On error, the terminal state is restored,
60.I errno
c112329f 61is set to indicate the error, and NULL is returned.
fea681da 62.SH ERRORS
fea681da
MK
63.TP
64.B ENXIO
c13182ef 65The process does not have a controlling terminal.
2b2581ee
MK
66.SH FILES
67.I /dev/tty
68.\" .SH HISTORY
69.\" A
70.\" .BR getpass ()
71.\" function appeared in Version 7 AT&T UNIX.
3f970b11 72.SH ATTRIBUTES
34ed6a7e
MK
73For an explanation of the terms used in this section, see
74.BR attributes (7).
c466875e
MK
75.ad l
76.nh
34ed6a7e
MK
77.TS
78allbox;
c466875e 79lbx lb lb
34ed6a7e
MK
80l l l.
81Interface Attribute Value
82T{
3f970b11 83.BR getpass ()
1143466a 84T} Thread safety MT-Unsafe term
34ed6a7e 85.TE
c466875e
MK
86.hy
87.ad
88.sp 1
3113c7f3 89.SH STANDARDS
2b2581ee
MK
90Present in SUSv2, but marked LEGACY.
91Removed in POSIX.1-2001.
fea681da 92.SH NOTES
af3253ca
MK
93.\" For libc4 and libc5, the prompt is not written to
94.\" .I /dev/tty
95.\" but to
96.\" .IR stderr .
97.\" Moreover, if
98.\" .I /dev/tty
99.\" cannot be opened, the password is read from
100.\" .IR stdin .
101.\" The static buffer has length 128 so that only the first 127
102.\" bytes of the password are returned.
103.\" While reading the password, signal generation
104.\" .RB ( SIGINT ,
105.\" .BR SIGQUIT ,
106.\" .BR SIGSTOP ,
107.\" .BR SIGTSTP )
108.\" is disabled and the corresponding characters
109.\" (usually control-C, control-\e, control-Z and control-Y)
110.\" are transmitted as part of the password.
111.\" Since libc 5.4.19 also line editing is disabled, so that also
112.\" backspace and the like will be seen as part of the password.
7f740303 113.
af3253ca 114In the GNU C library implementation, if
fea681da
MK
115.I /dev/tty
116cannot be opened, the prompt is written to
117.I stderr
118and the password is read from
119.IR stdin .
120There is no limit on the length of the password.
121Line editing is not disabled.
122.PP
fb307ec7 123According to SUSv2, the value of
2f0af33b
MK
124.B PASS_MAX
125must be defined in
fea681da
MK
126.I <limits.h>
127in case it is smaller than 8, and can in any case be obtained using
128.IR sysconf(_SC_PASS_MAX) .
2f0af33b
MK
129However, POSIX.2 withdraws the constants
130.B PASS_MAX
131and
132.BR _SC_PASS_MAX ,
133and the function
f87925c6 134.BR getpass ().
a6cc92e3
MK
135.\" Libc4 and libc5 have never supported
136.\" .B PASS_MAX
137.\" or
138.\" .BR _SC_PASS_MAX .
139The glibc version accepts
0daa9e92 140.B _SC_PASS_MAX
66ee0c7e 141and returns
2f0af33b
MK
142.B BUFSIZ
143(e.g., 8192).
fea681da
MK
144.SH BUGS
145The calling process should zero the password as soon as possible to avoid
146leaving the cleartext password visible in the process's address space.
47297adb 147.SH SEE ALSO
e37e3282 148.BR crypt (3)