1.\" $OpenBSD: readpassphrase.3,v 1.2 2000/12/24 00:30:50 aaron 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 November 20, 2000 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 76On success, 77.Fn readpassphrase 78returns a pointer to the null-terminated passphrase. 79If the 80.Dv RPP_REQUIRE_TTY 81flag is set and 82.Pa /dev/tty 83is inaccessible, 84.Fn readpassphrase 85returns a null pointer. 86.Sh EXAMPLES 87The following code fragment will read a passphrase from 88.Pa /dev/tty 89into the buffer 90.Fa passbuf. 91.Bd -literal -offset indent 92char passbuf[1024]; 93 94\&... 95 96if (readpassphrase("Response: ", passbuf, sizeof(passbuf), 97 RPP_REQUIRE_TTY) == NULL) 98 errx(1, "unable to read passphrase"); 99 100if (compare(transform(passbuf), epass) != 0) 101 errx(1, "bad passphrase"); 102 103\&... 104 105memset(passbuf, 0, sizeof(passbuf)); 106.Sh FILES 107.Bl -tag -width /dev/tty -compact 108.It Pa /dev/tty 109.El 110.Sh SEE ALSO 111.Xr getpass 3 112.Sh HISTORY 113The 114.Fn readpassphrase 115function first appeared in 116.Ox 2.9 . 117