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, write to the Free
20 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
23 .TH GETPASS 3 2010-09-20 "Linux" "Linux Programmer's Manual"
25 getpass \- get a password
27 .B #include <unistd.h>
29 .BI "char *getpass( const char *" prompt );
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
44 (_XOPEN_SOURCE\ >=\ 500 ||
45 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
46 !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
49 Before glibc 2.2.2: none
54 This function is obsolete.
61 (the controlling terminal of the process), outputs the string
63 turns off echoing, reads one line (the "password"),
64 restores the terminal state and closes
70 returns a pointer to a static buffer containing (the first
72 bytes of) the password without the trailing
73 newline, terminated by a null byte (\(aq\\0\(aq).
74 This buffer may be overwritten by a following call.
75 On error, the terminal state is restored,
77 is set appropriately, and NULL is returned.
79 The function may fail if
82 The process does not have a controlling terminal.
88 .\" function appeared in Version 7 AT&T UNIX.
90 Present in SUSv2, but marked LEGACY.
91 Removed in POSIX.1-2001.
93 For libc4 and libc5, the prompt is not written to
99 cannot be opened, the password is read from
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
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.
116 cannot be opened, the prompt is written to
118 and the password is read from
120 There is no limit on the length of the password.
121 Line editing is not disabled.
123 According to the SUSv2, the value of
127 in case it is smaller than 8, and can in any case be obtained using
128 .IR sysconf(_SC_PASS_MAX) .
129 However, POSIX.2 withdraws the constants
135 Libc4 and libc5 have never supported
145 The calling process should zero the password as soon as possible to avoid
146 leaving the cleartext password visible in the process's address space.