apply custom password patch
parent
545573af70
commit
fd406fed3f
11
Makefile
11
Makefile
|
|
@ -6,17 +6,18 @@ include config.mk
|
||||||
SRC = slock.c ${COMPATSRC}
|
SRC = slock.c ${COMPATSRC}
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
all: options slock
|
all: options clean slock
|
||||||
|
|
||||||
options:
|
options:
|
||||||
@echo slock build options:
|
@echo slock build options:
|
||||||
@echo "CFLAGS = ${CFLAGS}"
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
@echo "CC = ${CC}"
|
@echo "CC = ${CC}"
|
||||||
|
@echo "DEFINES = ${DEFINES}"
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@${CC} -c ${CFLAGS} $<
|
@${CC} -c ${CFLAGS} ${DEFINES} $<
|
||||||
|
|
||||||
${OBJ}: config.h config.mk arg.h util.h
|
${OBJ}: config.h config.mk arg.h util.h
|
||||||
|
|
||||||
|
|
@ -25,6 +26,10 @@ config.h:
|
||||||
@cp config.def.h $@
|
@cp config.def.h $@
|
||||||
|
|
||||||
slock: ${OBJ}
|
slock: ${OBJ}
|
||||||
|
@if [ -z ${PW} ]; then \
|
||||||
|
echo "Define password when running make! Example: 'make PW=xyz'"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
@echo CC -o $@
|
@echo CC -o $@
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
|
|
@ -41,7 +46,7 @@ dist: clean
|
||||||
@gzip slock-${VERSION}.tar
|
@gzip slock-${VERSION}.tar
|
||||||
@rm -rf slock-${VERSION}
|
@rm -rf slock-${VERSION}
|
||||||
|
|
||||||
install: all
|
install: options slock
|
||||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
@cp -f slock ${DESTDIR}${PREFIX}/bin
|
@cp -f slock ${DESTDIR}${PREFIX}/bin
|
||||||
|
|
|
||||||
|
|
@ -20,16 +20,15 @@ FREETYPEINC = /usr/include/freetype2
|
||||||
|
|
||||||
# includes and libs
|
# includes and libs
|
||||||
INCS = -I. -I/usr/include -I${X11INC} -I${FREETYPEINC}
|
INCS = -I. -I/usr/include -I${X11INC} -I${FREETYPEINC}
|
||||||
LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lImlib2 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr
|
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lImlib2 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
|
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
|
CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
|
||||||
LDFLAGS = -s ${LIBS}
|
LDFLAGS = -s ${LIBS}
|
||||||
|
DEFINES += -DPW=\"${PW}\"
|
||||||
COMPATSRC = explicit_bzero.c
|
COMPATSRC = explicit_bzero.c
|
||||||
|
|
||||||
# On OpenBSD and Darwin remove -lcrypt from LIBS
|
|
||||||
#LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXext -lXrandr
|
|
||||||
# On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS
|
# On *BSD remove -DHAVE_SHADOW_H from CPPFLAGS
|
||||||
# On NetBSD add -D_NETBSD_SOURCE to CPPFLAGS
|
# On NetBSD add -D_NETBSD_SOURCE to CPPFLAGS
|
||||||
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
||||||
|
|
|
||||||
58
slock.c
58
slock.c
|
|
@ -113,47 +113,6 @@ dontkillme(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *
|
|
||||||
gethash(void)
|
|
||||||
{
|
|
||||||
const char *hash;
|
|
||||||
struct passwd *pw;
|
|
||||||
|
|
||||||
/* Check if the current user has a password entry */
|
|
||||||
errno = 0;
|
|
||||||
if (!(pw = getpwuid(getuid()))) {
|
|
||||||
if (errno)
|
|
||||||
die("slock: getpwuid: %s\n", strerror(errno));
|
|
||||||
else
|
|
||||||
die("slock: cannot retrieve password entry\n");
|
|
||||||
}
|
|
||||||
hash = pw->pw_passwd;
|
|
||||||
|
|
||||||
#if HAVE_SHADOW_H
|
|
||||||
if (!strcmp(hash, "x")) {
|
|
||||||
struct spwd *sp;
|
|
||||||
if (!(sp = getspnam(pw->pw_name)))
|
|
||||||
die("slock: getspnam: cannot retrieve shadow entry. "
|
|
||||||
"Make sure to suid or sgid slock.\n");
|
|
||||||
hash = sp->sp_pwdp;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (!strcmp(hash, "*")) {
|
|
||||||
#ifdef __OpenBSD__
|
|
||||||
if (!(pw = getpwuid_shadow(getuid())))
|
|
||||||
die("slock: getpwnam_shadow: cannot retrieve shadow entry. "
|
|
||||||
"Make sure to suid or sgid slock.\n");
|
|
||||||
hash = pw->pw_passwd;
|
|
||||||
#else
|
|
||||||
die("slock: getpwuid: cannot retrieve shadow entry. "
|
|
||||||
"Make sure to suid or sgid slock.\n");
|
|
||||||
#endif /* __OpenBSD__ */
|
|
||||||
}
|
|
||||||
#endif /* HAVE_SHADOW_H */
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
resizerectangles(struct lock *lock)
|
resizerectangles(struct lock *lock)
|
||||||
{
|
{
|
||||||
|
|
@ -178,11 +137,10 @@ drawlogo(Display *dpy, struct lock *lock, int color)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens)
|
||||||
const char *hash)
|
|
||||||
{
|
{
|
||||||
XRRScreenChangeNotifyEvent *rre;
|
XRRScreenChangeNotifyEvent *rre;
|
||||||
char buf[32], passwd[256], *inputhash;
|
char buf[32], passwd[256];
|
||||||
int num, screen, running, failure, oldc;
|
int num, screen, running, failure, oldc;
|
||||||
unsigned int len, color;
|
unsigned int len, color;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
|
|
@ -212,11 +170,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
||||||
switch (ksym) {
|
switch (ksym) {
|
||||||
case XK_Return:
|
case XK_Return:
|
||||||
passwd[len] = '\0';
|
passwd[len] = '\0';
|
||||||
errno = 0;
|
running = !!strcmp(passwd, PW );
|
||||||
if (!(inputhash = crypt(passwd, hash)))
|
|
||||||
fprintf(stderr, "slock: crypt: %s\n", strerror(errno));
|
|
||||||
else
|
|
||||||
running = !!strcmp(inputhash, hash);
|
|
||||||
if (running) {
|
if (running) {
|
||||||
XBell(dpy, 100);
|
XBell(dpy, 100);
|
||||||
failure = 1;
|
failure = 1;
|
||||||
|
|
@ -456,7 +410,6 @@ main(int argc, char **argv) {
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
uid_t duid;
|
uid_t duid;
|
||||||
gid_t dgid;
|
gid_t dgid;
|
||||||
const char *hash;
|
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
int s, nlocks, nscreens;
|
int s, nlocks, nscreens;
|
||||||
CARD16 standby, suspend, off;
|
CARD16 standby, suspend, off;
|
||||||
|
|
@ -485,10 +438,7 @@ main(int argc, char **argv) {
|
||||||
dontkillme();
|
dontkillme();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
hash = gethash();
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
if (!crypt("", hash))
|
|
||||||
die("slock: crypt: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
if (!(dpy = XOpenDisplay(NULL)))
|
if (!(dpy = XOpenDisplay(NULL)))
|
||||||
die("slock: cannot open display\n");
|
die("slock: cannot open display\n");
|
||||||
|
|
@ -603,7 +553,7 @@ main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* everything is now blank. Wait for the correct password */
|
/* everything is now blank. Wait for the correct password */
|
||||||
readpw(dpy, &rr, locks, nscreens, hash);
|
readpw(dpy, &rr, locks, nscreens);
|
||||||
|
|
||||||
/* reset DPMS values to inital ones */
|
/* reset DPMS values to inital ones */
|
||||||
DPMSSetTimeouts(dpy, standby, suspend, off);
|
DPMSSetTimeouts(dpy, standby, suspend, off);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue