feature: allow custom passwords.
This commit is contained in:
parent
8745098fa4
commit
1ba98464fd
22
slock.c
22
slock.c
@ -23,6 +23,8 @@
|
|||||||
#include <bsd_auth.h>
|
#include <bsd_auth.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
char *g_pw = NULL;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int screen;
|
int screen;
|
||||||
Window root, win;
|
Window root, win;
|
||||||
@ -55,16 +57,20 @@ dontkillme(void) {
|
|||||||
if (fd < 0 && errno == ENOENT)
|
if (fd < 0 && errno == ENOENT)
|
||||||
return;
|
return;
|
||||||
if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
|
if (fd < 0 || write(fd, "-1000\n", 6) != 6 || close(fd) != 0)
|
||||||
die("cannot disable the out-of-memory killer for this process\n");
|
fprintf(stderr, "cannot disable the out-of-memory killer for this process\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_BSD_AUTH
|
#ifndef HAVE_BSD_AUTH
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getpw(void) { /* only run as root */
|
getpw(void) { /* only run as root */
|
||||||
const char *rval;
|
const char *rval;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
|
if (g_pw)
|
||||||
|
return g_pw;
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
if (!pw) {
|
if (!pw) {
|
||||||
@ -135,7 +141,11 @@ readpw(Display *dpy, const char *pws)
|
|||||||
#ifdef HAVE_BSD_AUTH
|
#ifdef HAVE_BSD_AUTH
|
||||||
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
|
running = !auth_userokay(getlogin(), NULL, "auth-xlock", passwd);
|
||||||
#else
|
#else
|
||||||
running = !!strcmp(crypt(passwd, pws), pws);
|
if (g_pw) {
|
||||||
|
running = !!strcmp(passwd, g_pw);
|
||||||
|
} else {
|
||||||
|
running = !!strcmp(crypt(passwd, pws), pws);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if(running)
|
if(running)
|
||||||
XBell(dpy, 100);
|
XBell(dpy, 100);
|
||||||
@ -240,7 +250,7 @@ lockscreen(Display *dpy, int screen) {
|
|||||||
unlockscreen(dpy, lock);
|
unlockscreen(dpy, lock);
|
||||||
lock = NULL;
|
lock = NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
XSelectInput(dpy, lock->root, SubstructureNotifyMask);
|
XSelectInput(dpy, lock->root, SubstructureNotifyMask);
|
||||||
|
|
||||||
return lock;
|
return lock;
|
||||||
@ -260,7 +270,9 @@ main(int argc, char **argv) {
|
|||||||
Display *dpy;
|
Display *dpy;
|
||||||
int screen;
|
int screen;
|
||||||
|
|
||||||
if((argc == 2) && !strcmp("-v", argv[1]))
|
if((argc >= 2) && !strcmp("-p", argv[1]))
|
||||||
|
g_pw = argv[2];
|
||||||
|
else if((argc >= 2) && !strcmp("-v", argv[1]))
|
||||||
die("slock-%s, © 2006-2012 Anselm R Garbe\n", VERSION);
|
die("slock-%s, © 2006-2012 Anselm R Garbe\n", VERSION);
|
||||||
else if(argc != 1)
|
else if(argc != 1)
|
||||||
usage();
|
usage();
|
||||||
@ -269,7 +281,7 @@ main(int argc, char **argv) {
|
|||||||
dontkillme();
|
dontkillme();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(!getpwuid(getuid()))
|
if(!g_pw && !getpwuid(getuid()))
|
||||||
die("slock: no passwd entry for you\n");
|
die("slock: no passwd entry for you\n");
|
||||||
|
|
||||||
#ifndef HAVE_BSD_AUTH
|
#ifndef HAVE_BSD_AUTH
|
||||||
|
Loading…
Reference in New Issue
Block a user