apply custom password patch

master
Ryan 2023-10-15 18:58:11 -04:00
parent 545573af70
commit fd406fed3f
Signed by: ryan
GPG Key ID: 7D7E2E94267DAD95
3 changed files with 14 additions and 60 deletions

View File

@ -6,17 +6,18 @@ include config.mk
SRC = slock.c ${COMPATSRC}
OBJ = ${SRC:.c=.o}
all: options slock
all: options clean slock
options:
@echo slock build options:
@echo "CFLAGS = ${CFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "CC = ${CC}"
@echo "DEFINES = ${DEFINES}"
.c.o:
@echo CC $<
@${CC} -c ${CFLAGS} $<
@${CC} -c ${CFLAGS} ${DEFINES} $<
${OBJ}: config.h config.mk arg.h util.h
@ -25,6 +26,10 @@ config.h:
@cp config.def.h $@
slock: ${OBJ}
@if [ -z ${PW} ]; then \
echo "Define password when running make! Example: 'make PW=xyz'"; \
exit 1; \
fi
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
@ -41,7 +46,7 @@ dist: clean
@gzip slock-${VERSION}.tar
@rm -rf slock-${VERSION}
install: all
install: options slock
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
@mkdir -p ${DESTDIR}${PREFIX}/bin
@cp -f slock ${DESTDIR}${PREFIX}/bin

View File

@ -20,16 +20,15 @@ FREETYPEINC = /usr/include/freetype2
# includes and libs
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
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS}
CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
DEFINES += -DPW=\"${PW}\"
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 NetBSD add -D_NETBSD_SOURCE to CPPFLAGS
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE

58
slock.c
View File

@ -113,47 +113,6 @@ dontkillme(void)
}
#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
resizerectangles(struct lock *lock)
{
@ -178,11 +137,10 @@ drawlogo(Display *dpy, struct lock *lock, int color)
}
static void
readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
const char *hash)
readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens)
{
XRRScreenChangeNotifyEvent *rre;
char buf[32], passwd[256], *inputhash;
char buf[32], passwd[256];
int num, screen, running, failure, oldc;
unsigned int len, color;
KeySym ksym;
@ -212,11 +170,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
switch (ksym) {
case XK_Return:
passwd[len] = '\0';
errno = 0;
if (!(inputhash = crypt(passwd, hash)))
fprintf(stderr, "slock: crypt: %s\n", strerror(errno));
else
running = !!strcmp(inputhash, hash);
running = !!strcmp(passwd, PW );
if (running) {
XBell(dpy, 100);
failure = 1;
@ -456,7 +410,6 @@ main(int argc, char **argv) {
struct group *grp;
uid_t duid;
gid_t dgid;
const char *hash;
Display *dpy;
int s, nlocks, nscreens;
CARD16 standby, suspend, off;
@ -485,10 +438,7 @@ main(int argc, char **argv) {
dontkillme();
#endif
hash = gethash();
errno = 0;
if (!crypt("", hash))
die("slock: crypt: %s\n", strerror(errno));
if (!(dpy = XOpenDisplay(NULL)))
die("slock: cannot open display\n");
@ -603,7 +553,7 @@ main(int argc, char **argv) {
}
/* 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 */
DPMSSetTimeouts(dpy, standby, suspend, off);