| 1 | #include <stdio.h> |
| 2 | #include <sys/types.h> |
| 3 | #include <stat.h> |
| 4 | #include <signal.h> |
| 5 | #include <sgtty.h> |
| 6 | |
| 7 | /* |
| 8 | * Lock a terminal up until the knowledgeable Joe returns. |
| 9 | */ |
| 10 | char masterp[] = "hasta la vista\n"; |
| 11 | struct sgttyb tty, ntty; |
| 12 | char s[BUFSIZ], s1[BUFSIZ]; |
| 13 | |
| 14 | main(argc, argv) |
| 15 | char **argv; |
| 16 | { |
| 17 | register int t; |
| 18 | struct stat statb; |
| 19 | |
| 20 | for (t = 1; t <= 16; t++) |
| 21 | signal(t, SIG_IGN); |
| 22 | if (argc > 0) |
| 23 | argv[0] = 0; |
| 24 | if (gtty(0, &tty)) |
| 25 | exit(1); |
| 26 | ntty = tty; ntty.sg_flags &= ~ECHO; |
| 27 | stty(0, &ntty); |
| 28 | printf("Key: "); |
| 29 | fgets(s, sizeof s, stdin); |
| 30 | printf("\nAgain: "); |
| 31 | fgets(s1, sizeof s1, stdin); |
| 32 | putchar('\n'); |
| 33 | if (strcmp(s1, s)) { |
| 34 | putchar(07); |
| 35 | stty(0, &tty); |
| 36 | exit(1); |
| 37 | } |
| 38 | s[0] = 0; |
| 39 | for (;;) { |
| 40 | fgets(s, sizeof s, stdin); |
| 41 | if (strcmp(s1, s) == 0) |
| 42 | break; |
| 43 | if (strcmp(s, masterp) == 0) |
| 44 | break; |
| 45 | putchar(07); |
| 46 | if (gtty(0, &ntty)) |
| 47 | exit(1); |
| 48 | } |
| 49 | stty(0, &tty); |
| 50 | } |