Package: xtrlock
Version: 2.0-12
Severity: wishlist
Tags: patch

The attached patch adds two command-line options to xtrlock:

  --forever: completely disables unlocking

  --hide-cursor: makes the mouse cursor invisible

I've used both of these options for a wall-mounted display showing
various status pages, so other people might find them useful as well.

Cheers,
-=[david]=-


-- System Information:
Debian Release: 5.0.4
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.26-2-686 (SMP w/1 CPU core)
Locale: LANG=C, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages xtrlock depends on:
ii  libc6                       2.7-18lenny2 GNU C Library: Shared libraries
ii  libx11-6                    2:1.1.5-2    X11 client-side library

xtrlock recommends no packages.

xtrlock suggests no packages.

-- no debconf information
diff -ruN xtrlock-original/xtrlock-2.0/Makefile.noimake xtrlock-modified/xtrlock-2.0/Makefile.noimake
--- xtrlock-original/xtrlock-2.0/Makefile.noimake	1995-11-07 15:51:48.000000000 +0100
+++ xtrlock-modified/xtrlock-2.0/Makefile.noimake	2010-02-05 18:53:17.000000000 +0100
@@ -20,7 +20,7 @@
 
 xtrlock:	xtrlock.o
 
-xtrlock.o:	xtrlock.c lock.bitmap mask.bitmap patchlevel.h
+xtrlock.o:	xtrlock.c lock.bitmap mask.bitmap
 
 install:	xtrlock
 		$(INSTALL) -c -m 755 xtrlock /usr/bin/X11
diff -ruN xtrlock-original/xtrlock-2.0/patchlevel.h xtrlock-modified/xtrlock-2.0/patchlevel.h
--- xtrlock-original/xtrlock-2.0/patchlevel.h	1995-03-14 01:48:22.000000000 +0100
+++ xtrlock-modified/xtrlock-2.0/patchlevel.h	1970-01-01 01:00:00.000000000 +0100
@@ -1 +0,0 @@
-const char program_version[] = "2.0";
diff -ruN xtrlock-original/xtrlock-2.0/xtrlock.c xtrlock-modified/xtrlock-2.0/xtrlock.c
--- xtrlock-original/xtrlock-2.0/xtrlock.c	2005-01-17 11:43:05.000000000 +0100
+++ xtrlock-modified/xtrlock-2.0/xtrlock.c	2010-02-05 18:43:41.000000000 +0100
@@ -36,6 +36,7 @@
 #include <math.h>
 #include <ctype.h>
 #include <values.h>
+#include <argp.h>
 
 #ifdef SHADOW_PWD
 #include <shadow.h>
@@ -43,7 +44,6 @@
 
 #include "lock.bitmap"
 #include "mask.bitmap"
-#include "patchlevel.h"
 
 Display *display;
 Window window, root;
@@ -53,6 +53,48 @@
 #define INITIALGOODWILL MAXGOODWILL
 #define GOODWILLPORTION 0.3
 
