diff options
| author | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2022-10-25 22:25:36 -0400 |
|---|---|---|
| committer | Douglas Rumbaugh <doug@douglasrumbaugh.com> | 2022-10-25 22:25:36 -0400 |
| commit | 189a79d971bcb609103dfea929535c38f9f68bb5 (patch) | |
| tree | f9ce14c91722e3fd07b8fbe69248966b7fa9f3cc | |
| parent | f3dc7b88a52e37f4749a1a16af92711e6957921b (diff) | |
| download | slock-189a79d971bcb609103dfea929535c38f9f68bb5.tar.gz | |
OpenBSD supportopenbsd
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | README | 4 | ||||
| -rw-r--r-- | config.def.h | 42 | ||||
| -rw-r--r-- | config.mk | 14 | ||||
| -rw-r--r-- | slock.c | 121 |
5 files changed, 55 insertions, 130 deletions
@@ -30,13 +30,13 @@ slock: ${OBJ} clean: @echo cleaning - @rm -f slock ${OBJ} slock-${VERSION}.tar.gz config.h + @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 \ - ${SRC} explicit_bzero.c 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} @gzip slock-${VERSION}.tar @rm -rf slock-${VERSION} @@ -2,10 +2,10 @@ slock - simple screen locker ============================ simple screen locker utility for X. + Requirements ------------ -In order to build slock you need the Xlib header files. The PAM patch -integrated also requires the libpam header files (libpam-dev on Ubuntu). +In order to build slock you need the Xlib header files. Installation diff --git a/config.def.h b/config.def.h index 8ce4fc5..f9fb545 100644 --- a/config.def.h +++ b/config.def.h @@ -1,17 +1,15 @@ /* user and group to drop privileges to */ static const char *user = "nobody"; -static const char *group = "nogroup"; // use this one for Ubuntu -//static const char *group = "nobody"; // use this one for Arch Linux +static const char *group = "nogroup"; static const char *colorname[NUMCOLS] = { - [INIT] = "black", /* after initialization */ + [BACKGROUND] = "white", + [INIT] = "2d2d2d", /* after initialization */ [INPUT] = "#005577", /* during input */ [FAILED] = "#CC3333", /* wrong password */ - [CAPS] = "red", /* CapsLock on */ - [PAM] = "#9400D3", /* waiting for PAM */ + [CAPS] = "red", /* CapsLock on */ }; - /* * Xresources preferences to load at startup */ @@ -20,35 +18,25 @@ ResourcePref resources[] = { { "color4", STRING, &colorname[INPUT] }, { "color1", STRING, &colorname[FAILED] }, { "color3", STRING, &colorname[CAPS] }, - { "color5", STRING, &colorname[PAM] }, }; - /* treat a cleared input like a wrong password (color) */ -static const int failonclear = 0; - -static const int use_pam = 0; - -/* PAM service that's used for authentication */ -static const char* pam_service = "login"; +static const int failonclear = 1; -/* insert grid pattern with scale 1:1, the size can be changed with logosize */ static const int logosize = 75; -/* grid width and height for right center alignment */ -static const int logow = 12; +static const int logow = 12; /* Grid width and height for right center alignment*/ static const int logoh = 6; static XRectangle rectangles[9] = { - /* x y w h */ - { 0, 3, 1, 3 }, - { 1, 3, 2, 1 }, - { 0, 5, 8, 1 }, - { 3, 0, 1, 5 }, - { 5, 3, 1, 2 }, - { 7, 3, 1, 2 }, - { 8, 3, 4, 1 }, - { 9, 4, 1, 2 }, - { 11, 4, 1, 2 }, + {0, 3, 1, 3}, + {1, 3, 2, 1}, + {0, 5, 8, 1}, + {3, 0, 1, 5}, + {5, 3, 1, 2}, + {7, 3, 1, 2}, + {8, 3, 4, 1}, + {9, 4, 1, 2}, + {11,4, 1, 2}, }; /*Enable blur*/ @@ -1,5 +1,5 @@ # slock version -VERSION = 1.4 +VERSION = 1.5 # Customize below to fit your system @@ -10,20 +10,16 @@ MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib -# Xinerama -XINERAMALIBS = -lXinerama -XINERAMAFLAGS = -DXINERAMA - # freetype FREETYPELIBS = -lXft -FREETYPEINC = /usr/include/freetype2 +FREETYPEINC = ${X11INC}/freetype2 # includes and libs -INCS = -I. -I/usr/include -I${X11INC} -I${FREETYPEINC} -LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr -lImlib2 -lpam +INCS = -I. -I/usr/include -I/usr/local/include -I${X11INC} -I${FREETYPEINC} +LIBS = -L/usr/lib -L/usr/local/lib -lc -L${X11LIB} -lX11 -lImlib2 ${XINERAMALIBS} ${FREETYPELIBS} -lXext -lXrandr # flags -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE -DHAVE_SHADOW_H ${XINERAMAFLAGS} +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_DEFAULT_SOURCE ${XINERAMAFLAGS} CFLAGS = -std=c99 -pedantic -Wall -Ofast ${INCS} ${CPPFLAGS} LDFLAGS = -s ${LIBS} COMPATSRC = explicit_bzero.c @@ -23,27 +23,21 @@ #include <X11/keysym.h> #include <X11/Xlib.h> #include <X11/Xutil.h> -#include <X11/Xft/Xft.h> +#include <Imlib2.h> #include <X11/Xresource.h> #include <X11/XKBlib.h> -#include <Imlib2.h> -#include <security/pam_appl.h> -#include <security/pam_misc.h> #include "arg.h" #include "util.h" char *argv0; -static int pam_conv(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *appdata_ptr); -struct pam_conv pamc = {pam_conv, NULL}; -char passwd[256]; enum { + BACKGROUND, INIT, INPUT, FAILED, CAPS, - PAM, NUMCOLS }; @@ -68,11 +62,11 @@ struct lock { Pixmap pmap; Pixmap bgmap; unsigned long colors[NUMCOLS]; - unsigned int x, y; - unsigned int xoff, yoff, mw, mh; - Drawable drawable; - GC gc; - XRectangle rectangles[LENGTH(rectangles)]; + unsigned int x, y; + unsigned int xoff, yoff, mw, mh; + Drawable drawable; + GC gc; + XRectangle rectangles[LENGTH(rectangles)]; }; struct xrandr { @@ -94,31 +88,6 @@ die(const char *errstr, ...) exit(1); } -static int -pam_conv(int num_msg, const struct pam_message **msg, - struct pam_response **resp, void *appdata_ptr) -{ - int retval = PAM_CONV_ERR; - for(int i=0; i<num_msg; i++) { - if (msg[i]->msg_style == PAM_PROMPT_ECHO_OFF && - strncmp(msg[i]->msg, "Password: ", 10) == 0) { - struct pam_response *resp_msg = malloc(sizeof(struct pam_response)); - if (!resp_msg) - die("malloc failed\n"); - char *password = malloc(strlen(passwd) + 1); - if (!password) - die("malloc failed\n"); - memset(password, 0, strlen(passwd) + 1); - strcpy(password, passwd); - resp_msg->resp_retcode = 0; - resp_msg->resp = password; - resp[i] = resp_msg; - retval = PAM_SUCCESS; - } - } - return retval; -} - #ifdef __linux__ #include <fcntl.h> #include <linux/oom.h> @@ -183,10 +152,6 @@ gethash(void) } #endif /* HAVE_SHADOW_H */ - /* pam, store user name */ - if (use_pam) - hash = pw->pw_name; - return hash; } @@ -208,10 +173,8 @@ resizerectangles(struct lock *lock) static void drawlogo(Display *dpy, struct lock *lock, int color) { - lock->drawable = lock->bgmap; XSetForeground(dpy, lock->gc, lock->colors[color]); - XFillRectangles(dpy, lock->drawable, lock->gc, lock->rectangles, LENGTH(rectangles)); - XCopyArea(dpy, lock->drawable, lock->win, lock->gc, 0, 0, lock->x, lock->y, 0, 0); + XFillRectangles(dpy, lock->win, lock->gc, lock->rectangles, LENGTH(rectangles)); XSync(dpy, False); } @@ -220,12 +183,11 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, const char *hash) { XRRScreenChangeNotifyEvent *rre; - char buf[32], *inputhash; - int caps, num, screen, running, failure, oldc, retval; + char buf[32], passwd[256], *inputhash; + int caps, num, screen, running, failure, oldc; unsigned int len, color, indicators; KeySym ksym; XEvent ev; - pam_handle_t *pamh; len = 0; caps = 0; @@ -256,33 +218,10 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, case XK_Return: passwd[len] = '\0'; errno = 0; - - if (use_pam) { - retval = pam_start(pam_service, hash, &pamc, &pamh); - color = PAM; - for (screen = 0; screen < nscreens; screen++) { - drawlogo(dpy, locks[screen], color); - } - - if (retval == PAM_SUCCESS) - retval = pam_authenticate(pamh, 0); - if (retval == PAM_SUCCESS) - retval = pam_acct_mgmt(pamh, 0); - - running = 1; - if (retval == PAM_SUCCESS) - running = 0; - else - fprintf(stderr, "slock: %s\n", pam_strerror(pamh, retval)); - pam_end(pamh, retval); - } else { - if (!(inputhash = crypt(passwd, hash))) - fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); - else - running = !!strcmp(inputhash, hash); - } - - + if (!(inputhash = crypt(passwd, hash))) + fprintf(stderr, "slock: crypt: %s\n", strerror(errno)); + else + running = !!strcmp(inputhash, hash); if (running) { XBell(dpy, 100); failure = 1; @@ -293,7 +232,6 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, case XK_Escape: explicit_bzero(&passwd, sizeof(passwd)); len = 0; - failure = 0; break; case XK_BackSpace: if (len) @@ -313,7 +251,12 @@ readpw(Display *dpy, struct xrandr *rr, struct lock **locks, int nscreens, color = len ? (caps ? CAPS : INPUT) : (failure || failonclear ? FAILED : INIT); if (running && oldc != color) { for (screen = 0; screen < nscreens; screen++) { - drawlogo(dpy, locks[screen], color); + if(locks[screen]->bgmap) + XSetWindowBackgroundPixmap(dpy, locks[screen]->win, locks[screen]->bgmap); + else + XSetWindowBackground(dpy, locks[screen]->win, locks[screen]->colors[0]); + //XClearWindow(dpy, locks[screen]->win); + drawlogo(dpy, locks[screen], color); } oldc = color; } @@ -359,7 +302,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) lock->screen = screen; lock->root = RootWindow(dpy, lock->screen); - if(image) + if(image) { lock->bgmap = XCreatePixmap(dpy, lock->root, DisplayWidth(dpy, lock->screen), DisplayHeight(dpy, lock->screen), DefaultDepth(dpy, lock->screen)); imlib_context_set_image(image); @@ -398,6 +341,7 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) /* init */ wa.override_redirect = 1; + wa.background_pixel = lock->colors[BACKGROUND]; lock->win = XCreateWindow(dpy, lock->root, 0, 0, lock->x, lock->y, 0, DefaultDepth(dpy, lock->screen), @@ -548,12 +492,10 @@ main(int argc, char **argv) { dontkillme(); #endif - /* the contents of hash are used to transport the current user name */ hash = gethash(); errno = 0; - - if (!use_pam && !crypt("", hash)) - die("slock: crypt %s\n", strerror(errno)); + if (!crypt("", hash)) + die("slock: crypt: %s\n", strerror(errno)); if (!(dpy = XOpenDisplay(NULL))) die("slock: cannot open display\n"); @@ -572,20 +514,20 @@ main(int argc, char **argv) { imlib_context_set_image(image); imlib_context_set_display(dpy); imlib_context_set_visual(DefaultVisual(dpy,0)); - imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr))); + imlib_context_set_drawable(RootWindow(dpy,XScreenNumberOfScreen(scr))); imlib_copy_drawable_to_image(0,0,0,scr->width,scr->height,0,0,1); #ifdef BLUR /*Blur function*/ imlib_image_blur(blurRadius); -#endif // BLUR +#endif // BLUR #ifdef PIXELATION /*Pixelation*/ int width = scr->width; int height = scr->height; - + for(int y = 0; y < height; y += pixelSize) { for(int x = 0; x < width; x += pixelSize) @@ -594,7 +536,7 @@ main(int argc, char **argv) { int green = 0; int blue = 0; - Imlib_Color pixel; + Imlib_Color pixel; Imlib_Color* pp; pp = &pixel; for(int j = 0; j < pixelSize && j < height; j++) @@ -617,11 +559,10 @@ main(int argc, char **argv) { blue = 0; } } - - + + #endif - config_init(dpy); - + config_init(dpy); /* check for Xrandr support */ rr.active = XRRQueryExtension(dpy, &rr.evbase, &rr.errbase); |