Locking your terminal System V style
Alan Fargusson
alan at drivax.UUCP
Tue Sep 17 08:41:47 AEST 1985
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 <signal.h>
#include <stdio.h>
#include <pwd.h>
#include <termio.h>
#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
More information about the Comp.sources.unix
mailing list