1GETPASS(3) Linux Programmer's Manual GETPASS(3)
2
3
4
6 getpass - get a password
7
9 #include <unistd.h>
10
11 char *getpass( const char *prompt);
12
13 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
14
15 getpass():
16 Since glibc 2.2.2:
17 _BSD_SOURCE ||
18 (_XOPEN_SOURCE >= 500 ||
19 _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) &&
20 !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600)
21 Before glibc 2.2.2:
22 none
23
25 This function is obsolete. Do not use it. If you want to read input
26 without terminal echoing enabled, see the description of the ECHO flag
27 in termios(3).
28
29 The getpass() function opens /dev/tty (the controlling terminal of the
30 process), outputs the string prompt, turns off echoing, reads one line
31 (the "password"), restores the terminal state and closes /dev/tty
32 again.
33
35 The function getpass() returns a pointer to a static buffer containing
36 (the first PASS_MAX bytes of) the password without the trailing new‐
37 line, terminated by a null byte ('\0'). This buffer may be overwritten
38 by a following call. On error, the terminal state is restored, errno
39 is set appropriately, and NULL is returned.
40
42 The function may fail if
43
44 ENXIO The process does not have a controlling terminal.
45
47 /dev/tty
48
50 Multithreading (see pthreads(7))
51 The getpass() function is not thread-safe.
52
54 Present in SUSv2, but marked LEGACY. Removed in POSIX.1-2001.
55
57 For libc4 and libc5, the prompt is not written to /dev/tty but to
58 stderr. Moreover, if /dev/tty cannot be opened, the password is read
59 from stdin. The static buffer has length 128 so that only the first
60 127 bytes of the password are returned. While reading the password,
61 signal generation (SIGINT, SIGQUIT, SIGSTOP, SIGTSTP) is disabled and
62 the corresponding characters (usually control-C, control-\, control-Z
63 and control-Y) are transmitted as part of the password. Since libc
64 5.4.19 also line editing is disabled, so that also backspace and the
65 like will be seen as part of the password.
66
67 For glibc2, if /dev/tty cannot be opened, the prompt is written to
68 stderr and the password is read from stdin. There is no limit on the
69 length of the password. Line editing is not disabled.
70
71 According to the SUSv2, the value of PASS_MAX must be defined in <lim‐
72 its.h> in case it is smaller than 8, and can in any case be obtained
73 using sysconf(_SC_PASS_MAX). However, POSIX.2 withdraws the constants
74 PASS_MAX and _SC_PASS_MAX, and the function getpass(). Libc4 and libc5
75 have never supported PASS_MAX or _SC_PASS_MAX. Glibc2 accepts
76 _SC_PASS_MAX and returns BUFSIZ (e.g., 8192).
77
79 The calling process should zero the password as soon as possible to
80 avoid leaving the cleartext password visible in the process's address
81 space.
82
84 crypt(3)
85
87 This page is part of release 3.53 of the Linux man-pages project. A
88 description of the project, and information about reporting bugs, can
89 be found at http://www.kernel.org/doc/man-pages/.
90
91
92
93Linux 2013-06-21 GETPASS(3)