On Sat, May 31, 2008 at 01:42:14PM +0200, Claudio M. Alessi wrote:
>
> Hi to all dvtm users,
> i wrote a little'n simple routine which allow to lock the screen
> until a passphrase has been inserted. It's doesn't deal with encrypted
> key (that's because i don't need it; it's quite easy to implement, btw).
> I hope someone else (other than me) will found it useful too.
Hi again,
I have changed your patch a bit, the password is now read from the
keyboard if lock is called with a NULL argument. This should work for
people who are afraid that their password is stored in the binary
(see `strings dvtm`).
Your method is however still supported. Please test.
Marc
--
Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
diff --git a/config.h b/config.h
index bac99da..6b0c7e8 100644
--- a/config.h
+++ b/config.h
@@ -84,6 +84,7 @@ Key keys[] = {
{ MOD, 'q', { quit, { NULL } } },
{ MOD, 'G', { escapekey, { NULL } } },
{ MOD, 'L', { redraw, { NULL } } },
+ { MOD, 'X', { lock, { NULL } } },
};
/* possible values for the mouse buttons are listed below:
diff --git a/dvtm.c b/dvtm.c
index 7c1c784..e287387 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -109,6 +109,7 @@ void setmwfact(const char *args[]);
void setlayout(const char *args[]);
void redraw(const char *args[]);
void zoom(const char *args[]);
+void lock(const char *key[]);
#if defined(HANDLE_MOUSE)
void mouse_focus(const char *args[]);
@@ -545,6 +546,47 @@ escapekey(const char *args[]) {
}
}
+/*
+ * Lock the screen until the correct password is entered.
+ * The password can either be specified in config.h which is
+ * not recommended because `strings dvtm` will contain it. If
+ * no password is specified in the configuration file it is read
+ * from the keyboard before the screen is locked.
+ *
+ * NOTE: this function doesn't handle the input from clients. All
+ * foreground operations are temporarly suspended since the
+ * function doesn't return.
+ */
+void
+lock(const char *args[]) {
+ size_t len = 0, i = 0;
+ char buf[16], *pass = buf, c;
+
+ erase();
+ curs_set(0);
+
+ if (args && args[0]) {
+ len = strlen(args[0]);
+ pass = (char *)args[0];
+ } else {
+ mvprintw(LINES / 2, COLS / 2 - 7, "Enter password");
+ while (len < sizeof buf && (c = getch()) != '\n')
+ if (c != ERR)
+ buf[len++] = c;
+ }
+
+ mvprintw(LINES / 2, COLS / 2 - 7, "Screen locked!");
+
+ while (i != len) {
+ for(i = 0; i < len; i++) {
+ if (getch() != pass[i])
+ break;
+ }
+ }
+
+ arrange();
+}
+
void
killclient(const char *args[]) {
if (!sel)