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