final fixes and cleanups
This commit is contained in:
parent
1fd4e7b23e
commit
6fdf8be204
3 changed files with 20 additions and 18 deletions
2
README
2
README
|
@ -21,4 +21,4 @@ necessary as root):
|
||||||
|
|
||||||
Running slock
|
Running slock
|
||||||
-------------
|
-------------
|
||||||
Simply invoke the 'slock' command.
|
Simply invoke the 'slock' command. To get out of it, enter your password.
|
||||||
|
|
|
@ -5,7 +5,6 @@ VERSION = 0.7
|
||||||
|
|
||||||
# paths
|
# paths
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = ${PREFIX}/share/man
|
|
||||||
|
|
||||||
X11INC = /usr/X11R6/include
|
X11INC = /usr/X11R6/include
|
||||||
X11LIB = /usr/X11R6/lib
|
X11LIB = /usr/X11R6/lib
|
||||||
|
|
35
slock.c
35
slock.c
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -16,15 +17,23 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.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 *
|
const char *
|
||||||
get_password() { /* only run as root */
|
get_password() { /* only run as root */
|
||||||
const char *rval;
|
const char *rval;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
if(geteuid() != 0) {
|
if(geteuid() != 0)
|
||||||
fputs("slock: cannot retrieve password entry (make sure to suid slock)\n", stderr);
|
eprint("slock: cannot retrieve password entry (make sure to suid slock)\n");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
endpwent();
|
endpwent();
|
||||||
rval = pw->pw_passwd;
|
rval = pw->pw_passwd;
|
||||||
|
@ -38,10 +47,8 @@ get_password() { /* only run as root */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* drop privileges */
|
/* drop privileges */
|
||||||
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0) {
|
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
|
||||||
fputs("slock: cannot drop privileges\n",stdout);
|
eprint("slock: cannot drop privileges\n");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,15 +69,11 @@ main(int argc, char **argv) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
|
||||||
if((argc > 1) && !strncmp(argv[1], "-v", 3)) {
|
if((argc > 1) && !strncmp(argv[1], "-v", 3))
|
||||||
fputs("slock-"VERSION", © 2006-2007 Anselm R. Garbe\n", stdout);
|
eprint("slock-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n");
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
pws = get_password();
|
pws = get_password();
|
||||||
if(!(dpy = XOpenDisplay(0))) {
|
if(!(dpy = XOpenDisplay(0)))
|
||||||
fputs("slock: cannot open display\n", stderr);
|
eprint("slock: cannot open display\n");
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue