1 static char *sccsid = "@(#)lock.c 4.2 (Berkeley) 02/11/82"; 2 #include <stdio.h> 3 #include <sys/types.h> 4 #include <sys/stat.h> 5 #include <signal.h> 6 #include <sgtty.h> 7 8 /* 9 * Lock a terminal up until the knowledgeable Joe returns. 10 */ 11 char masterp[] = "hasta la vista\n"; 12 struct sgttyb tty, ntty; 13 char s[BUFSIZ], s1[BUFSIZ]; 14 15 main(argc, argv) 16 char **argv; 17 { 18 register int t; 19 struct stat statb; 20 21 22 /* 23 * Ignore signals generated from tty keyboard. These signals 24 * are for xBSD only. This program should be compiled with 25 * the jobs library (cc ... -ljobs). 26 */ 27 sigset( SIGINT, SIG_IGN ); 28 sigset( SIGQUIT, SIG_IGN ); 29 sigset( SIGTSTP, SIG_IGN ); 30 31 if (argc > 0) 32 argv[0] = 0; 33 if (gtty(0, &tty)) 34 exit(1); 35 ntty = tty; ntty.sg_flags &= ~ECHO; 36 stty(0, &ntty); 37 printf("Key: "); 38 fgets(s, sizeof s, stdin); 39 printf("\nAgain: "); 40 fgets(s1, sizeof s1, stdin); 41 putchar('\n'); 42 if (strcmp(s1, s)) { 43 putchar(07); 44 stty(0, &tty); 45 exit(1); 46 } 47 s[0] = 0; 48 for (;;) { 49 fgets(s, sizeof s, stdin); 50 if (strcmp(s1, s) == 0) 51 break; 52 if (strcmp(s, masterp) == 0) 53 break; 54 putchar(07); 55 if (gtty(0, &ntty)) 56 exit(1); 57 } 58 stty(0, &tty); 59 } 60