NetBSD/lib/libc/gen/getpass.3

201 lines
5.3 KiB
Groff
Raw Normal View History

2012-04-14 14:34:29 +04:00
.\" $NetBSD: getpass.3,v 1.22 2012/04/14 10:34:29 wiz Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)getpass.3 8.1 (Berkeley) 6/4/93
1993-03-21 12:45:37 +03:00
.\"
2012-04-13 18:39:34 +04:00
.Dd April 13, 2012
1993-03-21 12:45:37 +03:00
.Dt GETPASS 3
.Os
.Sh NAME
.Nm getpass
.Nd get a password
1998-02-05 21:45:17 +03:00
.Sh LIBRARY
.Lb libc
1993-03-21 12:45:37 +03:00
.Sh SYNOPSIS
.In unistd.h
1993-03-21 12:45:37 +03:00
.Ft char *
.Fn getpass "const char *prompt"
.Ft char *
.Fn getpass_r "const char *prompt" "char *buf" "size_t buflen"
.Ft char *
.Fn getpassfd "const char *prompt" "char *buf" "size_t buflen" "int *fd" "int flags" "int timeout"
1993-03-21 12:45:37 +03:00
.Sh DESCRIPTION
The
.Fn getpass
function displays a prompt to, and reads in a password from,
.Pa /dev/tty .
If this file is not accessible,
2010-05-06 15:09:39 +04:00
.Fn getpass
1993-03-21 12:45:37 +03:00
displays the prompt on the standard error output and reads from the standard
input.
.Pp
2012-04-13 00:15:37 +04:00
The password may be up to
.Xr sysconf 3
.Dv _SC_PASS_MAX
1993-03-21 12:45:37 +03:00
characters in length.
Any additional
characters and the terminating newline character are discarded.
.Pp
2010-05-06 15:09:39 +04:00
.Fn getpass
1993-03-21 12:45:37 +03:00
turns off character echoing while reading the password.
.Pp
.Fn getpass_r
is similar to
.Fn getpass
only it puts its result in
.Fa buf
for up to
.Fa buflen
characters.
If the
.Fa buf
argument is
.Dv NULL ,
then a buffer will be dynamically allocated.
.Pp
The
.Fn getpassfd
function allows one to specify the three file descriptors corresponding to
.Dv stdin ,
.Dv stdout ,
and
2012-04-14 14:34:29 +04:00
.Dv stderr
in the
2012-04-14 14:34:29 +04:00
.Fa fd
argument, or if
.Fa fd
is
.Dv NULL ,
.Fn getpassfd
first attempts to open
.Pa /dev/tty
and if that fails, defaults to
.Dv STDIN_FILENO
for input and
.Dv STDERR_FILENO
for output.
.Pp
The behavior of
.Fn getpassfd
is controlled by the
.Fa flags
argument:
2012-04-14 06:01:12 +04:00
.Bl -tag -width GETPASS_FORCE_UPPER
.It Dv GETPASS_NEED_TTY
Fail if we are unable to set the tty modes like we want.
.It Dv GETPASS_FAIL_EOF
Fail if we get the end-of-file character instead of returning the result so far.
.It Dv GETPASS_BUF_LIMIT
Beep when the buffer limit is reached, instead of silently absorbing it.
.It Dv GETPASS_NO_SIGNAL
Don't make ttychars send signals.
.It Dv GETPASS_NO_BEEP
Don't beep if we erase past the beginning of the buffer or we try to enter past
the end.
2012-04-13 03:16:38 +04:00
.It Dv GETPASS_ECHO_STAR
Echo a
2012-04-13 10:38:18 +04:00
.Sq *
2012-04-13 03:16:38 +04:00
for each character entered.
.It Dv GETPASS_ECHO
Echo characters as they are typed.
.It Dv GETPASS_ECHO_NL
Echoes a newline if successful.
.It Dv GETPASS_7BIT
Mask the high bit for each entered character.
.It Dv GETPASS_FORCE_LOWER
2012-04-14 14:34:29 +04:00
Lowercase each entered character.
.It Dv GETPASS_FORCE_UPPER
2012-04-14 14:34:29 +04:00
Uppercase each entered character.
.El
2012-04-14 06:01:12 +04:00
.Pp
2012-04-13 18:39:34 +04:00
Finally if the
.Fa timeout
argument is non zero,
.Fn getpassfd
will wait for
.Fa timeout
2012-04-14 06:01:12 +04:00
seconds for input after each character before returning an error, instead of
waiting forever.
1993-03-21 12:45:37 +03:00
.Sh RETURN VALUES
The
2010-05-06 15:09:39 +04:00
.Fn getpass
function returns a pointer to the NUL terminated password, or an empty
string on error.
The
.Fn getpass_r
and
.Fn getpassfd
functions return a pointer to the NUL terminated password, or
.Dv NULL
on error.
1993-03-21 12:45:37 +03:00
.Sh FILES
.Bl -tag -width /dev/tty -compact
1993-03-21 12:45:37 +03:00
.It Pa /dev/tty
.El
.Sh SEE ALSO
.Xr crypt 3
.Sh STANDARDS
The
.Fn getpass
function appeared in
.St -susv2 ,
but it was already marked as legacy.
The function was removed in the
.St -p1003.1-2001
standard.
1993-03-21 12:45:37 +03:00
.Sh HISTORY
A
2010-05-06 15:09:39 +04:00
.Fn getpass
1993-03-21 12:45:37 +03:00
function appeared in
.At v7 .
The
.Fn getpass_r
and
.Fn getpassfd
functions appeared in
.Nx 7.0 .
1993-03-21 12:45:37 +03:00
.Sh BUGS
The
2010-05-06 15:09:39 +04:00
.Fn getpass
1993-03-21 12:45:37 +03:00
function leaves its result in an internal static object and returns
a pointer to that object.
Subsequent calls to
2010-05-06 15:09:39 +04:00
.Fn getpass
1993-03-21 12:45:37 +03:00
will modify the same object.
.Sh SECURITY CONSIDERATIONS
1993-03-21 12:45:37 +03:00
The calling process should zero the password as soon as possible to
avoid leaving the cleartext password visible in the process's address
space.
.Pp
Historically
.Nm
accepted and returned a password if it could not modify the terminal
settings to turn echo off (or if the input was not a terminal).
In this implementation, only terminal input is accepted.