Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!dsac.dla.mil!dsacg3.dsac.dla.mil!nts0302 From: nts0302@dsacg3.dsac.dla.mil (Bob Fisher) Newsgroups: comp.lang.c Subject: Re: Catching ^C and ^Z Message-ID: <2468@dsacg3.dsac.dla.mil> Date: 5 Sep 90 11:45:16 GMT References: Organization: Defense Logistics Agency Systems Automation Center, Columbus Lines: 71 From article , by deen@utopia.rutgers.edu (Cinnamon Raisin): > > I am trying to write a quick programme to lock a terminal(TTY) > when I leave it. Essentially I want to capture all the > interrupts that can be sent from the keyboard, such as > SIG_INT,SIG_QUIT and so on. The only reasonable thing I've > found that lets me do this is ioctl(). Here's a quickie that we use on our BSD systems. I know this isn't the right group to post to, but it's small. It's based on a book on Unix security - Pat Woods, I think. #include #include main () { static char rcsid[]="$Header: termlock.c,v 1.2 89/02/13 15:29:12 root Exp $"; char passbuf[20], *passwd, *getpass (); int validentry = 0; if(strcmp(ttyname(0), "/dev/console") == 0) { printf("\nYOU CAN'T LOCK THE CONSOLE\n\n"); return(0); } printf("\n\nThis process enables you to lock your terminal without\n"); printf("logging out. A password provided by you will be required\n"); printf("to re-activate this terminal. Don't forget it.\n\n"); while ( ! validentry ) { strcpy (passbuf, getpass ("Enter password: ")); if ( strlen (passbuf) < 4 ) printf ("Please enter at least four characters\n"); else validentry = 1; } signal (SIGINT, SIG_IGN); signal (SIGQUIT, SIG_IGN); signal (SIGSTOP, SIG_IGN); signal (SIGTSTP, SIG_IGN); printf ("\n\n\n\n\n\n\n"); printf ("\t\t********************************************\n"); printf ("\t\t* *\n"); printf ("\t\t* *\n"); printf ("\t\t* *\n"); printf ("\t\t* TERMINAL LOCKED !!! *\n"); printf ("\t\t* *\n"); printf ("\t\t* *\n"); printf ("\t\t* *\n"); printf ("\t\t********************************************\n"); printf ("\n\n\n\n\n\n\n"); validentry = 0; while ( ! validentry ) { passwd = getpass ("Enter password: "); if ( strcmp (passwd, passbuf) != 0 ) { printf ("Bad password, try again.\n"); } else validentry = 1; } system("clear"); return(0); } -- Bob Fisher US Defense Logistics Agency Systems Automation Center DSAC-TSX, Box 1605, Columbus, OH 43216-5002 614-238-9071 (AV 850-9071) bfisher@dsac.dla.mil osu-cis!dsacg1!bfisher