home *** CD-ROM | disk | FTP | other *** search
- RCS_ID_C="$Id: getpass.c,v 1.4 1994/01/21 08:13:47 ppessi Exp $";
- /*
- * getpass() --- password checking routine
- *
- * Author: ppessi <Pekka.Pessi@hut.fi>
- *
- * This file is part of the AmiTCP/IP usergroup.library.
- *
- * Copyright © 1993 AmiTCP/IP Group, <AmiTCP-Group@hut.fi>
- * Helsinki University of Technology, Finland.
- *
- * Created : Sun Nov 28 17:45:55 1993 ppessi
- * Last modified: Fri Jan 21 06:49:11 1994 ppessi
- *
- * $Log: getpass.c,v $
- * Revision 1.4 1994/01/21 08:13:47 ppessi
- * Updated documentation
- *
- * Revision 1.3 1994/01/19 10:04:03 ppessi
- * Added error checking
- *
- * Revision 1.2 94/01/15 05:40:38 ppessi
- * Hard disk crash
- *
- * Revision 1.1 93/11/30 03:32:14 ppessi
- * Initial revision
- *
- */
-
- #include "base.h"
- #include "libfunc.h"
-
- #define EOF (-1)
-
- /****** usergroup.library/getpass ******************************************
-
- NAME
- getpass - get a password
-
- SYNOPSIS
- password = getpass(prompt)
- D0 A1
-
- char *getpass(const char *);
-
- FUNCTION
- The getpass() function displays a prompt to, and reads in a password
- from "CONSOLE:". If this device is not accessible, getpass()
- displays the prompt on the standard error output and reads from the
- standard input.
-
- The password may be up to _PASSWORD_LEN (currently 128) characters
- in length. Any additional characters and the terminating newline
- character are discarded.
-
- Getpass turns off character echoing while reading the password.
-
- RESULT
- password - a pointer to the null terminated password
-
- FILES
- Special device "CONSOLE:"
-
- SEE ALSO
- crypt()
-
- HISTORY
- A getpass function appeared in Version 7 AT&T UNIX.
-
- BUGS
- The getpass function leaves its result in an internal static object
- and returns a pointer to that object. Subsequent calls to getpass
- will modify the same object.
-
- The calling program should zero the password as soon as possible to
- avoid leaving the cleartext password visible in the memory.
-
- ****************************************************************************
- */
-
- /*
- * read the password
- */
- SAVEDS ASM char *R_getpass(REG(a1) const char *prompt)
- {
- BPTR conout, conin = Open("CONSOLE:", MODE_OLDFILE);
- static char ch, *p, buf[_PASSWORD_LEN];
- int useconsole = conin != NULL;
-
- /*
- * read and write to CONSOLE: if possible; else read from
- * stdin and write to stderr.
- */
- if (useconsole) {
- conout = conin;
- } else {
- conin = Input();
- conout = Output();
- }
-
- FPuts(conout, (UBYTE *)prompt);
- Flush(conout);
-
- SetMode(conin, 1); /* Raw */
-
- for (p = buf; (ch = FGetC(conin)) != EOF && ch != '\n' && ch != '\r';)
- if (p < buf + _PASSWORD_LEN)
- *p++ = ch;
- *p = '\0';
-
- Write(conout, "\n", 1);
- SetMode(conin, 0); /* Cooked */
-
- if (useconsole)
- Close(conin);
-
- return buf;
- }
-