Compare commits
No commits in common. "85b967adf8d94960e8c0289314fcbb126ea06eeb" and "4f045545a25cc02c64bfc08d27ed2ccecb962292" have entirely different histories.
85b967adf8
...
4f045545a2
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
config.h
|
|
||||||
slock
|
|
||||||
*.o
|
|
1
LICENSE
1
LICENSE
@ -4,7 +4,6 @@ MIT/X Consortium License
|
|||||||
© 2014 Dimitris Papastamos <sin@2f30.org>
|
© 2014 Dimitris Papastamos <sin@2f30.org>
|
||||||
© 2006-2014 Anselm R Garbe <anselm@garbe.us>
|
© 2006-2014 Anselm R Garbe <anselm@garbe.us>
|
||||||
© 2014-2016 Laslo Hunhold <dev@frign.de>
|
© 2014-2016 Laslo Hunhold <dev@frign.de>
|
||||||
© 2016-2023 Hiltjo Posthuma <hiltjo@codemadness.org>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
copy of this software and associated documentation files (the "Software"),
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
58
Makefile
58
Makefile
@ -6,38 +6,56 @@ include config.mk
|
|||||||
SRC = slock.c ${COMPATSRC}
|
SRC = slock.c ${COMPATSRC}
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
|
|
||||||
all: slock
|
all: options slock
|
||||||
|
|
||||||
|
options:
|
||||||
|
@echo slock build options:
|
||||||
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
|
@echo "CC = ${CC}"
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
${CC} -c ${CFLAGS} $<
|
@echo CC $<
|
||||||
|
@${CC} -c ${CFLAGS} $<
|
||||||
|
|
||||||
${OBJ}: config.def.h config.mk arg.h util.h
|
${OBJ}: config.h config.mk arg.h util.h
|
||||||
|
|
||||||
|
config.h:
|
||||||
|
@echo creating $@ from config.def.h
|
||||||
|
@cp config.def.h $@
|
||||||
|
|
||||||
slock: ${OBJ}
|
slock: ${OBJ}
|
||||||
${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@echo CC -o $@
|
||||||
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f slock ${OBJ} slock-${VERSION}.tar.gz
|
@echo cleaning
|
||||||
|
@rm -f slock ${OBJ} slock-${VERSION}.tar.gz
|
||||||
|
|
||||||
dist: clean
|
dist: clean
|
||||||
mkdir -p slock-${VERSION}
|
@echo creating dist tarball
|
||||||
cp -R LICENSE Makefile README slock.1 config.mk \
|
@mkdir -p slock-${VERSION}
|
||||||
|
@cp -R LICENSE Makefile README slock.1 config.mk \
|
||||||
${SRC} config.def.h arg.h util.h slock-${VERSION}
|
${SRC} config.def.h arg.h util.h slock-${VERSION}
|
||||||
tar -cf slock-${VERSION}.tar slock-${VERSION}
|
@tar -cf slock-${VERSION}.tar slock-${VERSION}
|
||||||
gzip slock-${VERSION}.tar
|
@gzip slock-${VERSION}.tar
|
||||||
rm -rf slock-${VERSION}
|
@rm -rf slock-${VERSION}
|
||||||
|
|
||||||
install: all
|
install: all
|
||||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||||
cp -f slock ${DESTDIR}${PREFIX}/bin
|
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
chmod 755 ${DESTDIR}${PREFIX}/bin/slock
|
@cp -f slock ${DESTDIR}${PREFIX}/bin
|
||||||
chmod u+s ${DESTDIR}${PREFIX}/bin/slock
|
@chmod 755 ${DESTDIR}${PREFIX}/bin/slock
|
||||||
mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
@chmod u+s ${DESTDIR}${PREFIX}/bin/slock
|
||||||
sed "s/VERSION/${VERSION}/g" <slock.1 >${DESTDIR}${MANPREFIX}/man1/slock.1
|
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||||
chmod 644 ${DESTDIR}${MANPREFIX}/man1/slock.1
|
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
|
@sed "s/VERSION/${VERSION}/g" <slock.1 >${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
|
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f ${DESTDIR}${PREFIX}/bin/slock
|
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
||||||
rm -f ${DESTDIR}${MANPREFIX}/man1/slock.1
|
@rm -f ${DESTDIR}${PREFIX}/bin/slock
|
||||||
|
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||||
|
@rm -f ${DESTDIR}${MANPREFIX}/man1/slock.1
|
||||||
|
|
||||||
.PHONY: all clean dist install uninstall
|
.PHONY: all options clean dist install uninstall
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
/* user and group to drop privileges to */
|
/* user and group to drop privileges to */
|
||||||
static const char *user = "nobody";
|
static const char *user = "nobody";
|
||||||
static const char *group = "nobody";
|
static const char *group = "nogroup";
|
||||||
|
|
||||||
static const char *colorname[NUMCOLS] = {
|
static const char *colorname[NUMCOLS] = {
|
||||||
[INIT] = "black", /* after initialization */
|
[INIT] = "black", /* after initialization */
|
||||||
[INPUT] = "#005577", /* during input */
|
[INPUT] = "#005577", /* during input */
|
||||||
[FAILED] = "#CC3333", /* wrong password */
|
[FAILED] = "#CC3333", /* wrong password */
|
||||||
[CAPS] = "red", /* CapsLock on */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* treat a cleared input like a wrong password (color) */
|
/* treat a cleared input like a wrong password (color) */
|
||||||
static const int failonclear = 0;
|
static const int failonclear = 1;
|
||||||
|
@ -27,3 +27,6 @@ COMPATSRC = explicit_bzero.c
|
|||||||
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
#CPPFLAGS = -DVERSION=\"${VERSION}\" -D_BSD_SOURCE -D_NETBSD_SOURCE
|
||||||
# On OpenBSD set COMPATSRC to empty
|
# On OpenBSD set COMPATSRC to empty
|
||||||
#COMPATSRC =
|
#COMPATSRC =
|
||||||
|
|
||||||
|
# compiler and linker
|
||||||
|
CC = cc
|
||||||
|
26
slock.1
26
slock.1
@ -1,6 +1,5 @@
|
|||||||
.Dd October 6, 2023
|
.Dd 2016-08-23
|
||||||
.Dt SLOCK 1
|
.Dt SLOCK 1
|
||||||
.Os
|
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm slock
|
.Nm slock
|
||||||
.Nd simple X screen locker
|
.Nd simple X screen locker
|
||||||
@ -10,36 +9,31 @@
|
|||||||
.Op Ar cmd Op Ar arg ...
|
.Op Ar cmd Op Ar arg ...
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
.Nm
|
.Nm
|
||||||
is a simple X screen locker.
|
is a simple X screen locker. If provided,
|
||||||
If provided,
|
.Ar cmd Op Ar arg ...
|
||||||
.Ar cmd
|
|
||||||
is executed after the screen has been locked.
|
is executed after the screen has been locked.
|
||||||
.Pp
|
.Sh OPTIONS
|
||||||
The options are as follows:
|
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Print version information to stdout and exit.
|
Print version information to stdout and exit.
|
||||||
.El
|
.El
|
||||||
.Sh EXIT STATUS
|
|
||||||
.Ex -std
|
|
||||||
.Sh EXAMPLES
|
|
||||||
$
|
|
||||||
.Nm
|
|
||||||
/usr/sbin/s2ram
|
|
||||||
.Sh SECURITY CONSIDERATIONS
|
.Sh SECURITY CONSIDERATIONS
|
||||||
To make sure a locked screen can not be bypassed by switching VTs
|
To make sure a locked screen can not be bypassed by switching VTs
|
||||||
or killing the X server with Ctrl+Alt+Backspace, it is recommended
|
or killing the X server with Ctrl+Alt+Backspace, it is recommended
|
||||||
to disable both in
|
to disable both in
|
||||||
.Xr xorg.conf 5
|
.Xr xorg.conf 5
|
||||||
for maximum security:
|
for maximum security:
|
||||||
.Bd -literal
|
.Bd -literal -offset left
|
||||||
Section "ServerFlags"
|
Section "ServerFlags"
|
||||||
Option "DontVTSwitch" "True"
|
Option "DontVTSwitch" "True"
|
||||||
Option "DontZap" "True"
|
Option "DontZap" "True"
|
||||||
EndSection
|
EndSection
|
||||||
.Ed
|
.Ed
|
||||||
|
.Sh EXAMPLES
|
||||||
|
$
|
||||||
|
.Nm
|
||||||
|
/usr/sbin/s2ram
|
||||||
.Sh CUSTOMIZATION
|
.Sh CUSTOMIZATION
|
||||||
.Nm
|
.Nm
|
||||||
can be customized by creating a custom config.h from config.def.h and
|
can be customized by creating a custom config.h from config.def.h and
|
||||||
(re)compiling the source code.
|
(re)compiling the source code. This keeps it fast, secure and simple.
|
||||||
This keeps it fast, secure and simple.
|
|
||||||
|
19
slock.c
19
slock.c
@ -18,7 +18,6 @@
|
|||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/XKBlib.h>
|
|
||||||
|
|
||||||
#include "arg.h"
|
#include "arg.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@ -29,7 +28,6 @@ enum {
|
|||||||
INIT,
|
INIT,
|
||||||
INPUT,
|
INPUT,
|
||||||
FAILED,
|
FAILED,
|
||||||
CAPS,
|
|
||||||
NUMCOLS
|
NUMCOLS
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,7 +44,7 @@ struct xrandr {
|
|||||||
int errbase;
|
int errbase;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "config.def.h"
|
#include "config.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
die(const char *errstr, ...)
|
die(const char *errstr, ...)
|
||||||
@ -132,20 +130,16 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
{
|
{
|
||||||
XRRScreenChangeNotifyEvent *rre;
|
XRRScreenChangeNotifyEvent *rre;
|
||||||
char buf[32], passwd[256], *inputhash;
|
char buf[32], passwd[256], *inputhash;
|
||||||
int caps, num, screen, running, failure, oldc;
|
int num, screen, running, failure, oldc;
|
||||||
unsigned int len, color, indicators;
|
unsigned int len, color;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
|
|
||||||
len = 0;
|
len = 0;
|
||||||
caps = 0;
|
|
||||||
running = 1;
|
running = 1;
|
||||||
failure = 0;
|
failure = 0;
|
||||||
oldc = INIT;
|
oldc = INIT;
|
||||||
|
|
||||||
if (!XkbGetIndicatorState(dpy, XkbUseCoreKbd, &indicators))
|
|
||||||
caps = indicators & 1;
|
|
||||||
|
|
||||||
while (running && !XNextEvent(dpy, &ev)) {
|
while (running && !XNextEvent(dpy, &ev)) {
|
||||||
if (ev.type == KeyPress) {
|
if (ev.type == KeyPress) {
|
||||||
explicit_bzero(&buf, sizeof(buf));
|
explicit_bzero(&buf, sizeof(buf));
|
||||||
@ -185,9 +179,6 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
if (len)
|
if (len)
|
||||||
passwd[--len] = '\0';
|
passwd[--len] = '\0';
|
||||||
break;
|
break;
|
||||||
case XK_Caps_Lock:
|
|
||||||
caps = !caps;
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
if (num && !iscntrl((int)buf[0]) &&
|
if (num && !iscntrl((int)buf[0]) &&
|
||||||
(len + num < sizeof(passwd))) {
|
(len + num < sizeof(passwd))) {
|
||||||
@ -196,7 +187,7 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
color = len ? (caps ? CAPS : INPUT) : (failure || failonclear ? FAILED : INIT);
|
color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
|
||||||
if (running && oldc != color) {
|
if (running && oldc != color) {
|
||||||
for (screen = 0; screen < nscreens; screen++) {
|
for (screen = 0; screen < nscreens; screen++) {
|
||||||
XSetWindowBackground(dpy,
|
XSetWindowBackground(dpy,
|
||||||
@ -326,7 +317,7 @@ main(int argc, char **argv) {
|
|||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'v':
|
case 'v':
|
||||||
puts("slock-"VERSION);
|
fprintf(stderr, "slock-"VERSION"\n");
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user