xlock.c revision 919
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Permission is hereby granted, free of charge, to any person obtaining a
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * copy of this software and associated documentation files (the "Software"),
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * to deal in the Software without restriction, including without limitation
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * the rights to use, copy, modify, merge, publish, distribute, sublicense,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and/or sell copies of the Software, and to permit persons to whom the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Software is furnished to do so, subject to the following conditions:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The above copyright notice and this permission notice (including the next
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * paragraph) shall be included in all copies or substantial portions of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Software.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright * DEALINGS IN THE SOFTWARE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
12b65585e720714b31036daaa2b30eb76014048eGordon Ross/*
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * xlock.c - X11 client to lock a display and show a screen saver.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Copyright (c) 1988-91 by Patrick J. Naughton.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Permission to use, copy, modify, and distribute this software and its
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * documentation for any purpose and without fee is hereby granted,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * provided that the above copyright notice appear in all copies and that
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * both that copyright notice and this permission notice appear in
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai * supporting documentation.
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * This file is provided AS IS with no warranties of any kind. The author
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * shall have no liability with respect to the infringement of copyrights,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * trade secrets or any patents by this file or any part thereof. In no
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * event will the author be liable for any lost revenue or profits or
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * other special, indirect and consequential damages.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Comments and additions should be sent to the author:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai *
3db3f65c6274eb042354801a308c8e9bc4994553amw * naughton@eng.sun.com
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * Patrick J. Naughton
3db3f65c6274eb042354801a308c8e9bc4994553amw * MS 10-20
3db3f65c6274eb042354801a308c8e9bc4994553amw * Sun Laboritories, Inc.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 2550 Garcia Ave
3db3f65c6274eb042354801a308c8e9bc4994553amw * Mountain View, CA 94043
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * Revision History:
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * 24-Jun-91: make foreground and background color get used on mono.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 24-May-91: added -usefirst.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 16-May-91: added pyro and random modes.
3db3f65c6274eb042354801a308c8e9bc4994553amw * ripped big comment block out of all other files.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 08-Jan-91: fix some problems with password entry.
3db3f65c6274eb042354801a308c8e9bc4994553amw * removed renicing code.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 29-Oct-90: added cast to XFree() arg.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added volume arg to call to XBell().
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * 28-Oct-90: center prompt screen.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * make sure Xlib input buffer does not use up all of swap.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * make displayed text come from resource file for better I18N.
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * add backward compatible signal handlers for pre 4.1 machines.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 31-Aug-90: added blank mode.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added swarm mode.
3db3f65c6274eb042354801a308c8e9bc4994553amw * moved usleep() and seconds() out to usleep.c.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added SVR4 defines to xlock.h
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * 29-Jul-90: added support for multiple screens to be locked by one xlock.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * moved global defines to xlock.h
3db3f65c6274eb042354801a308c8e9bc4994553amw * removed use of allowsig().
3db3f65c6274eb042354801a308c8e9bc4994553amw * 07-Jul-90: reworked commandline args and resources to use Xrm.
3db3f65c6274eb042354801a308c8e9bc4994553amw * moved resource processing out to resource.c
3db3f65c6274eb042354801a308c8e9bc4994553amw * 02-Jul-90: reworked colors to not use dynamic colormap.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 23-May-90: added autoraise when obscured.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 15-Apr-90: added hostent alias searching for host authentication.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 18-Feb-90: added SunOS3.5 fix.
3db3f65c6274eb042354801a308c8e9bc4994553amw * changed -mono -> -color, and -saver -> -lock.
3db3f65c6274eb042354801a308c8e9bc4994553amw * allow non-locking screensavers to display on remote machine.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added -echokeys to disable echoing of '?'s on input.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleaned up all of the parameters and defaults.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 20-Dec-89: added -xhost to allow access control list to be left alone.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added -screensaver (don't disable screen saver) for the paranoid.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Moved seconds() here from all of the display mode source files.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Fixed bug with calling XUngrabHosts() in finish().
3db3f65c6274eb042354801a308c8e9bc4994553amw * 19-Dec-89: Fixed bug in GrabPointer.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Changed fontname to XLFD style.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 23-Sep-89: Added fix to allow local hostname:0 as a display.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Put empty case for Enter/Leave events.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Moved colormap installation later in startup.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * 20-Sep-89: Linted and made -saver mode grab the keyboard and mouse.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Replaced SunView code for life mode with Jim Graham's version,
3db3f65c6274eb042354801a308c8e9bc4994553amw * so I could contrib it without legal problems.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Sent to expo for X11R4 contrib.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 19-Sep-89: Added '?'s on input.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 27-Mar-89: Added -qix mode.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Fixed GContext->GC.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 20-Mar-89: Added backup font (fixed) if XQueryLoadFont() fails.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Changed default font to lucida-sans-24.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 08-Mar-89: Added -nice, -mode and -display, built vector for life and hop.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 24-Feb-89: Replaced hopalong display with life display from SunView1.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 22-Feb-89: Added fix for color servers with n < 8 planes.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 16-Feb-89: Updated calling conventions for XCreateHsbColormap();
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added -count for number of iterations per color.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Fixed defaulting mechanism.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Ripped out VMS hacks.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Sent to expo for X11R3 contrib.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 15-Feb-89: Changed default font to pellucida-sans-18.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 20-Jan-89: Added -verbose and fixed usage message.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 19-Jan-89: Fixed monochrome gc bug.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 16-Dec-88: Added SunView style password prompting.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 19-Sep-88: Changed -color to -mono. (default is color on color displays).
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added -saver option. (just do display... don't lock.)
3db3f65c6274eb042354801a308c8e9bc4994553amw * 31-Aug-88: Added -time option.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Removed code for fractals to separate file for modularity.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added signal handler to restore host access.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Installs dynamic colormap with a Hue Ramp.
3db3f65c6274eb042354801a308c8e9bc4994553amw * If grabs fail then exit.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added VMS Hacks. (password 'iwiwuu').
3db3f65c6274eb042354801a308c8e9bc4994553amw * Sent to expo for X11R2 contrib.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 08-Jun-88: Fixed root password pointer problem and changed PASSLENGTH to 20.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 20-May-88: Added -root to allow root to unlock.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 12-Apr-88: Added root password override.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added screen saver override.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Removed XGrabServer/XUngrabServer.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Added access control handling instead.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 01-Apr-88: Added XGrabServer/XUngrabServer for more security.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 30-Mar-88: Removed startup password requirement.
3db3f65c6274eb042354801a308c8e9bc4994553amw * Removed cursor to avoid phosphor burn.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 27-Mar-88: Rotate fractal by 45 degrees clockwise.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 24-Mar-88: Added color support. [-color]
3db3f65c6274eb042354801a308c8e9bc4994553amw * wrote the man page.
3db3f65c6274eb042354801a308c8e9bc4994553amw * 23-Mar-88: Added HOPALONG routines from Scientific American Sept. 86 p. 14.
3db3f65c6274eb042354801a308c8e9bc4994553amw * added password requirement for invokation
3db3f65c6274eb042354801a308c8e9bc4994553amw * removed option for command line password
3db3f65c6274eb042354801a308c8e9bc4994553amw * added requirement for display to be "unix:0".
3db3f65c6274eb042354801a308c8e9bc4994553amw * 22-Mar-88: Recieved Walter Milliken's comp.windows.x posting.
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <stdio.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <signal.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <string.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <shadow.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <pwd.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#include "xlock.h"
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#include <X11/cursorfont.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#include <X11/Xatom.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef USE_PAM
3db3f65c6274eb042354801a308c8e9bc4994553amw# include <security/pam_appl.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw# ifndef XLOCK_PAM_SERVICE
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego# define XLOCK_PAM_SERVICE "xlock"
3db3f65c6274eb042354801a308c8e9bc4994553amw# endif
3db3f65c6274eb042354801a308c8e9bc4994553amw# define PAM_ERROR_PRINT(pamfunc) \
3db3f65c6274eb042354801a308c8e9bc4994553amw if (verbose) { \
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "%s: %s failure: %s\n", ProgramName, pamfunc, \
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_strerror(pamh, pam_error)); \
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw# ifdef sun
3db3f65c6274eb042354801a308c8e9bc4994553amw# include <deflt.h>
12b65585e720714b31036daaa2b30eb76014048eGordon Ross# endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw
12b65585e720714b31036daaa2b30eb76014048eGordon Rosschar *ProgramName; /* argv[0] */
3db3f65c6274eb042354801a308c8e9bc4994553amwperscreen Scr[MAXSCREENS];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwDisplay *dsp = NULL; /* server display connection */
3db3f65c6274eb042354801a308c8e9bc4994553amwint screen; /* current screen */
3db3f65c6274eb042354801a308c8e9bc4994553amwvoid (*callback) () = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amwvoid (*init) () = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int screens; /* number of screens */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Window win[MAXSCREENS]; /* window used to cover screen */
12b65585e720714b31036daaa2b30eb76014048eGordon Rossstatic Window icon[MAXSCREENS]; /* window used during password typein */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Window root[MAXSCREENS]; /* convenience pointer to the root window */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic GC textgc[MAXSCREENS]; /* graphics context used for text rendering */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic XColor fgcol[MAXSCREENS];/* used for text rendering */
12b65585e720714b31036daaa2b30eb76014048eGordon Rossstatic XColor bgcol[MAXSCREENS];/* background of text screen */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwXColor ssblack[MAXSCREENS];/* black color for screen saver screen */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwXColor sswhite[MAXSCREENS];/* white color for screen saver screen */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int iconx[MAXSCREENS]; /* location of left edge of icon */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int icony[MAXSCREENS]; /* location of top edge of icon */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Cursor mycursor; /* blank cursor */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic Cursor passwdcursor; /* cursor used in getPassword */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic Pixmap lockc;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic Pixmap lockm; /* pixmaps for cursor and mask */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rossstatic char no_bits[] = {0}; /* dummy array for the blank cursor */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int passx; /* position of the ?'s */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int passy;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic XFontStruct *font;
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int sstimeout; /* screen saver parameters */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int ssinterval;
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int ssblanking;
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int ssexposures;
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic char buffer[PAM_MAX_RESP_SIZE];
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Bool reallyechokeys = False; /* Echo real keys instead of ?'s */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Bool stoptryingfornow = False;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#define FALLBACK_FONTNAME "fixed"
3db3f65c6274eb042354801a308c8e9bc4994553amw#define ICONW 64
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define ICONH 64
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef DEBUG
3db3f65c6274eb042354801a308c8e9bc4994553amw#define WIDTH WidthOfScreen(scr) - 100
3db3f65c6274eb042354801a308c8e9bc4994553amw#define HEIGHT HeightOfScreen(scr) - 100
3db3f65c6274eb042354801a308c8e9bc4994553amw#define CWMASK CWBackPixel | CWEventMask | CWColormap
3db3f65c6274eb042354801a308c8e9bc4994553amw#else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#define WIDTH WidthOfScreen(scr)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#define HEIGHT HeightOfScreen(scr)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#define CWMASK CWOverrideRedirect | CWBackPixel | CWEventMask | CWColormap
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#endif
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#define AllPointerEventMask \
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross (ButtonPressMask | ButtonReleaseMask | \
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross EnterWindowMask | LeaveWindowMask | \
3db3f65c6274eb042354801a308c8e9bc4994553amw PointerMotionMask | PointerMotionHintMask | \
3db3f65c6274eb042354801a308c8e9bc4994553amw Button1MotionMask | Button2MotionMask | \
3db3f65c6274eb042354801a308c8e9bc4994553amw Button3MotionMask | Button4MotionMask | \
3db3f65c6274eb042354801a308c8e9bc4994553amw Button5MotionMask | ButtonMotionMask | \
3db3f65c6274eb042354801a308c8e9bc4994553amw KeymapStateMask)
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* VARARGS1 */
3db3f65c6274eb042354801a308c8e9bc4994553amwvoid
3db3f65c6274eb042354801a308c8e9bc4994553amwerror(s1, s2)
3db3f65c6274eb042354801a308c8e9bc4994553amw char *s1, *s2;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, s1, ProgramName, s2);
3db3f65c6274eb042354801a308c8e9bc4994553amw exit(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw/*
3db3f65c6274eb042354801a308c8e9bc4994553amw * Server access control support.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic XHostAddress *XHosts; /* the list of "friendly" client machines */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int HostAccessCount; /* the number of machines in XHosts */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic Bool HostAccessState; /* whether or not we even look at the list */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwXGrabHosts(dsp)
3db3f65c6274eb042354801a308c8e9bc4994553amw Display *dsp;
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw XHosts = XListHosts(dsp, &HostAccessCount, &HostAccessState);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (XHosts)
3db3f65c6274eb042354801a308c8e9bc4994553amw XRemoveHosts(dsp, XHosts, HostAccessCount);
3db3f65c6274eb042354801a308c8e9bc4994553amw XEnableAccessControl(dsp);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwXUngrabHosts(dsp)
3db3f65c6274eb042354801a308c8e9bc4994553amw Display *dsp;
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw if (XHosts) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XAddHosts(dsp, XHosts, HostAccessCount);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFree((char *) XHosts);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (HostAccessState == False)
3db3f65c6274eb042354801a308c8e9bc4994553amw XDisableAccessControl(dsp);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego}
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego/*
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright * Simple wrapper to get an asynchronous grab on the keyboard and mouse.
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego * If either grab fails, we sleep for one second and try again since some
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego * window manager might have had the mouse grabbed to drive the menu choice
3db3f65c6274eb042354801a308c8e9bc4994553amw * that picked "Lock Screen..". If either one fails the second time we print
3db3f65c6274eb042354801a308c8e9bc4994553amw * an error message and exit.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwGrabKeyboardAndMouse()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego Status status;
3db3f65c6274eb042354801a308c8e9bc4994553amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego status = XGrabKeyboard(dsp, win[0], True,
3db3f65c6274eb042354801a308c8e9bc4994553amw GrabModeAsync, GrabModeAsync, CurrentTime);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (status != GrabSuccess) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego sleep(1);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego status = XGrabKeyboard(dsp, win[0], True,
f96bd5c800e73e351b0b6e4bd7f00b578dad29bbAlan Wright GrabModeAsync, GrabModeAsync, CurrentTime);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego if (status != GrabSuccess)
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego error("%s: couldn't grab keyboard! (%d)\n", status);
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego }
3db3f65c6274eb042354801a308c8e9bc4994553amw status = XGrabPointer(dsp, win[0], True, AllPointerEventMask,
3db3f65c6274eb042354801a308c8e9bc4994553amw GrabModeAsync, GrabModeAsync, None, mycursor,
3db3f65c6274eb042354801a308c8e9bc4994553amw CurrentTime);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (status != GrabSuccess) {
3db3f65c6274eb042354801a308c8e9bc4994553amw sleep(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw status = XGrabPointer(dsp, win[0], True, AllPointerEventMask,
3db3f65c6274eb042354801a308c8e9bc4994553amw GrabModeAsync, GrabModeAsync, None, mycursor,
3db3f65c6274eb042354801a308c8e9bc4994553amw CurrentTime);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (status != GrabSuccess)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error("%s: couldn't grab pointer! (%d)\n", status);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw/*
3db3f65c6274eb042354801a308c8e9bc4994553amw * Assuming that we already have an asynch grab on the pointer,
3db3f65c6274eb042354801a308c8e9bc4994553amw * just grab it again with a new cursor shape and ignore the return code.
3db3f65c6274eb042354801a308c8e9bc4994553amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwXChangeGrabbedCursor(cursor)
3db3f65c6274eb042354801a308c8e9bc4994553amw Cursor cursor;
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifndef DEBUG
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) XGrabPointer(dsp, win[0], True, AllPointerEventMask,
3db3f65c6274eb042354801a308c8e9bc4994553amw GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
3db3f65c6274eb042354801a308c8e9bc4994553amw/*
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown * Restore all grabs, reset screensaver, restore colormap, close connection.
3db3f65c6274eb042354801a308c8e9bc4994553amw */
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwfinish()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw XSync(dsp, False);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!nolock && !allowaccess)
3db3f65c6274eb042354801a308c8e9bc4994553amw XUngrabHosts(dsp);
3db3f65c6274eb042354801a308c8e9bc4994553amw XUngrabPointer(dsp, CurrentTime);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross XUngrabKeyboard(dsp, CurrentTime);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!enablesaver)
3db3f65c6274eb042354801a308c8e9bc4994553amw XSetScreenSaver(dsp, sstimeout, ssinterval, ssblanking, ssexposures);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFlush(dsp);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown XCloseDisplay(dsp);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic int
3db3f65c6274eb042354801a308c8e9bc4994553amwReadXString(s, slen)
3db3f65c6274eb042354801a308c8e9bc4994553amw char *s;
3db3f65c6274eb042354801a308c8e9bc4994553amw int slen;
3db3f65c6274eb042354801a308c8e9bc4994553amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XEvent event;
3db3f65c6274eb042354801a308c8e9bc4994553amw char keystr[20];
3db3f65c6274eb042354801a308c8e9bc4994553amw char c;
3db3f65c6274eb042354801a308c8e9bc4994553amw int i;
3db3f65c6274eb042354801a308c8e9bc4994553amw int bp;
3db3f65c6274eb042354801a308c8e9bc4994553amw int len;
3db3f65c6274eb042354801a308c8e9bc4994553amw int thisscreen = screen;
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai char pwbuf[PAM_MAX_RESP_SIZE];
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw for (screen = 0; screen < screens; screen++)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (thisscreen == screen)
3db3f65c6274eb042354801a308c8e9bc4994553amw init(icon[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw else
3db3f65c6274eb042354801a308c8e9bc4994553amw init(win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw bp = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *s = 0;
3db3f65c6274eb042354801a308c8e9bc4994553amw while (True) {
3db3f65c6274eb042354801a308c8e9bc4994553amw unsigned long lasteventtime = seconds();
3db3f65c6274eb042354801a308c8e9bc4994553amw while (!XPending(dsp)) {
3db3f65c6274eb042354801a308c8e9bc4994553amw for (screen = 0; screen < screens; screen++)
3db3f65c6274eb042354801a308c8e9bc4994553amw if (thisscreen == screen)
3db3f65c6274eb042354801a308c8e9bc4994553amw callback(icon[screen]);
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai else
3db3f65c6274eb042354801a308c8e9bc4994553amw callback(win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFlush(dsp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw usleep(delay);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (seconds() - lasteventtime > timeout) {
3db3f65c6274eb042354801a308c8e9bc4994553amw screen = thisscreen;
3db3f65c6274eb042354801a308c8e9bc4994553amw stoptryingfornow = True;
3db3f65c6274eb042354801a308c8e9bc4994553amw return 1;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw screen = thisscreen;
3db3f65c6274eb042354801a308c8e9bc4994553amw XNextEvent(dsp, &event);
3db3f65c6274eb042354801a308c8e9bc4994553amw switch (event.type) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case KeyPress:
3db3f65c6274eb042354801a308c8e9bc4994553amw len = XLookupString((XKeyEvent *) & event, keystr, 20, NULL, NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw for (i = 0; i < len; i++) {
3db3f65c6274eb042354801a308c8e9bc4994553amw c = keystr[i];
3db3f65c6274eb042354801a308c8e9bc4994553amw switch (c) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case 8: /* ^H */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case 127: /* DEL */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (bp > 0)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bp--;
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw case 10: /* ^J */
3db3f65c6274eb042354801a308c8e9bc4994553amw case 13: /* ^M */
3db3f65c6274eb042354801a308c8e9bc4994553amw s[bp] = '\0';
3db3f65c6274eb042354801a308c8e9bc4994553amw /*
3db3f65c6274eb042354801a308c8e9bc4994553amw * eat all events if there are more than enough pending... this
3db3f65c6274eb042354801a308c8e9bc4994553amw * keeps the Xlib event buffer from growing larger than all
3db3f65c6274eb042354801a308c8e9bc4994553amw * available memory and crashing xlock.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (XPending(dsp) > 100) { /* 100 is arbitrarily big enough */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw register Status status;
3db3f65c6274eb042354801a308c8e9bc4994553amw do {
3db3f65c6274eb042354801a308c8e9bc4994553amw status = XCheckMaskEvent(dsp,
3db3f65c6274eb042354801a308c8e9bc4994553amw KeyPressMask | KeyReleaseMask, &event);
3db3f65c6274eb042354801a308c8e9bc4994553amw } while (status);
3db3f65c6274eb042354801a308c8e9bc4994553amw XBell(dsp, 100);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw return 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case 21: /* ^U */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw bp = 0;
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw default:
3db3f65c6274eb042354801a308c8e9bc4994553amw s[bp] = c;
3db3f65c6274eb042354801a308c8e9bc4994553amw if (bp < slen - 1)
3db3f65c6274eb042354801a308c8e9bc4994553amw bp++;
3db3f65c6274eb042354801a308c8e9bc4994553amw else
3db3f65c6274eb042354801a308c8e9bc4994553amw XSync(dsp, True); /* flush input buffer */
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XSetForeground(dsp, Scr[screen].gc, bgcol[screen].pixel);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (echokeys || reallyechokeys) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (reallyechokeys) {
3db3f65c6274eb042354801a308c8e9bc4994553amw memcpy(pwbuf, s, slen);
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(pwbuf, '?', slen);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw XFillRectangle(dsp, win[screen], Scr[screen].gc,
3db3f65c6274eb042354801a308c8e9bc4994553amw passx, passy - font->ascent,
3db3f65c6274eb042354801a308c8e9bc4994553amw XTextWidth(font, pwbuf, slen),
3db3f65c6274eb042354801a308c8e9bc4994553amw font->ascent + font->descent);
3db3f65c6274eb042354801a308c8e9bc4994553amw XDrawString(dsp, win[screen], textgc[screen],
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw passx, passy, pwbuf, bp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /*
3db3f65c6274eb042354801a308c8e9bc4994553amw * eat all events if there are more than enough pending... this
3db3f65c6274eb042354801a308c8e9bc4994553amw * keeps the Xlib event buffer from growing larger than all
3db3f65c6274eb042354801a308c8e9bc4994553amw * available memory and crashing xlock.
3db3f65c6274eb042354801a308c8e9bc4994553amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (XPending(dsp) > 100) { /* 100 is arbitrarily big enough */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw register Status status;
3db3f65c6274eb042354801a308c8e9bc4994553amw do {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw status = XCheckMaskEvent(dsp,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw KeyPressMask | KeyReleaseMask, &event);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw } while (status);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XBell(dsp, 100);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case ButtonPress:
3db3f65c6274eb042354801a308c8e9bc4994553amw if (((XButtonEvent *) & event)->window == icon[screen]) {
3db3f65c6274eb042354801a308c8e9bc4994553amw stoptryingfornow = True;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return 1;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case VisibilityNotify:
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (event.xvisibility.state != VisibilityUnobscured) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#ifndef DEBUG
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross XRaiseWindow(dsp, win[screen]);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw s[0] = '\0';
3db3f65c6274eb042354801a308c8e9bc4994553amw return 1;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case KeymapNotify:
3db3f65c6274eb042354801a308c8e9bc4994553amw case KeyRelease:
3db3f65c6274eb042354801a308c8e9bc4994553amw case ButtonRelease:
3db3f65c6274eb042354801a308c8e9bc4994553amw case MotionNotify:
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case LeaveNotify:
3db3f65c6274eb042354801a308c8e9bc4994553amw case EnterNotify:
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw default:
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "%s: unexpected event: %d\n",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ProgramName, event.type);
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwCheckPassword()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw struct spwd *rspw, *uspw;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct passwd *upw;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *user;
3db3f65c6274eb042354801a308c8e9bc4994553amw#else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw struct passwd *rpw, *upw;
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* SYSV */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw rspw = getspnam("root");
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw upw = (struct passwd *)getpwuid(getuid());
3db3f65c6274eb042354801a308c8e9bc4994553amw if (upw == NULL) { /* should not pass NULL to getspnam */
3db3f65c6274eb042354801a308c8e9bc4994553amw user = "";
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else {
3db3f65c6274eb042354801a308c8e9bc4994553amw user = upw->pw_name;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw uspw = getspnam(user);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!uspw) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (allowroot) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!rspw)
3db3f65c6274eb042354801a308c8e9bc4994553amw return(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw else
3db3f65c6274eb042354801a308c8e9bc4994553amw return(0);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#else /* SYSV */
3db3f65c6274eb042354801a308c8e9bc4994553amw rpw = (struct passwd *)getpwuid(0);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw upw = (struct passwd *)getpwuid(getuid());
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!upw) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (allowroot) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!rpw)
3db3f65c6274eb042354801a308c8e9bc4994553amw return(1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return(0);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* SYSV */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw return(0);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void passwordPrompt(const char *prompt)
3db3f65c6274eb042354801a308c8e9bc4994553amw{
12b65585e720714b31036daaa2b30eb76014048eGordon Ross int y, left;
12b65585e720714b31036daaa2b30eb76014048eGordon Ross Screen *scr = ScreenOfDisplay(dsp, screen);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw left = iconx[screen] + ICONW + font->max_bounds.width;
3db3f65c6274eb042354801a308c8e9bc4994553amw y = icony[screen] + font->ascent + font->ascent + font->descent + 2;
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XSetForeground(dsp, Scr[screen].gc, bgcol[screen].pixel);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XFillRectangle(dsp, win[screen], Scr[screen].gc,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw left, y - font->ascent, WIDTH - left,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw font->ascent + font->descent + 2);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XDrawString(dsp, win[screen], textgc[screen],
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw left, y, prompt, strlen(prompt));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XDrawString(dsp, win[screen], textgc[screen],
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw left + 1, y, prompt, strlen(prompt));
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw passx = left + 1 + XTextWidth(font, prompt, strlen(prompt))
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw + XTextWidth(font, " ", 1);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw passy = y;
12b65585e720714b31036daaa2b30eb76014048eGordon Ross}
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void displayTextInfo(const char *infoMsg)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw{
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw int y;
3db3f65c6274eb042354801a308c8e9bc4994553amw Screen *scr = ScreenOfDisplay(dsp, screen);
3db3f65c6274eb042354801a308c8e9bc4994553amw
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross y = icony[screen] + ICONH + font->ascent + 2;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross XSetForeground(dsp, Scr[screen].gc, bgcol[screen].pixel);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
3db3f65c6274eb042354801a308c8e9bc4994553amw XFillRectangle(dsp, win[screen], Scr[screen].gc,
3db3f65c6274eb042354801a308c8e9bc4994553amw iconx[screen], y - font->ascent,
3db3f65c6274eb042354801a308c8e9bc4994553amw WIDTH - iconx[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw font->ascent + font->descent + 2);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw XDrawString(dsp, win[screen], textgc[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw iconx[screen], y, infoMsg, strlen(infoMsg));
3db3f65c6274eb042354801a308c8e9bc4994553amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef USE_PAM
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int pamconv(int num_msg, struct pam_message **msg,
3db3f65c6274eb042354801a308c8e9bc4994553amw struct pam_response **response, void *appdata_ptr)
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw int i;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego int status = PAM_SUCCESS;
3db3f65c6274eb042354801a308c8e9bc4994553amw
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego struct pam_message *m;
3db3f65c6274eb042354801a308c8e9bc4994553amw struct pam_response *r;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *response = calloc(num_msg, sizeof (struct pam_response));
3db3f65c6274eb042354801a308c8e9bc4994553amw if (*response == NULL)
3db3f65c6274eb042354801a308c8e9bc4994553amw return (PAM_BUF_ERR);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw m = *msg;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw r = *response;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross for (i = 0; i < num_msg; i++ , m++ , r++) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#ifdef DEBUG
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (verbose) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross fprintf(stderr, "pam_msg: %d: '%s'\n", m->msg_style, m->msg);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross }
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw switch (m->msg_style) {
3db3f65c6274eb042354801a308c8e9bc4994553amw case PAM_ERROR_MSG:
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai case PAM_TEXT_INFO:
3db3f65c6274eb042354801a308c8e9bc4994553amw displayTextInfo(m->msg);
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw case PAM_PROMPT_ECHO_ON:
3db3f65c6274eb042354801a308c8e9bc4994553amw reallyechokeys = True;
3db3f65c6274eb042354801a308c8e9bc4994553amw /* FALLTHRU */
3db3f65c6274eb042354801a308c8e9bc4994553amw case PAM_PROMPT_ECHO_OFF:
3db3f65c6274eb042354801a308c8e9bc4994553amw passwordPrompt(m->msg);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (ReadXString(buffer, PAM_MAX_RESP_SIZE)) {
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego /* timeout or other error */
3db3f65c6274eb042354801a308c8e9bc4994553amw status = PAM_CONV_ERR;
2c2961f8403049d948b9f3e6c35d6488b6b7e1aajose borrego i = num_msg;
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw r->resp = strdup(buffer);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (r->resp == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw status = PAM_BUF_ERR;
3db3f65c6274eb042354801a308c8e9bc4994553amw i = num_msg;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef DEBUG
3db3f65c6274eb042354801a308c8e9bc4994553amw if (verbose) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw fprintf(stderr, "pam_resp: '%s'\n", r->resp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw reallyechokeys = False;
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw default:
3db3f65c6274eb042354801a308c8e9bc4994553amw if (verbose) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw fprintf(stderr, "%s: Unknown PAM msg_style: %d\n",
3db3f65c6274eb042354801a308c8e9bc4994553amw ProgramName, m->msg_style);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (status != PAM_SUCCESS) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* free responses */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw r = *response;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < num_msg; i++, r++) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (r->resp)
3db3f65c6274eb042354801a308c8e9bc4994553amw free(r->resp);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw free(*response);
3db3f65c6274eb042354801a308c8e9bc4994553amw *response = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw return status;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <syslog.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <bsm/adt.h>
3db3f65c6274eb042354801a308c8e9bc4994553amw#include <bsm/adt_event.h>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
3db3f65c6274eb042354801a308c8e9bc4994553amw * audit_lock - audit entry to screenlock
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * Entry Process running with appropriate privilege to generate
3db3f65c6274eb042354801a308c8e9bc4994553amw * audit records and real uid of the user.
3db3f65c6274eb042354801a308c8e9bc4994553amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Exit ADT_screenlock audit record written.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwaudit_lock(void)
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_session_data_t *ah; /* audit session handle */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw adt_event_data_t *event; /* audit event handle */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw /* Audit start of screen lock -- equivalent to logout ;-) */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (adt_start_session(&ah, NULL, ADT_USE_PROC_DATA) != 0) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT, "adt_start_session: %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw return;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if ((event = adt_alloc_event(ah, ADT_screenlock)) == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_alloc_event(ADT_screenlock): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (adt_put_event(event, ADT_SUCCESS, ADT_SUCCESS) != 0) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_put_event(ADT_screenlock): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_free_event(event);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) adt_end_session(ah);
12b65585e720714b31036daaa2b30eb76014048eGordon Ross}
12b65585e720714b31036daaa2b30eb76014048eGordon Ross
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw/*
3db3f65c6274eb042354801a308c8e9bc4994553amw * audit_unlock - audit screen unlock
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Entry Process running with appropriate privilege to generate
3db3f65c6274eb042354801a308c8e9bc4994553amw * audit records and real uid of the user.
3db3f65c6274eb042354801a308c8e9bc4994553amw * pam_status = PAM error code; reason for failure.
3db3f65c6274eb042354801a308c8e9bc4994553amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * Exit ADT_screenunlock audit record written.
3db3f65c6274eb042354801a308c8e9bc4994553amw */
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desaistatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwaudit_unlock(int pam_status)
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_session_data_t *ah; /* audit session handle */
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_event_data_t *event; /* audit event handle */
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (adt_start_session(&ah, NULL, ADT_USE_PROC_DATA) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_start_session(ADT_screenunlock): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw return;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if ((event = adt_alloc_event(ah, ADT_screenunlock)) == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
e3f2c991a8548408db0a2787bd8b43d5124821d3Keyur Desai syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_alloc_event(ADT_screenunlock): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (adt_put_event(event,
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status == PAM_SUCCESS ? ADT_SUCCESS : ADT_FAILURE,
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status == PAM_SUCCESS ? ADT_SUCCESS : ADT_FAIL_PAM +
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status) != 0) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_put_event(ADT_screenunlock(%s): %m",
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw pam_strerror(NULL, pam_status));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw adt_free_event(event);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) adt_end_session(ah);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/*
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * audit_passwd - audit password change
3db3f65c6274eb042354801a308c8e9bc4994553amw * Entry Process running with appropriate privilege to generate
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * audit records and real uid of the user.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * pam_status = PAM error code; reason for failure.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw *
3db3f65c6274eb042354801a308c8e9bc4994553amw * Exit ADT_passwd audit record written.
12b65585e720714b31036daaa2b30eb76014048eGordon Ross */
12b65585e720714b31036daaa2b30eb76014048eGordon Rossstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwaudit_passwd(int pam_status)
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_session_data_t *ah; /* audit session handle */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw adt_event_data_t *event; /* audit event handle */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (adt_start_session(&ah, NULL, ADT_USE_PROC_DATA) != 0) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_start_session(ADT_passwd): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw return;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if ((event = adt_alloc_event(ah, ADT_passwd)) == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT,
3db3f65c6274eb042354801a308c8e9bc4994553amw "adt_alloc_event(ADT_passwd): %m");
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (adt_put_event(event,
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status == PAM_SUCCESS ? ADT_SUCCESS : ADT_FAILURE,
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status == PAM_SUCCESS ? ADT_SUCCESS : ADT_FAIL_PAM +
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_status) != 0) {
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw syslog(LOG_AUTH | LOG_ALERT,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross "adt_put_event(ADT_passwd(%s): %m",
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_strerror(NULL, pam_status));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw adt_free_event(event);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw (void) adt_end_session(ah);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic int
3db3f65c6274eb042354801a308c8e9bc4994553amwgetPassword()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw char *userpass = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *rootpass = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw XWindowAttributes xgwa;
3db3f65c6274eb042354801a308c8e9bc4994553amw int y, left, done;
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw struct spwd *rspw, *uspw;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *suserpass = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *srootpass = NULL;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *user;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#else
3db3f65c6274eb042354801a308c8e9bc4994553amw char *user = getenv("USER");
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#endif /* SYSV */
3db3f65c6274eb042354801a308c8e9bc4994553amw struct passwd *rpw, *upw;
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef USE_PAM
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_handle_t *pamh = NULL;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross struct pam_conv pc;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross Bool use_pam = True;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross int pam_error;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross int pam_flags = 0;
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#endif
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross const char *authErrMsg = text_invalid;
3db3f65c6274eb042354801a308c8e9bc4994553amw
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw rpw = getpwuid(0);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (rpw) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross user = rpw->pw_name;
3db3f65c6274eb042354801a308c8e9bc4994553amw rootpass = strdup(rpw->pw_passwd);
3db3f65c6274eb042354801a308c8e9bc4994553amw
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross rspw = getspnam(user);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (rspw && rspw->sp_pwdp)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross srootpass = strdup(rspw->sp_pwdp);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross upw = getpwuid(getuid());
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (upw) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross user = upw->pw_name;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross userpass = strdup(upw->pw_passwd);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross uspw = getspnam(user);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (uspw && uspw->sp_pwdp)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross suserpass = strdup(uspw->sp_pwdp);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross else
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross user = "";
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#else
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross rpw = (struct passwd *)getpwuid(0);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (rpw)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross rootpass = strdup(rpw->pw_passwd);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross upw = (struct passwd *)getpwuid(getuid());
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (upw)
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross userpass = strdup(upw->pw_passwd);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#endif /* SYSV */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#ifdef USE_PAM
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pc.conv = pamconv;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error = pam_start(XLOCK_PAM_SERVICE, user, &pc, &pamh);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (pam_error != PAM_SUCCESS) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross use_pam = False;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross PAM_ERROR_PRINT("pam_start");
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross } else {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#ifdef sun
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross /* Check /etc/default/login to see if we should add
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross PAM_DISALLOW_NULL_AUTHTOK to pam_flags */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (defopen("/etc/default/login") == 0) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross char *ptr;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross int flags = defcntl(DC_GETFLAGS, 0);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross TURNOFF(flags, DC_CASE);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross (void) defcntl(DC_SETFLAGS, flags);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if ((ptr = defread("PASSREQ=")) != NULL &&
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross strcasecmp("YES", ptr) == 0) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_flags |= PAM_DISALLOW_NULL_AUTHTOK;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross (void) defopen((char *)NULL); /* close current file */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#endif
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#ifdef SYSV
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross /* Disable user password non-PAM authentication */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (userpass) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross memset(userpass, 0, strlen(userpass));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross free(userpass);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross userpass = NULL;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (suserpass) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross memset(suserpass, 0, strlen(suserpass));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross free(suserpass);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross suserpass = NULL;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#endif
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross }
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#endif /* USE_PAM */
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XGetWindowAttributes(dsp, win[screen], &xgwa);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XChangeGrabbedCursor(passwdcursor);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XSetForeground(dsp, Scr[screen].gc, bgcol[screen].pixel);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XFillRectangle(dsp, win[screen], Scr[screen].gc,
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross 0, 0, xgwa.width, xgwa.height);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XMapWindow(dsp, icon[screen]);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XRaiseWindow(dsp, icon[screen]);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross left = iconx[screen] + ICONW + font->max_bounds.width;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross y = icony[screen] + font->ascent;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XDrawString(dsp, win[screen], textgc[screen],
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross left, y, text_name, strlen(text_name));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XDrawString(dsp, win[screen], textgc[screen],
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross left + 1, y, text_name, strlen(text_name));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XDrawString(dsp, win[screen], textgc[screen],
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross left + XTextWidth(font, text_name, strlen(text_name)), y,
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross user, strlen(user));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross y = icony[screen] - (font->descent + 2);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XDrawString(dsp, win[screen], textgc[screen],
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross iconx[screen], y, text_info, strlen(text_info));
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross passwordPrompt(text_pass);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross XFlush(dsp);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross y = icony[screen] + ICONH + font->ascent + 2
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross + font->ascent + font->descent + 2;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross done = False;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross stoptryingfornow = False;
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross while (!done) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross#ifdef USE_PAM
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (use_pam) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error = pam_authenticate(pamh, pam_flags);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (pam_error == PAM_SUCCESS) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross const char *pam_error_from = "pam_acct_mgmt";
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error = pam_acct_mgmt(pamh, pam_flags);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross if (pam_error == PAM_NEW_AUTHTOK_REQD) {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross do {
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error = pam_chauthtok(pamh,
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross PAM_CHANGE_EXPIRED_AUTHTOK);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross } while (pam_error == PAM_AUTHTOK_ERR ||
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error == PAM_TRY_AGAIN);
7f3ef643e446c82e27a9386991b140b128baf22cGordon Ross pam_error_from = "pam_chauthtok";
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
3db3f65c6274eb042354801a308c8e9bc4994553amw audit_passwd(pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (pam_error == PAM_SUCCESS) {
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_error = pam_setcred(pamh,PAM_REFRESH_CRED);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (pam_error != PAM_SUCCESS) {
3db3f65c6274eb042354801a308c8e9bc4994553amw PAM_ERROR_PRINT("pam_setcred(PAM_REFRESH_CRED)");
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = True;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
3db3f65c6274eb042354801a308c8e9bc4994553amw audit_unlock(pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw PAM_ERROR_PRINT(pam_error_from);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross } else if (stoptryingfornow) {
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
3db3f65c6274eb042354801a308c8e9bc4994553amw audit_unlock(pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw PAM_ERROR_PRINT("pam_authenticate");
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (pam_error != PAM_SUCCESS) {
3db3f65c6274eb042354801a308c8e9bc4994553amw authErrMsg = pam_strerror(pamh, pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw } else
3db3f65c6274eb042354801a308c8e9bc4994553amw if (ReadXString(buffer, PAM_MAX_RESP_SIZE))
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw /*
3db3f65c6274eb042354801a308c8e9bc4994553amw * This section gets a little messy. In SYSV, the number of
3db3f65c6274eb042354801a308c8e9bc4994553amw * cases to handle increases because of the existence of the
3db3f65c6274eb042354801a308c8e9bc4994553amw * shadow file. There are also a number of cases that need
3db3f65c6274eb042354801a308c8e9bc4994553amw * to be dealt with where either root or user passwords are
3db3f65c6274eb042354801a308c8e9bc4994553amw * nil. Hopefully the code below is easy enough to follow.
3db3f65c6274eb042354801a308c8e9bc4994553amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw if (userpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (*userpass == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (*buffer == NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (!strcmp(crypt(buffer, userpass), userpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!done && suserpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (*suserpass == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (*buffer == NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (!strcmp(crypt(buffer, suserpass), suserpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!done && allowroot) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (srootpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (*srootpass == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (*buffer == NULL);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw done = (!strcmp(crypt(buffer, srootpass), srootpass));
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross }
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!done && rootpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (*rootpass == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw done = (*buffer == NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw done = (!strcmp(crypt(buffer, rootpass), rootpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#else
3db3f65c6274eb042354801a308c8e9bc4994553amw done = !((strcmp(crypt(buffer, userpass), userpass))
3db3f65c6274eb042354801a308c8e9bc4994553amw && (!allowroot || strcmp(crypt(buffer, rootpass), rootpass)));
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!done && *buffer == NULL) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* just hit return, and it wasn't his password */
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (*userpass == NULL && *buffer != NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw /*
3db3f65c6274eb042354801a308c8e9bc4994553amw * the user has no password, but something was typed anyway.
3db3f65c6274eb042354801a308c8e9bc4994553amw * sounds fishy: don't let him in...
3db3f65c6274eb042354801a308c8e9bc4994553amw */
3db3f65c6274eb042354801a308c8e9bc4994553amw done = False;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* SYSV */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw /* clear plaintext password so you can't grunge around /dev/kmem */
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(buffer, 0, sizeof(buffer));
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw displayTextInfo(text_valid);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (done) {
3db3f65c6274eb042354801a308c8e9bc4994553amw /* clear encrypted passwords just in case */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (rootpass) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw memset(rootpass, 0, strlen(rootpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(rootpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (userpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(userpass, 0, strlen(userpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(userpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (srootpass) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw memset(srootpass, 0, strlen(srootpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(srootpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (suserpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(suserpass, 0, strlen(suserpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(suserpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef USE_PAM
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw audit_unlock(pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_end(pamh, pam_error);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw return 0;
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw XSync(dsp, True); /* flush input buffer */
3db3f65c6274eb042354801a308c8e9bc4994553amw sleep(1);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw displayTextInfo(authErrMsg);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (echokeys || reallyechokeys) /* erase old echo */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XFillRectangle(dsp, win[screen], Scr[screen].gc,
3db3f65c6274eb042354801a308c8e9bc4994553amw passx, passy - font->ascent,
3db3f65c6274eb042354801a308c8e9bc4994553amw xgwa.width - passx,
3db3f65c6274eb042354801a308c8e9bc4994553amw font->ascent + font->descent);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* clear encrypted passwords just in case */
3db3f65c6274eb042354801a308c8e9bc4994553amw if (rootpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(rootpass, 0, strlen(rootpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(rootpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (userpass) {
3db3f65c6274eb042354801a308c8e9bc4994553amw memset(userpass, 0, strlen(userpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(userpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (srootpass) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw memset(srootpass, 0, strlen(srootpass));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw free(srootpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (suserpass) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw memset(suserpass, 0, strlen(suserpass));
3db3f65c6274eb042354801a308c8e9bc4994553amw free(suserpass);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#endif
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown#ifdef USE_PAM
3db3f65c6274eb042354801a308c8e9bc4994553amw pam_end(pamh, pam_error);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XChangeGrabbedCursor(mycursor);
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown XUnmapWindow(dsp, icon[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw return 1;
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
12b65585e720714b31036daaa2b30eb76014048eGordon Rossstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwjustDisplay()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw XEvent event;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw for (screen = 0; screen < screens; screen++)
3db3f65c6274eb042354801a308c8e9bc4994553amw init(win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw do {
3db3f65c6274eb042354801a308c8e9bc4994553amw while (!XPending(dsp)) {
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown for (screen = 0; screen < screens; screen++)
3db3f65c6274eb042354801a308c8e9bc4994553amw callback(win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFlush(dsp);
3db3f65c6274eb042354801a308c8e9bc4994553amw usleep(delay);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw XNextEvent(dsp, &event);
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifndef DEBUG
3db3f65c6274eb042354801a308c8e9bc4994553amw if (event.type == VisibilityNotify)
3db3f65c6274eb042354801a308c8e9bc4994553amw XRaiseWindow(dsp, event.xany.window);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw } while (event.type != ButtonPress && event.type != KeyPress);
3db3f65c6274eb042354801a308c8e9bc4994553amw for (screen = 0; screen < screens; screen++)
3db3f65c6274eb042354801a308c8e9bc4994553amw if (event.xbutton.root == RootWindow(dsp, screen))
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw if (usefirst)
3db3f65c6274eb042354801a308c8e9bc4994553amw XPutBackEvent(dsp, &event);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brownstatic void
3db3f65c6274eb042354801a308c8e9bc4994553amwsigcatch()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw finish();
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown error("%s: caught terminate signal.\nAccess control list restored.\n",(char*)NULL);
3db3f65c6274eb042354801a308c8e9bc4994553amw}
3db3f65c6274eb042354801a308c8e9bc4994553amw
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
3db3f65c6274eb042354801a308c8e9bc4994553amwstatic void
12b65585e720714b31036daaa2b30eb76014048eGordon RosslockDisplay()
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!allowaccess) {
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw sigset_t oldsigmask;
3db3f65c6274eb042354801a308c8e9bc4994553amw sigset_t newsigmask;
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown
3db3f65c6274eb042354801a308c8e9bc4994553amw sigemptyset(&newsigmask);
3db3f65c6274eb042354801a308c8e9bc4994553amw sigaddset(&newsigmask, SIGHUP);
3db3f65c6274eb042354801a308c8e9bc4994553amw sigaddset(&newsigmask, SIGINT);
3db3f65c6274eb042354801a308c8e9bc4994553amw sigaddset(&newsigmask, SIGQUIT);
3db3f65c6274eb042354801a308c8e9bc4994553amw sigaddset(&newsigmask, SIGTERM);
3db3f65c6274eb042354801a308c8e9bc4994553amw sigprocmask(SIG_BLOCK, &newsigmask, &oldsigmask);
3db3f65c6274eb042354801a308c8e9bc4994553amw#else
3db3f65c6274eb042354801a308c8e9bc4994553amw int oldsigmask;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw oldsigmask = sigblock(sigmask(SIGHUP) |
3db3f65c6274eb042354801a308c8e9bc4994553amw sigmask(SIGINT) |
bbf6f00c25b6a2bed23c35eac6d62998ecdb338cJordan Brown sigmask(SIGQUIT) |
3db3f65c6274eb042354801a308c8e9bc4994553amw sigmask(SIGTERM));
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw signal(SIGHUP, (void (*)()) sigcatch);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross signal(SIGINT, (void (*)()) sigcatch);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross signal(SIGQUIT, (void (*)()) sigcatch);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross signal(SIGTERM, (void (*)()) sigcatch);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross XGrabHosts(dsp);
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef SYSV
3db3f65c6274eb042354801a308c8e9bc4994553amw sigprocmask(SIG_SETMASK, &oldsigmask, &oldsigmask);
3db3f65c6274eb042354801a308c8e9bc4994553amw#else
3db3f65c6274eb042354801a308c8e9bc4994553amw sigsetmask(oldsigmask);
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifdef sun
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw audit_lock();
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif /* sun */
3db3f65c6274eb042354801a308c8e9bc4994553amw do {
3db3f65c6274eb042354801a308c8e9bc4994553amw justDisplay();
3db3f65c6274eb042354801a308c8e9bc4994553amw } while (getPassword());
3db3f65c6274eb042354801a308c8e9bc4994553amw}
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amwint
3db3f65c6274eb042354801a308c8e9bc4994553amwmain(argc, argv)
3db3f65c6274eb042354801a308c8e9bc4994553amw int argc;
3db3f65c6274eb042354801a308c8e9bc4994553amw char *argv[];
3db3f65c6274eb042354801a308c8e9bc4994553amw{
3db3f65c6274eb042354801a308c8e9bc4994553amw XSetWindowAttributes xswa;
3db3f65c6274eb042354801a308c8e9bc4994553amw XGCValues xgcv;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw ProgramName = strrchr(argv[0], '/');
3db3f65c6274eb042354801a308c8e9bc4994553amw if (ProgramName)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw ProgramName++;
3db3f65c6274eb042354801a308c8e9bc4994553amw else
3db3f65c6274eb042354801a308c8e9bc4994553amw ProgramName = argv[0];
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw srandom(time((long *) 0)); /* random mode needs the seed set. */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw GetResources(argc, argv);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw CheckResources();
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw font = XLoadQueryFont(dsp, fontname);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (font == NULL) {
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "%s: can't find font: %s, using %s...\n",
3db3f65c6274eb042354801a308c8e9bc4994553amw ProgramName, fontname, FALLBACK_FONTNAME);
3db3f65c6274eb042354801a308c8e9bc4994553amw font = XLoadQueryFont(dsp, FALLBACK_FONTNAME);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (font == NULL)
3db3f65c6274eb042354801a308c8e9bc4994553amw error("%s: can't even find %s!!!\n", FALLBACK_FONTNAME);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (CheckPassword()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw fprintf(stderr, "%s: can't get the user password. Exiting ...\n",
3db3f65c6274eb042354801a308c8e9bc4994553amw ProgramName);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr,"\tYou need to run xlock in setuid root mode on your local machine.\n");
3db3f65c6274eb042354801a308c8e9bc4994553amw error("\tContact your system administrator.\n", (char *) NULL);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw screens = ScreenCount(dsp);
3db3f65c6274eb042354801a308c8e9bc4994553amw if (screens > MAXSCREENS)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw error("%s: can only support %d screens.\n", MAXSCREENS);
3db3f65c6274eb042354801a308c8e9bc4994553amw for (screen = 0; screen < screens; screen++) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XColor tmp;
3db3f65c6274eb042354801a308c8e9bc4994553amw Screen *scr = ScreenOfDisplay(dsp, screen);
3db3f65c6274eb042354801a308c8e9bc4994553amw Visual *vis = XDefaultVisual(dsp, screen);
3db3f65c6274eb042354801a308c8e9bc4994553amw Colormap cmap;
3db3f65c6274eb042354801a308c8e9bc4994553amw root[screen] = RootWindowOfScreen(scr);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw cmap = XCreateColormap(dsp, root[screen], vis, AllocNone);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw XAllocNamedColor(dsp, cmap, "White", &sswhite[screen], &tmp);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XAllocNamedColor(dsp, cmap, "Black", &ssblack[screen], &tmp);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (mono || CellsOfScreen(scr) == 2) {
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!XAllocNamedColor(dsp, cmap, background,
3db3f65c6274eb042354801a308c8e9bc4994553amw &bgcol[screen], &tmp)) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XAllocNamedColor(dsp, cmap, "White", &bgcol[screen], &tmp);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (!XAllocNamedColor(dsp, cmap, foreground,
3db3f65c6274eb042354801a308c8e9bc4994553amw &fgcol[screen], &tmp)) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XAllocNamedColor(dsp, cmap, "Black", &fgcol[screen], &tmp);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].pixels[0] = fgcol[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].pixels[1] = bgcol[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].npixels = 2;
3db3f65c6274eb042354801a308c8e9bc4994553amw } else {
3db3f65c6274eb042354801a308c8e9bc4994553amw int colorcount = NUMCOLORS;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw u_char red[NUMCOLORS];
3db3f65c6274eb042354801a308c8e9bc4994553amw u_char green[NUMCOLORS];
3db3f65c6274eb042354801a308c8e9bc4994553amw u_char blue[NUMCOLORS];
3db3f65c6274eb042354801a308c8e9bc4994553amw int i;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!XAllocNamedColor(dsp, cmap, background,
3db3f65c6274eb042354801a308c8e9bc4994553amw &bgcol[screen], &tmp)) {
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "couldn't allocate: %s\n", background);
3db3f65c6274eb042354801a308c8e9bc4994553amw XAllocNamedColor(dsp, cmap, "White", &bgcol[screen], &tmp);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!XAllocNamedColor(dsp, cmap, foreground,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw &fgcol[screen], &tmp)) {
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "couldn't allocate: %s\n", foreground);
3db3f65c6274eb042354801a308c8e9bc4994553amw XAllocNamedColor(dsp, cmap, "Black", &fgcol[screen], &tmp);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw hsbramp(0.0, saturation, 1.0, 1.0, saturation, 1.0, colorcount,
3db3f65c6274eb042354801a308c8e9bc4994553amw red, green, blue);
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].npixels = 0;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw for (i = 0; i < colorcount; i++) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XColor xcolor;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xcolor.red = red[i] << 8;
3db3f65c6274eb042354801a308c8e9bc4994553amw xcolor.green = green[i] << 8;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xcolor.blue = blue[i] << 8;
3db3f65c6274eb042354801a308c8e9bc4994553amw xcolor.flags = DoRed | DoGreen | DoBlue;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!XAllocColor(dsp, cmap, &xcolor))
3db3f65c6274eb042354801a308c8e9bc4994553amw break;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].pixels[i] = xcolor.pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].npixels++;
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw if (verbose)
3db3f65c6274eb042354801a308c8e9bc4994553amw fprintf(stderr, "%d pixels allocated\n", Scr[screen].npixels);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.override_redirect = True;
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.background_pixel = ssblack[screen].pixel;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xswa.event_mask = KeyPressMask | ButtonPressMask | VisibilityChangeMask;
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.colormap = cmap; /* In DEBUG mode, we do not see this */
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw win[screen] = XCreateWindow(dsp, root[screen], 0, 0, WIDTH, HEIGHT, 0,
3db3f65c6274eb042354801a308c8e9bc4994553amw CopyFromParent, InputOutput, CopyFromParent,
3db3f65c6274eb042354801a308c8e9bc4994553amw CWMASK, &xswa);
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw#ifdef DEBUG
3db3f65c6274eb042354801a308c8e9bc4994553amw {
3db3f65c6274eb042354801a308c8e9bc4994553amw XWMHints xwmh;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xwmh.flags = InputHint;
3db3f65c6274eb042354801a308c8e9bc4994553amw xwmh.input = True;
3db3f65c6274eb042354801a308c8e9bc4994553amw XChangeProperty(dsp, win[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw XA_WM_HINTS, XA_WM_HINTS, 32, PropModeReplace,
3db3f65c6274eb042354801a308c8e9bc4994553amw (unsigned char *) &xwmh, sizeof(xwmh) / sizeof(int));
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw iconx[screen] = (DisplayWidth(dsp, screen) -
3db3f65c6274eb042354801a308c8e9bc4994553amw XTextWidth(font, text_info, strlen(text_info))) / 2;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw icony[screen] = DisplayHeight(dsp, screen) / 6;
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.border_pixel = fgcol[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.background_pixel = bgcol[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.event_mask = ButtonPressMask;
3db3f65c6274eb042354801a308c8e9bc4994553amw xswa.colormap = cmap; /* In DEBUG mode, we do not see this */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw#define CIMASK CWBorderPixel | CWBackPixel | CWEventMask | CWColormap
3db3f65c6274eb042354801a308c8e9bc4994553amw icon[screen] = XCreateWindow(dsp, win[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw iconx[screen], icony[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw ICONW, ICONH, 1, CopyFromParent,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw InputOutput, CopyFromParent,
3db3f65c6274eb042354801a308c8e9bc4994553amw CIMASK, &xswa);
3db3f65c6274eb042354801a308c8e9bc4994553amw
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw XMapWindow(dsp, win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw XRaiseWindow(dsp, win[screen]);
3db3f65c6274eb042354801a308c8e9bc4994553amw XInstallColormap(dsp, cmap);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xgcv.foreground = sswhite[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw xgcv.background = ssblack[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw Scr[screen].gc = XCreateGC(dsp, win[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw GCForeground | GCBackground, &xgcv);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw xgcv.foreground = fgcol[screen].pixel;
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw xgcv.background = bgcol[screen].pixel;
3db3f65c6274eb042354801a308c8e9bc4994553amw xgcv.font = font->fid;
3db3f65c6274eb042354801a308c8e9bc4994553amw textgc[screen] = XCreateGC(dsp, win[screen],
3db3f65c6274eb042354801a308c8e9bc4994553amw GCFont | GCForeground | GCBackground, &xgcv);
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw lockc = XCreateBitmapFromData(dsp, root[0], no_bits, 1, 1);
3db3f65c6274eb042354801a308c8e9bc4994553amw lockm = XCreateBitmapFromData(dsp, root[0], no_bits, 1, 1);
3db3f65c6274eb042354801a308c8e9bc4994553amw mycursor = XCreatePixmapCursor(dsp, lockc, lockm,
3db3f65c6274eb042354801a308c8e9bc4994553amw &fgcol[screen], &bgcol[screen], 0, 0);
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw passwdcursor = XCreateFontCursor(dsp, XC_left_ptr);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFreePixmap(dsp, lockc);
3db3f65c6274eb042354801a308c8e9bc4994553amw XFreePixmap(dsp, lockm);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (!enablesaver) {
3db3f65c6274eb042354801a308c8e9bc4994553amw XGetScreenSaver(dsp, &sstimeout, &ssinterval,
3db3f65c6274eb042354801a308c8e9bc4994553amw &ssblanking, &ssexposures);
3db3f65c6274eb042354801a308c8e9bc4994553amw XSetScreenSaver(dsp, 0, 0, 0, 0); /* disable screen saver */
3db3f65c6274eb042354801a308c8e9bc4994553amw }
3db3f65c6274eb042354801a308c8e9bc4994553amw#ifndef DEBUG
3db3f65c6274eb042354801a308c8e9bc4994553amw GrabKeyboardAndMouse();
3db3f65c6274eb042354801a308c8e9bc4994553amw#endif
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw
3db3f65c6274eb042354801a308c8e9bc4994553amw nice(nicelevel);
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw if (nolock)
3db3f65c6274eb042354801a308c8e9bc4994553amw justDisplay();
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw else
3db3f65c6274eb042354801a308c8e9bc4994553amw lockDisplay();
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw finish();
3db3f65c6274eb042354801a308c8e9bc4994553amw
3db3f65c6274eb042354801a308c8e9bc4994553amw return 0;
3db3f65c6274eb042354801a308c8e9bc4994553amw}
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw