READPASSPHRASE(3)
π READPASSPHRASE(3) β like, the library functions manual bestie
okay so real talk: this is readpassphrase from section 3 of the manual (that's the library-functions girlies β¨). She's the one you call when you need a passphrase from a human and you don't want it just floating around on screen for everyone to see. Very main character, very discreet. π
πΈ NAME πΈ
readpassphrase β get a passphrase from the user, bestie. That's it, that's the vibe.
β¨ SYNOPSIS β¨
#include <readpassphrase.h>
char *
readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags);
π DESCRIPTION π
so the readpassphrase() function pops a prompt on screen and reads a passphrase from /dev/tty. Like, from the actual terminal, not your messy redirected stdin. iconic behaviour honestly.
but !! here's the tea π« β if that file is inaccessible and the RPP_REQUIRE_TTY flag is not set, then readpassphrase() displays the prompt on the standard error output and reads from standard input instead. and in that case? yeah, it's generally not possible to turn off echo. π your characters are gonna be visible, ngl.
up to bufsiz - 1 characters get read into the buffer buf (the minus one is for the NUL, she needs her space π«Ά). any extra characters and the terminating newline (or return) character get discarded. bye.
the readpassphrase() function takes these optional flags:
RPP_ECHO_OFFβ turn off echo. this is the default behavior, no cap.RPP_ECHO_ONβ leave echo on. bold choice, but ok.RPP_REQUIRE_TTYβ fail if there's no tty. she's not doing charity work.RPP_FORCELOWERβ force input to lower case.RPP_FORCEUPPERβ force input to upper case.RPP_SEVENBITβ strip the high bit from input.RPP_STDINβ force read of passphrase from stdin.
ok so this part is important, listen up π β the calling process should zero the passphrase as soon as possible, to avoid leaving the cleartext passphrase visible in the process's address space. like, don't just leave it lying around. that's giving security hazard energy. π
π RETURN VALUES π
upon successful completion, readpassphrase() returns a pointer to the NUL-terminated passphrase. π
if an error is encountered, the terminal state is restored and a NULL pointer is returned. so she cleans up after herself, that's classy.
π¦ FILES π¦
/dev/tty
π EXAMPLES π
the following code fragment will read a passphrase from /dev/tty into the buffer passbuf. look at her go β¨
char passbuf[1024];
...
if (readpassphrase("Response: ", passbuf, sizeof(passbuf),
RPP_REQUIRE_TTY) == NULL)
errx(1, "unable to read passphrase");
if (compare(transform(passbuf), epass) != 0)
errx(1, "bad passphrase");
...
memset(passbuf, 0, sizeof(passbuf));
π ERRORS π
[EINTR]β thereadpassphrase()function was interrupted by a signal. rude.[EINVAL]β thebufsizargument was zero. girl. zero? zero?! π[EIO]β the process is a member of a background process attempting to read from its controlling terminal, the process is ignoring or blocking theSIGTTINsignal, or the process group is orphaned.[EMFILE]β the process has already reached its limit for open file descriptors.[ENFILE]β the system file table is full. full full.[ENOTTY]β there is no controlling terminal and theRPP_REQUIRE_TTYflag was specified.
π₯ SIGNALS π₯
the readpassphrase() function will catch the following signals:
SIGALRM SIGHUP SIGINT
SIGPIPE SIGQUIT SIGTERM
SIGTSTP SIGTTIN SIGTTOU
when one of the above signals is intercepted, terminal echo will be restored if it had previously been turned off. mhm, she puts it back π
if a signal handler was installed for the signal when readpassphrase() was called, that handler is then executed. if no handler was previously installed for the signal then the default action is taken as per sigaction(2).
and here's the special-guest part β β the SIGTSTP, SIGTTIN and SIGTTOU signals (stop signals generated from keyboard or due to terminal I/O from a background process) are treated specially. when the process is resumed after it has been stopped, readpassphrase() will reprint the prompt and the user may then enter a passphrase. like she literally picks up right where she left off, obsessed.
π§ SEE ALSO π§
π STANDARDS π
the readpassphrase() function is an extension and should not be used if portability is desired. so like, she's not everywhere, bestie. check if your platform's invited to the party first. π
π HISTORY π
the readpassphrase() function first appeared in FreeBSD 4.6 and OpenBSD 2.9.
and that's the whole page, no notes π this cutie comes to you from the Debian crew, dated May 31, 2007 β yeah she's vintage, she's aged like fine wine, she's still serving. mwah ππ«Ά
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms