|
|
1.1 ! root 1: /* getpassword.c - generic read-the-password-from-the-tty */ ! 2: ! 3: #ifndef lint ! 4: static char *rcsid = "$Header: /f/osi/compat/RCS/getpassword.c,v 7.0 89/11/23 21:23:01 mrose Rel $"; ! 5: #endif ! 6: ! 7: /* ! 8: * $Header: /f/osi/compat/RCS/getpassword.c,v 7.0 89/11/23 21:23:01 mrose Rel $ ! 9: * ! 10: * ! 11: * $Log: getpassword.c,v $ ! 12: * Revision 7.0 89/11/23 21:23:01 mrose ! 13: * Release 6.0 ! 14: * ! 15: */ ! 16: ! 17: /* ! 18: * NOTICE ! 19: * ! 20: * Acquisition, use, and distribution of this module and related ! 21: * materials are subject to the restrictions of a license agreement. ! 22: * Consult the Preface in the User's Manual for the full terms of ! 23: * this agreement. ! 24: * ! 25: */ ! 26: ! 27: ! 28: /* LINTLIBRARY */ ! 29: ! 30: #include <signal.h> ! 31: #include <stdio.h> ! 32: #include "general.h" ! 33: #include "manifest.h" ! 34: #ifdef BSD42 ! 35: #include <sys/file.h> ! 36: #endif ! 37: #ifdef SYS5 ! 38: #include <fcntl.h> ! 39: #include <termio.h> ! 40: #endif ! 41: #include <sys/ioctl.h> ! 42: ! 43: ! 44: #ifdef BSD44 ! 45: char *getpass (); ! 46: #endif ! 47: ! 48: /* */ ! 49: ! 50: /* roll our own since want to get past UNIX's limit of 8 octets... */ ! 51: ! 52: char *getpassword (prompt) ! 53: char *prompt; ! 54: { ! 55: #ifndef BSD44 ! 56: register int c; ! 57: int flags, ! 58: isopen; ! 59: register char *bp, ! 60: *ep; ! 61: #ifndef SYS5 ! 62: struct sgttyb sg; ! 63: #else ! 64: struct termio sg; ! 65: #endif ! 66: SFP istat; ! 67: FILE *fp; ! 68: static char buffer[BUFSIZ]; ! 69: ! 70: if ((c = open ("/dev/tty", O_RDWR)) != NOTOK && (fp = fdopen (c, "r"))) ! 71: setbuf (fp, NULLCP), isopen = 1; ! 72: else { ! 73: if (c != NOTOK) ! 74: (void) close (c); ! 75: ! 76: fp = stdin, isopen = 0; ! 77: } ! 78: ! 79: istat = signal (SIGINT, SIG_IGN); ! 80: ! 81: #ifndef SYS5 ! 82: (void) gtty (fileno (fp), &sg); ! 83: flags = sg.sg_flags; ! 84: sg.sg_flags &= ~ECHO; ! 85: (void) stty (fileno (fp), &sg); ! 86: #else ! 87: (void) ioctl (fileno (fp), TCGETA, (char *) &sg); ! 88: flags = sg.c_lflag; ! 89: sg.c_lflag &= ~ECHO; ! 90: (void) ioctl (fileno (fp), TCSETAW, (char *) &sg); ! 91: #endif ! 92: ! 93: fprintf (stderr, "%s", prompt); ! 94: (void) fflush (stderr); ! 95: ! 96: for (ep = (bp = buffer) + sizeof buffer - 1; (c = getc (fp)) != EOF;) ! 97: #ifndef apollo ! 98: if (c == '\n') ! 99: #else ! 100: if (c == '\n' || c == '\r') ! 101: #endif ! 102: break; ! 103: else ! 104: if (bp < ep) ! 105: *bp++ = c; ! 106: *bp = NULL; ! 107: ! 108: fprintf (stderr, "\n"); ! 109: (void) fflush (stderr); ! 110: ! 111: #ifndef SYS5 ! 112: sg.sg_flags = flags; ! 113: (void) stty (fileno (fp), &sg); ! 114: #else ! 115: sg.c_lflag = flags; ! 116: (void) ioctl (fileno (fp), TCSETAW, (char *) &sg); ! 117: #endif ! 118: ! 119: (void) signal (SIGINT, istat); ! 120: ! 121: if (isopen) ! 122: (void) fclose (fp); ! 123: ! 124: return buffer; ! 125: #else ! 126: return getpass (prompt); ! 127: #endif ! 128: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.