diff options
| -rw-r--r-- | core/dwm/config.h | 8 | ||||
| -rw-r--r-- | core/slock/config.h | 12 | ||||
| -rw-r--r-- | core/slock/explicit_bzero.o | bin | 0 -> 1464 bytes | |||
| -rwxr-xr-x | core/slock/slock | bin | 0 -> 34944 bytes | |||
| -rw-r--r-- | core/slock/slock.c | 2 | ||||
| -rw-r--r-- | core/slock/slock.o | bin | 0 -> 28296 bytes | |||
| -rw-r--r-- | slogin/Makefile | 16 | ||||
| -rw-r--r-- | slogin/slogin.c | 166 |
8 files changed, 199 insertions, 5 deletions
diff --git a/core/dwm/config.h b/core/dwm/config.h index 497dc66..c89c80d 100644 --- a/core/dwm/config.h +++ b/core/dwm/config.h @@ -6,8 +6,8 @@ static const unsigned int gappx = 3; /* gaps between windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ -static const char *fonts[] = { "monospace:size=10" }; -static const char dmenufont[] = "monospace:size=10"; +static const char *fonts[] = { "Monaco:size=12" }; +static const char dmenufont[] = "Monaco:size=12"; static const char col_gray1[] = "#000000"; static const char col_gray2[] = "#555555"; static const char col_gray3[] = "#dddddd"; @@ -71,9 +71,9 @@ static const char *screenshotcmd[] = { "flameshot", "gui", NULL }; static const char *mediaplaypause[] = { "playerctl", "play-pause", NULL }; static const char *medianext[] = { "playerctl", "next", NULL }; static const char *mediaprev[] = { "playerctl", "previous", NULL }; -static const char *calendarcmd[] = { "/bin/sh", "-c", "st -e sh -c 'cal -3 | less -+F'", NULL }; +static const char *calendarcmd[] = { "/bin/sh", "-c", "st -e sh -c 'cal -3 | less'", NULL }; static const char *dunstlogcmd[] = { "/bin/sh", "-c", "st -e sh -c 'less -+F \"$HOME/.cache/dunst/dunst.log\"'", NULL }; -static const char *powermenucmd[] = { "/bin/sh", "-c", "printf 'lock\\nreboot\\nshutdown' | dmenu | xargs -r -I{} sh -c 'case \"{}\" in lock) slock ;; reboot) loginctl reboot ;; shutdown) loginctl poweroff ;; esac'", NULL }; +static const char *powermenucmd[] = { "/bin/sh", "-c", "printf '%s\n' lock reboot shutdown | dmenu | xargs -r -I{} sh -c 'case \"{}\" in lock) slock ;; reboot) loginctl reboot ;; shutdown) loginctl poweroff ;; esac'", NULL }; static const Key keys[] = { /* modifier key function argument */ diff --git a/core/slock/config.h b/core/slock/config.h new file mode 100644 index 0000000..9855e21 --- /dev/null +++ b/core/slock/config.h @@ -0,0 +1,12 @@ +/* user and group to drop privileges to */ +static const char *user = "nobody"; +static const char *group = "nogroup"; + +static const char *colorname[NUMCOLS] = { + [INIT] = "black", /* after initialization */ + [INPUT] = "#005577", /* during input */ + [FAILED] = "#CC3333", /* wrong password */ +}; + +/* treat a cleared input like a wrong password (color) */ +static const int failonclear = 1; diff --git a/core/slock/explicit_bzero.o b/core/slock/explicit_bzero.o Binary files differnew file mode 100644 index 0000000..192474c --- /dev/null +++ b/core/slock/explicit_bzero.o diff --git a/core/slock/slock b/core/slock/slock Binary files differnew file mode 100755 index 0000000..0d85d2f --- /dev/null +++ b/core/slock/slock diff --git a/core/slock/slock.c b/core/slock/slock.c index 962cc1d..297e076 100644 --- a/core/slock/slock.c +++ b/core/slock/slock.c @@ -180,7 +180,7 @@ blurbackground(Display *dpy, struct lock *lock) if (!img) return; imlib_context_set_image(img); - imlib_image_blur(20); + imlib_image_blur(75); lock->bgmap = XCreatePixmap(dpy, lock->root, w, h, DefaultDepth(dpy, lock->screen)); diff --git a/core/slock/slock.o b/core/slock/slock.o Binary files differnew file mode 100644 index 0000000..f28cbdd --- /dev/null +++ b/core/slock/slock.o diff --git a/slogin/Makefile b/slogin/Makefile new file mode 100644 index 0000000..4d8c919 --- /dev/null +++ b/slogin/Makefile @@ -0,0 +1,16 @@ +CC = cc +CFLAGS = -std=c99 -Wall -Wextra -pedantic -Os +LDFLAGS = -lX11 -lcrypt +PREFIX ?= /usr/local + +all: slogin + +slogin: slogin.c + $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) + +clean: + rm -f slogin + +install: slogin + mkdir -p $(DESTDIR)$(PREFIX)/bin + cp -f slogin $(DESTDIR)$(PREFIX)/bin diff --git a/slogin/slogin.c b/slogin/slogin.c new file mode 100644 index 0000000..856585b --- /dev/null +++ b/slogin/slogin.c @@ -0,0 +1,166 @@ +#define _XOPEN_SOURCE 700 +#include <X11/Xlib.h> +#include <X11/keysym.h> +#include <ctype.h> +#include <grp.h> +#include <pwd.h> +#if HAVE_SHADOW_H +#include <shadow.h> +#endif +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <crypt.h> +#include "../accent.h" + +#define WIDTH 400 +#define HEIGHT 100 + +static int +auth(const char *user, const char *pass) +{ + struct passwd *pw = getpwnam(user); + const char *hash; + if (!pw) + return 0; +#if HAVE_SHADOW_H + struct spwd *sp = getspnam(user); + hash = sp ? sp->sp_pwdp : pw->pw_passwd; +#else + hash = pw->pw_passwd; +#endif + if (!hash || hash[0] == '!' || hash[0] == '*') + return 0; + return strcmp(crypt(pass, hash), hash) == 0; +} + +static void +draw(Display *dpy, Window win, GC gc, const char *prompt, + const char *input, int hidden) +{ + XClearWindow(dpy, win); + XDrawString(dpy, win, gc, 10, 25, prompt, strlen(prompt)); + if (input && *input) { + char buf[128]; + const char *show = input; + if (hidden) { + size_t n = strlen(input); + if (n >= sizeof buf) + n = sizeof buf - 1; + memset(buf, '*', n); + buf[n] = '\0'; + show = buf; + } + XDrawString(dpy, win, gc, 10, 50, show, strlen(show)); + } + XFlush(dpy); +} + +int +main(void) +{ + Display *dpy; + Window win; + XEvent ev; + GC gc; + XFontStruct *font; + int screen; + Colormap cmap; + XColor xcol; + ColorShm *blk = NULL; + char accent[8] = "#005577"; + + if (!(dpy = XOpenDisplay(NULL))) { + fprintf(stderr, "slogin: cannot open display\n"); + return 1; + } + readaccent(&blk, accent); + screen = DefaultScreen(dpy); + cmap = DefaultColormap(dpy, screen); + XParseColor(dpy, cmap, accent, &xcol); + XAllocColor(dpy, cmap, &xcol); + win = XCreateSimpleWindow(dpy, RootWindow(dpy, screen), + DisplayWidth(dpy, screen)/2 - WIDTH/2, + DisplayHeight(dpy, screen)/2 - HEIGHT/2, + WIDTH, HEIGHT, 2, xcol.pixel, BlackPixel(dpy, screen)); + XStoreName(dpy, win, "slogin"); + XSelectInput(dpy, win, ExposureMask | KeyPressMask); + XMapRaised(dpy, win); + gc = XCreateGC(dpy, win, 0, NULL); + XSetForeground(dpy, gc, xcol.pixel); + font = XLoadQueryFont(dpy, "fixed"); + if (font) + XSetFont(dpy, gc, font->fid); + + char user[64] = ""; + char pass[64] = ""; + int stage = 0; + draw(dpy, win, gc, "user:", user, 0); + + for (;;) { + if (XPending(dpy)) { + XNextEvent(dpy, &ev); + if (ev.type == Expose) { + draw(dpy, win, gc, stage ? "pass:" : "user:", + stage ? pass : user, stage); + } else if (ev.type == KeyPress) { + char buf[32]; + KeySym ksym; + int len = XLookupString(&ev.xkey, buf, sizeof buf, &ksym, NULL); + if (ksym == XK_Return) { + if (stage == 0) { + stage = 1; + draw(dpy, win, gc, "pass:", pass, 1); + } else { + if (auth(user, pass)) { + struct passwd *pw = getpwnam(user); + if (!pw) + exit(1); + chdir(pw->pw_dir); + setenv("HOME", pw->pw_dir, 1); + setenv("SHELL", pw->pw_shell, 1); + setenv("USER", pw->pw_name, 1); + setenv("LOGNAME", pw->pw_name, 1); + initgroups(pw->pw_name, pw->pw_gid); + setgid(pw->pw_gid); + setuid(pw->pw_uid); + execlp(pw->pw_shell, pw->pw_shell, "-l", NULL); + perror("execlp"); + exit(1); + } else { + user[0] = pass[0] = '\0'; + stage = 0; + draw(dpy, win, gc, "user:", user, 0); + } + } + } else if (ksym == XK_BackSpace) { + if (stage == 0) { + size_t n = strlen(user); + if (n) user[n-1] = '\0'; + draw(dpy, win, gc, "user:", user, 0); + } else { + size_t n = strlen(pass); + if (n) pass[n-1] = '\0'; + draw(dpy, win, gc, "pass:", pass, 1); + } + } else if (len && !iscntrl((unsigned char)buf[0])) { + if (stage == 0 && strlen(user) + len < sizeof user - 1) { + strncat(user, buf, len); + draw(dpy, win, gc, "user:", user, 0); + } else if (stage == 1 && strlen(pass) + len < sizeof pass - 1) { + strncat(pass, buf, len); + draw(dpy, win, gc, "pass:", pass, 1); + } + } + } + } + if (readaccent(&blk, accent)) { + XParseColor(dpy, cmap, accent, &xcol); + XAllocColor(dpy, cmap, &xcol); + XSetForeground(dpy, gc, xcol.pixel); + XSetWindowBorder(dpy, win, xcol.pixel); + } + usleep(20000); + } +} |
