1READPASSPHRASE(3bsd) LOCAL READPASSPHRASE(3bsd)
2
4 readpassphrase — get a passphrase from the user
5
7 Utility functions from BSD systems (libbsd, -lbsd)
8
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
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
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
48 /dev/tty
49
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
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
76 attempting 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.
84
85 [ENOTTY] There is no controlling terminal and the
86 RPP_REQUIRE_TTY flag was specified.
87
89 readpassphrase() will catch the following signals:
90
91 SIGALRM SIGHUP SIGINT
92 SIGPIPE SIGQUIT SIGTERM
93 SIGTSTP SIGTTIN SIGTTOU
94
95 When one of the above signals is intercepted, terminal echo will be
96 restored if it had previously been turned off. If a signal handler was
97 installed for the signal when readpassphrase() was called, that handler
98 is then executed. If no handler was previously installed for the signal
99 then the default action is taken as per sigaction(2).
100
101 The SIGTSTP, SIGTTIN, and SIGTTOU signals (stop signals generated from
102 keyboard or due to terminal I/O from a background process) are treated
103 specially. When the process is resumed after it has been stopped,
104 readpassphrase() will reprint the prompt and the user may then enter a
105 passphrase.
106
108 sigaction(2), getpass(3)
109
111 The readpassphrase() function is an OpenBSD extension and should not be
112 used if portability is desired.
113
115 The readpassphrase() function first appeared in OpenBSD 2.9.
116
117BSD May 10, 2020 BSD