|
|
1.1 ! root 1: #ifndef lint ! 2: static char *sccsid = "@@(#)lock.c 4.3 (Berkeley) 6/10/83"; ! 3: #endif ! 4: ! 5: /* ! 6: * Lock a terminal up until the knowledgeable Joe returns. ! 7: */ ! 8: #include <stdio.h> ! 9: #include <sys/types.h> ! 10: #include <sys/stat.h> ! 11: #include <signal.h> ! 12: #include <sgtty.h> ! 13: ! 14: char masterp[] = "hasta la vista\n"; ! 15: struct sgttyb tty, ntty; ! 16: char s[BUFSIZ], s1[BUFSIZ]; ! 17: ! 18: main(argc, argv) ! 19: char **argv; ! 20: { ! 21: register int t; ! 22: struct stat statb; ! 23: ! 24: signal(SIGINT, SIG_IGN); ! 25: signal(SIGQUIT, SIG_IGN); ! 26: signal(SIGTSTP, SIG_IGN); ! 27: if (argc > 0) ! 28: argv[0] = 0; ! 29: if (ioctl(0, TIOCGETP, &tty)) ! 30: exit(1); ! 31: ntty = tty; ntty.sg_flags &= ~ECHO; ! 32: ioctl(0, TIOCSETN, &ntty); ! 33: printf("Key: "); ! 34: fgets(s, sizeof s, stdin); ! 35: printf("\nAgain: "); ! 36: fgets(s1, sizeof s1, stdin); ! 37: putchar('\n'); ! 38: if (strcmp(s1, s)) { ! 39: putchar(07); ! 40: stty(0, &tty); ! 41: exit(1); ! 42: } ! 43: printf("LOCKED\n"); ! 44: s[0] = 0; ! 45: for (;;) { ! 46: fgets(s, sizeof s, stdin); ! 47: if (strcmp(s1, s) == 0) ! 48: break; ! 49: if (strcmp(s, masterp) == 0) ! 50: break; ! 51: putchar(07); ! 52: if (ioctl(0, TIOCGETP, &ntty)) ! 53: exit(1); ! 54: } ! 55: ioctl(0, TIOCSETN, &tty); ! 56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.