summaryrefslogtreecommitdiffstats
path: root/slock.c
diff options
context:
space:
mode:
authorDouglas Rumbaugh <doug@douglasrumbaugh.com>2022-10-25 22:25:36 -0400
committerDouglas Rumbaugh <doug@douglasrumbaugh.com>2022-10-25 22:25:36 -0400
commit189a79d971bcb609103dfea929535c38f9f68bb5 (patch)
treef9ce14c91722e3fd07b8fbe69248966b7fa9f3cc /slock.c
parentf3dc7b88a52e37f4749a1a16af92711e6957921b (diff)
downloadslock-openbsd.tar.gz
OpenBSD supportopenbsd
Diffstat (limited to 'slock.c')
-rw-r--r--slock.c121
1 files changed, 31 insertions, 90 deletions
diff --git a/slock.c b/slock.c
index 799d2db..f1f7c8f 100644
--- a/slock.c
+++ b/slock.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);