OSDN Git Service

(split) LDP: Update original to LDP v3.50.
[linuxjm/LDP_man-pages.git] / original / man3 / getpass.3
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  2013-03-15 "Linux" "Linux Programmer's Manual"
25 .SH NAME
26 getpass \- get a password
27 .SH SYNOPSIS
28 .B #include <unistd.h>
29 .sp
30 .BI "char *getpass( const char *" prompt );
31 .sp
32 .in -4n
33 Feature Test Macro Requirements for glibc (see
34 .BR feature_test_macros (7)):
35 .in
36 .sp
37 .BR getpass ():
38 .ad l
39 .RS 4
40 .PD 0
41 .TP 4
42 Since glibc 2.2.2:
43 .nf
44 _BSD_SOURCE ||
45     (_XOPEN_SOURCE\ >=\ 500 ||
46         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
47     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
48 .TP 4
49 .fi
50 Before glibc 2.2.2: none
51 .PD
52 .RE
53 .ad b
54 .SH DESCRIPTION
55 This function is obsolete.
56 Do not use it.
57 If you want to read input without terminal echoing enabled,
58 see the description of the
59 .I ECHO
60 flag in
61 .BR termios (3).
62 .PP
63 The
64 .BR getpass ()
65 function opens
66 .I /dev/tty
67 (the controlling terminal of the process), outputs the string
68 .IR prompt ,
69 turns off echoing, reads one line (the "password"),
70 restores the terminal state and closes
71 .I /dev/tty
72 again.
73 .SH RETURN VALUE
74 The function
75 .BR getpass ()
76 returns a pointer to a static buffer containing (the first
77 .B PASS_MAX
78 bytes of) the password without the trailing
79 newline, terminated by a null byte (\(aq\\0\(aq).
80 This buffer may be overwritten by a following call.
81 On error, the terminal state is restored,
82 .I errno
83 is set appropriately, and NULL is returned.
84 .SH ERRORS
85 The function may fail if
86 .TP
87 .B ENXIO
88 The process does not have a controlling terminal.
89 .SH FILES
90 .I /dev/tty
91 .\" .SH HISTORY
92 .\" A
93 .\" .BR getpass ()
94 .\" function appeared in Version 7 AT&T UNIX.
95 .SH CONFORMING TO
96 Present in SUSv2, but marked LEGACY.
97 Removed in POSIX.1-2001.
98 .SH NOTES
99 For libc4 and libc5, the prompt is not written to
100 .I /dev/tty
101 but to
102 .IR stderr .
103 Moreover, if
104 .I /dev/tty
105 cannot be opened, the password is read from
106 .IR stdin .
107 The static buffer has length 128 so that only the first 127
108 bytes of the password are returned.
109 While reading the password, signal generation
110 .RB ( SIGINT ,
111 .BR SIGQUIT ,
112 .BR SIGSTOP ,
113 .BR SIGTSTP )
114 is disabled and the corresponding characters
115 (usually control-C, control-\e, control-Z and control-Y)
116 are transmitted as part of the password.
117 Since libc 5.4.19 also line editing is disabled, so that also
118 backspace and the like will be seen as part of the password.
119 .PP
120 For glibc2, if
121 .I /dev/tty
122 cannot be opened, the prompt is written to
123 .I stderr
124 and the password is read from
125 .IR stdin .
126 There is no limit on the length of the password.
127 Line editing is not disabled.
128 .PP
129 According to the SUSv2, the value of
130 .B PASS_MAX
131 must be defined in
132 .I <limits.h>
133 in case it is smaller than 8, and can in any case be obtained using
134 .IR sysconf(_SC_PASS_MAX) .
135 However, POSIX.2 withdraws the constants
136 .B PASS_MAX
137 and
138 .BR _SC_PASS_MAX ,
139 and the function
140 .BR getpass ().
141 Libc4 and libc5 have never supported
142 .B PASS_MAX
143 or
144 .BR _SC_PASS_MAX .
145 Glibc2 accepts
146 .B _SC_PASS_MAX
147 and returns
148 .B BUFSIZ
149 (e.g., 8192).
150 .SH BUGS
151 The calling process should zero the password as soon as possible to avoid
152 leaving the cleartext password visible in the process's address space.
153 .SH SEE ALSO
154 .BR crypt (3)