diff options
author | Anselm R. Garbe <garbeam@gmail.com> | 2007-11-24 21:17:32 +0100 |
---|---|---|
committer | Anselm R. Garbe <garbeam@gmail.com> | 2007-11-24 21:17:32 +0100 |
commit | 6fdf8be2044145c11f7e1eb165613f791c514520 (patch) | |
tree | 970d35d140311a6ac7c796e8d98903bbb723091a | |
parent | 1fd4e7b23e872c16902d222b6c870116c948903c (diff) |
final fixes and cleanups
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | config.mk | 1 | ||||
-rw-r--r-- | slock.c | 35 |
3 files changed, 20 insertions, 18 deletions
@@ -21,4 +21,4 @@ necessary as root): | |||
21 | 21 | ||
22 | Running slock | 22 | Running slock |
23 | ------------- | 23 | ------------- |
24 | Simply invoke the 'slock' command. | 24 | Simply invoke the 'slock' command. To get out of it, enter your password. |
@@ -5,7 +5,6 @@ VERSION = 0.7 | |||
5 | 5 | ||
6 | # paths | 6 | # paths |
7 | PREFIX = /usr/local | 7 | PREFIX = /usr/local |
8 | MANPREFIX = ${PREFIX}/share/man | ||
9 | 8 | ||
10 | X11INC = /usr/X11R6/include | 9 | X11INC = /usr/X11R6/include |
11 | X11LIB = /usr/X11R6/lib | 10 | X11LIB = /usr/X11R6/lib |
@@ -7,6 +7,7 @@ | |||
7 | 7 | ||
8 | #include <ctype.h> | 8 | #include <ctype.h> |
9 | #include <pwd.h> | 9 | #include <pwd.h> |
10 | #include <stdarg.h> | ||
10 | #include <stdlib.h> | 11 | #include <stdlib.h> |
11 | #include <stdio.h> | 12 | #include <stdio.h> |
12 | #include <string.h> | 13 | #include <string.h> |
@@ -16,15 +17,23 @@ | |||
16 | #include <X11/Xlib.h> | 17 | #include <X11/Xlib.h> |
17 | #include <X11/Xutil.h> | 18 | #include <X11/Xutil.h> |
18 | 19 | ||
20 | void | ||
21 | eprint(const char *errstr, ...) { | ||
22 | va_list ap; | ||
23 | |||
24 | va_start(ap, errstr); | ||
25 | vfprintf(stderr, errstr, ap); | ||
26 | va_end(ap); | ||
27 | exit(EXIT_FAILURE); | ||
28 | } | ||
29 | |||
19 | const char * | 30 | const char * |
20 | get_password() { /* only run as root */ | 31 | get_password() { /* only run as root */ |
21 | const char *rval; | 32 | const char *rval; |
22 | struct passwd *pw; | 33 | struct passwd *pw; |
23 | 34 | ||
24 | if(geteuid() != 0) { | 35 | if(geteuid() != 0) |
25 | fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr); | 36 | eprint("slock: cannot retrieve password entry (make sure to suid slock)\n"); |
26 | exit(EXIT_FAILURE); | ||
27 | } | ||
28 | pw = getpwuid(getuid()); | 37 | pw = getpwuid(getuid()); |
29 | endpwent(); | 38 | endpwent(); |
30 | rval = pw->pw_passwd; | 39 | rval = pw->pw_passwd; |
@@ -38,10 +47,8 @@ get_password() { /* only run as root */ | |||
38 | } | 47 | } |
39 | #endif | 48 | #endif |
40 | /* drop privileges */ | 49 | /* drop privileges */ |
41 | if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) { | 50 | if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) |
42 | fputs("slock: cannot drop privileges\n",stdout); | 51 | eprint("slock: cannot drop privileges\n"); |
43 | exit(EXIT_FAILURE); | ||
44 | } | ||
45 | return rval; | 52 | return rval; |
46 | } | 53 | } |
47 | 54 | ||
@@ -62,15 +69,11 @@ main(int argc, char **argv) { | |||
62 | XEvent ev; | 69 | XEvent ev; |
63 | XSetWindowAttributes wa; | 70 | XSetWindowAttributes wa; |
64 | 71 | ||
65 | if((argc > 1) && !strncmp(argv[1], "-v", 3)) { | 72 | if((argc > 1) && !strncmp(argv[1], "-v", 3)) |
66 | fputs("slock-"VERSION", © 2006-2007 Anselm R. Garbe\n", stdout); | 73 | eprint("slock-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n"); |
67 | exit(EXIT_SUCCESS); | ||
68 | } | ||
69 | pws = get_password(); | 74 | pws = get_password(); |
70 | if(!(dpy = XOpenDisplay(0))) { | 75 | if(!(dpy = XOpenDisplay(0))) |
71 | fputs("slock: cannot open display\n", stderr); | 76 | eprint("slock: cannot open display\n"); |
72 | exit(EXIT_FAILURE); | ||
73 | } | ||
74 | screen = DefaultScreen(dpy); | 77 | screen = DefaultScreen(dpy); |
75 | root = RootWindow(dpy, screen); | 78 | root = RootWindow(dpy, screen); |
76 | 79 | ||