1*f14fb602SLionel Sambuc.\" $NetBSD: getpass.3,v 1.22 2012/04/14 10:34:29 wiz Exp $ 22fe8fb19SBen Gras.\" 32fe8fb19SBen Gras.\" Copyright (c) 1989, 1991, 1993 42fe8fb19SBen Gras.\" The Regents of the University of California. All rights reserved. 52fe8fb19SBen Gras.\" 62fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without 72fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions 82fe8fb19SBen Gras.\" are met: 92fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright 102fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer. 112fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright 122fe8fb19SBen Gras.\" notice, this list of conditions and the following disclaimer in the 132fe8fb19SBen Gras.\" documentation and/or other materials provided with the distribution. 142fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors 152fe8fb19SBen Gras.\" may be used to endorse or promote products derived from this software 162fe8fb19SBen Gras.\" without specific prior written permission. 172fe8fb19SBen Gras.\" 182fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 192fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 202fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 212fe8fb19SBen Gras.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 222fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 232fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 242fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 252fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 262fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 272fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 282fe8fb19SBen Gras.\" SUCH DAMAGE. 292fe8fb19SBen Gras.\" 302fe8fb19SBen Gras.\" @(#)getpass.3 8.1 (Berkeley) 6/4/93 312fe8fb19SBen Gras.\" 32*f14fb602SLionel Sambuc.Dd April 13, 2012 332fe8fb19SBen Gras.Dt GETPASS 3 342fe8fb19SBen Gras.Os 352fe8fb19SBen Gras.Sh NAME 362fe8fb19SBen Gras.Nm getpass 372fe8fb19SBen Gras.Nd get a password 382fe8fb19SBen Gras.Sh LIBRARY 392fe8fb19SBen Gras.Lb libc 402fe8fb19SBen Gras.Sh SYNOPSIS 412fe8fb19SBen Gras.In unistd.h 422fe8fb19SBen Gras.Ft char * 432fe8fb19SBen Gras.Fn getpass "const char *prompt" 44*f14fb602SLionel Sambuc.Ft char * 45*f14fb602SLionel Sambuc.Fn getpass_r "const char *prompt" "char *buf" "size_t buflen" 46*f14fb602SLionel Sambuc.Ft char * 47*f14fb602SLionel Sambuc.Fn getpassfd "const char *prompt" "char *buf" "size_t buflen" "int *fd" "int flags" "int timeout" 482fe8fb19SBen Gras.Sh DESCRIPTION 492fe8fb19SBen GrasThe 502fe8fb19SBen Gras.Fn getpass 512fe8fb19SBen Grasfunction displays a prompt to, and reads in a password from, 522fe8fb19SBen Gras.Pa /dev/tty . 532fe8fb19SBen GrasIf this file is not accessible, 542fe8fb19SBen Gras.Fn getpass 552fe8fb19SBen Grasdisplays the prompt on the standard error output and reads from the standard 562fe8fb19SBen Grasinput. 572fe8fb19SBen Gras.Pp 58*f14fb602SLionel SambucThe password may be up to 59*f14fb602SLionel Sambuc.Xr sysconf 3 60*f14fb602SLionel Sambuc.Dv _SC_PASS_MAX 612fe8fb19SBen Grascharacters in length. 622fe8fb19SBen GrasAny additional 632fe8fb19SBen Grascharacters and the terminating newline character are discarded. 642fe8fb19SBen Gras.Pp 652fe8fb19SBen Gras.Fn getpass 662fe8fb19SBen Grasturns off character echoing while reading the password. 67*f14fb602SLionel Sambuc.Pp 68*f14fb602SLionel Sambuc.Fn getpass_r 69*f14fb602SLionel Sambucis similar to 702fe8fb19SBen Gras.Fn getpass 71*f14fb602SLionel Sambuconly it puts its result in 72*f14fb602SLionel Sambuc.Fa buf 73*f14fb602SLionel Sambucfor up to 74*f14fb602SLionel Sambuc.Fa buflen 75*f14fb602SLionel Sambuccharacters. 76*f14fb602SLionel SambucIf the 77*f14fb602SLionel Sambuc.Fa buf 78*f14fb602SLionel Sambucargument is 79*f14fb602SLionel Sambuc.Dv NULL , 80*f14fb602SLionel Sambucthen a buffer will be dynamically allocated. 81*f14fb602SLionel Sambuc.Pp 82*f14fb602SLionel SambucThe 83*f14fb602SLionel Sambuc.Fn getpassfd 84*f14fb602SLionel Sambucfunction allows one to specify the three file descriptors corresponding to 85*f14fb602SLionel Sambuc.Dv stdin , 86*f14fb602SLionel Sambuc.Dv stdout , 87*f14fb602SLionel Sambucand 88*f14fb602SLionel Sambuc.Dv stderr 89*f14fb602SLionel Sambucin the 90*f14fb602SLionel Sambuc.Fa fd 91*f14fb602SLionel Sambucargument, or if 92*f14fb602SLionel Sambuc.Fa fd 93*f14fb602SLionel Sambucis 94*f14fb602SLionel Sambuc.Dv NULL , 95*f14fb602SLionel Sambuc.Fn getpassfd 96*f14fb602SLionel Sambucfirst attempts to open 97*f14fb602SLionel Sambuc.Pa /dev/tty 98*f14fb602SLionel Sambucand if that fails, defaults to 99*f14fb602SLionel Sambuc.Dv STDIN_FILENO 100*f14fb602SLionel Sambucfor input and 101*f14fb602SLionel Sambuc.Dv STDERR_FILENO 102*f14fb602SLionel Sambucfor output. 103*f14fb602SLionel Sambuc.Pp 104*f14fb602SLionel SambucThe behavior of 105*f14fb602SLionel Sambuc.Fn getpassfd 106*f14fb602SLionel Sambucis controlled by the 107*f14fb602SLionel Sambuc.Fa flags 108*f14fb602SLionel Sambucargument: 109*f14fb602SLionel Sambuc.Bl -tag -width GETPASS_FORCE_UPPER 110*f14fb602SLionel Sambuc.It Dv GETPASS_NEED_TTY 111*f14fb602SLionel SambucFail if we are unable to set the tty modes like we want. 112*f14fb602SLionel Sambuc.It Dv GETPASS_FAIL_EOF 113*f14fb602SLionel SambucFail if we get the end-of-file character instead of returning the result so far. 114*f14fb602SLionel Sambuc.It Dv GETPASS_BUF_LIMIT 115*f14fb602SLionel SambucBeep when the buffer limit is reached, instead of silently absorbing it. 116*f14fb602SLionel Sambuc.It Dv GETPASS_NO_SIGNAL 117*f14fb602SLionel SambucDon't make ttychars send signals. 118*f14fb602SLionel Sambuc.It Dv GETPASS_NO_BEEP 119*f14fb602SLionel SambucDon't beep if we erase past the beginning of the buffer or we try to enter past 120*f14fb602SLionel Sambucthe end. 121*f14fb602SLionel Sambuc.It Dv GETPASS_ECHO_STAR 122*f14fb602SLionel SambucEcho a 123*f14fb602SLionel Sambuc.Sq * 124*f14fb602SLionel Sambucfor each character entered. 125*f14fb602SLionel Sambuc.It Dv GETPASS_ECHO 126*f14fb602SLionel SambucEcho characters as they are typed. 127*f14fb602SLionel Sambuc.It Dv GETPASS_ECHO_NL 128*f14fb602SLionel SambucEchoes a newline if successful. 129*f14fb602SLionel Sambuc.It Dv GETPASS_7BIT 130*f14fb602SLionel SambucMask the high bit for each entered character. 131*f14fb602SLionel Sambuc.It Dv GETPASS_FORCE_LOWER 132*f14fb602SLionel SambucLowercase each entered character. 133*f14fb602SLionel Sambuc.It Dv GETPASS_FORCE_UPPER 134*f14fb602SLionel SambucUppercase each entered character. 135*f14fb602SLionel Sambuc.El 136*f14fb602SLionel Sambuc.Pp 137*f14fb602SLionel SambucFinally if the 138*f14fb602SLionel Sambuc.Fa timeout 139*f14fb602SLionel Sambucargument is non zero, 140*f14fb602SLionel Sambuc.Fn getpassfd 141*f14fb602SLionel Sambucwill wait for 142*f14fb602SLionel Sambuc.Fa timeout 143*f14fb602SLionel Sambucseconds for input after each character before returning an error, instead of 144*f14fb602SLionel Sambucwaiting forever. 145*f14fb602SLionel Sambuc.Sh RETURN VALUES 146*f14fb602SLionel SambucThe 147*f14fb602SLionel Sambuc.Fn getpass 148*f14fb602SLionel Sambucfunction returns a pointer to the NUL terminated password, or an empty 149*f14fb602SLionel Sambucstring on error. 150*f14fb602SLionel SambucThe 151*f14fb602SLionel Sambuc.Fn getpass_r 152*f14fb602SLionel Sambucand 153*f14fb602SLionel Sambuc.Fn getpassfd 154*f14fb602SLionel Sambucfunctions return a pointer to the NUL terminated password, or 155*f14fb602SLionel Sambuc.Dv NULL 156*f14fb602SLionel Sambucon error. 1572fe8fb19SBen Gras.Sh FILES 1582fe8fb19SBen Gras.Bl -tag -width /dev/tty -compact 1592fe8fb19SBen Gras.It Pa /dev/tty 1602fe8fb19SBen Gras.El 1612fe8fb19SBen Gras.Sh SEE ALSO 1622fe8fb19SBen Gras.Xr crypt 3 1632fe8fb19SBen Gras.Sh STANDARDS 1642fe8fb19SBen GrasThe 1652fe8fb19SBen Gras.Fn getpass 1662fe8fb19SBen Grasfunction appeared in 1672fe8fb19SBen Gras.St -susv2 , 1682fe8fb19SBen Grasbut it was already marked as legacy. 1692fe8fb19SBen GrasThe function was removed in the 1702fe8fb19SBen Gras.St -p1003.1-2001 1712fe8fb19SBen Grasstandard. 1722fe8fb19SBen Gras.Sh HISTORY 1732fe8fb19SBen GrasA 1742fe8fb19SBen Gras.Fn getpass 1752fe8fb19SBen Grasfunction appeared in 1762fe8fb19SBen Gras.At v7 . 177*f14fb602SLionel SambucThe 178*f14fb602SLionel Sambuc.Fn getpass_r 179*f14fb602SLionel Sambucand 180*f14fb602SLionel Sambuc.Fn getpassfd 181*f14fb602SLionel Sambucfunctions appeared in 182*f14fb602SLionel Sambuc.Nx 7.0 . 1832fe8fb19SBen Gras.Sh BUGS 1842fe8fb19SBen GrasThe 1852fe8fb19SBen Gras.Fn getpass 1862fe8fb19SBen Grasfunction leaves its result in an internal static object and returns 1872fe8fb19SBen Grasa pointer to that object. 1882fe8fb19SBen GrasSubsequent calls to 1892fe8fb19SBen Gras.Fn getpass 1902fe8fb19SBen Graswill modify the same object. 1912fe8fb19SBen Gras.Sh SECURITY CONSIDERATIONS 1922fe8fb19SBen GrasThe calling process should zero the password as soon as possible to 1932fe8fb19SBen Grasavoid leaving the cleartext password visible in the process's address 1942fe8fb19SBen Grasspace. 195*f14fb602SLionel Sambuc.Pp 196*f14fb602SLionel SambucHistorically 197*f14fb602SLionel Sambuc.Nm 198*f14fb602SLionel Sambucaccepted and returned a password if it could not modify the terminal 199*f14fb602SLionel Sambucsettings to turn echo off (or if the input was not a terminal). 200*f14fb602SLionel SambucIn this implementation, only terminal input is accepted. 201