aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitignore132
-rw-r--r--LICENSE1
-rw-r--r--Makefile58
-rw-r--r--config.def.h9
-rw-r--r--config.h2
-rw-r--r--config.mk17
-rw-r--r--slock.126
-rw-r--r--slock.c83
8 files changed, 64 insertions, 264 deletions
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index ef8b8d6..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,132 +0,0 @@
-# Created by https://www.gitignore.io/api/c,linux,emacs
-# Edit at https://www.gitignore.io/?templates=c,linux,emacs
-
-### C ###
-# Prerequisites
-*.d
-
-# Object files
-*.o
-*.ko
-*.obj
-*.elf
-
-# Linker output
-*.ilk
-*.map
-*.exp
-
-# Precompiled Headers
-*.gch
-*.pch
-
-# Libraries
-*.lib
-*.a
-*.la
-*.lo
-
-# Shared objects (inc. Windows DLLs)
-*.dll
-*.so
-*.so.*
-*.dylib
-
-# Executables
-*.exe
-*.out
-*.app
-*.i*86
-*.x86_64
-*.hex
-
-# Debug files
-*.dSYM/
-*.su
-*.idb
-*.pdb
-
-# Kernel Module Compile Results
-*.mod*
-*.cmd
-.tmp_versions/
-modules.order
-Module.symvers
-Mkfile.old
-dkms.conf
-
-### Emacs ###
-# -*- mode: gitignore; -*-
-*~
-\#*\#
-/.emacs.desktop
-/.emacs.desktop.lock
-*.elc
-auto-save-list
-tramp
-.\#*
-
-# Org-mode
-.org-id-locations
-*_archive
-
-# flymake-mode
-*_flymake.*
-
-# eshell files
-/eshell/history
-/eshell/lastdir
-
-# elpa packages
-/elpa/
-
-# reftex files
-*.rel
-
-# AUCTeX auto folder
-/auto/
-
-# cask packages
-.cask/
-dist/
-
-# Flycheck
-flycheck_*.el
-
-# server auth directory
-/server/
-
-# projectiles files
-.projectile
-
-# directory configuration
-.dir-locals.el
-
-# network security
-/network-security.data
-
-
-### Linux ###
-
-# temporary files which can be created if a process still has a handle open of a deleted file
-.fuse_hidden*
-
-# KDE directory preferences
-.directory
-
-# Linux trash folder which might appear on any partition or disk
-.Trash-*
-
-# .nfs files are created when an open file is removed but is still being accessed
-.nfs*
-
-# End of https://www.gitignore.io/api/c,linux,emacs
-
-*.diff
-*.o
-*.def.h
-*.rej
-*.orig
-.ccls*
-slock
-compile_flags.txt
diff --git a/LICENSE b/LICENSE
index 2e4419b..cb52dba 100644
--- a/LICENSE
+++ b/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"),
diff --git a/Makefile b/Makefile
index f4ffbb7..eb4672b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,56 +6,42 @@ 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 $@
+ cp config.def.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
+ rm -f config.h
dist: clean
- @echo creating dist tarball
- @mkdir -p slock-${VERSION}
- @cp -R LICENSE Makefile README slock.1 config.mk \
- ${SRC} explicit_bzero.c config.def.h arg.h util.h slock-${VERSION}
- @tar -cf slock-${VERSION}.tar slock-${VERSION}
- @gzip slock-${VERSION}.tar
- @rm -rf slock-${VERSION}
+ 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}
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
diff --git a/config.def.h b/config.def.h
index eb88b3d..7e8776d 100644
--- a/config.def.h
+++ b/config.def.h
@@ -3,13 +3,10 @@ static const char *user = "nobody";
static const char *group = "nobody";
static const char *colorname[NUMCOLS] = {
- [INIT] = "black", /* after initialization */
- [INPUT] = "#005577", /* during input */
- [FAILED] = "#CC3333", /* wrong password */
+ [INIT] = "#000000", /* after initialization */
+ [INPUT] = "#458588", /* during input */
+ [FAILED] = "#9d0006", /* wrong password */
};
/* treat a cleared input like a wrong password (color) */
static const int failonclear = 1;
-
-/* Background image path, should be available to the user above */
-static const char* background_image = "";
diff --git a/config.h b/config.h
index 4550a94..0a941fb 100644
--- a/config.h
+++ b/config.h
@@ -12,4 +12,4 @@ static const char *colorname[NUMCOLS] = {
static const int failonclear = 1;
/* Background image path, should be available to the user above */
-static const char* background_image = "/home/jozan/pics/lock/caco.png";
+static const char* background_image = "/home/jozan/pics/lock/black_hole.jpg";
diff --git a/config.mk b/config.mk
index f93c9b0..dcd27d0 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
# slock version
-VERSION = 1.4
+VERSION = 1.6
# Customize below to fit your system
@@ -7,16 +7,16 @@ VERSION = 1.4
PREFIX = /usr/local
MANPREFIX = ${PREFIX}/share/man
-X11INC = /usr/local/include
-X11LIB = /usr/local/lib
+X11INC = /usr/X11R6/include
+X11LIB = /usr/X11R6/lib
# includes and libs
-INCS = -I. -I/usr/include -I/usr/local/include/xorg -I${X11INC}
-LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr -lImlib2
+INCS = -I. -I/usr/include -I${X11INC}
+LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXext -lXrandr
# flags
-CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE
-CFLAGS = -std=c99 -pedantic -Wall -march=ivybridge -O3 -pipe ${INCS} ${CPPFLAGS}
+CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H
+CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
LDFLAGS = -s ${LIBS}
COMPATSRC = explicit_bzero.c
@@ -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
diff --git a/slock.1 b/slock.1
index 82cdcd6..40c15e1 100644
--- a/slock.1
+++ b/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.
diff --git a/slock.c b/slock.c
index ac1ff20..f16781f 100644
--- a/slock.c
+++ b/slock.c
@@ -13,12 +13,12 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <spawn.h>
#include <sys/types.h>
#include <X11/extensions/Xrandr.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
-#include <Imlib2.h>
#include "arg.h"
#include "util.h"
@@ -36,7 +36,6 @@ struct lock {
int screen;
Window root, win;
Pixmap pmap;
- Pixmap bgmap;
unsigned long colors[NUMCOLS];
};
@@ -48,8 +47,6 @@ struct xrandr {
#include "config.h"
-Imlib_Image image;
-
static void
die(const char *errstr, ...)
{
@@ -188,25 +185,18 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens,
(len + num < sizeof(passwd))) {
memcpy(passwd + len, buf, num);
len += num;
+ } else if (buf[0] == '\025') { /* ctrl-u clears input */
+ explicit_bzero(&passwd, sizeof(passwd));
+ len = 0;
}
break;
}
color = len ? INPUT : ((failure || failonclear) ? FAILED : INIT);
- printf("%d\n", len);
if (running && oldc != color) {
for (screen = 0; screen < nscreens; screen++) {
- if (background_image != NULL && len == 0) {
- if (locks[screen]->bgmap)
- XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap);
- else
- XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]);
- }
- else {
- XSetWindowBackground(dpy,
- locks[screen]->win,
- locks[screen]->colors[color]);
-
- }
+ XSetWindowBackground(dpy,
+ locks[screen]->win,
+ locks[screen]->colors[color]);
XClearWindow(dpy, locks[screen]->win);
}
oldc = color;
@@ -249,17 +239,6 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
lock->screen = screen;
lock->root = RootWindow(dpy, lock->screen);
- if(background_image != NULL && image)
- {
- lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen));
- imlib_context_set_display(dpy);
- imlib_context_set_visual(DefaultVisual(dpy, lock->screen));
- imlib_context_set_colormap(DefaultColormap(dpy, lock->screen));
- imlib_context_set_drawable(lock->bgmap);
- imlib_render_image_on_drawable(0, 0);
- imlib_free_image();
- }
-
for (i = 0; i < NUMCOLS; i++) {
XAllocNamedColor(dpy, DefaultColormap(dpy, lock->screen),
colorname[i], &color, &dummy);
@@ -276,8 +255,6 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
CopyFromParent,
DefaultVisual(dpy, lock->screen),
CWOverrideRedirect | CWBackPixel, &wa);
- if(background_image != NULL && lock->bgmap)
- XSetWindowBackgroundPixmap(dpy, lock->win, lock->bgmap);
lock->pmap = XCreateBitmapFromData(dpy, lock->win, curs, 8, 8);
invisible = XCreatePixmapCursor(dpy, lock->pmap, lock->pmap,
&color, &color, 0, 0);
@@ -344,7 +321,7 @@ main(int argc, char **argv) {
ARGBEGIN {
case 'v':
- fprintf(stderr, "slock-"VERSION"\n");
+ puts("slock-"VERSION);
return 0;
default:
usage();
@@ -382,35 +359,6 @@ main(int argc, char **argv) {
if (setuid(duid) < 0)
die("slock: setuid: %s\n", strerror(errno));
- /* Load picture */
- if (background_image != NULL) {
- Imlib_Image buffer = imlib_load_image(background_image);
- imlib_context_set_image(buffer);
- int background_image_width = imlib_image_get_width();
- int background_image_height = imlib_image_get_height();
-
- /* Create an image to be rendered */
- Screen *scr = ScreenOfDisplay(dpy, DefaultScreen(dpy));
- image = imlib_create_image(scr->width, scr->height);
- imlib_context_set_image(image);
-
- /* Fill the image for every X monitor */
- XRRMonitorInfo *monitors;
- int number_of_monitors;
- monitors = XRRGetMonitors(dpy, RootWindow(dpy, XScreenNumberOfScreen(scr)), True, &number_of_monitors);
-
- int i;
- for (i = 0; i < number_of_monitors; i++) {
- imlib_blend_image_onto_image(buffer, 0, 0, 0, background_image_width, background_image_height, monitors[i].x, monitors[i].y, monitors[i].width, monitors[i].height);
- }
-
-
- /* Clean up */
- imlib_context_set_image(buffer);
- imlib_free_image();
- imlib_context_set_image(image);
- }
-
/* check for Xrandr support */
rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase);
@@ -432,15 +380,12 @@ main(int argc, char **argv) {
/* run post-lock command */
if (argc > 0) {
- switch (fork()) {
- case -1:
- die("slock: fork failed: %s\n", strerror(errno));
- case 0:
- if (close(ConnectionNumber(dpy)) < 0)
- die("slock: close: %s\n", strerror(errno));
- execvp(argv[0], argv);
- fprintf(stderr, "slock: execvp %s: %s\n", argv[0], strerror(errno));
- _exit(1);
+ pid_t pid;
+ extern char **environ;
+ int err = posix_spawnp(&pid, argv[0], NULL, NULL, argv, environ);
+ if (err) {
+ die("slock: failed to execute post-lock command: %s: %s\n",
+ argv[0], strerror(err));
}
}