Debian Codegraph @

upstream/debian-unstable/man3/getpass.3

raw
1 '\" t
2 .\" Copyright 2000, Andries E. Brouwer <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: GPL-2.0-or-later
6 .\"
7 .TH getpass 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 getpass \- get a password
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <unistd.h>
16 .P
17 .BI "[[deprecated]] char *getpass(const char *" prompt );
18 .fi
19 .P
20 .RS -4
21 Feature Test Macro Requirements for glibc (see
22 .BR feature_test_macros (7)):
23 .RE
24 .P
25 .BR getpass ():
26 .nf
27 Since glibc 2.2.2:
28 _XOPEN_SOURCE && ! (_POSIX_C_SOURCE >= 200112L)
29 || /* glibc >= 2.19: */ _DEFAULT_SOURCE
30 || /* glibc <= 2.19: */ _BSD_SOURCE
31 Before glibc 2.2.2:
32 none
33 .fi
34 .SH DESCRIPTION
35 This function is obsolete.
36 Do not use it.
37 See NOTES.
38 If you want to read input without terminal echoing enabled,
39 see the description of the
40 .I ECHO
41 flag in
42 .BR termios (3).
43 .P
44 The
45 .BR getpass ()
46 function opens
47 .I /dev/tty
48 (the controlling terminal of the process), outputs the string
49 .IR prompt ,
50 turns off echoing, reads one line (the "password"),
51 restores the terminal state and closes
52 .I /dev/tty
53 again.
54 .SH RETURN VALUE
55 The function
56 .BR getpass ()
57 returns a pointer to a static buffer containing (the first
58 .B PASS_MAX
59 bytes of) the password without the trailing
60 newline, terminated by a null byte (\[aq]\[rs]0\[aq]).
61 This buffer may be overwritten by a following call.
62 On error, the terminal state is restored,
63 .I errno
64 is set to indicate the error, and NULL is returned.
65 .SH ERRORS
66 .TP
67 .B ENXIO
68 The process does not have a controlling terminal.
69 .SH FILES
70 .I /dev/tty
71 .SH ATTRIBUTES
72 For an explanation of the terms used in this section, see
73 .BR attributes (7).
74 .TS
75 allbox;
76 lbx lb lb
77 l l l.
78 Interface Attribute Value
79 T{
80 .na
81 .nh
82 .BR getpass ()
83 T} Thread safety MT-Unsafe term
84 .TE
85 .SH STANDARDS
86 None.
87 .SH HISTORY
88 Version 7 AT&T UNIX.
89 Present in SUSv2, but marked LEGACY.
90 Removed in POSIX.1-2001.
91 .SH NOTES
92 .\" For libc4 and libc5, the prompt is not written to
93 .\" .I /dev/tty
94 .\" but to
95 .\" .IR stderr .
96 .\" Moreover, if
97 .\" .I /dev/tty
98 .\" cannot be opened, the password is read from
99 .\" .IR stdin .
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
103 .\" .RB ( SIGINT ,
104 .\" .BR SIGQUIT ,
105 .\" .BR SIGSTOP ,
106 .\" .BR SIGTSTP )
107 .\" is disabled and the corresponding characters
108 .\" (usually control-C, control-\[rs], 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.
112 You should use instead
113 .BR readpassphrase (3bsd),
114 provided by
115 .IR libbsd .
116 .P
117 In the GNU C library implementation, if
118 .I /dev/tty
119 cannot be opened, the prompt is written to
120 .I stderr
121 and the password is read from
122 .IR stdin .
123 There is no limit on the length of the password.
124 Line editing is not disabled.
125 .P
126 According to SUSv2, the value of
127 .B PASS_MAX
128 must be defined in
129 .I <limits.h>
130 in case it is smaller than 8, and can in any case be obtained using
131 .IR sysconf(_SC_PASS_MAX) .
132 However, POSIX.2 withdraws the constants
133 .B PASS_MAX
134 and
135 .BR _SC_PASS_MAX ,
136 and the function
137 .BR getpass ().
138 .\" Libc4 and libc5 have never supported
139 .\" .B PASS_MAX
140 .\" or
141 .\" .BR _SC_PASS_MAX .
142 The glibc version accepts
143 .B _SC_PASS_MAX
144 and returns
145 .B BUFSIZ
146 (e.g., 8192).
147 .SH BUGS
148 The calling process should zero the password as soon as possible to avoid
149 leaving the cleartext password visible in the process's address space.
150 .SH SEE ALSO
151 .BR crypt (3)