aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--LICENSE2
-rw-r--r--config.mk11
-rw-r--r--slock.c34
3 files changed, 39 insertions, 8 deletions
diff --git a/LICENSE b/LICENSE
index 9425c10..490492c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
1MIT/X Consortium License 1MIT/X Consortium License
2 2
3© 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> 3© 2006-2008 Anselm R Garbe <garbeam at gmail dot com>
4 4
5Permission is hereby granted, free of charge, to any person obtaining a 5Permission is hereby granted, free of charge, to any person obtaining a
6copy of this software and associated documentation files (the "Software"), 6copy of this software and associated documentation files (the "Software"),
diff --git a/config.mk b/config.mk
index 345475c..d17c762 100644
--- a/config.mk
+++ b/config.mk
@@ -11,17 +11,22 @@ X11LIB = /usr/X11R6/lib
11 11
12# includes and libs 12# includes and libs
13INCS = -I. -I/usr/include -I${X11INC} 13INCS = -I. -I/usr/include -I${X11INC}
14LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 14LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext
15 15
16# flags 16# flags
17CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H 17CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H
18LDFLAGS = ${LIBS} 18LDFLAGS = ${LIBS}
19#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H 19#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H
20#LDFLAGS = -g ${LIBS} 20#LDFLAGS = -g ${LIBS}
21 21
22# On *BSD remove -DHAVE_SHADOW_H from CFLAGS 22# On *BSD remove -DHAVE_SHADOW_H from CFLAGS and add -DHAVE_BSD_AUTH
23# On OpenBSD and Darwin remove -lcrypt from LIBS 23# On OpenBSD and Darwin remove -lcrypt from LIBS
24 24
25# compiler and linker 25# compiler and linker
26CC = cc 26CC = cc
27LD = ${CC} 27LD = ${CC}
28
29# Install mode. On BSD systems MODE=2755 and GROUP=auth
30# On others MODE=4755 and GROUP=root
31#MODE=2755
32#GROUP=auth
diff --git a/slock.c b/slock.c
index 4723102..2dc9648 100644
--- a/slock.c
+++ b/slock.c
@@ -1,4 +1,4 @@
1/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> 1/* © 2006-2008 Anselm R Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details. */ 2 * See LICENSE file for license details. */
3#define _XOPEN_SOURCE 500 3#define _XOPEN_SOURCE 500
4#if HAVE_SHADOW_H 4#if HAVE_SHADOW_H
@@ -16,6 +16,12 @@
16#include <X11/keysym.h> 16#include <X11/keysym.h>
17#include <X11/Xlib.h> 17#include <X11/Xlib.h>
18#include <X11/Xutil.h> 18#include <X11/Xutil.h>
19#include <X11/extensions/dpms.h>
20
21#if HAVE_BSD_AUTH
22#include <login_cap.h>
23#include <bsd_auth.h>
24#endif
19 25
20void 26void
21eprint(const char *errstr, ...) { 27eprint(const char *errstr, ...) {
@@ -27,6 +33,7 @@ eprint(const char *errstr, ...) {
27 exit(EXIT_FAILURE); 33 exit(EXIT_FAILURE);
28} 34}
29 35
36#ifndef HAVE_BSD_AUTH
30const char * 37const char *
31get_password() { /* only run as root */ 38get_password() { /* only run as root */
32 const char *rval; 39 const char *rval;
@@ -46,18 +53,23 @@ get_password() { /* only run as root */
46 rval = sp->sp_pwdp; 53 rval = sp->sp_pwdp;
47 } 54 }
48#endif 55#endif
56
49 /* drop privileges */ 57 /* drop privileges */
50 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) 58 if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
51 eprint("slock: cannot drop privileges\n"); 59 eprint("slock: cannot drop privileges\n");
52 return rval; 60 return rval;
53} 61}
62#endif
54 63
55int 64int
56main(int argc, char **argv) { 65main(int argc, char **argv) {
57 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0}; 66 char curs[] = {0, 0, 0, 0, 0, 0, 0, 0};
58 char buf[32], passwd[256]; 67 char buf[32], passwd[256];
59 int num, screen; 68 int num, screen;
69
70#ifndef HAVE_BSD_AUTH
60 const char *pws; 71 const char *pws;
72#endif
61 unsigned int len; 73 unsigned int len;
62 Bool running = True; 74 Bool running = True;
63 Cursor invisible; 75 Cursor invisible;
@@ -70,10 +82,14 @@ main(int argc, char **argv) {
70 XSetWindowAttributes wa; 82 XSetWindowAttributes wa;
71 83
72 if((argc == 2) && !strcmp("-v", argv[1])) 84 if((argc == 2) && !strcmp("-v", argv[1]))
73 eprint("slock-"VERSION", © 2006-2007 Anselm R. Garbe\n"); 85 eprint("slock-"VERSION", © 2006-2008 Anselm R Garbe\n");
74 else if(argc != 1) 86 else if(argc != 1)
75 eprint("usage: slock [-v]\n"); 87 eprint("usage: slock [-v]\n");
88
89#ifndef HAVE_BSD_AUTH
76 pws = get_password(); 90 pws = get_password();
91#endif
92
77 if(!(dpy = XOpenDisplay(0))) 93 if(!(dpy = XOpenDisplay(0)))
78 eprint("slock: cannot open display\n"); 94 eprint("slock: cannot open display\n");
79 screen = DefaultScreen(dpy); 95 screen = DefaultScreen(dpy);
@@ -109,7 +125,9 @@ main(int argc, char **argv) {
109 XSync(dpy, False); 125 XSync(dpy, False);
110 126
111 /* main event loop */ 127 /* main event loop */
112 while(running && !XNextEvent(dpy, &ev)) 128 while(running && !XNextEvent(dpy, &ev)) {
129 if(len == 0)
130 DPMSForceLevel(dpy, DPMSModeOff);
113 if(ev.type == KeyPress) { 131 if(ev.type == KeyPress) {
114 buf[0] = 0; 132 buf[0] = 0;
115 num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0); 133 num = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, 0);
@@ -120,7 +138,14 @@ main(int argc, char **argv) {
120 switch(ksym) { 138 switch(ksym) {
121 case XK_Return: 139 case XK_Return:
122 passwd[len] = 0; 140 passwd[len] = 0;
123 if((running = strcmp(crypt(passwd, pws), pws)) != 0) 141
142#ifdef HAVE_BSD_AUTH
143 running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
144#else
145 running = strcmp(crypt(passwd, pws), pws);
146#endif
147
148 if (running != 0)
124 XBell(dpy, 100); 149 XBell(dpy, 100);
125 len = 0; 150 len = 0;
126 break; 151 break;
@@ -139,6 +164,7 @@ main(int argc, char **argv) {
139 break; 164 break;
140 } 165 }
141 } 166 }
167 }
142 XUngrabPointer(dpy, CurrentTime); 168 XUngrabPointer(dpy, CurrentTime);
143 XFreePixmap(dpy, pmap); 169 XFreePixmap(dpy, pmap);
144 XDestroyWindow(dpy, w); 170 XDestroyWindow(dpy, w);