1readpassphrase(3bsd)                 LOCAL                readpassphrase(3bsd)
2

NAME

4     readpassphrase — get a passphrase from the user
5

LIBRARY

7     Utility functions from BSD systems (libbsd, -lbsd)
8

SYNOPSIS

10     #include <readpassphrase.h>
11     (See libbsd(7) for include usage.)
12
13     char *
14     readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags);
15

DESCRIPTION

17     The readpassphrase() function displays a prompt to, and reads in a
18     passphrase from, /dev/tty.  If this file is inaccessible and the
19     RPP_REQUIRE_TTY flag is not set, readpassphrase() displays the prompt on
20     the standard error output and reads from the standard input.  In this
21     case it is generally not possible to turn off echo.
22
23     Up to bufsiz - 1 characters (one is for the NUL) are read into the pro‐
24     vided buffer buf.  Any additional characters and the terminating newline
25     (or return) character are discarded.
26
27     The flags argument is the bitwise OR of zero or more of the following
28     values:
29
30           RPP_ECHO_OFF            turn off echo (default behavior)
31           RPP_ECHO_ON             leave echo on
32           RPP_REQUIRE_TTY         fail if there is no tty
33           RPP_FORCELOWER          force input to lower case
34           RPP_FORCEUPPER          force input to upper case
35           RPP_SEVENBIT            strip the high bit from input
36           RPP_STDIN               read passphrase from stdin; ignore prompt
37
38     The calling process should zero the passphrase as soon as possible to
39     avoid leaving the cleartext passphrase visible in the process's address
40     space.
41

RETURN VALUES

43     Upon successful completion, readpassphrase() returns a pointer to the
44     NUL-terminated passphrase.  If an error is encountered, the terminal
45     state is restored and a null pointer is returned.
46

FILES

48     /dev/tty
49

EXAMPLES

51     The following code fragment will read a passphrase from /dev/tty into the
52     buffer passbuf.
53
54           char passbuf[1024];
55
56           ...
57
58           if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
59               RPP_REQUIRE_TTY) == NULL)
60                   errx(1, "unable to read passphrase");
61
62           if (compare(transform(passbuf), epass) != 0)
63                   errx(1, "bad passphrase");
64
65           ...
66
67           explicit_bzero(passbuf, sizeof(passbuf));
68

ERRORS

70     [EINTR]            The readpassphrase() function was interrupted by a
71                        signal.
72
73     [EINVAL]           The bufsiz argument was zero.
74
75     [EIO]              The process is a member of a background process at‐
76                        tempting to read from its controlling terminal, the
77                        process is ignoring or blocking the SIGTTIN signal, or
78                        the process group is orphaned.
79
80     [EMFILE]           The process has already reached its limit for open
81                        file descriptors.
82
83     [ENFILE]           The system file table is full.
8