xlock.c revision 546
970N/A * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 970N/A * Use is subject to license terms. 970N/A * Permission is hereby granted, free of charge, to any person obtaining a 970N/A * copy of this software and associated documentation files (the 970N/A * "Software"), to deal in the Software without restriction, including 970N/A * without limitation the rights to use, copy, modify, merge, publish, 970N/A * distribute, and/or sell copies of the Software, and to permit persons 970N/A * to whom the Software is furnished to do so, provided that the above 970N/A * copyright notice(s) and this permission notice appear in all copies of 970N/A * the Software and that both the above copyright notice(s) and this 970N/A * permission notice appear in supporting documentation. 970N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 970N/A * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 970N/A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 970N/A * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 970N/A * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 970N/A * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 970N/A * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 970N/A * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 970N/A * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 970N/A * Except as contained in this notice, the name of a copyright holder 970N/A * shall not be used in advertising or otherwise to promote the sale, use 970N/A * or other dealings in this Software without prior written authorization 970N/A * of the copyright holder. 970N/A * xlock.c - X11 client to lock a display and show a screen saver. 970N/A * Copyright (c) 1988-91 by Patrick J. Naughton. 970N/A * Permission to use, copy, modify, and distribute this software and its 970N/A * documentation for any purpose and without fee is hereby granted, 970N/A * provided that the above copyright notice appear in all copies and that 970N/A * both that copyright notice and this permission notice appear in 970N/A * supporting documentation. 970N/A * This file is provided AS IS with no warranties of any kind. The author 970N/A * shall have no liability with respect to the infringement of copyrights, 1105N/A * trade secrets or any patents by this file or any part thereof. In no 970N/A * event will the author be liable for any lost revenue or profits or 970N/A * other special, indirect and consequential damages. 970N/A * Comments and additions should be sent to the author: 970N/A * Sun Laboritories, Inc. 970N/A * Mountain View, CA 94043 970N/A * 24-Jun-91: make foreground and background color get used on mono. 970N/A * 24-May-91: added -usefirst. 970N/A * 16-May-91: added pyro and random modes. 970N/A * ripped big comment block out of all other files. 970N/A * 08-Jan-91: fix some problems with password entry. 970N/A * removed renicing code. 970N/A * 29-Oct-90: added cast to XFree() arg. 970N/A * added volume arg to call to XBell(). 970N/A * 28-Oct-90: center prompt screen. 970N/A * make sure Xlib input buffer does not use up all of swap. 1130N/A * make displayed text come from resource file for better I18N. 970N/A * add backward compatible signal handlers for pre 4.1 machines. 970N/A * 31-Aug-90: added blank mode. 970N/A * 29-Jul-90: added support for multiple screens to be locked by one xlock. 970N/A * removed use of allowsig(). 970N/A * 07-Jul-90: reworked commandline args and resources to use Xrm. 970N/A * 02-Jul-90: reworked colors to not use dynamic colormap. 970N/A * 23-May-90: added autoraise when obscured. 970N/A * 15-Apr-90: added hostent alias searching for host authentication. 970N/A * 18-Feb-90: added SunOS3.5 fix. 970N/A * changed -mono -> -color, and -saver -> -lock. 970N/A * allow non-locking screensavers to display on remote machine. 970N/A * added -echokeys to disable echoing of '?'s on input. 970N/A * cleaned up all of the parameters and defaults. 970N/A * 20-Dec-89: added -xhost to allow access control list to be left alone. 970N/A * added -screensaver (don't disable screen saver) for the paranoid. 970N/A * Moved seconds() here from all of the display mode source files. 970N/A * Fixed bug with calling XUngrabHosts() in finish(). 970N/A * 19-Dec-89: Fixed bug in GrabPointer. 970N/A * Changed fontname to XLFD style. 970N/A * 23-Sep-89: Added fix to allow local hostname:0 as a display. 970N/A * Moved colormap installation later in startup. 970N/A * 20-Sep-89: Linted and made -saver mode grab the keyboard and mouse. 1105N/A * Replaced SunView code for life mode with Jim Graham's version, 1105N/A * so I could contrib it without legal problems. 970N/A * Sent to expo for X11R4 contrib. 1105N/A * 19-Sep-89: Added '?'s on input. 970N/A * 27-Mar-89: Added -qix mode. 970N/A * 20-Mar-89: Added backup font (fixed) if XQueryLoadFont() fails. 970N/A * Changed default font to lucida-sans-24. 970N/A * 08-Mar-89: Added -nice, -mode and -display, built vector for life and hop. 970N/A * 24-Feb-89: Replaced hopalong display with life display from SunView1. 977N/A * 22-Feb-89: Added fix for color servers with n < 8 planes. 970N/A * 16-Feb-89: Updated calling conventions for XCreateHsbColormap(); 970N/A * Added -count for number of iterations per color. 970N/A * Fixed defaulting mechanism. 970N/A * Ripped out VMS hacks. 970N/A * Sent to expo for X11R3 contrib. 970N/A * 15-Feb-89: Changed default font to pellucida-sans-18. 970N/A * 20-Jan-89: Added -verbose and fixed usage message. 970N/A * 19-Jan-89: Fixed monochrome gc bug. 970N/A * 16-Dec-88: Added SunView style password prompting. 982N/A * 19-Sep-88: Changed -color to -mono. (default is color on color displays). 970N/A * Added -saver option. (just do display... don't lock.) 970N/A * 31-Aug-88: Added -time option. 970N/A * Removed code for fractals to separate file for modularity. 970N/A * Added signal handler to restore host access. 970N/A * Installs dynamic colormap with a Hue Ramp. 970N/A * If grabs fail then exit. 970N/A * Added VMS Hacks. (password 'iwiwuu'). 970N/A * Sent to expo for X11R2 contrib. 970N/A * 08-Jun-88: Fixed root password pointer problem and changed PASSLENGTH to 20. 970N/A * 20-May-88: Added -root to allow root to unlock. 970N/A * 12-Apr-88: Added root password override. 970N/A * Added screen saver override. 982N/A * Added access control handling instead. 970N/A * 30-Mar-88: Removed startup password requirement. 970N/A * Removed cursor to avoid phosphor burn. 970N/A * 27-Mar-88: Rotate fractal by 45 degrees clockwise. 1105N/A * 24-Mar-88: Added color support. [-color] 970N/A * 23-Mar-88: Added HOPALONG routines from Scientific American Sept. 86 p. 14. 1105N/A * added password requirement for invokation 970N/A * removed option for command line password 970N/A * added requirement for display to be "unix:0". 1120N/A * 22-Mar-88: Recieved Walter Milliken's comp.windows.x posting. 970N/Astatic char no_bits[] = {0};
/* dummy array for the blank cursor */ 970N/A * Server access control support. 970N/A * Simple wrapper to get an asynchronous grab on the keyboard and mouse. 970N/A * If either grab fails, we sleep for one second and try again since some 970N/A * window manager might have had the mouse grabbed to drive the menu choice 970N/A * that picked "Lock Screen..". If either one fails the second time we print 970N/A * an error message and exit. 970N/A * Assuming that we already have an asynch grab on the pointer, 970N/A * just grab it again with a new cursor shape and ignore the return code. 970N/A * Restore all grabs, reset screensaver, restore colormap, close connection. 970N/A * eat all events if there are more than enough pending... this 970N/A * keeps the Xlib event buffer from growing larger than all 970N/A * available memory and crashing xlock. 970N/A * eat all events if there are more than enough pending... this 1130N/A * keeps the Xlib event buffer from growing larger than all 1130N/A * available memory and crashing xlock. if (
upw ==
NULL) {
/* should not pass NULL to getspnam */ for (i = 0; i <
num_msg; i++ , m++ , r++) {
/* timeout or other error */ for (i = 0; i <
num_msg; i++, r++) {
* audit_lock - audit entry to screenlock * Entry Process running with appropriate privilege to generate * audit records and real uid of the user. * Exit ADT_screenlock audit record written. /* Audit start of screen lock -- equivalent to logout ;-) */ "adt_alloc_event(ADT_screenlock): %m");
"adt_put_event(ADT_screenlock): %m");
* audit_unlock - audit screen unlock * Entry Process running with appropriate privilege to generate * audit records and real uid of the user. * pam_status = PAM error code; reason for failure. * Exit ADT_screenunlock audit record written. "adt_start_session(ADT_screenunlock): %m");
"adt_alloc_event(ADT_screenunlock): %m");
"adt_put_event(ADT_screenunlock(%s): %m",
* audit_passwd - audit password change * Entry Process running with appropriate privilege to generate * audit records and real uid of the user. * pam_status = PAM error code; reason for failure. * Exit ADT_passwd audit record written. "adt_start_session(ADT_passwd): %m");
"adt_alloc_event(ADT_passwd): %m");
"adt_put_event(ADT_passwd(%s): %m",
PAM_DISALLOW_NULL_AUTHTOK to pam_flags */ /* Disable user password non-PAM authentication */ * This section gets a little messy. In SYSV, the number of * cases to handle increases because of the existence of the * shadow file. There are also a number of cases that need * to be dealt with where either root or user passwords are * nil. Hopefully the code below is easy enough to follow. /* just hit return, and it wasn't his password */ * the user has no password, but something was typed anyway. * sounds fishy: don't let him in... /* clear plaintext password so you can't grunge around /dev/kmem */ /* clear encrypted passwords just in case */ /* clear encrypted passwords just in case */ error(
"%s: caught terminate signal.\nAccess control list restored.\n",(
char*)
NULL);
srandom(
time((
long *) 0));
/* random mode needs the seed set. */ fprintf(
stderr,
"%s: can't get the user password. Exiting ...\n",
fprintf(
stderr,
"\tYou need to run xlock in setuid root mode on your local machine.\n");
error(
"\tContact your system administrator.\n", (
char *)
NULL);
(
unsigned char *) &
xwmh,
sizeof(
xwmh) /
sizeof(
int));