+#define ARG_FOREVER   256
+
+const char *argp_program_version = "xtrlock 2.1";
+
+static char doc[] =
+"Locks the X server till the user enters their password at the keyboard.";
+
+static struct argp_option options[] = {
+  {"hide-cursor",         'h', 0, 0,
+    "Make the mouse cursor invisible while locked." },
+  {"forever",     ARG_FOREVER, 0, 0, "Disallow unlocking." },
+  { 0 }
+};
+
+struct {
+  int hide_cursor;
+  int forever;
+} arguments;
+
+/* Parse a single option. */
+static error_t parse_opt(int key, char *arg, struct argp_state *state) {
+  switch (key) {
+  case ARG_FOREVER:
+    arguments.forever = 1;
+    break;
+  case 'h':
+    arguments.hide_cursor = 1;
+    break;
+  case ARGP_KEY_ARG:
+    /* Don't accept any non-flags arguments. */
+    argp_usage(state);
+    break;
+  case ARGP_KEY_END:
+    break;
+  default:
+    return ARGP_ERR_UNKNOWN;
+  }
+  return 0;
+}
+
+static struct argp argp = { options, parse_opt, 0, doc };
+
 struct passwd *pw;
 int passwordok(const char *s) {
 #if 0
@@ -86,20 +128,24 @@
   struct spwd *sp;
 #endif
 
-  if (argc != 1) {
-    fprintf(stderr,"xtrlock (version %s): no arguments allowed\n",program_version);
-    exit(1);
-  }
+  memset(&arguments, 0, sizeof(arguments));
+  argp_parse(&argp, argc, argv, 0, 0, 0);
   
-  errno=0;  pw= getpwuid(getuid());
-  if (!pw) { perror("password entry for uid not found"); exit(1); }
+  if (!arguments.forever) {
+    errno=0;  pw= getpwuid(getuid());
+    if (!pw) { perror("password entry for uid not found"); exit(1); }
 #ifdef SHADOW_PWD
-  sp = getspnam(pw->pw_name);
-  if (sp)
-    pw->pw_passwd = sp->sp_pwdp;
-  endspent();
+    sp = getspnam(pw->pw_name);
+    if (sp)
+      pw->pw_passwd = sp->sp_pwdp;
+    endspent();
 #endif
 
+    if (strlen(pw->pw_passwd) < 13) {
+      fputs("password entry has no pwd\n",stderr); exit(1);
+    }
+  }
+
   /* logically, if we need to do the following then the same 
      applies to being installed setgid shadow.  
      we do this first, because of a bug in linux. --jdamery */ 
@@ -108,15 +154,10 @@
      and we don't need root privileges any longer.  --marekm */
   setuid(getuid());
 
-  if (strlen(pw->pw_passwd) < 13) {
-    fputs("password entry has no pwd\n",stderr); exit(1);
-  }
-  
   display= XOpenDisplay(0);
 
   if (display==NULL) {
-    fprintf(stderr,"xtrlock (version %s): cannot open display\n",
-	    program_version);
+    fprintf(stderr, "xtrlock: cannot open display\n");
     exit(1);
   }
 
@@ -127,6 +168,11 @@
                         
   XSelectInput(display,window,KeyPressMask|KeyReleaseMask);
 
+  if (arguments.hide_cursor) {
+    /* Hiding the cursor is done by setting the mask to "fully transparent". */
+    memset(mask_bits, 0, sizeof(mask_bits));
+  }
+
   csr_source= XCreateBitmapFromData(display,window,lock_bits,lock_width,lock_height);
   csr_mask= XCreateBitmapFromData(display,window,mask_bits,mask_width,mask_height);
 
@@ -169,6 +215,12 @@
 
   for (;;) {
     XNextEvent(display,&ev);
+
+    if (arguments.forever) {
+      /* Ignore all keys if unlocking is disallowed. */
+      continue;
+    }
+
     switch (ev.type) {
     case KeyPress:
       if (ev.xkey.time < timeout) { XBell(display,0); break; }
diff -ruN xtrlock-original/xtrlock-2.0/xtrlock.man xtrlock-modified/xtrlock-2.0/xtrlock.man
--- xtrlock-original/xtrlock-2.0/xtrlock.man	2005-01-20 14:59:28.000000000 +0100
+++ xtrlock-modified/xtrlock-2.0/xtrlock.man	2010-02-05 19:42:51.000000000 +0100
@@ -26,7 +26,24 @@
 The X server screen saver continues to operate normally; if it comes
 into operation the display may be restored by the usual means of
 touching a key (Shift, for example) or the mouse.
-.SH OPTIONS, X RESOURCES, CONFIGURATION
+.SH OPTIONS
+.TP
+\fB\-\-forever\fR
+Disallow unlocking.  This is useful when running a machine in kiosk
+mode, when the screen is never supposed to be unlocked.
+.TP
+\fB\-h\fR, \fB\-\-hide\-cursor\fR
+Make the mouse cursor invisible instead of changing it into a padlock.
+.TP
+\-?, \fB\-\-help\fR
+Give this help list
+.TP
+\fB\-\-usage\fR
+Give a short usage message
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Print program version
+.SH X RESOURCES, CONFIGURATION
 None.
 .SH BUGS
 Additional input devices other than the keyboard and mouse are not

Reply via email to