Skip to content

Commit ba3acfc

Browse files
committed
applied Robert Schneider's Linux suggestions, also bumped version and updated LICENSE file's copyright notice
1 parent 3092d3b commit ba3acfc

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

Diff for: LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT/X Consortium License
22

3-
© 2006-2012 Anselm R Garbe <[email protected]>
3+
© 2006-2013 Anselm R Garbe <[email protected]>
44

55
Permission is hereby granted, free of charge, to any person obtaining a
66
copy of this software and associated documentation files (the "Software"),

Diff for: config.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# slock version
2-
VERSION = 1.1
2+
VERSION = 1.2
33

44
# Customize below to fit your system
55

Diff for: slock.c

+28-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ die(const char *errstr, ...) {
4444
exit(EXIT_FAILURE);
4545
}
4646

47+
#ifdef __linux__
48+
#include <fcntl.h>
49+
50+
static void
51+
dontkillme(void) {
52+
int fd;
53+
54+
fd = open("/proc/self/oom_score_adj", O_WRONLY);
55+
if (fd < 0 && errno == ENOENT)
56+
return;
57+
if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
58+
die("cannot disable the out-of-memory killer for this process\n");
59+
}
60+
#endif
61+
4762
#ifndef HAVE_BSD_AUTH
4863
static const char *
4964
getpw(void) { /* only run as root */
@@ -52,7 +67,7 @@ getpw(void) { /* only run as root */
5267

5368
pw = getpwuid(getuid());
5469
if(!pw)
55-
die("slock: cannot retrieve password entry (make sure to suid or sgid slock)");
70+
die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n");
5671
endpwent();
5772
rval = pw->pw_passwd;
5873

@@ -68,8 +83,9 @@ getpw(void) { /* only run as root */
6883
#endif
6984

7085
/* drop privileges */
71-
if(setgid(pw->pw_gid) < 0 || setuid(pw->pw_uid) < 0)
72-
die("slock: cannot drop privileges");
86+
if (geteuid() == 0
87+
&& ((getegid() != pw->pw_gid && setgid(pw->pw_gid) < 0) || setuid(pw->pw_uid) < 0))
88+
die("slock: cannot drop privileges\n");
7389
return rval;
7490
}
7591
#endif
@@ -114,9 +130,9 @@ readpw(Display *dpy, const char *pws)
114130
#ifdef HAVE_BSD_AUTH
115131
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
116132
#else
117-
running = strcmp(crypt(passwd, pws), pws);
133+
running = !!strcmp(crypt(passwd, pws), pws);
118134
#endif
119-
if(running != False)
135+
if(running)
120136
XBell(dpy, 100);
121137
len = 0;
122138
break;
@@ -244,20 +260,24 @@ main(int argc, char **argv) {
244260
else if(argc != 1)
245261
usage();
246262

263+
#ifdef __linux__
264+
dontkillme();
265+
#endif
266+
247267
if(!getpwuid(getuid()))
248-
die("slock: no passwd entry for you");
268+
die("slock: no passwd entry for you\n");
249269

250270
#ifndef HAVE_BSD_AUTH
251271
pws = getpw();
252272
#endif
253273

254274
if(!(dpy = XOpenDisplay(0)))
255-
die("slock: cannot open display");
275+
die("slock: cannot open display\n");
256276
/* Get the number of screens in display "dpy" and blank them all. */
257277
nscreens = ScreenCount(dpy);
258278
locks = malloc(sizeof(Lock *) * nscreens);
259279
if(locks == NULL)
260-
die("slock: malloc: %s", strerror(errno));
280+
die("slock: malloc: %s\n", strerror(errno));
261281
int nlocks = 0;
262282
for(screen = 0; screen < nscreens; screen++) {
263283
if ( (locks[screen] = lockscreen(dpy, screen)) != NULL)

0 commit comments

Comments
 (0)