| GETPASS(3) | Library Functions Manual | GETPASS(3) |
getpass,
getpass_r, getpassfd
— get a password
Standard C Library (libc, -lc)
#include
<unistd.h>
char *
getpass(const
char *prompt);
char *
getpass_r(const
char *prompt, char
*buf, size_t
buflen);
char *
getpassfd(const
char *prompt, char
*buf, size_t
buflen, int *fd,
int flags,
int timeout);
The
getpass()
function displays a prompt to, and reads in a password from,
/dev/tty. If this file is not accessible,
getpass() displays the prompt on the standard error
output and reads from the standard input.
The password may be up to
sysconf(3)
_SC_PASS_MAX characters in length. Any additional
characters and the terminating newline character are discarded.
getpass()
turns off character echoing while reading the password.
getpass_r()
is similar to getpass() only it puts its result in
buf for up to buflen characters.
If the buf argument is NULL,
then a buffer will be dynamically allocated.
The
getpassfd()
function allows one to specify the three file descriptors corresponding to
stdin, stdout, and
stderr in the fd argument, or
if fd is NULL,
getpassfd() first attempts to open
/dev/tty and if that fails, defaults to
STDIN_FILENO for input and
STDERR_FILENO for output.
The behavior of
getpassfd()
is controlled by the flags argument:
GETPASS_NEED_TTYGETPASS_FAIL_EOFGETPASS_BUF_LIMITGETPASS_NO_SIGNALGETPASS_NO_BEEPGETPASS_ECHO_STARGETPASS_ECHOGETPASS_ECHO_NLGETPASS_7BITGETPASS_FORCE_LOWERGETPASS_FORCE_UPPERFinally if the timeout
argument is non zero,
getpassfd()
will wait for timeout seconds for input after each
character before returning an error, instead of waiting forever.
The getpass() function returns a pointer
to the NUL terminated password, or an empty string on error. The
getpass_r() and getpassfd()
functions return a pointer to the NUL terminated password, or
NULL on error.
The getpass() function appeared in
Version 2 of the Single UNIX Specification
(“SUSv2”), but it was already marked as legacy. The
function was removed in the IEEE Std 1003.1-2001
(“POSIX.1”) standard.
A getpass() function appeared in
Version 7 AT&T UNIX. The
getpass_r() and getpassfd()
functions appeared in NetBSD 7.0.
The getpass() function leaves its result
in an internal static object and returns a pointer to that object.
Subsequent calls to getpass() will modify the same
object.
The calling process should zero the password as soon as possible to avoid leaving the cleartext password visible in the process's address space.
Historically getpass 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.
| April 13, 2012 | NetBSD 11.0 |