Path: utzoo!mnetor!uunet!husc6!bbn!rochester!cornell!batcomputer!sun.soe.clarkson.edu!naughton From: naughton@sun.soe.clarkson.edu (Patrick Naughton) Newsgroups: comp.windows.x Subject: Re: How to lock a sun under X Message-ID: <626@sun.soe.clarkson.edu> Date: 25 Mar 88 04:35:08 GMT References: <22533@bbn.COM> Organization: Clarkson University, Potsdam, NY Lines: 378 > In article <22533@bbn.COM>, milliken@heron.bbn.com (Walter Milliken) writes: > I posted such a program for X10 to the xpert list a while back. > Here's the X11 version (apologies for posting source here, but it's > relatively short). I have taken the code posted by Walter Milliken to lock an X11 terminal and modified it to increase both the security of its use and the aesthetics of its display. I (and others) noticed that it should only be allowed to run on "unix:0", and I also removed the option for a command line password, since anyone could lock your terminal with any random password using this option. As an added measure, I have it set up so you need to enter your password in order to lock the terminal as well as unlock it. (This is an arguable point and may be removed given enough opposition.) I also wrote a "standard" X11 man page for it. The most noticeable enhancement is in the display. I coded the "HOPALONG" routine from the September 1986 issue of Scientific American. These "real plane fractals" are quite nice to watch. There is a command line option to support color and it will change patterns after 10-20K iterations or when Return is pressed. Control-H and Control-U are supported for line editing as in login. If anyone has any comments or additions, I will be happy to make the changes and make the full sources available via anonymous ftp from sun.soe.clarkson.edu (128.153.12.3) along with the X distribution and lots of other X related software. (in ~ftp/pub/X.V11R2/local) -Patrick ___________________________________________ | | | Internet: naughton@sun.soe.clarkson.edu | | BITNET: naughton@CLUTX.BITNET | | uucp: {rpics, gould}!clutx!naughton | |___________________________________________| -----------------------------cut here------------------------------------ #!/bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #!/bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # xlock.c # xlock.man # Imakefile # This archive created: Thu Mar 24 23:06:55 1988 export PATH; PATH=/bin:$PATH if test -f 'xlock.c' then echo shar: over-writing existing file "'xlock.c'" fi cat << \SHAR_EOF > 'xlock.c' /* * XLOCK V1.1 * * A Terminal Locker for X11 * * Copyright (c) 1988 by Patrick J. Naughton * * All Rights Reserved * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that * both that copyright notice and this permission notice appear in * supporting documentation. * * Original version posted to comp.windows.x by: * Walter Milliken * (milliken@heron.bbn.com) * BBN Advanced Computers, Inc., Cambridge, MA * * Comments and additions may be sent the author at: * * naughton@sun.soe.clarkson.edu * * or by Snail Mail: * Patrick J. Naughton * 23 Pleasant Street, #3 * Potsdam, NY 13676 * or * (315) 265-2853 (voice) * * * Revision History: * 24-Mar-88: Added color support. [-color] * wrote the man page. * 23-Mar-88: Added HOPALONG routines from Scientific American Sept. 86 p. 14. * added password requirement for invokation * removed option for command line password * added requirement for display to be "unix:0". * changed the icon. * 22-Mar-88: Recieved Walter Milliken's comp.windows.x posting. * */ #include #include #include #include #include char *crypt(); struct passwd *pw; Display *dsp = NULL; /* current display (must be inited) */ Window w; /* window used to cover screen */ GContext gc; int width; /* width of screen */ int height; /* height of screen */ Window rootw; /* root window */ int screen; /* current screen */ Colormap cmap; /* colormap of current screen */ Cursor mycursor; /* "locked" cursor */ unsigned long black_pixel; /* pixel value for black */ unsigned long white_pixel; /* pixel value for white */ XColor black_color; /* color value for black */ XColor white_color; /* color value for white */ #define lock_width 48 #define lock_height 16 #define lock_x_hot 24 #define lock_y_hot 8 static char lock_bits[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x3c, 0x3c, 0x66, 0x7e, 0x3e, 0x06, 0x66, 0x66, 0x66, 0x7e, 0x76, 0x06, 0x66, 0x46, 0x66, 0x06, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x06, 0x1e, 0x3e, 0x66, 0x06, 0x66, 0x06, 0x1e, 0x3e, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x06, 0x36, 0x06, 0x66, 0x06, 0x66, 0x46, 0x66, 0x06, 0x66, 0x7e, 0x66, 0x66, 0x66, 0x7e, 0x76, 0x7e, 0x3c, 0x3c, 0x66, 0x7e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; static char lock_mask[] = { 0x0f, 0x7e, 0x7e, 0xff, 0xff, 0x7f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0xff, 0xef, 0xff, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x0f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x7f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x7f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x7f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x7f, 0xff, 0x0f, 0xff, 0x0f, 0x7f, 0x0f, 0xff, 0x0f, 0xff, 0xef, 0xff, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x7e, 0xff, 0xff, 0x7f}; int centerx, centery, iter, maxiter, range, color; double a, b, c, i, j; ReadXString(s, slen) char *s; int slen; { int bp; char c; XEvent evt; XKeyEvent *kpevt = (XKeyEvent *) &evt; char keystr[20]; bp = 0; while (1) { if (XPending(dsp)) { XNextEvent(dsp, &evt); if (evt.type == KeyPress) { if (XLookupString(kpevt, keystr, 20, NULL, NULL) > 0) { c = keystr[0]; switch (c) { case 8: /* ^H */ if (bp > 0) bp--; break; case 13: /* ^M */ s[bp] = '\0'; return; case 21: /* ^U */ bp = 0; break; default: s[bp] = c; if (bp < slen-1) bp++; } } } } else iterate(); } } main(argc, argv) int argc; char *argv[]; { char buf[10]; char *pass; XSetWindowAttributes attrs; XGCValues xgcv; Pixmap lockc, lockm; char *getpass(); color = 0; if (argc > 1) { if (!strcmp("-color", argv[1])) color++; else { fprintf (stderr, "usage: %s [-color]\n", argv[0]); exit(1); } } pw = getpwuid(getuid()); pass = crypt(getpass("Password:"), pw->pw_passwd); if (strcmp(pw->pw_passwd, pass)) { fprintf(stderr, "Sorry\n"); exit(1); } if (!(dsp = XOpenDisplay("unix:0"))) { fprintf (stderr, "%s: unable to open display.\n", argv[0]); exit(1); } rootw = DefaultRootWindow(dsp); screen = DefaultScreen(dsp); width = DisplayWidth(dsp, screen); height = DisplayHeight(dsp, screen); centerx = width / 2; centery = height / 2; range = (int) sqrt((double)centerx*centerx+(double)centery*centery); cmap = DefaultColormap(dsp, screen); black_pixel = BlackPixel(dsp, screen); black_color.pixel = black_pixel; XQueryColor(dsp, cmap, &black_color); white_pixel = WhitePixel(dsp, screen); white_color.pixel = white_pixel; XQueryColor(dsp, cmap, &white_color); attrs.background_pixel = black_pixel; attrs.override_redirect = True; attrs.event_mask = KeyPressMask; w = XCreateWindow(dsp, rootw, 0, 0, width, height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWEventMask, &attrs); lockc = XCreateBitmapFromData(dsp, w, lock_bits, lock_width, lock_height); lockm = XCreateBitmapFromData(dsp, w, lock_mask, lock_width, lock_height); mycursor = XCreatePixmapCursor(dsp, lockc, lockm, &black_color, &white_color, lock_x_hot, lock_y_hot); XFreePixmap(dsp, lockc); XFreePixmap(dsp, lockm); XMapWindow(dsp, w); xgcv.foreground = white_pixel; xgcv.background = black_pixel; gc = (GContext) XCreateGC(dsp, w, GCForeground | GCBackground, &xgcv); XGrabKeyboard(dsp, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); XGrabPointer(dsp, w, False, -1, GrabModeAsync, GrabModeAsync, None, mycursor, CurrentTime); srandom(time(NULL)); do { inithop(); ReadXString(buf, 10); } while (strcmp(crypt(buf, pw->pw_passwd), pw->pw_passwd)); XUngrabPointer(dsp, CurrentTime); XUngrabKeyboard(dsp, CurrentTime); XDestroyWindow(dsp, w); XFlush(dsp); } iterate() { double oldj; register int k; for (k=0;k<500;k++) { if (color) XSetForeground(dsp, gc, (iter % 25) * 10 + 5); XDrawPoint(dsp, w, gc, (int)i+centerx,centery-(int)j); oldj=j; j=a-i; i = oldj + (i<0?sqrt(fabs(b*i - c)):-sqrt(fabs(b*i - c))); iter++; } if (iter > maxiter) inithop(); } inithop() { a = random() % (range * 100) * (random()%2?-1.0:1.0) / 100.0; b = random() % (range * 100) * (random()%2?-1.0:1.0) / 100.0; c = random() % (range * 100) * (random()%2?-1.0:1.0) / 100.0; if (!(random()%3)) a /= 10.0; if (!(random()%2)) b /= 100.0; maxiter = (color?10000+random()%20000:20000+random()%50000); iter = 0; i = j = 0.0; XClearWindow(dsp, w); } SHAR_EOF if test -f 'xlock.man' then echo shar: over-writing existing file "'xlock.man'" fi cat << \SHAR_EOF > 'xlock.man' .TH XLOCK 1 "24 Mar 1988" "X Version 11" .SH NAME xlock \- Locks the X terminal till a password is entered. .SH SYNOPSIS .B xlock [\fI-color\fP] .SH DESCRIPTION .I xlock prompts the user for their password then locks the screen such that no mouse or keyboard actions are recognized till the user re-enters their password at the keyboard. The screen is blanked and the mouse cursor changes to the word \fILOCKED\fP. Then the "real plane" iterative fractals from the September 1986 issue of Scientific American are put on the screen. The pattern changes after 10-20K iterations or when the Return key is pressed. The password is not echoed to the screen and ^U and ^H are active as clear and rubout repectively. The [\fI-color\fP] option allows users of color frame buffers to get color output of the fractals. .SH BUGS There are no known bugs. .SH ENVIRONMENT DISPLAY is ignored! "unix:0" is used as the display for security reasons. .SH SEE ALSO X(1), Xlib Documentation. .SH AUTHOR Copyright (c) 1988 by Patrick Naughton (naughton@sun.soe.clarkson.edu) Clarkson University, Potsdam, NY Original version posted to comp.windows.x by: Walter Milliken (milliken@heron.bbn.com) BBN Advanced Computers, Inc., Cambridge, MA Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. SHAR_EOF if test -f 'Imakefile' then echo shar: over-writing existing file "'Imakefile'" fi cat << \SHAR_EOF > 'Imakefile' LOCAL_LIBRARIES = $(XLIB) SYS_LIBRARIES = -lm CFLAGS = -O -fswitch SRCS = xlock.c OBJS = xlock.o ComplexProgramTarget(xlock) SHAR_EOF # End of shell archive exit 0