6 Commits
0.5 ... 0.7

Author SHA1 Message Date
Anselm R. Garbe
6fdf8be204 final fixes and cleanups 2007-11-24 21:17:32 +01:00
arg@suckless.org
1fd4e7b23e applied Ryan Sorensen bugfix which allows slock to acquire the keyboard grab asynchroneously 2007-11-13 18:16:18 +01:00
Anselm R. Garbe
20e294a66f updating copyright stuff in slock as well 2007-04-13 11:48:17 +02:00
Anselm R. Garbe
1726ff0816 Added tag 0.6 for changeset dd226a81c09a 2007-03-07 13:31:49 +01:00
Anselm R. Garbe
48a7ab2225 grab on the root window, it is correct, all lockers do that 2007-03-07 10:57:23 +01:00
Anselm R. Garbe
d8ea936899 Added tag 0.5 for changeset bd24ea7fcca2 2007-03-05 11:28:53 +01:00
6 changed files with 30 additions and 28 deletions

View File

@@ -2,3 +2,5 @@
da5cb1f0a685258d5315ea109860bacbc2871a57 0.2
f9157b1864388ad8f1920e5fde7c5849e73d8327 0.3
4c2cf4d6a2d0e08cbe280ec50ef76c9aecfc0fbe 0.4
bd24ea7fcca26b161225c464df23ecbfe85280e1 0.5
dd226a81c09adfa86db232419b3000b7e406df68 0.6

View File

@@ -1,6 +1,6 @@
MIT/X Consortium License
(C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
© 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),

View File

@@ -1,5 +1,5 @@
# slock - simple screen locker
# (C)opyright MMVI-MMVII Anselm R. Garbe
# © 2006-2007 Anselm R. Garbe, Sander van Dijk
include config.mk

2
README
View File

@@ -21,4 +21,4 @@ necessary as root):
Running slock
-------------
Simply invoke the 'slock' command.
Simply invoke the 'slock' command. To get out of it, enter your password.

View File

@@ -1,11 +1,10 @@
# slock version
VERSION = 0.5
VERSION = 0.7
# Customize below to fit your system
# paths
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib

47
slock.c
View File

@@ -1,6 +1,5 @@
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details. */
#define _XOPEN_SOURCE 500
#if HAVE_SHADOW_H
#include <shadow.h>
@@ -8,6 +7,7 @@
#include <ctype.h>
#include <pwd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -17,15 +17,23 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
void
eprint(const char *errstr, ...) {
va_list ap;
va_start(ap, errstr);
vfprintf(stderr, errstr, ap);
va_end(ap);
exit(EXIT_FAILURE);
}
const char *
get_password() { /* only run as root */
const char *rval;
struct passwd *pw;
if(geteuid() != 0) {
fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
exit(EXIT_FAILURE);
}
if(geteuid() != 0)
eprint("slock: cannot retrieve password entry (make sure to suid slock)\n");
pw = getpwuid(getuid());
endpwent();
rval = pw->pw_passwd;
@@ -39,10 +47,8 @@ get_password() { /* only run as root */
}
#endif
/* drop privileges */
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
fputs("slock: cannot drop privileges\n",stdout);
exit(EXIT_FAILURE);
}
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
eprint("slock: cannot drop privileges\n");
return rval;
}
@@ -63,15 +69,11 @@ main(int argc, char **argv) {
XEvent ev;
XSetWindowAttributes wa;
if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
fputs("slock-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
exit(EXIT_SUCCESS);
}
if((argc > 1) && !strncmp(argv[1], "-v", 3))
eprint("slock-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n");
pws = get_password();
if(!(dpy = XOpenDisplay(0))) {
fputs("slock: cannot open display\n", stderr);
exit(EXIT_FAILURE);
}
if(!(dpy = XOpenDisplay(0)))
eprint("slock: cannot open display\n");
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
@@ -81,21 +83,20 @@ main(int argc, char **argv) {
w = XCreateWindow(dpy, root, 0, 0, DisplayWidth(dpy, screen), DisplayHeight(dpy, screen),
0, DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixel, &wa);
XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "black", &black, &dummy);
pmap = XCreateBitmapFromData(dpy, w, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, pmap, pmap, &black, &black, 0, 0);
XDefineCursor(dpy, w, invisible);
XMapRaised(dpy, w);
for(len = 1000; len; len--) {
if(XGrabPointer(dpy, w, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeSync, None, invisible, CurrentTime) == GrabSuccess)
if(XGrabPointer(dpy, root, False, ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, invisible, CurrentTime) == GrabSuccess)
break;
usleep(1000);
}
if((running = running && (len > 0))) {
for(len = 1000; len; len--) {
if(XGrabKeyboard(dpy, w, True, GrabModeAsync, GrabModeAsync, CurrentTime)
if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
break;
usleep(1000);