diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5b8cfc9 --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +PREFIX = /usr/local + +X11INC = /usr/X11R6/include +X11LIB = /usr/X11R6/lib + +# includes and libs +INCS = -I/usr/include/freetype2 -I${X11INC} +LIBS = -L/usr/lib -lc -lcrypt -L${X11LIB} -lX11 -lXxf86vm -lXft + +CC = gcc +CFLAGS = -O2 ${INCS} ${CPPFLAGS} # -pedantic -Wall +LDFLAGS = ${LIBS} + +all: loqy + + +loqy: + ${CC} main.c ${CFLAGS} ${LDFLAGS} -o loqy + +install: all + @echo installing executable file to ${DESTDIR}${PREFIX}/bin + @mkdir -p ${DESTDIR}${PREFIX}/bin + @cp -f loqy ${DESTDIR}${PREFIX}/bin + @chmod 755 ${DESTDIR}${PREFIX}/bin/loqy + @chmod u+s ${DESTDIR}${PREFIX}/bin/loqy + +uninstall: + @echo removing executable file from ${DESTDIR}${PREFIX}/bin + @rm -f ${DESTDIR}${PREFIX}/bin/loqy diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ccc2f4 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# LOQY +A simple and minimalistic lockscreen for X11, written in C. diff --git a/a.out b/a.out deleted file mode 100755 index 4616c10..0000000 Binary files a/a.out and /dev/null differ diff --git a/bak.c b/bak.c deleted file mode 100644 index 204728c..0000000 --- a/bak.c +++ /dev/null @@ -1,159 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - - -#define PASS_LEN 20 -#define FONT_SIZE 12 - - -typedef struct { unsigned long flags; - unsigned long functions; - unsigned long decorations; - long inputMode; - unsigned long status; -} Hints; - - - - -char *message = "Password"; - - -void catch_fire(char *string, int error){ - fprintf(stderr, string); - exit(error); -} - - -void draw_gui(Display*, Window, Visual*, Colormap, int, int, int); - - - -int main(void) { - - Display *d = XOpenDisplay(NULL); - - if ( d == NULL ) - catch_fire("Cannot open display\n", 1); - - - int s = DefaultScreen(d); - - - Window w; - XEvent e; - Visual *visual = DefaultVisual(d, s); - Colormap cmap = DefaultColormap(d, s); - - int depth = DefaultDepth(d, s); - int width = DisplayWidth(d, s); - int height = DisplayHeight(d, s); - - int mode_count; - - - // VIDEO MODES - XF86VidModeModeInfo **modes, *video_mode; - XF86VidModeGetAllModeLines(d, s, &mode_count, &modes); - video_mode = modes[0]; - - - // ATTRIBUTES - XSetWindowAttributes attributes; - attributes.override_redirect = True; - attributes.background_pixel = BlackPixel(d, s); - - - - // COCKS FOR FULLSCREEN QOQS - Hints hints; - hints.flags = 2; - hints.decorations = 0; - - Atom roperty = XInternAtom(d, "_MOTIF_WM_HINTS", True); - - - w = XCreateWindow(d, XRootWindow(d, s), 0, 0, width, height, 0, depth, InputOutput, visual, CWBackPixel|CWOverrideRedirect, &attributes); - - - draw_gui(d, w, visual, cmap, width, height, s); - - - XSelectInput(d, w, ExposureMask | KeyPressMask); - XMapWindow(d, w); - - - // SETTING FULLSCREEN - XF86VidModeSwitchToMode(d, s, video_mode); - XF86VidModeSetViewPort(d, s, 0, 0); - XMoveResizeWindow(d, w, 0, 0, width, height); - XMapRaised(d, w); - XGrabPointer(d, w, True, 0, GrabModeAsync, GrabModeAsync, w, 0L, CurrentTime); - XGrabKeyboard(d, w, True, GrabModeAsync, GrabModeAsync, CurrentTime); - - - - - while (1) { - XNextEvent(d, &e); - - if (e.type == KeyPress) - break; - } - - XCloseDisplay(d); - return 0; -} - - - - - - - - - - - - -void draw_gui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int height, int s){ - - // FONT - char font_name[strlen("monospace-") +2]; - sprintf(font_name, "monospace-%d", FONT_SIZE); - XftFont *font = XftFontOpenName(d, s, font_name); - - // FONT COLORS - XftColor xft_black; - XftColorAllocName (d, visual, cmap, "black", &xft_black); - XftColor xft_white; - XftColorAllocName (d, visual, cmap, "white", &xft_white); - - - - XftDraw *xftdraw = XftDrawCreate(d, w, visual, cmap); - - - // WHITE RECTANGLE - XftDrawRect(xftdraw, &xft_white, width/2 - ((strlen(message) + PASS_LEN) / 2)*FONT_SIZE, height/2 - 2*FONT_SIZE, - (strlen(message) + PASS_LEN)*FONT_SIZE, 4*FONT_SIZE); - - // BLACK RECTANGLE - XftDrawRect(xftdraw, &xft_black, width/2 - ((PASS_LEN - strlen(message)) / 2)*FONT_SIZE, height/2 - 2*FONT_SIZE + FONT_SIZE/2, - (PASS_LEN * FONT_SIZE) - FONT_SIZE/2, 3*FONT_SIZE); - - // MESSAGE STRING - XftDrawString8(xftdraw, &xft_black, font, width/2 - ((strlen(message) + PASS_LEN) / 2)*FONT_SIZE + FONT_SIZE/2, - height/2 + FONT_SIZE/2, message, strlen(message)); - - - -} - - diff --git a/loqy b/loqy new file mode 100755 index 0000000..9b4c2d5 Binary files /dev/null and b/loqy differ diff --git a/main.c b/main.c index 18dd30a..edb7c78 100644 --- a/main.c +++ b/main.c @@ -43,7 +43,7 @@ void catch_fire (char*, int); void draw_ui (Display*, Window, Visual*, Colormap, int, int, int); void window_attr (Display*, Window, int, int, int); void anullate (char*, int); -void get_passwd(Display*, const char*); +void get_passwd(Display*, Window w, Visual *v, Colormap cmap, int width, int height, int screen, const char*); static const char *generate_hash(void); @@ -105,18 +105,23 @@ int main(void) { hash = generate_hash(); crypt("", hash); - /* drop privileges */ - if (setgroups(0, NULL) < 0) - ; - if (setgid(dgid) < 0) - ; - if (setuid(duid) < 0) - ; - get_passwd(d, hash); + // DROP PRIVILEGES + if (setgroups(0, NULL) < 0) + catch_fire("Can't set group", 8); + + if (setgid(dgid) < 0) + catch_fire("Can't set group", 8); + + if (setuid(duid) < 0) + catch_fire("Can't set group", 8); + + + // CHECK THE DAMNED PASSWORD + get_passwd(d, w, visual, cmap, width, height, s, hash); - XCloseDisplay(d); - return 0; + XCloseDisplay(d); + return 0; } void catch_fire (char *string, int error){ @@ -131,6 +136,7 @@ void catch_fire (char *string, int error){ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int height, int s){ + //FONT SHENANIGANS char font_name[strlen("monospace-") +2]; sprintf(font_name, "monospace-%d", FONT_SIZE); @@ -171,6 +177,18 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int + // PRINT ASTERISKS + char pass_asterisks[PASS_BOX_LEN + 1]; + int i = 0; + for(i = 0; i < strlen(passwd) && i < PASS_BOX_LEN; ++i){ + pass_asterisks[i] = '*'; + } + pass_asterisks[i] = '\0'; + + XftDrawString8(xftdraw, &xft_white, font, black_rect_x + FONT_SIZE/2, height/2 + FONT_SIZE/2 , pass_asterisks, strlen(pass_asterisks)); + + + } @@ -225,7 +243,7 @@ void anullate(char *str, int size){ -void get_passwd(Display *d, const char *hash){ +void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int height, int screen, const char *hash){ int num, failure = 0, check = 1; unsigned int len = 0; @@ -301,6 +319,8 @@ void get_passwd(Display *d, const char *hash){ break; } + draw_ui(d, w, v, cmap, width, height, screen); + if(!check) exit(0); diff --git a/ss.png b/ss.png new file mode 100644 index 0000000..0c95e09 Binary files /dev/null and b/ss.png differ