1.\" $OpenBSD: readpassphrase.3,v 1.8 2002/05/09 16:47:07 millert Exp $ 2.\" 3.\" Copyright (c) 2000 Todd C. Miller <Todd.Miller@courtesan.com> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. The name of the author may not be used to endorse or promote products 15.\" derived from this software without specific prior written permission. 16.\" 17.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 19.\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 20.\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21.\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22.\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23.\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26.\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27.\" 28.Dd December 7, 2001 29.Dt READPASSPHRASE 3 30.Os 31.Sh NAME 32.Nm readpassphrase 33.Nd get a passphrase from the user 34.Sh SYNOPSIS 35.Fd #include <readpassphrase.h> 36.Ft char * 37.Fn readpassphrase "const char *prompt" "char *buf" "size_t bufsiz" "int flags" 38.Sh DESCRIPTION 39The 40.Fn readpassphrase 41function displays a prompt to, and reads in a passphrase from, 42.Pa /dev/tty . 43If this file is inaccessible 44and the 45.Dv RPP_REQUIRE_TTY 46flag is not set, 47.Fn readpassphrase 48displays the prompt on the standard error output and reads from the standard 49input. 50In this case it is generally not possible to turn off echo. 51.Pp 52Up to 53.Fa bufsiz 54- 1 characters (one is for the NUL) are read into the provided buffer 55.Fa buf . 56Any additional 57characters and the terminating newline (or return) character are discarded. 58.Pp 59.Fn readpassphrase 60takes the following optional 61.Fa flags : 62.Pp 63.Bd -literal -offset indent -compact 64RPP_ECHO_OFF turn off echo (default behavior) 65RPP_ECHO_ON leave echo on 66RPP_REQUIRE_TTY fail if there is no tty 67RPP_FORCELOWER force input to lower case 68RPP_FORCEUPPER force input to upper case 69RPP_SEVENBIT strip the high bit from input 70.Ed 71.Pp 72The calling process should zero the passphrase as soon as possible to 73avoid leaving the cleartext passphrase visible in the process's address 74space. 75.Sh RETURN VALUES 76Upon successful completion, 77.Fn readpassphrase 78returns a pointer to the null-terminated passphrase. 79If an error is encountered, the terminal state is restored and 80a null pointer is returned. 81.Sh ERRORS 82.Bl -tag -width Er 83.It Bq Er EINTR 84The 85.Fn readpassphrase 86function was interrupted by a signal. 87.It Bq Er EINVAL 88The 89.Ar bufsiz 90argument was zero. 91.It Bq Er EIO 92The process is a member of a background process attempting to read 93from its controlling terminal, the process is ignoring or blocking 94the SIGTTIN signal or the process group is orphaned. 95.It Bq Er EMFILE 96The process has already reached its limit for open file descriptors. 97.It Bq Er ENFILE 98The system file table is full. 99.It Bq Er ENOTTY 100There is no controlling terminal and the 101.Dv RPP_REQUIRE_TTY 102flag was specified. 103.El 104.Sh EXAMPLES 105The following code fragment will read a passphrase from 106.Pa /dev/tty 107into the buffer 108.Fa passbuf. 109.Bd -literal -offset indent 110char passbuf[1024]; 111 112\&... 113 114if (readpassphrase("Response: ", passbuf, sizeof(passbuf), 115 RPP_REQUIRE_TTY) == NULL) 116 errx(1, "unable to read passphrase"); 117 118if (compare(transform(passbuf), epass) != 0) 119 errx(1, "bad passphrase"); 120 121\&... 122 123memset(passbuf, 0, sizeof(passbuf)); 124.Ed 125.Sh SIGNALS 126.Fn readpassphrase 127will catch the following signals: 128.Pp 129.Bd -literal -offset indent -compact 130SIGALRM 131SIGHUP 132SIGINT 133SIGPIPE 134SIGQUIT 135SIGTERM 136SIGTSTP 137SIGTTIN 138SIGTTOU 139.Ed 140.Pp 141When one of the above signals is intercepted, terminal echo will 142be restored if it had previously been turned off. 143If a signal handler was installed for the signal when 144.Fn readpassphrase 145was called that handler is then executed. 146If no handler was previously installed for the signal then the 147default action is taken as per 148.Xr sigaction 2 . 149.Pp 150The 151.Dv SIGTSTP , 152.Dv SIGTTIN , 153.Dv SIGTTOU , 154signals (stop signal generated from keyboard or due to terminal I/O 155from a background proccess) are treated specially. 156When the process is resumed after it has been stopped, 157.Fn readpassphrase 158will reprint the prompt and the user may then enter a passphrase. 159.Sh FILES 160.Bl -tag -width /dev/tty -compact 161.It Pa /dev/tty 162.El 163.Sh SEE ALSO 164.Xr sigaction 2 , 165.Xr getpass 3 166.Sh STANDARDS 167The 168.Fn readpassphrase 169function is an 170.Ox 171extension and should not be used if portability is desired. 172.Sh HISTORY 173The 174.Fn readpassphrase 175function first appeared in 176.Ox 2.9 . 177