aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--config.mk1
-rw-r--r--slock.c35
3 files changed, 20 insertions, 18 deletions
diff --git a/README b/README
index fc24b27..5940337 100644
--- a/README
+++ b/README
@@ -21,4 +21,4 @@ necessary as root):
21 21
22Running slock 22Running slock
23------------- 23-------------
24Simply invoke the 'slock' command. 24Simply invoke the 'slock' command. To get out of it, enter your password.
diff --git a/config.mk b/config.mk
index 1a17285..6dbd4c4 100644
--- a/config.mk
+++ b/config.mk
@@ -5,7 +5,6 @@ VERSION = 0.7
5 5
6# paths 6# paths
7PREFIX = /usr/local 7PREFIX = /usr/local
8MANPREFIX = ${PREFIX}/share/man
9 8
10X11INC = /usr/X11R6/include 9X11INC = /usr/X11R6/include
11X11LIB = /usr/X11R6/lib 10X11LIB = /usr/X11R6/lib
diff --git a/slock.c b/slock.c
index daa3cf7..a7f79d9 100644
--- a/slock.c
+++ b/slock.c
@@ -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
20void
21eprint(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
19const char * 30const char *
20get_password() { /* only run as root */ 31get_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