diff options
author | Anselm R Garbe <garbeam@gmail.com> | 2008-02-22 10:13:12 +0000 |
---|---|---|
committer | Anselm R Garbe <garbeam@gmail.com> | 2008-02-22 10:13:12 +0000 |
commit | 98e2fef63d2e6dbda63929867db70bee1f8b55f5 (patch) | |
tree | 1b15d1afa22d6411b4c95e525b7d76eab7d853d3 | |
parent | a430a647e48a894499143b03da86e5707b4127df (diff) |
applied two patches, BSD_AUTH patch and Gottox' DPMS support patch
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | config.mk | 11 | ||||
-rw-r--r-- | slock.c | 34 |
3 files changed, 39 insertions, 8 deletions
@@ -1,6 +1,6 @@ | |||
1 | MIT/X Consortium License | 1 | MIT/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 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a | 5 | Permission is hereby granted, free of charge, to any person obtaining a |
6 | copy of this software and associated documentation files (the "Software"), | 6 | copy of this software and associated documentation files (the "Software"), |
@@ -11,17 +11,22 @@ X11LIB = /usr/X11R6/lib | |||
11 | 11 | ||
12 | # includes and libs | 12 | # includes and libs |
13 | INCS = -I. -I/usr/include -I${X11INC} | 13 | INCS = -I. -I/usr/include -I${X11INC} |
14 | LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 | 14 | LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext |
15 | 15 | ||
16 | # flags | 16 | # flags |
17 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H | 17 | CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" -DHAVE_SHADOW_H |
18 | LDFLAGS = ${LIBS} | 18 | LDFLAGS = ${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 |
26 | CC = cc | 26 | CC = cc |
27 | LD = ${CC} | 27 | LD = ${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 | ||
@@ -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 | ||
20 | void | 26 | void |
21 | eprint(const char *errstr, ...) { | 27 | eprint(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 | ||
30 | const char * | 37 | const char * |
31 | get_password() { /* only run as root */ | 38 | get_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 | ||
55 | int | 64 | int |
56 | main(int argc, char **argv) { | 65 | main(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); |