„Honeypot“-Patch for xtrlock 2.8 by APic@IRCnet License: GPLv3 Credits to the original Author Ian Jackson, and to all Contributors and/or Maintainers TODO: Instead of displaying Alarm-Text on „Intrusion“, optionally show a Goatse-Picture diff --git a/Imakefile b/Imakefile index 68605d8..d8395ec 100644 --- a/Imakefile +++ b/Imakefile @@ -12,6 +12,7 @@ #! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #! GNU General Public License for more details. -SingleProgramTarget(xtrlock,xtrlock.o,-lcrypt -lX11,) +INCLUDES=-I/usr/include/freetype2 +SingleProgramTarget(xtrlock,xtrlock.o,-lcrypt -lX11 -lXft,) InstallProgram(xtrlock,$(BINDIR)) InstallManPage(xtrlock,$(MANDIR)) diff --git a/Makefile.noimake b/Makefile.noimake index 460cd67..80080c9 100644 --- a/Makefile.noimake +++ b/Makefile.noimake @@ -13,9 +13,9 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -LDLIBS=-lX11 +LDLIBS=-lX11 -lXft -lcrypt CC=gcc -CFLAGS=-Wall +CFLAGS=-Wall -I/usr/include/freetype2 INSTALL=install xtrlock: xtrlock.o diff --git a/patchlevel.h b/patchlevel.h index e482441..1a533a3 100644 --- a/patchlevel.h +++ b/patchlevel.h @@ -1 +1 @@ -const char program_version[] = "2.8"; +const char program_version[] = "2.8+honeypot0.1"; diff --git a/xtrlock.c b/xtrlock.c index 6117c6f..e414842 100644 --- a/xtrlock.c +++ b/xtrlock.c @@ -21,7 +21,9 @@ #include #include #include +#include +#include #include #include #include @@ -46,7 +48,9 @@ #include "patchlevel.h" Display *display; -Window window, root; +Window window, root, winalarm; + +bool alarmactive = false; #define TIMEOUTPERATTEMPT 30000 #define MAXGOODWILL (TIMEOUTPERATTEMPT*5) @@ -135,8 +139,9 @@ int main(int argc, char **argv){ attrib.override_redirect= True; + screen = DefaultScreen(display); + if (blank) { - screen = DefaultScreen(display); attrib.background_pixel = BlackPixel(display, screen); window= XCreateWindow(display,DefaultRootWindow(display), 0,0,DisplayWidth(display, screen),DisplayHeight(display, screen), @@ -149,7 +154,7 @@ int main(int argc, char **argv){ CWOverrideRedirect,&attrib); } - XSelectInput(display,window,KeyPressMask|KeyReleaseMask); + XSelectInput(display,window,KeyPressMask|KeyReleaseMask|ButtonPressMask|ButtonReleaseMask); csr_source= XCreateBitmapFromData(display,window,lock_bits,lock_width,lock_height); csr_mask= XCreateBitmapFromData(display,window,mask_bits,mask_width,mask_height); @@ -207,15 +212,35 @@ int main(int argc, char **argv){ exit(1); } - if (XGrabPointer(display,window,False,(KeyPressMask|KeyReleaseMask)&0, + if (XGrabPointer(display,window,False,ButtonPressMask | ButtonReleaseMask, GrabModeAsync,GrabModeAsync,None, - cursor,CurrentTime)!=GrabSuccess) { + None,CurrentTime)!=GrabSuccess) { XUngrabKeyboard(display,CurrentTime); fprintf(stderr,"xtrlock (version %s): cannot grab pointer\n", program_version); exit(1); } + const char *fontname = "fixed:size=137:antialias=true"; + XftFont *font = XftFontOpenName(display, screen, fontname); + if(!font) { + fprintf(stderr,"xtrlock (version %s): unable to load font\n", + program_version); + exit(1); + } + XftColor fontfgcolor, fontbgcolor; + if(!XftColorAllocName(display, DefaultVisual(display, screen), + DefaultColormap(display, screen), + "#f00000", &fontfgcolor) || + !XftColorAllocName(display, DefaultVisual(display, screen), + DefaultColormap(display, screen), + "#000000", &fontbgcolor)) { + fprintf(stderr, + "xtrlock (version %s): unable to allocate font colours\n", + program_version); + exit(1); + } + if (fork_after) { pid_t pid = fork(); if (pid < 0) { @@ -227,9 +252,57 @@ int main(int argc, char **argv){ } } + + honeyloop: + for (;;) { + XNextEvent(display,&ev); + switch (ev.type) { + case KeyPress: + clen= XLookupString(&ev.xkey,cbuf,9,&ks,0); + if(ks==XK_Escape) + goto pwentry; + // fall through + case ButtonPress: + XBell(display, 0); + if(alarmactive) + break; + alarmactive = true; + + winalarm = XCreateWindow(display, DefaultRootWindow(display), 0, 0, + DisplayWidth(display, screen), + DisplayHeight(display, screen), 0, + CopyFromParent, CopyFromParent, CopyFromParent, + CWOverrideRedirect, &attrib); + XMapWindow(display, winalarm); + + XftDraw *draw = XftDrawCreate(display, winalarm, + DefaultVisual(display, screen), + DefaultColormap(display, screen)); + + XGlyphInfo extents; + XftTextExtentsUtf8(display, font, (const FcChar8 *)"Alarm.", 6, &extents); + + XftDrawRect(draw, &fontbgcolor, DisplayWidth(display, screen)/2 - extents.width/2, + DisplayHeight(display, screen)/2 - extents.height/2, + extents.width, extents.height); + XftDrawStringUtf8(draw, &fontfgcolor, font, DisplayWidth(display, screen)/2 - extents.width/2, + DisplayHeight(display, screen)/2 + extents.height/2, + (const FcChar8 *)"Alarm.", 6); + XftDrawDestroy(draw); + } + } + + pwentry: + if(alarmactive) { + XDestroyWindow(display, winalarm); + alarmactive = false; + } + for (;;) { XNextEvent(display,&ev); switch (ev.type) { + case ButtonPress: + goto honeyloop; case KeyPress: if (ev.xkey.time < timeout) { XBell(display,0); break; } clen= XLookupString(&ev.xkey,cbuf,9,&ks,0); @@ -254,7 +327,7 @@ int main(int argc, char **argv){ timeout= -goodwill*GOODWILLPORTION; goodwill+= timeout; timeout+= ev.xkey.time + TIMEOUTPERATTEMPT; - break; + goto honeyloop; default: if (clen != 1) break; /* allow space for the trailing \0 */