Initial commit
This commit is contained in:
parent
d07ed0bfaf
commit
c1b4cb0ca1
29
Makefile
Normal file
29
Makefile
Normal file
|
@ -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
|
2
README.md
Normal file
2
README.md
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
# LOQY
|
||||||
|
A simple and minimalistic lockscreen for X11, written in C.
|
159
bak.c
159
bak.c
|
@ -1,159 +0,0 @@
|
||||||
#include <X11/Xlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <X11/Xatom.h>
|
|
||||||
#include <X11/extensions/xf86vmode.h>
|
|
||||||
#include <X11/Xutil.h>
|
|
||||||
#include <X11/Xft/Xft.h>
|
|
||||||
|
|
||||||
|
|
||||||
#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));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
38
main.c
38
main.c
|
@ -43,7 +43,7 @@ void catch_fire (char*, int);
|
||||||
void draw_ui (Display*, Window, Visual*, Colormap, int, int, int);
|
void draw_ui (Display*, Window, Visual*, Colormap, int, int, int);
|
||||||
void window_attr (Display*, Window, int, int, int);
|
void window_attr (Display*, Window, int, int, int);
|
||||||
void anullate (char*, 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);
|
static const char *generate_hash(void);
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,18 +105,23 @@ int main(void) {
|
||||||
hash = generate_hash();
|
hash = generate_hash();
|
||||||
crypt("", hash);
|
crypt("", hash);
|
||||||
|
|
||||||
/* drop privileges */
|
|
||||||
|
// DROP PRIVILEGES
|
||||||
if (setgroups(0, NULL) < 0)
|
if (setgroups(0, NULL) < 0)
|
||||||
;
|
catch_fire("Can't set group", 8);
|
||||||
|
|
||||||
if (setgid(dgid) < 0)
|
if (setgid(dgid) < 0)
|
||||||
;
|
catch_fire("Can't set group", 8);
|
||||||
|
|
||||||
if (setuid(duid) < 0)
|
if (setuid(duid) < 0)
|
||||||
;
|
catch_fire("Can't set group", 8);
|
||||||
|
|
||||||
get_passwd(d, hash);
|
|
||||||
|
|
||||||
XCloseDisplay(d);
|
// CHECK THE DAMNED PASSWORD
|
||||||
return 0;
|
get_passwd(d, w, visual, cmap, width, height, s, hash);
|
||||||
|
|
||||||
|
XCloseDisplay(d);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void catch_fire (char *string, int error){
|
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){
|
void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int height, int s){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FONT SHENANIGANS
|
//FONT SHENANIGANS
|
||||||
char font_name[strlen("monospace-") +2];
|
char font_name[strlen("monospace-") +2];
|
||||||
sprintf(font_name, "monospace-%d", FONT_SIZE);
|
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;
|
int num, failure = 0, check = 1;
|
||||||
unsigned int len = 0;
|
unsigned int len = 0;
|
||||||
|
@ -301,6 +319,8 @@ void get_passwd(Display *d, const char *hash){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
draw_ui(d, w, v, cmap, width, height, screen);
|
||||||
|
|
||||||
if(!check)
|
if(!check)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue