mirror of
https://git.suckless.org/slock
synced 2026-09-30 21:12:42 +07:00
remove support for running post lock command
This command was used for example to suspend-to-ram (man page example). On Linux running this command inherits OOM killer immunity. This could be abused by an other local user on the same machine (abusing resources). To keep the use-case for suspend-to-ram an user could write a wrapper script for it, outside the scope of slock. Simplify argument handling, because the post-lock command parameter is removed. Reported by: Acts1631 <acts1631kjv@proton.me>
This commit is contained in:
@@ -11,7 +11,7 @@ all: slock
|
||||
.c.o:
|
||||
${CC} -c ${CFLAGS} $<
|
||||
|
||||
${OBJ}: config.h config.mk arg.h util.h
|
||||
${OBJ}: config.h config.mk util.h
|
||||
|
||||
config.h:
|
||||
cp config.def.h $@
|
||||
@@ -25,7 +25,7 @@ clean:
|
||||
dist: clean
|
||||
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 util.h slock-${VERSION}
|
||||
tar -cf slock-${VERSION}.tar slock-${VERSION}
|
||||
gzip slock-${VERSION}.tar
|
||||
rm -rf slock-${VERSION}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copy me if you can.
|
||||
* by 20h
|
||||
*/
|
||||
|
||||
#ifndef ARG_H__
|
||||
#define ARG_H__
|
||||
|
||||
extern char *argv0;
|
||||
|
||||
/* use main(int argc, char *argv[]) */
|
||||
#define ARGBEGIN for (argv0 = *argv, argv++, argc--;\
|
||||
argv[0] && argv[0][0] == '-'\
|
||||
&& argv[0][1];\
|
||||
argc--, argv++) {\
|
||||
char argc_;\
|
||||
char **argv_;\
|
||||
int brk_;\
|
||||
if (argv[0][1] == '-' && argv[0][2] == '\0') {\
|
||||
argv++;\
|
||||
argc--;\
|
||||
break;\
|
||||
}\
|
||||
for (brk_ = 0, argv[0]++, argv_ = argv;\
|
||||
argv[0][0] && !brk_;\
|
||||
argv[0]++) {\
|
||||
if (argv_ != argv)\
|
||||
break;\
|
||||
argc_ = argv[0][0];\
|
||||
switch (argc_)
|
||||
|
||||
/* Handles obsolete -NUM syntax */
|
||||
#define ARGNUM case '0':\
|
||||
case '1':\
|
||||
case '2':\
|
||||
case '3':\
|
||||
case '4':\
|
||||
case '5':\
|
||||
case '6':\
|
||||
case '7':\
|
||||
case '8':\
|
||||
case '9'
|
||||
|
||||
#define ARGEND }\
|
||||
}
|
||||
|
||||
#define ARGC() argc_
|
||||
|
||||
#define ARGNUMF() (brk_ = 1, estrtonum(argv[0], 0, INT_MAX))
|
||||
|
||||
#define EARGF(x) ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
((x), abort(), (char *)0) :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#define ARGF() ((argv[0][1] == '\0' && argv[1] == NULL)?\
|
||||
(char *)0 :\
|
||||
(brk_ = 1, (argv[0][1] != '\0')?\
|
||||
(&argv[0][1]) :\
|
||||
(argc--, argv++, argv[0])))
|
||||
|
||||
#define LNGARG() &argv[0][0]
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
.Dd October 6, 2023
|
||||
.Dd September 5, 2026
|
||||
.Dt SLOCK 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
@@ -7,14 +7,9 @@
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl v
|
||||
.Op Ar cmd Op Ar arg ...
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
is a simple X screen locker.
|
||||
If provided,
|
||||
.Ar cmd
|
||||
is executed after the screen has been locked.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width Ds
|
||||
.It Fl v
|
||||
@@ -22,10 +17,6 @@ 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
|
||||
|
||||
@@ -13,14 +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 "arg.h"
|
||||
#include "util.h"
|
||||
|
||||
char *argv0;
|
||||
@@ -304,7 +302,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
die("usage: slock [-v] [cmd [arg ...]]\n");
|
||||
die("usage: slock [-v]\n");
|
||||
}
|
||||
|
||||
int
|
||||
@@ -319,13 +317,12 @@ main(int argc, char **argv) {
|
||||
Display *dpy;
|
||||
int s, nlocks, nscreens;
|
||||
|
||||
ARGBEGIN {
|
||||
case 'v':
|
||||
if (argc > 1 && !strcmp(argv[1], "-v")) {
|
||||
puts("slock-"VERSION);
|
||||
return 0;
|
||||
default:
|
||||
} else if (argc > 1) {
|
||||
usage();
|
||||
} ARGEND
|
||||
}
|
||||
|
||||
/* validate drop-user and -group */
|
||||
errno = 0;
|
||||
@@ -378,17 +375,6 @@ main(int argc, char **argv) {
|
||||
if (nlocks != nscreens)
|
||||
return 1;
|
||||
|
||||
/* run post-lock command */
|
||||
if (argc > 0) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
/* everything is now blank. Wait for the correct password */
|
||||
readpw(dpy, &rr, locks, nscreens, hash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user