Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site drivax.UUCP
Path: utzoo!watmath!clyde!cbosgd!ihnp4!qantel!hplabs!amdahl!drivax!alan
From: alan@drivax.UUCP (Alan Fargusson)
Newsgroups: net.sources
Subject: Locking your terminal System V style
Message-ID: <235@drivax.UUCP>
Date: Mon, 16-Sep-85 18:41:47 EDT
Article-I.D.: drivax.235
Posted: Mon Sep 16 18:41:47 1985
Date-Received: Fri, 20-Sep-85 03:59:12 EDT
Distribution: net
Organization: Digital Research, Monterey, CA
Lines: 57

Here is a modified version of one of the 'lock terminal' programs
which I changed to work with System V. It disables signal processing
and layer switching with an ioctl to prevent any escaping from the
lock.

------------------------- cut here -------------------------
/* Lock a terminal which is not in use. Give own password to unlock */
#include 
#include 
#include 
#include 

#define BELL    007

struct  passwd *getpwuid();

struct termio old, new;

main()
{
	int t;
	char *pass;
	char    pwbuf[10];
	char *getpass();
	char    *strcpy();
	char    *crypt();
	char    *pw;
	register struct passwd *pwd;

	/* get password entry */
	pwd = getpwuid(getuid());

	/* save old termio, and disable signals (and layer switching) */
	ioctl( 0, TCGETA, &old );
	new = old;
	new.c_lflag &= ~ISIG;
	ioctl( 0, TCSETAW, &new );

	/* loop here to wait for correct password */
	while (1) {
		strcpy(pwbuf, getpass("Password:"));
		pw = crypt(pwbuf, pwd->pw_passwd);
		if(strcmp(pw, pwd->pw_passwd) == 0)
			break;
		putchar(BELL);
		fflush(stdout);
	}

	/* restore termio modes */
	ioctl( 0, TCSETAW, &old );
}
------------------------- cut here -------------------------
-- 

Alan Fargusson.

{ ihnp4, amdahl, mot }!drivax!alan