1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
3 .\" This is free documentation; you can redistribute it and/or
4 .\" modify it under the terms of the GNU General Public License as
5 .\" published by the Free Software Foundation; either version 2 of
6 .\" the License, or (at your option) any later version.
8 .\" The GNU General Public License's references to "object code"
9 .\" and "executables" are to be interpreted as the output of any
10 .\" document formatting or typesetting system, including
11 .\" intermediate and printed output.
13 .\" This manual is distributed in the hope that it will be useful,
14 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
15 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 .\" GNU General Public License for more details.
18 .\" You should have received a copy of the GNU General Public
19 .\" License along with this manual; if not, see
20 .\" <http://www.gnu.org/licenses/>.
22 .TH GETPASS 3 2010-09-20 "Linux" "Linux Programmer's Manual"
24 getpass \- get a password
26 .B #include <unistd.h>
28 .BI "char *getpass( const char *" prompt );
31 Feature Test Macro Requirements for glibc (see
32 .BR feature_test_macros (7)):
43 (_XOPEN_SOURCE\ >=\ 500 ||
44 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
45 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
48 Before glibc 2.2.2: none
53 This function is obsolete.
60 (the controlling terminal of the process), outputs the string
62 turns off echoing, reads one line (the "password"),
63 restores the terminal state and closes
69 returns a pointer to a static buffer containing (the first
71 bytes of) the password without the trailing
72 newline, terminated by a null byte (\(aq\\0\(aq).
73 This buffer may be overwritten by a following call.
74 On error, the terminal state is restored,
76 is set appropriately, and NULL is returned.
78 The function may fail if
81 The process does not have a controlling terminal.
87 .\" function appeared in Version 7 AT&T UNIX.
89 Present in SUSv2, but marked LEGACY.
90 Removed in POSIX.1-2001.
92 For libc4 and libc5, the prompt is not written to
98 cannot be opened, the password is read from
100 The static buffer has length 128 so that only the first 127
101 bytes of the password are returned.
102 While reading the password, signal generation
107 is disabled and the corresponding characters
108 (usually control-C, control-\e, control-Z and control-Y)
109 are transmitted as part of the password.
110 Since libc 5.4.19 also line editing is disabled, so that also
111 backspace and the like will be seen as part of the password.
115 cannot be opened, the prompt is written to
117 and the password is read from
119 There is no limit on the length of the password.
120 Line editing is not disabled.
122 According to the SUSv2, the value of
126 in case it is smaller than 8, and can in any case be obtained using
127 .IR sysconf(_SC_PASS_MAX) .
128 However, POSIX.2 withdraws the constants
134 Libc4 and libc5 have never supported
144 The calling process should zero the password as soon as possible to avoid
145 leaving the cleartext password visible in the process's address space.