1READPASSPHRASE(3) BSD Library Functions Manual READPASSPHRASE(3)
2
4 readpassphrase — get a passphrase from the user
5
7 Utility functions from BSD systems (libbsd, -lbsd)
8
10 #include <readpassphrase.h>
11
12 char *
13 readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags);
14
16 The readpassphrase() function displays a prompt to, and reads in a
17 passphrase from, /dev/tty. If this file is inaccessible and the
18 RPP_REQUIRE_TTY flag is not set, readpassphrase() displays the prompt on
19 the standard error output and reads from the standard input. In this
20 case it is generally not possible to turn off echo.
21
22 Up to bufsiz - 1 characters (one is for the NUL) are read into the pro‐
23 vided buffer buf. Any additional characters and the terminating newline
24 (or return) character are discarded.
25
26 readpassphrase() takes the following optional flags:
27
28 RPP_ECHO_OFF turn off echo (default behavior)
29 RPP_ECHO_ON leave echo on
30 RPP_REQUIRE_TTY fail if there is no tty
31 RPP_FORCELOWER force input to lower case
32 RPP_FORCEUPPER force input to upper case
33 RPP_SEVENBIT strip the high bit from input
34 RPP_STDIN force read of passphrase from stdin
35
36 The calling process should zero the passphrase as soon as possible to
37 avoid leaving the cleartext passphrase visible in the process's address
38 space.
39
41 Upon successful completion, readpassphrase() returns a pointer to the
42 NUL-terminated passphrase. If an error is encountered, the terminal
43 state is restored and a null pointer is returned.
44
46 /dev/tty
47
49 The following code fragment will read a passphrase from /dev/tty into the
50 buffer passbuf.
51
52 char passbuf[1024];
53
54 ...
55
56 if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
57 RPP_REQUIRE_TTY) == NULL)
58 errx(1, "unable to read passphrase");
59
60 if (compare(transform(passbuf), epass) != 0)
61 errx(1, "bad passphrase");
62
63 ...
64
65 memset(passbuf, 0, sizeof(passbuf));
66
68 [EINTR] The readpassphrase() function was interrupted by a
69 signal.
70
71 [EINVAL] The bufsiz argument was zero.
72
73 [EIO] The process is a member of a background process
74 attempting to read from its controlling terminal, the
75 process is ignoring or blocking the SIGTTIN signal, or
76 the process group is orphaned.
77
78 [EMFILE] The process has already reached its limit for open
79 file descriptors.
80
81 [ENFILE] The system file table is full.
82
83 [ENOTTY] There is no controlling terminal and the
84 RPP_REQUIRE_TTY flag was specified.
85
87 readpassphrase() will catch the following signals:
88
89 SIGALRM SIGHUP SIGINT
90 SIGPIPE SIGQUIT SIGTERM
91 SIGTSTP SIGTTIN SIGTTOU
92
93 When one of the above signals is intercepted, terminal echo will be
94 restored if it had previously been turned off. If a signal handler was
95 installed for the signal when readpassphrase() was called, that handler
96 is then executed. If no handler was previously installed for the signal
97 then the default action is taken as per sigaction(2).
98
99 The SIGTSTP, SIGTTIN, and SIGTTOU signals (stop signals generated from
100 keyboard or due to terminal I/O from a background process) are treated
101 specially. When the process is resumed after it has been stopped,
102 readpassphrase() will reprint the prompt and the user may then enter a
103 passphrase.
104
106 sigaction(2), getpass(3)
107
109 The readpassphrase() function is an OpenBSD extension and should not be
110 used if portability is desired.
111
113 The readpassphrase() function first appeared in OpenBSD 2.9.
114
115BSD June 22, 2019 BSD