[net.sources] Lock your terminal for launch.

dap@teklds.UUCP (Damon Permezel) (09/12/85)

[eat me]

At Waterloo, we had a nifty programme to keep turkeys from stealing ones
terminal when one wasn't around (ie, gone home for the night, etc).

/*
 * somb - intelligent 'lock'
 *
 * Author:
 *	Damon Anton Permezel
 *	- recreating a programme I once knew and loved
 */

#include <stdio.h>
#include <sys/types.h>
#include <signal.h>
#include <sgtty.h>
#include <pwd.h>

#define BUFSZ	512

struct	sgttyb tty, ntty;
struct passwd *pwd, *getpwuid();
int somb();

main(argc, argv)
char **argv; {
	register int t;
	int uid;

	uid = getuid();
	pwd = getpwuid(uid);

	for (t = 1; t <= NSIG; t++)
		if (t != SIGHUP)
			signal(t, SIG_IGN);

	signal(SIGINT, somb);

	if (gtty(0, &tty))
		exit(1);

	ntty = tty;
	ntty.sg_flags &= ~ECHO;

	stty(0, &ntty);

	for (;;)
		pause();
}

somb() {
	char buf[BUFSZ];

	signal(SIGINT, SIG_IGN);

	printf("Password: ");
	gets(buf);

	if (strcmp(crypt(buf, pwd->pw_passwd), pwd->pw_passwd)) {
		printf("\nGo away.\n");
		signal(SIGINT, somb);
	} else {
		stty(0, &tty);
		putchar('\n');
		exit(0);
	}
}