|
|
1.1 ! root 1: #ifndef lint ! 2: static char sccsid[] = "@(#)getpass.c 4.1 (Berkeley) 5/26/83"; ! 3: #endif ! 4: ! 5: #include <stdio.h> ! 6: #include <signal.h> ! 7: #include <sgtty.h> ! 8: ! 9: /* ! 10: * Changes ! 11: * . from Usenet: increase length of password buffer ! 12: */ ! 13: #define PASSLEN 100 /* max password length */ ! 14: ! 15: char * ! 16: getpass(prompt) ! 17: char *prompt; ! 18: { ! 19: struct sgttyb ttyb; ! 20: int flags; ! 21: register char *p; ! 22: register c; ! 23: FILE *fi; ! 24: static char pbuf[PASSLEN+1]; ! 25: int (*signal())(); ! 26: int (*sig)(); ! 27: ! 28: if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL) ! 29: fi = stdin; ! 30: else ! 31: setbuf(fi, (char *)NULL); ! 32: sig = signal(SIGINT, SIG_IGN); ! 33: gtty(fileno(fi), &ttyb); ! 34: flags = ttyb.sg_flags; ! 35: ttyb.sg_flags &= ~ECHO; ! 36: stty(fileno(fi), &ttyb); ! 37: fprintf(stderr, "%s", prompt); fflush(stderr); ! 38: for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { ! 39: if (p < &pbuf[PASSLEN]) ! 40: *p++ = c; ! 41: } ! 42: *p = '\0'; ! 43: fprintf(stderr, "\n"); fflush(stderr); ! 44: ttyb.sg_flags = flags; ! 45: stty(fileno(fi), &ttyb); ! 46: signal(SIGINT, sig); ! 47: if (fi != stdin) ! 48: fclose(fi); ! 49: return(pbuf); ! 50: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.