Lockscreen
Andrea Malagoli
malagoli at oddjob.uchicago.edu
Tue Sep 18 03:05:36 AEST 1990
This is my first posting to the network.
I have developed a lockscreen utility for Irises 4D. It works
on my PI. I am no expert C programmer, so I would appreciate
receiving comments and/or revised versions of this program.
Andrea Malagoli
Astronomy Department
University of Chicago
5640 S.Ellis Ave.
Chicago, IL 60613
e-mail: malagoli at mhd4.uchicago.edu
-------------------------cut here----------------------------
/*
* L O C K S C R E E N
*
* lockscreen utiliy for the SGI machines
*
* lockscreen allows a user to lock the access to the monitor
* without logging out. This is useful when one needs to go
* out of the office and does not want to leave the machine
* accessible to anybody.
*
* After calling lockscreen, the screen gets blank and a bouncing
* ball appears on a black background. To unlock, press the
* RIGHT MOUSE BUTTON. When the prompt asking for the password
* appears, just enter the correct password.
*
* Just compile with
* cc -o lockscreen lockscreen.c -lgl_s
*
* This code has been written borrowing some routines available
* in 4Dgifts/examples/grafix.
*
* WRITTEN BY: Andrea Malagoli
* Astronomy Department
* University of Chicago
* malagoli at mhd.uchicago.edu
* DATE: 15 June 1990
*
*/
#include <sys/types.h>
#include <gl.h>
#include <device.h>
#include <pwd.h>
#include <string.h>
Icoord maxxval; /* width of prompt window ( in screen coords) */
long menu; /* defined menu's identifier */
long oldmode; /* previous drawmode */
char filename[20]; /* array to store standard input for the prompt */
struct passwd mypwd; /* User information from /etc/passwd */
int curpos, prevpos; /* cursor current and previous positions */
long xvelocity = 0, yvelocity = 0; /* initial ball velocity */
int iter=1;
#define XMIN 0
#define XMAX XMAXSCREEN
#define YMIN 0
#define YMAX YMAXSCREEN
/* setup for the prompt box */
Screencoord mask1, mask2, mask3, mask4; /* full window */
main()
{
Device dev;
short val;
long menuval;
int check_pwd();
init();
hyde_cursor();
xvelocity = (long int) (rand(0.6)/32767.*150);
yvelocity = (long int) (rand(0.3)/32767.*150);
/* process events forever */
while(TRUE) {
drawball();
while( qtest() ){
dev=qread(&val);
switch(dev) {
case RIGHTMOUSE:
if(val) {
color( BLUE );
clear();
swapbuffers();
mktxtport();
if(check_pwd(filename) == 1){
endit();
break;
} else break;
}
break;
default:
break;
}
}
}
}
endit() {
clr_overlay();
gexit();
exit(0);
}
init() { /* do all the basic graphics setup */
ginit();
/* enable overlay, and be sure rubber band box will be red */
drawmode(OVERDRAW);
overlay(2);
mapcolor(BLACK, 0, 0, 0);
mapcolor(RED, 255, 0, 0);
drawmode(NORMALDRAW);
doublebuffer();
gconfig();
maxxval = 590; /* prompt window's width in pixels */
/* initial values for restoring screenmask */
getscrmask(&mask1, &mask2, &mask3, &mask4);
qdevice(RIGHTMOUSE);
}
clearpup() { /* clear the pup plane where we asked for the filename */
setupprompt(0);
color(PUP_CLEAR);
clear(); /* clear the PUPDRAW plane */
endprompt();
}
clr_overlay() { /* clear any left over junk in overlay and pup planes */
drawmode(OVERDRAW);
color(BLACK);
clear();
drawmode(PUPDRAW);
color(PUP_CLEAR);
clear();
drawmode(NORMALDRAW);
}
/* screen positionings of prompt box */
#define FILEX 340
#define FILEY 500
#define FILEYHI (30+FILEY) /* 30 pixels hi */
#define TEXTX (FILEX+5)
#define TEXTY (FILEY+10)
/* Clear prompt, move to start of prompt box, and output requested prompt */
clearprompt(prmpt)
char *prmpt;
{
color(PUP_WHITE);
clear();
color(PUP_BLACK);
linewidth(2);
recti(FILEX+2, FILEY+2, FILEX+maxxval-6, FILEYHI-3);
linewidth(1);
cmov2i(TEXTX, TEXTY);
charstr(prmpt);
}
setupprompt(sav) {
if(sav)
oldmode = getdrawmode();
drawmode(PUPDRAW);
/* so can clear just text */
scrmask(FILEX, (Screencoord)(FILEX+maxxval-6), FILEY, FILEYHI);
}
endprompt() {
scrmask(mask1, mask2, mask3, mask4); /* restore old */
drawmode(oldmode);
}
mktxtport() /* get name of file */
{
int curstrlen;
short c;
char *cc = "a";
char *str;
Device dev;
long maxwidth;
size_t maxlen = sizeof(filename);
static char fprompt[] = "Enter Password for ";
char *prmpt = fprompt;
mypwd = *getpwuid( getuid() ); /* Get User ID and encrypted password */
prmpt = strcat(fprompt,mypwd.pw_name);
prmpt = strcat(prmpt,": ");
maxwidth = (XMAXSCREEN-11) - (FILEX + strwidth(fprompt));
setupprompt(1);
/* display prompt */
curstrlen = 0;
clearprompt(prmpt);
prevpos = curpos;
curpos = TEXTX + strwidth(prmpt) + 2;
draw_bar();
qdevice(KEYBD);
/* read until carriage return or linefeed */
while(dev = qread(&c)) {
if(dev != KEYBD)
continue; /* don't care */
switch(c) {
case '\027': /* ctrl-W sets back to start of prompt */
curstrlen = 0;
clearprompt(prmpt);
prevpos = curpos;
curpos = TEXTX + strwidth(prmpt) + 2;
draw_bar();
break;
case '\n':
case '\r':
goto done;
case '\b':
if(curstrlen) {
*cc = filename[--curstrlen];
filename[curstrlen] = '\0';
clearprompt(prmpt);
/* display rightmost portion */
for(str=filename; *str && strwidth(str) > maxwidth; str++);
prevpos = curpos;
curpos = curpos - strwidth(cc);
draw_bar();
/* charstr(str);
*/
}
break;
default:
str = &filename[curstrlen];
filename[curstrlen++] = c;
filename[curstrlen] = '\0';
*cc = c;
prevpos = curpos;
curpos = curpos + strwidth(cc);
draw_bar();
/* charstr(str);
*/
break;
}
}
done:
unqdevice(KEYBD);
endprompt();
clearpup();
clr_overlay();
}
int check_pwd(char *pww)
{
char *salt="12";
strncpy(salt, mypwd.pw_passwd, 2);
if( strcmp(mypwd.pw_passwd,crypt(pww,salt)) == 0 ){
return 1;
} else {
return 0;
}
}
drawball()
{
static xpos = 500,ypos = 500;
long radius = 20;
if( iter >= 200 ) {
xvelocity = (long int) (rand(0.6)/32767.*60);
yvelocity = (long int) (rand(0.3)/32767.*60);
iter = 0;
}
iter++;
color(BLACK);
clear();
xpos += xvelocity;
ypos += yvelocity;
if (xpos > XMAX - radius ||
xpos < XMIN + radius) {
xpos -= xvelocity;
xvelocity = -xvelocity;
}
if (ypos > YMAX - radius ||
ypos < YMIN + radius) {
ypos -= yvelocity;
yvelocity = -yvelocity;
}
color(YELLOW);
circfi(xpos, ypos, radius);
swapbuffers();
}
hyde_cursor()
{
short index;
static short blank[16][16]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
curstype(C16X1);
drawmode(CURSORDRAW);
defcursor(1, blank);
setcursor(1, 0, 0);
drawmode(NORMALDRAW);
}
draw_bar()
{
static int ydown = (FILEY + 5);
static int yup = (FILEYHI - 7);
int vert[2];
linewidth(1);
if( prevpos != curpos ){
color( PUP_WHITE );
bgnline();
vert[0] = prevpos; vert[1] = ydown;
v2i(vert);
vert[0] = prevpos; vert[1] = yup;
v2i(vert);
endline;
color( PUP_BLACK );
bgnline();
vert[0] = curpos; vert[1] = ydown;
v2i(vert);
vert[0] = curpos; vert[1] = yup;
v2i(vert);
endline;
} else {
color( PUP_BLACK );
bgnline();
vert[0] = curpos; vert[1] = ydown;
v2i(vert);
vert[0] = curpos; vert[1] = yup;
v2i(vert);
endline;
}
}
More information about the Comp.sys.sgi
mailing list