* discard all pending xevents after wrong password to prevent
strange folks for blocking the current session by filling the eventqueue with wrong authentification and thus block the real authentification (kind of denial of service :) * added suuport to load / have different cursor-shapes + -cursor theme|xcursor:<filename> * added support for xcursor * restructuring + contrib/ -> for stuff coming from the "outside" contrib/xcursor-watch -> xcursor taken from 5532-BlueGlass-XCursors-3D-0.4.tar.bz2 + src/ --HG-- extra : convert_revision : svn%3Aeebe1cee-a9af-4fe4-bd26-ad572b19c5ab/trunk%405
This commit is contained in:
parent
8b6f5c89cd
commit
c9b53228ec
6 changed files with 158 additions and 67 deletions
19
SConstruct
19
SConstruct
|
@ -8,7 +8,7 @@
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
aklock_version = '0.2'
|
aklock_version = '0.2'
|
||||||
aklock_optfile = 'scons.opts'
|
aklock_optfile = [ 'scons.opts', 'user.opts' ]
|
||||||
|
|
||||||
aklock_target = 'src/aklock'
|
aklock_target = 'src/aklock'
|
||||||
|
|
||||||
|
@ -20,12 +20,16 @@ aklock_options.AddOptions(
|
||||||
BoolOption('debug', 'build debug version', 0),
|
BoolOption('debug', 'build debug version', 0),
|
||||||
BoolOption('shadow', 'support for shadowpasswords', 0),
|
BoolOption('shadow', 'support for shadowpasswords', 0),
|
||||||
BoolOption('pam', 'support for pam', 1),
|
BoolOption('pam', 'support for pam', 1),
|
||||||
|
|
||||||
|
BoolOption('xcursor', 'support xcursor-themes', 1),
|
||||||
|
|
||||||
PathOption('prefix', 'install-path base', '/usr/local')
|
PathOption('prefix', 'install-path base', '/usr/local')
|
||||||
)
|
)
|
||||||
|
|
||||||
aklock_env = Environment(options = aklock_options,
|
aklock_env = Environment(options = aklock_options,
|
||||||
TARFLAGS = '-c -z',
|
TARFLAGS = '-c -z',
|
||||||
TARSUFFIX = '.tgz')
|
TARSUFFIX = '.tgz')
|
||||||
|
aklock_options.Update(aklock_env)
|
||||||
Help(aklock_options.GenerateHelpText(aklock_env))
|
Help(aklock_options.GenerateHelpText(aklock_env))
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
@ -62,6 +66,19 @@ if aklock_env['shadow']:
|
||||||
aklock_env.AppendUnique(
|
aklock_env.AppendUnique(
|
||||||
CPPDEFINES = [ 'SHADOW_PWD' ])
|
CPPDEFINES = [ 'SHADOW_PWD' ])
|
||||||
|
|
||||||
|
if aklock_env['xcursor']:
|
||||||
|
conf = aklock_env.Configure()
|
||||||
|
if conf.CheckLib('Xcursor', 'XcursorSupportsARGB', 1):
|
||||||
|
aklock_env.AppendUnique(
|
||||||
|
CPPDEFINES = [ 'HAVE_XCURSOR' ],
|
||||||
|
LIBS = [ 'Xcursor' ])
|
||||||
|
else:
|
||||||
|
aklock_env['xcursor'] = 0
|
||||||
|
print "sorry, no xcursor-support found."
|
||||||
|
conf.Finish()
|
||||||
|
|
||||||
|
aklock_options.Save('scons.opts', aklock_env)
|
||||||
|
|
||||||
aklock_program = SConscript(
|
aklock_program = SConscript(
|
||||||
'src/SConscript',
|
'src/SConscript',
|
||||||
exports = ['aklock_env']
|
exports = ['aklock_env']
|
||||||
|
|
BIN
contrib/xcursor-watch
Normal file
BIN
contrib/xcursor-watch
Normal file
Binary file not shown.
|
@ -24,6 +24,8 @@
|
||||||
/* ---------------------------------------------------------------- *\
|
/* ---------------------------------------------------------------- *\
|
||||||
\* ---------------------------------------------------------------- */
|
\* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
#include <X11/bitmaps/xlogo16>
|
||||||
|
|
||||||
#include "../bitmaps/mini.bitmap"
|
#include "../bitmaps/mini.bitmap"
|
||||||
#include "../bitmaps/mini_mask.bitmap"
|
#include "../bitmaps/mini_mask.bitmap"
|
||||||
|
|
||||||
|
@ -43,6 +45,10 @@ struct akCursor ak_cursors[] = {
|
||||||
xtr_width, xtr_height, xtr_x_hot, xtr_y_hot,
|
xtr_width, xtr_height, xtr_x_hot, xtr_y_hot,
|
||||||
xtr_bits, xtr_mask_bits },
|
xtr_bits, xtr_mask_bits },
|
||||||
|
|
||||||
|
{ "xlogo16",
|
||||||
|
xlogo16_width, xlogo16_height, xlogo16_width / 2, xlogo16_height / 2,
|
||||||
|
xlogo16_bits, xlogo16_bits },
|
||||||
|
|
||||||
{ NULL, 0, 0, 0, 0, NULL, NULL }
|
{ NULL, 0, 0, 0, 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
148
src/aklock.c
148
src/aklock.c
|
@ -31,6 +31,13 @@
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xos.h>
|
#include <X11/Xos.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_XPM
|
||||||
|
# include <X11/xpm.h>
|
||||||
|
#endif /* HAVE_XPM */
|
||||||
|
#ifdef HAVE_XCURSOR
|
||||||
|
# include <X11/Xcursor/Xcursor.h>
|
||||||
|
#endif /* HAVE_XCURSOR */
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -83,14 +90,7 @@ struct passwd *pw;
|
||||||
\*------------------------------------------------------------------*/
|
\*------------------------------------------------------------------*/
|
||||||
|
|
||||||
void displayUsage() {
|
void displayUsage() {
|
||||||
|
printf("\naklock [-h] [-v] [-blank] [-nolock] [-cursor <theme|xcursor:file>]\n");
|
||||||
printf("\naklock [-hv] [-blank]\n\n"
|
|
||||||
" -h shows this little help\n"
|
|
||||||
" -v shows the version number\n"
|
|
||||||
" -blank hides the content of the screen\n"
|
|
||||||
" -cursor theme for the cursor\n"
|
|
||||||
"\n"
|
|
||||||
"when the screen is locked, just enter your password.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,6 +261,7 @@ void checkAuth() {
|
||||||
|
|
||||||
void initOpts(struct akOpts* opts) {
|
void initOpts(struct akOpts* opts) {
|
||||||
|
|
||||||
|
opts->dont_lock = 0;
|
||||||
opts->use_blank = 0;
|
opts->use_blank = 0;
|
||||||
|
|
||||||
opts->cursor_name = "mini";
|
opts->cursor_name = "mini";
|
||||||
|
@ -277,11 +278,10 @@ void initXInfo(struct akXInfo* xinfo, struct akOpts* opts) {
|
||||||
XColor color_fg;
|
XColor color_fg;
|
||||||
XColor color_bg;
|
XColor color_bg;
|
||||||
XColor tmp_color;
|
XColor tmp_color;
|
||||||
Colormap color_map;
|
|
||||||
Pixmap pixmap_cursor;
|
Pixmap pixmap_cursor;
|
||||||
Pixmap pixmap_cursor_mask;
|
Pixmap pixmap_cursor_mask;
|
||||||
XWindowAttributes xgwa;
|
XWindowAttributes xgwa;
|
||||||
struct akCursor* cursor;
|
struct akCursor* cursor = NULL;
|
||||||
|
|
||||||
if (!dpy) {
|
if (!dpy) {
|
||||||
perror("aklock: error, can't open connection to X");
|
perror("aklock: error, can't open connection to X");
|
||||||
|
@ -292,29 +292,64 @@ void initXInfo(struct akXInfo* xinfo, struct akOpts* opts) {
|
||||||
xinfo->window = 0;
|
xinfo->window = 0;
|
||||||
|
|
||||||
xinfo->root = DefaultRootWindow(dpy);
|
xinfo->root = DefaultRootWindow(dpy);
|
||||||
color_map = DefaultColormap(dpy, DefaultScreen(dpy));
|
xinfo->colormap = DefaultColormap(dpy, DefaultScreen(dpy));
|
||||||
|
|
||||||
XGetWindowAttributes(dpy, xinfo->root, &xgwa);
|
XGetWindowAttributes(dpy, xinfo->root, &xgwa);
|
||||||
|
|
||||||
xinfo->width = xgwa.width;
|
if (opts->use_blank) {
|
||||||
xinfo->height = xgwa.height;
|
xinfo->width = xgwa.width;
|
||||||
|
xinfo->height = xgwa.height;
|
||||||
for(cursor = ak_cursors; cursor->name != NULL; cursor++) {
|
} else {
|
||||||
if (!strcmp(cursor->name, opts->cursor_name))
|
xinfo->width = 1;
|
||||||
break;
|
xinfo->height = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor == NULL)
|
if((XAllocNamedColor(dpy, xinfo->colormap, opts->color_bg, &tmp_color, &color_bg)) == 0)
|
||||||
|
XAllocNamedColor(dpy, xinfo->colormap, "black", &tmp_color, &color_bg);
|
||||||
|
if((XAllocNamedColor(dpy, xinfo->colormap, opts->color_fg, &tmp_color, &color_fg)) == 0)
|
||||||
|
XAllocNamedColor(dpy, xinfo->colormap, "white", &tmp_color, &color_fg);
|
||||||
|
|
||||||
|
/* load cursors */
|
||||||
|
#ifdef HAVE_XCURSOR
|
||||||
|
if (opts->cursor_name && (strstr(opts->cursor_name, "xcursor:"))) {
|
||||||
|
Cursor xcursor;
|
||||||
|
if ((xcursor = XcursorFilenameLoadCursor(dpy, &opts->cursor_name[8]))) {
|
||||||
|
xinfo->cursor = xcursor;
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
printf("aklock: error, couldnt load [%s]\n", &opts->cursor_name[8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* HAVE_XCURSOR */
|
||||||
|
|
||||||
|
/* TODO: doesnt work yet. */
|
||||||
|
/*
|
||||||
|
* if (opts->cursor_name && (strstr(opts->cursor_name, "xbm:"))) {
|
||||||
|
unsigned int w, h, xhot, yhot;
|
||||||
|
if (XReadBitmapFile(dpy, xinfo->root, &opts->cursor_name[4],
|
||||||
|
&w, &h, &pixmap_cursor, &xhot, &yhot)) {
|
||||||
|
xinfo->cursor = XCreatePixmapCursor(dpy,
|
||||||
|
pixmap_cursor, NULL,
|
||||||
|
&color_fg, &color_bg,
|
||||||
|
xhot, yhot);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
printf("aklock: error, couldnt load [%s]\n", &opts->cursor_name[4]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/* look internal cursors */
|
||||||
|
for(cursor = ak_cursors; cursor->name != NULL; cursor++) {
|
||||||
|
if (!strcmp(cursor->name, opts->cursor_name))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cursor->name)
|
||||||
cursor = ak_cursors;
|
cursor = ak_cursors;
|
||||||
|
|
||||||
pixmap_cursor = XCreateBitmapFromData(dpy, xinfo->root, cursor->bits, cursor->width, cursor->height);
|
pixmap_cursor = XCreateBitmapFromData(dpy, xinfo->root, cursor->bits, cursor->width, cursor->height);
|
||||||
pixmap_cursor_mask = XCreateBitmapFromData(dpy, xinfo->root, cursor->mask, cursor->width, cursor->height);
|
pixmap_cursor_mask = XCreateBitmapFromData(dpy, xinfo->root, cursor->mask, cursor->width, cursor->height);
|
||||||
|
|
||||||
if((XAllocNamedColor(dpy, color_map, opts->color_bg, &tmp_color, &color_bg)) == 0)
|
|
||||||
XAllocNamedColor(dpy, color_map, "black", &tmp_color, &color_bg);
|
|
||||||
if((XAllocNamedColor(dpy, color_map, opts->color_fg, &tmp_color, &color_fg)) == 0)
|
|
||||||
XAllocNamedColor(dpy, color_map, "white", &tmp_color, &color_fg);
|
|
||||||
|
|
||||||
xinfo->cursor = XCreatePixmapCursor(dpy,
|
xinfo->cursor = XCreatePixmapCursor(dpy,
|
||||||
pixmap_cursor, pixmap_cursor_mask,
|
pixmap_cursor, pixmap_cursor_mask,
|
||||||
&color_fg, &color_bg,
|
&color_fg, &color_bg,
|
||||||
|
@ -346,6 +381,8 @@ int main(int argc, char **argv) {
|
||||||
for(arg = 1; arg <= argc; arg++) {
|
for(arg = 1; arg <= argc; arg++) {
|
||||||
if (!strcmp(argv[arg - 1], "-blank")) {
|
if (!strcmp(argv[arg - 1], "-blank")) {
|
||||||
opts.use_blank = 1;
|
opts.use_blank = 1;
|
||||||
|
} else if (!strcmp(argv[arg - 1], "-nolock")) {
|
||||||
|
opts.dont_lock = 1;
|
||||||
} else if (!strcmp(argv[arg - 1], "-cursor")) {
|
} else if (!strcmp(argv[arg - 1], "-cursor")) {
|
||||||
if (arg < argc)
|
if (arg < argc)
|
||||||
opts.cursor_name = argv[arg];
|
opts.cursor_name = argv[arg];
|
||||||
|
@ -364,7 +401,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkAuth();
|
if (!opts.dont_lock)
|
||||||
|
checkAuth();
|
||||||
|
|
||||||
initXInfo(&xinfo, &opts);
|
initXInfo(&xinfo, &opts);
|
||||||
|
|
||||||
|
@ -376,30 +414,49 @@ int main(int argc, char **argv) {
|
||||||
if (opts.use_blank) {
|
if (opts.use_blank) {
|
||||||
|
|
||||||
xswa.background_pixel = BlackPixel(xinfo.display, DefaultScreen(xinfo.display));
|
xswa.background_pixel = BlackPixel(xinfo.display, DefaultScreen(xinfo.display));
|
||||||
|
xswa.colormap = xinfo.colormap;
|
||||||
xsmask |= CWBackPixel;
|
xsmask |= CWBackPixel;
|
||||||
|
xsmask |= CWColormap;
|
||||||
xinfo.window = XCreateWindow(xinfo.display, xinfo.root,
|
|
||||||
0, 0, xinfo.width, xinfo.height,
|
|
||||||
0, /* borderwidth */
|
|
||||||
CopyFromParent, /* depth */
|
|
||||||
InputOutput, /* class */
|
|
||||||
CopyFromParent, /* visual */
|
|
||||||
xsmask, &xswa);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
xinfo.window = XCreateWindow(xinfo.display, xinfo.root,
|
|
||||||
0, 0, 1, 1,
|
|
||||||
0, /* borderwidth */
|
|
||||||
CopyFromParent, /* depth */
|
|
||||||
InputOnly, /* class */
|
|
||||||
CopyFromParent, /* visual */
|
|
||||||
xsmask, &xswa);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xinfo.window = XCreateWindow(xinfo.display, xinfo.root,
|
||||||
|
0, 0, xinfo.width, xinfo.height,
|
||||||
|
0, /* borderwidth */
|
||||||
|
CopyFromParent, /* depth */
|
||||||
|
InputOutput, /* class */
|
||||||
|
CopyFromParent, /* visual */
|
||||||
|
xsmask, &xswa);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XSelectInput(xinfo.display, xinfo.window, KeyPressMask|KeyReleaseMask);
|
XSelectInput(xinfo.display, xinfo.window, KeyPressMask|KeyReleaseMask);
|
||||||
XMapWindow(xinfo.display, xinfo.window);
|
XMapWindow(xinfo.display, xinfo.window);
|
||||||
XRaiseWindow(xinfo.display, xinfo.window);
|
XRaiseWindow(xinfo.display, xinfo.window);
|
||||||
|
|
||||||
|
/* TODO: -bg <blank|transparent|shaded> */
|
||||||
|
if (opts.use_blank) {
|
||||||
|
XImage* ximage;
|
||||||
|
|
||||||
|
ximage = XGetImage (xinfo.display, xinfo.root, 0, 0,
|
||||||
|
xinfo.width, xinfo.height, AllPlanes, ZPixmap);
|
||||||
|
|
||||||
|
if (ximage) {
|
||||||
|
GC gc;
|
||||||
|
XGCValues xgcv;
|
||||||
|
xgcv.background = BlackPixel(xinfo.display, DefaultScreen(xinfo.display));
|
||||||
|
xgcv.foreground = 0;
|
||||||
|
|
||||||
|
gc = XCreateGC(xinfo.display, xinfo.window, GCForeground|GCBackground, &xgcv);
|
||||||
|
|
||||||
|
XPutImage(xinfo.display, xinfo.window,
|
||||||
|
gc,
|
||||||
|
ximage,
|
||||||
|
0, 0,
|
||||||
|
0, 0, xinfo.width, xinfo.height);
|
||||||
|
XDestroyImage(ximage);
|
||||||
|
XFreeGC(xinfo.display, gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
/* try to grab 2 times, another process (windowmanager) may have grabbed
|
/* try to grab 2 times, another process (windowmanager) may have grabbed
|
||||||
* the keyboard already */
|
* the keyboard already */
|
||||||
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
if ((XGrabKeyboard(xinfo.display, xinfo.window, True, GrabModeAsync, GrabModeAsync,
|
||||||
|
@ -424,10 +481,15 @@ int main(int argc, char **argv) {
|
||||||
XNextEvent(xinfo.display, &ev);
|
XNextEvent(xinfo.display, &ev);
|
||||||
switch (ev.type) {
|
switch (ev.type) {
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
|
|
||||||
|
if (opts.dont_lock)
|
||||||
|
goto exit;
|
||||||
|
|
||||||
if (ev.xkey.time < timeout) {
|
if (ev.xkey.time < timeout) {
|
||||||
XBell(xinfo.display, 0);
|
XBell(xinfo.display, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
clen = XLookupString(&ev.xkey, cbuf, 9, &ks, 0);
|
clen = XLookupString(&ev.xkey, cbuf, 9, &ks, 0);
|
||||||
switch (ks) {
|
switch (ks) {
|
||||||
case XK_Escape:
|
case XK_Escape:
|
||||||
|
@ -444,8 +506,11 @@ int main(int argc, char **argv) {
|
||||||
if (rlen == 0)
|
if (rlen == 0)
|
||||||
break;
|
break;
|
||||||
rbuf[rlen] = 0;
|
rbuf[rlen] = 0;
|
||||||
|
|
||||||
if (passwordOk(rbuf))
|
if (passwordOk(rbuf))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
XSync(xinfo.display, True); /* discard pending events to start really fresh */
|
||||||
XBell(xinfo.display, 0);
|
XBell(xinfo.display, 0);
|
||||||
rlen = 0;
|
rlen = 0;
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
|
@ -474,6 +539,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
XDestroyWindow(xinfo.display, xinfo.window);
|
XDestroyWindow(xinfo.display, xinfo.window);
|
||||||
|
XFreeCursor(xinfo.display, xinfo.cursor);
|
||||||
XCloseDisplay(xinfo.display);
|
XCloseDisplay(xinfo.display);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -38,6 +38,7 @@ struct akXInfo {
|
||||||
Display* display;
|
Display* display;
|
||||||
Window root;
|
Window root;
|
||||||
Window window;
|
Window window;
|
||||||
|
Colormap colormap;
|
||||||
|
|
||||||
Cursor cursor;
|
Cursor cursor;
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ struct akXInfo {
|
||||||
|
|
||||||
struct akOpts {
|
struct akOpts {
|
||||||
|
|
||||||
|
char dont_lock;
|
||||||
char use_blank;
|
char use_blank;
|
||||||
|
|
||||||
char* cursor_name;
|
char* cursor_name;
|
||||||
|
|
Reference in a new issue