OSDN Git Service

(split) LDP man-pages の original/ を v3.29 に更新。
[linuxjm/LDP_man-pages.git] / original / man3 / getpass.3
1 .\" Copyright (c) 2000 Andries Brouwer (aeb@cwi.nl)
2 .\"
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.
7 .\"
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.
12 .\"
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.
17 .\"
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,
21 .\" USA.
22 .\"
23 .TH GETPASS 3  2010-09-20 "Linux" "Linux Programmer's Manual"
24 .SH NAME
25 getpass \- get a password
26 .SH SYNOPSIS
27 .B #include <unistd.h>
28 .sp
29 .BI "char *getpass( const char *" prompt );
30 .sp
31 .in -4n
32 Feature Test Macro Requirements for glibc (see
33 .BR feature_test_macros (7)):
34 .in
35 .sp
36 .BR getpass ():
37 .ad l
38 .RS 4
39 .PD 0
40 .TP 4
41 Since glibc 2.2.2:
42 .nf
43 _BSD_SOURCE ||
44     (_XOPEN_SOURCE\ >=\ 500 ||
45         _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED) &&
46     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
47 .TP 4
48 .fi
49 Before glibc 2.2.2: none
50 .PD
51 .RE
52 .ad b
53 .SH DESCRIPTION
54 This function is obsolete.
55 Do not use it.
56 .PP
57 The
58 .BR getpass ()
59 function opens
60 .I /dev/tty
61 (the controlling terminal of the process), outputs the string
62 .IR prompt ,
63 turns off echoing, reads one line (the "password"),
64 restores the terminal state and closes
65 .I /dev/tty
66 again.
67 .SH "RETURN VALUE"
68 The function
69 .BR getpass ()
70 returns a pointer to a static buffer containing (the first
71 .B PASS_MAX
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,
76 .I errno
77 is set appropriately, and NULL is returned.
78 .SH ERRORS
79 The function may fail if
80 .TP
81 .B ENXIO
82 The process does not have a controlling terminal.
83 .SH FILES
84 .I /dev/tty
85 .\" .SH HISTORY
86 .\" A
87 .\" .BR getpass ()
88 .\" function appeared in Version 7 AT&T UNIX.
89 .SH "CONFORMING TO"
90 Present in SUSv2, but marked LEGACY.
91 Removed in POSIX.1-2001.
92 .SH NOTES
93 For libc4 and libc5, the prompt is not written to
94 .I /dev/tty
95 but to
96 .IR stderr .
97 Moreover, if
98 .I /dev/tty
99 cannot be opened, the password is read from
100 .IR stdin .
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
104 .RB ( SIGINT ,
105 .BR SIGQUIT ,
106 .BR SIGSTOP ,
107 .BR SIGTSTP )
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.
113 .PP
114 For glibc2, if
115 .I /dev/tty
116 cannot be opened, the prompt is written to
117 .I stderr
118 and the password is read from
119 .IR stdin .
120 There is no limit on the length of the password.
121 Line editing is not disabled.
122 .PP
123 According to the SUSv2, the value of
124 .B PASS_MAX
125 must be defined in
126 .I <limits.h>
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
130 .B PASS_MAX
131 and
132 .BR _SC_PASS_MAX ,
133 and the function
134 .BR getpass ().
135 Libc4 and libc5 have never supported
136 .B PASS_MAX
137 or
138 .BR _SC_PASS_MAX .
139 Glibc2 accepts
140 .B _SC_PASS_MAX
141 and returns
142 .B BUFSIZ
143 (e.g., 8192).
144 .SH BUGS
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.
147 .SH "SEE ALSO"
148 .BR crypt (3)