1 /* (C)opyright MMIV-MMV Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
16 #include <sys/types.h>
17 #include <X11/keysym.h>
19 #include <X11/Xutil.h>
22 main(int argc, char **argv) {
23 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
24 char buf[32], passwd[256];
25 int num, prev_nitem, screen;
40 XSetWindowAttributes wa;
42 if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
43 fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
47 fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
51 sp = getspnam(getenv("USER"));
54 pw = getpwuid(getuid());
57 if(!(dpy = XOpenDisplay(0))) {
58 fputs("slock: cannot open display\n", stderr);
61 screen = DefaultScreen(dpy);
65 while(XGrabKeyboard(dpy, RootWindow(dpy, screen), True, GrabModeAsync,
66 GrabModeAsync, CurrentTime) != GrabSuccess)
69 wa.override_redirect = 1;
70 wa.background_pixel = BlackPixel(dpy, screen);
71 w = XCreateWindow(dpy, RootWindow(dpy, screen), 0, 0,
72 DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
73 0, DefaultDepth(dpy, screen), CopyFromParent,
74 DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
76 XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy);
77 pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
78 invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
79 XDefineCursor(dpy, w, invisible);
84 while(running && !XNextEvent(dpy, &ev))
85 if(ev.type == KeyPress) {
88 num = XLookupString(&ev.xkey, buf, sizeof(buf), &ksym, 0);
89 if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
90 || IsMiscFunctionKey(ksym) || IsPFKey(ksym)
91 || IsPrivateKeypadKey(ksym))
93 /* first check if a control mask is omitted */
94 if(ev.xkey.state & ControlMask) {
97 case XK_H: ksym = XK_BackSpace;
100 case XK_U: passwd[0] = 0;
107 if((running = strncmp(crypt(passwd, sp->sp_pwdp), sp->sp_pwdp, sizeof(passwd))))
109 if((running = strncmp(crypt(passwd, pw->pw_passwd), pw->pw_passwd, sizeof(passwd))))
122 if(num && !iscntrl((int) buf[0])) {
125 strncat(passwd, buf, sizeof(passwd));
127 strncpy(passwd, buf, sizeof(passwd));
132 XFreePixmap(dpy, pmap);
133 XDestroyWindow(dpy, w);