6 Commits
6 changed files with 30 additions and 28 deletions
+2
View File
@@ -2,3 +2,5 @@
da5cb1f0a685258d5315ea109860bacbc2871a57 0.2
f9157b1864388ad8f1920e5fde7c5849e73d8327 0.3
4c2cf4d6a2d0e08cbe280ec50ef76c9aecfc0fbe 0.4
bd24ea7fcca26b161225c464df23ecbfe85280e1 0.5
dd226a81c09adfa86db232419b3000b7e406df68 0.6
+1 -1
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"),
+1 -1
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
+1 -1
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.
+1 -2
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
+24 -23
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);