1 /* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <sys/types.h>
11 #include <X11/keysym.h>
13 #include <X11/Xutil.h>
16 main(int argc, char **argv) {
17 char buf[32], passwd[256];
26 if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
27 fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
30 if(!(sp = getspnam(getenv("USER")))) {
31 fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
35 if(!(dpy = XOpenDisplay(0))) {
36 fputs("slock: cannot open display\n", stderr);
42 while(XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
43 GrabModeAsync, CurrentTime) != GrabSuccess)
47 while(running && !XNextEvent(dpy, &ev))
48 if(ev.type == KeyPress) {
51 num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
52 if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
53 || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
54 || IsPrivateKeypadKey(ksym))
56 /* first check if a control mask is omitted */
57 if(ev.xkey.state & ControlMask) {
60 case XK_H: ksym = XK_BackSpace;
63 case XK_U: passwd[0] = 0;
69 running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd));
80 if(num && !iscntrl((int) buf[0])) {
83 strncat(passwd, buf, sizeof(passwd));
85 strncpy(passwd, buf, sizeof(passwd));