mount_setattr.2: Add a reference to mount_namespaces(7) in discussion of propagation...
[man-pages.git] / man3 / getpass.3
blob3c7deadde7571f6c55e0544567bdcf915f7b384a
1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
4 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, see
21 .\" <http://www.gnu.org/licenses/>.
22 .\" %%%LICENSE_END
23 .\"
24 .TH GETPASS 3  2021-03-22 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 getpass \- get a password
27 .SH SYNOPSIS
28 .nf
29 .B #include <unistd.h>
30 .PP
31 .BI "char *getpass(const char *" prompt );
32 .fi
33 .PP
34 .RS -4
35 Feature Test Macro Requirements for glibc (see
36 .BR feature_test_macros (7)):
37 .RE
38 .PP
39 .BR getpass ():
40 .nf
41     Since glibc 2.2.2:
42         _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
43             || /* Glibc since 2.19: */ _DEFAULT_SOURCE
44             || /* Glibc <= 2.19: */ _BSD_SOURCE
45     Before glibc 2.2.2:
46         none
47 .fi
48 .SH DESCRIPTION
49 This function is obsolete.
50 Do not use it.
51 If you want to read input without terminal echoing enabled,
52 see the description of the
53 .I ECHO
54 flag in
55 .BR termios (3).
56 .PP
57 The
58 .BR getpass ()
59 function opens
60 .I /dev/tty
61 (the controlling terminal of the process), outputs the string
62 .IR prompt ,
63 turns off echoing, reads one line (the "password"),
64 restores the terminal state and closes
65 .I /dev/tty
66 again.
67 .SH RETURN VALUE
68 The function
69 .BR getpass ()
70 returns a pointer to a static buffer containing (the first
71 .B PASS_MAX
72 bytes of) the password without the trailing
73 newline, terminated by a null byte (\(aq\e0\(aq).
74 This buffer may be overwritten by a following call.
75 On error, the terminal state is restored,
76 .I errno
77 is set to indicate the error, and NULL is returned.
78 .SH ERRORS
79 The function may fail if
80 .TP
81 .B ENXIO
82 The process does not have a controlling terminal.
83 .SH FILES
84 .I /dev/tty
85 .\" .SH HISTORY
86 .\" A
87 .\" .BR getpass ()
88 .\" function appeared in Version 7 AT&T UNIX.
89 .SH ATTRIBUTES
90 For an explanation of the terms used in this section, see
91 .BR attributes (7).
92 .ad l
93 .nh
94 .TS
95 allbox;
96 lbx lb lb
97 l l l.
98 Interface       Attribute       Value
100 .BR getpass ()
101 T}      Thread safety   MT-Unsafe term
105 .sp 1
106 .SH CONFORMING TO
107 Present in SUSv2, but marked LEGACY.
108 Removed in POSIX.1-2001.
109 .SH NOTES
110 .\" For libc4 and libc5, the prompt is not written to
111 .\" .I /dev/tty
112 .\" but to
113 .\" .IR stderr .
114 .\" Moreover, if
115 .\" .I /dev/tty
116 .\" cannot be opened, the password is read from
117 .\" .IR stdin .
118 .\" The static buffer has length 128 so that only the first 127
119 .\" bytes of the password are returned.
120 .\" While reading the password, signal generation
121 .\" .RB ( SIGINT ,
122 .\" .BR SIGQUIT ,
123 .\" .BR SIGSTOP ,
124 .\" .BR SIGTSTP )
125 .\" is disabled and the corresponding characters
126 .\" (usually control-C, control-\e, control-Z and control-Y)
127 .\" are transmitted as part of the password.
128 .\" Since libc 5.4.19 also line editing is disabled, so that also
129 .\" backspace and the like will be seen as part of the password.
131 In the GNU C library implementation, if
132 .I /dev/tty
133 cannot be opened, the prompt is written to
134 .I stderr
135 and the password is read from
136 .IR stdin .
137 There is no limit on the length of the password.
138 Line editing is not disabled.
140 According to SUSv2, the value of
141 .B PASS_MAX
142 must be defined in
143 .I <limits.h>
144 in case it is smaller than 8, and can in any case be obtained using
145 .IR sysconf(_SC_PASS_MAX) .
146 However, POSIX.2 withdraws the constants
147 .B PASS_MAX
149 .BR _SC_PASS_MAX ,
150 and the function
151 .BR getpass ().
152 .\" Libc4 and libc5 have never supported
153 .\" .B PASS_MAX
154 .\" or
155 .\" .BR _SC_PASS_MAX .
156 The glibc version accepts
157 .B _SC_PASS_MAX
158 and returns
159 .B BUFSIZ
160 (e.g., 8192).
161 .SH BUGS
162 The calling process should zero the password as soon as possible to avoid
163 leaving the cleartext password visible in the process's address space.
164 .SH SEE ALSO
165 .BR crypt (3)