1.\" $OpenBSD: readpassphrase.3,v 1.1 2000/11/21 00:48:37 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 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. In this case it is generally not possible to turn off echo. 50.Pp 51Up to 52.Fa bufsiz 53- 1 characters (one is for the NUL) are read into the provided buffer 54.Fa buf . 55Any additional 56characters and the terminating newline (or return) character are discarded. 57.Pp 58.Fn readpassphrase 59takes the following optional 60.Fa flags : 61.Pp 62.Bd -literal -offset indent -compact 63RPP_ECHO_OFF turn off echo (default behavior) 64RPP_ECHO_ON leave echo on 65RPP_REQUIRE_TTY fail if there is no tty 66RPP_FORCELOWER force input to lower case 67RPP_FORCEUPPER force input to upper case 68RPP_SEVENBIT strip the high bit from input 69.Ed 70.Pp 71The calling process should zero the passphrase as soon as possible to 72avoid leaving the cleartext passphrase visible in the process's address 73space. 74.Sh RETURN VALUES 75On success, 76.Fn readpassphrase 77returns a pointer to the NUL-terminated passphrase. If the 78.Dv RPP_REQUIRE_TTY 79flag is set and 80.Pa /dev/tty 81is inaccessible, 82.Fn readpassphrase 83returns the 84.Dv NULL pointer. 85.Sh EXAMPLES 86The following code fragment will read a passphrase from 87.Pa /dev/tty 88into the buffer 89.Fa passbuf. 90.Bd -literal -offset indent 91char passbuf[1024]; 92 93\&... 94 95if (readpassphrase("Response: ", passbuf, sizeof(passbuf), 96 RPP_REQUIRE_TTY) == NULL) 97 errx(1, "unable to read passphrase"); 98 99if (compare(transform(passbuf), epass) != 0) 100 errx(1, "bad passphrase"); 101 102\&... 103 104memset(passbuf, 0, sizeof(passbuf)); 105.Sh FILES 106.Bl -tag -width /dev/tty -compact 107.It Pa /dev/tty 108.El 109.Sh SEE ALSO 110.Xr getpass 3 111.Sh HISTORY 112The 113.Fn readpassphrase 114function first appeared in 115.Ox 2.9 . 116