Lock your terminal for lunch

Mike Williams mike at erix.UUCP
Wed Sep 11 00:59:08 AEST 1985


We use this one.

/* Lock a terminal which is not in use. Give own password to unlock */
#include <signal.h>
#include <stdio.h>
#include <pwd.h>

#define BELL    007

struct  passwd *getpwuid();


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());

	/* signal handling */
	for (t = 1; t <= 26; t++)
		signal(t, SIG_IGN);
	/* Process will die if HUP is received - good for modem lines!   */
		signal(SIGHUP,SIG_DFL);


	/* 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) exit(0);
		putchar(BELL);
		fflush(stdout);
	}
}



More information about the Comp.sources.unix mailing list