dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit aec133529a70ac45f4d090b3909274c93d3a628c
parent 3202d2e30653bc9b57402ba637f6ecb792e4da0e
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Mon,  9 Jun 2008 17:09:50 +0200

Implement screen locking based on a patch by Claudio M. Alessi

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.

Diffstat:
config.h | 1+
dvtm.1 | 3+++
dvtm.c | 42++++++++++++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 0 deletions(-)

diff --git 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.1 b/dvtm.1 @@ -88,6 +88,9 @@ Redraw whole screen. .B Mod\-G Escape the next typed key. .TP +.B Mod\-X +Lock screen. +.TP .B Mod\-q Quit dvtm. .SS Mouse commands diff --git 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 temporarily 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)