Package: xwrits
Version: 2.21-5
Severity: wishlist
Tags: patch

Here's a patch for xwrits which lets you tell it to choose the password
randomly.  I find this useful because I got so used to unlocking the
screen that I would do it without thinking about it.

I sent this upstream (to [EMAIL PROTECTED]) last September, but I didn't
hear anything back.  I figured I'd send it to the Debian BTS as
other people might find it useful.

diff -r -u xwrits-2.21/lock.c xwrits/lock.c
--- xwrits-2.21/lock.c  2002-05-06 19:29:24.000000000 -0400
+++ xwrits/lock.c       2004-09-17 10:34:51.000000000 -0400
@@ -5,7 +5,7 @@
 #include <assert.h>
 
 struct timeval lock_message_delay;
-char *lock_password;
+char random_password[MAX_PASSWORD_SIZE];
 
 #define REDRAW_MESSAGE         ((char *)1L)
 #define MAX_MESSAGE_SIZE       (256 + MAX_PASSWORD_SIZE)
@@ -122,7 +122,9 @@
       (nchars == 1 && (c == '\n' || c == '\r'))) {
     password[password_pos] = 0;
     password_pos = 0;
-    if (strcmp(lock_password, password) == 0)
+    if (strcmp(ocurrent->random_password_len
+                 ? random_password : ocurrent->lock_password,
+               password) == 0)
       return 1;
     else
       incorrect_message = 1;
@@ -138,7 +140,10 @@
     draw_message("Incorrect password! Try again");
   else {
     char message[MAX_MESSAGE_SIZE];
-    strcpy(message, "Enter password to unlock screen");
+    if (ocurrent->random_password_len)
+      sprintf(message, "Enter `%s' to unlock screen", random_password);
+    else
+      strcpy(message, "Enter password to unlock screen");
     if (password_pos > 0) {
       int i, pos = strlen(message);
       message[pos++] = ':';
@@ -235,6 +240,13 @@
   if (xwTIMEGEQ(now, break_over_time))
     return TRAN_AWAKE;
 
+  /* set up password */
+  if (ocurrent->random_password_len) {
+    for (i = 0; i < ocurrent->random_password_len; i++) 
+      random_password[i] = 'a' + rand() % 26;
+    random_password[i] = '\0';
+  }
+
   /* create covers */
   if (!covers) {
     covers = (Window *)xmalloc(sizeof(Window) * nports);
diff -r -u xwrits-2.21/main.c xwrits/main.c
--- xwrits-2.21/main.c  2002-05-06 20:42:30.000000000 -0400
+++ xwrits/main.c       2004-09-17 10:34:50.000000000 -0400
@@ -97,6 +97,7 @@
   breaktime=TIME, b=TIME    Breaks last for TIME (default 5 minutes).\n\
   +lock               Lock the keyboard during the break.\n\
   password=TEXT       Set the password for unlocking the keyboard.\n\
+  random-password=NUM Use a random password of length NUM for unlocking.\n\
   +mouse              Monitor your mouse movements.\n\
   +idle[=TIME]        Leaving the keyboard idle for TIME is the same as 
taking\n\
                       a break. On by default. Default TIME is breaktime.\n\
@@ -702,12 +703,14 @@
     else if (optparse(s, "okp", 1, "ss", &ready_slideshow_text))
       ;
     
-    else if (optparse(s, "password", 1, "ss", &lock_password))
+    else if (optparse(s, "password", 1, "ss", &o->lock_password))
       ;
     
     else if (optparse(s, "quota", 1, "tT", &quota_time))
       check_quota = optparse_yesno;
     
+    else if (optparse(s, "random-password", 2, "si", &o->random_password_len))
+      ;
     else if (optparse(s, "rest-picture", 3, "ss", &resting_slideshow_text)
             || optparse(s, "rp", 2, "ss", &resting_slideshow_text))
       ;
@@ -783,6 +786,16 @@
     if (xwTIMEGT(o->cancel_type_time, normal_type_time))
       o->cancel_type_time = normal_type_time;
   }
+
+  /* check lock_password */
+  if (strlen(o->lock_password) >= MAX_PASSWORD_SIZE)
+    error("password too long");
+
+  /* check random_password_len */
+  if (o->random_password_len < 0)
+    o->random_password_len = 0;
+  else if (o->random_password_len >= MAX_PASSWORD_SIZE)
+    o->random_password_len = MAX_PASSWORD_SIZE - 1;
   
   /* If the next set of options is supposed to appear before this one, replace
      this one with the next set. Iterate. */
@@ -832,7 +845,8 @@
   /* locking settings */
   xwSETTIME(onormal.lock_bounce_delay, 4, 0);
   xwSETTIME(lock_message_delay, 10, 0);
-  lock_password = "quit";
+  onormal.lock_password = "quit";
+  onormal.random_password_len = 0;
   
   /* keystroke registration functions */
   check_idle = 1;
@@ -1202,8 +1216,6 @@
   }
   
   /* check global options */
-  if (strlen(lock_password) >= MAX_PASSWORD_SIZE)
-    error("password too long");
   
   /* default for idle_time and warn_idle_time is based on break_delay;
      otherwise, warn_idle_time == idle_time */
diff -r -u xwrits-2.21/xwrits.1 xwrits/xwrits.1
--- xwrits-2.21/xwrits.1        2002-05-06 20:44:19.000000000 -0400
+++ xwrits/xwrits.1     2004-09-17 10:43:18.000000000 -0400
@@ -205,7 +205,8 @@
 \fB+lock\fP[=\fIjump-time\fP] (\fB\-lock\fP)
 Xwrits will lock your screen until your break is
 over. You can prematurely disable the lock and get a normal warning
-window by typing your password (see \fBpassword\fP below). The
+window by typing your password (see \fBpassword\fP and
+\fBrandom-password\fP below). The
 \fIjump-time\fP argument specifies how fast the screensaver will move;
 default is 4 seconds. If the keyboard has been grabbed by another
 application when the lock is attempted, the lock fails and a
@@ -268,6 +269,12 @@
 minute. See also \fBminbreaktime\fP.
 '
 .TP 5
+\fBrandom-password\fP=\fIlength\fP
+Generate a random password of \fIlength\fP characters to use for
+unlocking the screen (see \fB+lock\fP above).  This can be useful if you
+find that you unlock the screen without thinking about it.
+'
+.TP 5
 \fBready-picture\fP=\fIfile\fP [\fBokp\fP=\fIfile\fP]
 Sets the image that appears when your break is over to an arbitrary GIF.
 Animations are acceptable.
diff -r -u xwrits-2.21/xwrits.h xwrits/xwrits.h
--- xwrits-2.21/xwrits.h        2002-05-06 20:32:23.000000000 -0400
+++ xwrits/xwrits.h     2004-09-17 10:34:48.000000000 -0400
@@ -126,6 +126,7 @@
   const char *slideshow_text;
   const char *icon_slideshow_text;
   const char *window_title;
+  const char *lock_password;
   
   double flash_rate_ratio;             /* <1, flash fast; >1, flash slow */
   struct timeval multiply_delay;       /* time between window multiplies */
@@ -140,6 +141,7 @@
   unsigned lock: 1;                    /* lock screen? */
   unsigned break_clock: 1;             /* show clock time left in break? */
   int max_hands;                       /* max number of hands (+multiply) */
+  int random_password_len;             /* use a random unlock password */
   
   struct timeval next_delay;           /* delay till go to next options */
   Options *next;                       /* next options */
@@ -153,7 +155,6 @@
 
 #define MAX_PASSWORD_SIZE 256
 extern struct timeval lock_message_delay;
-extern char *lock_password;
 
 
 /*****************************************************************************/

-- 
Roderick Schertler
[EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to