Compare commits
4 commits
Author | SHA1 | Date | |
---|---|---|---|
Јован Ђокић-Шумарац | 25c3246dfa | ||
Јован Ђокић-Шумарац | fc4fcd1adf | ||
Јован Ђокић-Шумарац | 166ac56583 | ||
Јован Ђокић-Шумарац | 6f9e140639 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +0,0 @@
|
||||||
loqy
|
|
||||||
.gitignore
|
|
21
LICENSE
21
LICENSE
|
@ -1,21 +0,0 @@
|
||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2022 Јован Ђокић-Шумарац
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
|
@ -1,5 +1,2 @@
|
||||||
# LOQY
|
# LOQY
|
||||||
A simple and minimalistic lockscreen for X11, written in C.
|
A simple and minimalistic lockscreen for X11, written in C.
|
||||||
|
|
||||||
|
|
||||||
![LOL](https://gitlab.com/vojjvoda/loqy/-/raw/main/ss.png)
|
|
||||||
|
|
219
main.c
219
main.c
|
@ -15,42 +15,41 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/xf86vmode.h>
|
#include <X11/extensions/xf86vmode.h>
|
||||||
|
|
||||||
|
/* user and group to drop privileges to */
|
||||||
|
static const char *user = "overlord";
|
||||||
|
static const char *group = "wheel";
|
||||||
|
static const char *message = "Password";
|
||||||
#define PASS_LEN 1024
|
#define PASS_LEN 1024
|
||||||
#define PASS_BOX_LEN 20
|
#define PASS_BOX_LEN 20
|
||||||
#define FONT_SIZE 12
|
#define FONT_SIZE 12
|
||||||
|
|
||||||
|
|
||||||
/* user and group to drop privileges to */
|
typedef struct { unsigned long flags;
|
||||||
static const char *user = "overlord";
|
unsigned long functions;
|
||||||
static const char *group = "wheel";
|
unsigned long decorations;
|
||||||
static const char *message = "Password";
|
long inputMode;
|
||||||
|
unsigned long status;
|
||||||
|
} Hints;
|
||||||
typedef struct{unsigned long flags;
|
|
||||||
unsigned long functions;
|
|
||||||
unsigned long decorations;
|
|
||||||
long inputMode;
|
|
||||||
unsigned long status;
|
|
||||||
}Hints;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
char pass_buffer[PASS_LEN], passwd[PASS_LEN];
|
char pass_buffer[PASS_LEN], passwd[PASS_LEN];
|
||||||
|
|
||||||
|
|
||||||
void anullate(char*, int);
|
|
||||||
void catch_fire(char*, int);
|
void catch_fire (char*, int);
|
||||||
void draw_ui(Display*, Window, Visual*, Colormap, int);
|
void draw_ui (Display*, Window, Visual*, Colormap, int, int, int);
|
||||||
void get_passwd(Display*, Window, Visual*, Colormap, int, const char*);
|
void window_attr (Display*, Window, int, int, int);
|
||||||
|
void anullate (char*, int);
|
||||||
|
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);
|
||||||
void window_attr(Display*, Window, int);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(void){
|
int main(void) {
|
||||||
|
|
||||||
struct passwd *pwd;
|
struct passwd *pwd;
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
|
@ -61,48 +60,46 @@ int main(void){
|
||||||
|
|
||||||
|
|
||||||
Display *d = XOpenDisplay(NULL);
|
Display *d = XOpenDisplay(NULL);
|
||||||
if(d == NULL)
|
if ( d == NULL )
|
||||||
catch_fire("Cannot open display\n", 1);
|
catch_fire("Cannot open display\n", 1);
|
||||||
|
|
||||||
|
|
||||||
if(!(pwd = getpwnam(user)))
|
if (!(pwd = getpwnam(user)))
|
||||||
catch_fire("Cannot get user", 6);
|
catch_fire("Cannot get user", 6);
|
||||||
duid = pwd->pw_uid;
|
duid = pwd->pw_uid;
|
||||||
|
|
||||||
|
|
||||||
if(!(grp = getgrnam(group)))
|
if (!(grp = getgrnam(group)))
|
||||||
catch_fire("Can't get group", 7);
|
catch_fire("Can't get group", 7);
|
||||||
dgid = grp->gr_gid;
|
dgid = grp->gr_gid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int s = DefaultScreen(d);
|
int s = DefaultScreen(d);
|
||||||
int depth = DefaultDepth(d, s);
|
int depth = DefaultDepth(d, s);
|
||||||
width = DisplayWidth(d, s);
|
int width = DisplayWidth(d, s);
|
||||||
height = DisplayHeight(d, s);
|
int height = DisplayHeight(d, s);
|
||||||
|
|
||||||
|
|
||||||
Window w;
|
Window w;
|
||||||
Visual *visual = DefaultVisual(d, s);
|
Visual *visual = DefaultVisual(d, s);
|
||||||
Colormap cmap = DefaultColormap(d, s);
|
Colormap cmap = DefaultColormap(d, s);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// IGNORES WM RULES
|
// IGNORES WM RULES
|
||||||
XSetWindowAttributes attributes;
|
XSetWindowAttributes attributes;
|
||||||
attributes.override_redirect = True;
|
attributes.override_redirect = True;
|
||||||
attributes.background_pixel = BlackPixel(d, s);
|
attributes.background_pixel = BlackPixel(d, s);
|
||||||
|
|
||||||
// MAKE THE WINDOW
|
// MAKE THE WINDOW
|
||||||
w = XCreateWindow(d, XRootWindow(d, s), 0, 0, width, height, 0, depth,
|
w = XCreateWindow(d, XRootWindow(d, s), 0, 0, width, height, 0, depth,
|
||||||
InputOutput, visual, CWBackPixel | CWOverrideRedirect, &attributes);
|
InputOutput, visual, CWBackPixel | CWOverrideRedirect, &attributes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// SET WINDOW ATTRIBUTES
|
// SET WINDOW ATTRIBUTES
|
||||||
window_attr(d, w, s);
|
window_attr(d, w, s, width, height);
|
||||||
// DRAW THE RECTANGLES AND STRINGS
|
// DRAW THE RECTANGLES AND STRINGS
|
||||||
draw_ui(d, w, visual, cmap, s);
|
draw_ui(d, w, visual, cmap, width, height, s);
|
||||||
|
|
||||||
|
|
||||||
hash = generate_hash();
|
hash = generate_hash();
|
||||||
|
@ -121,25 +118,13 @@ int main(void){
|
||||||
|
|
||||||
|
|
||||||
// CHECK THE DAMNED PASSWORD
|
// CHECK THE DAMNED PASSWORD
|
||||||
get_passwd(d, w, visual, cmap, s, hash);
|
get_passwd(d, w, visual, cmap, width, height, s, hash);
|
||||||
|
|
||||||
|
|
||||||
XCloseDisplay(d);
|
XCloseDisplay(d);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void catch_fire (char *string, int error){
|
||||||
|
|
||||||
|
|
||||||
void anullate(char *str, int size){
|
|
||||||
memset(str, 0, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void catch_fire(char *string, int error){
|
|
||||||
fprintf(stderr, string);
|
fprintf(stderr, string);
|
||||||
exit(error);
|
exit(error);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +133,9 @@ void catch_fire(char *string, int error){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, 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];
|
||||||
|
@ -158,8 +145,9 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int s){
|
||||||
|
|
||||||
|
|
||||||
// FONT COLORS
|
// FONT COLORS
|
||||||
XftColor xft_black, xft_white;
|
XftColor xft_black;
|
||||||
XftColorAllocName (d, visual, cmap, "black", &xft_black);
|
XftColorAllocName (d, visual, cmap, "black", &xft_black);
|
||||||
|
XftColor xft_white;
|
||||||
XftColorAllocName (d, visual, cmap, "white", &xft_white);
|
XftColorAllocName (d, visual, cmap, "white", &xft_white);
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,11 +172,11 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int s){
|
||||||
XftDrawRect(xftdraw, &xft_black, black_rect_x, black_rect_y, black_rect_width, black_rect_height);
|
XftDrawRect(xftdraw, &xft_black, black_rect_x, black_rect_y, black_rect_width, black_rect_height);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PRINT PASS MESSAGE
|
// PRINT PASS MESSAGE
|
||||||
XftDrawString8(xftdraw, &xft_black, font, white_rect_x + FONT_SIZE/2, height/2 + FONT_SIZE/2 , message, strlen(message));
|
XftDrawString8(xftdraw, &xft_black, font, white_rect_x + FONT_SIZE/2, height/2 + FONT_SIZE/2 , message, strlen(message));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PRINT ASTERISKS
|
// PRINT ASTERISKS
|
||||||
char pass_asterisks[PASS_BOX_LEN + 1];
|
char pass_asterisks[PASS_BOX_LEN + 1];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -199,12 +187,14 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int s){
|
||||||
|
|
||||||
XftDrawString8(xftdraw, &xft_white, font, black_rect_x + FONT_SIZE/2, height/2 + FONT_SIZE/2 , pass_asterisks, strlen(pass_asterisks));
|
XftDrawString8(xftdraw, &xft_white, font, black_rect_x + FONT_SIZE/2, height/2 + FONT_SIZE/2 , pass_asterisks, strlen(pass_asterisks));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void window_attr(Display *d, Window w, int s){
|
void window_attr (Display *d, Window w, int s, int width, int height){
|
||||||
|
|
||||||
int mode_count;
|
int mode_count;
|
||||||
|
|
||||||
|
@ -214,7 +204,7 @@ void window_attr(Display *d, Window w, int s){
|
||||||
video_mode = modes[0];
|
video_mode = modes[0];
|
||||||
|
|
||||||
|
|
||||||
// DISABLE DECORATIONS
|
// COCKS FOR FULLSCREEN QOQS
|
||||||
Hints hints;
|
Hints hints;
|
||||||
hints.flags = 2;
|
hints.flags = 2;
|
||||||
hints.decorations = 0;
|
hints.decorations = 0;
|
||||||
|
@ -223,6 +213,8 @@ void window_attr(Display *d, Window w, int s){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
||||||
XMapWindow(d, w);
|
XMapWindow(d, w);
|
||||||
|
|
||||||
|
@ -232,7 +224,6 @@ void window_attr(Display *d, Window w, int s){
|
||||||
XF86VidModeSetViewPort(d, s, 0, 0);
|
XF86VidModeSetViewPort(d, s, 0, 0);
|
||||||
XMoveResizeWindow(d, w, 0, 0, width, height);
|
XMoveResizeWindow(d, w, 0, 0, width, height);
|
||||||
XMapRaised(d, w);
|
XMapRaised(d, w);
|
||||||
|
|
||||||
XGrabPointer(d, w, True, 0, GrabModeAsync, GrabModeAsync, w, 0L, CurrentTime);
|
XGrabPointer(d, w, True, 0, GrabModeAsync, GrabModeAsync, w, 0L, CurrentTime);
|
||||||
XGrabKeyboard(d, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
XGrabKeyboard(d, w, True, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||||
|
|
||||||
|
@ -243,7 +234,16 @@ void window_attr(Display *d, Window w, int s){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int screen, const char *hash){
|
|
||||||
|
void anullate(char *str, int size){
|
||||||
|
memset(str, 0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
@ -253,79 +253,80 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int screen, cons
|
||||||
|
|
||||||
|
|
||||||
// CHECK PASSWORD
|
// CHECK PASSWORD
|
||||||
while(1){
|
while (1) {
|
||||||
XNextEvent(d, &e);
|
XNextEvent(d, &e);
|
||||||
|
|
||||||
if(e.type == KeyPress){
|
if (e.type == KeyPress) {
|
||||||
|
|
||||||
anullate(pass_buffer, sizeof(pass_buffer));
|
anullate(pass_buffer, sizeof(pass_buffer));
|
||||||
|
|
||||||
num = XLookupString(&e.xkey, pass_buffer, sizeof(pass_buffer), &ksym, 0);
|
num = XLookupString(&e.xkey, pass_buffer, sizeof(pass_buffer), &ksym, 0);
|
||||||
|
|
||||||
|
if (IsKeypadKey(ksym)) {
|
||||||
if(IsKeypadKey(ksym)){
|
|
||||||
if(ksym == XK_KP_Enter)
|
|
||||||
ksym = XK_Return;
|
|
||||||
|
|
||||||
else if(ksym >= XK_KP_0 && ksym <= XK_KP_9)
|
if (ksym == XK_KP_Enter)
|
||||||
ksym = (ksym - XK_KP_0) + XK_0;
|
ksym = XK_Return;
|
||||||
|
|
||||||
|
else if (ksym >= XK_KP_0 && ksym <= XK_KP_9)
|
||||||
|
ksym = (ksym - XK_KP_0) + XK_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IsFunctionKey(ksym) ||
|
||||||
if (IsFunctionKey(ksym) ||
|
IsKeypadKey(ksym) ||
|
||||||
IsKeypadKey(ksym) ||
|
IsMiscFunctionKey(ksym) ||
|
||||||
IsMiscFunctionKey(ksym) ||
|
IsPFKey(ksym) ||
|
||||||
IsPFKey(ksym) ||
|
IsPrivateKeypadKey(ksym))
|
||||||
IsPrivateKeypadKey(ksym))
|
continue;
|
||||||
continue;
|
|
||||||
|
|
||||||
|
switch (ksym) {
|
||||||
switch(ksym){
|
|
||||||
|
|
||||||
case XK_Return:
|
case XK_Return:
|
||||||
passwd[len] = '\0';
|
passwd[len] = '\0';
|
||||||
|
|
||||||
if(!(input_hash = crypt(passwd, hash))){
|
|
||||||
|
if (!(input_hash = crypt(passwd, hash))){
|
||||||
fprintf(stderr, "loqy : crypt error : %s\n", strerror(errno));
|
fprintf(stderr, "loqy : crypt error : %s\n", strerror(errno));
|
||||||
fprintf(stderr, "%d %d\n", errno, EINVAL);
|
fprintf(stderr, "%d %d\n", errno, EINVAL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
check = !!strcmp(input_hash, hash);
|
check = !!strcmp(input_hash, hash);
|
||||||
|
|
||||||
|
|
||||||
if(check){
|
if (check) {
|
||||||
XBell(d, 100);
|
|
||||||
failure = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
anullate(passwd, sizeof(passwd));
|
XBell(d, 100);
|
||||||
len = 0;
|
failure = 1;
|
||||||
break;
|
}
|
||||||
|
|
||||||
case XK_Escape:
|
anullate(passwd, sizeof(passwd));
|
||||||
anullate(passwd, sizeof(passwd));
|
len = 0;
|
||||||
len = 0;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case XK_BackSpace:
|
case XK_Escape:
|
||||||
if(len)
|
anullate(passwd, sizeof(passwd));
|
||||||
passwd[--len] = '\0';
|
len = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case XK_BackSpace:
|
||||||
if(num && !iscntrl((int)pass_buffer[0]) && (len + num < sizeof(passwd))){
|
if (len)
|
||||||
memcpy(passwd + len, pass_buffer, num);
|
passwd[--len] = '\0';
|
||||||
len += num;
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (num && !iscntrl((int)pass_buffer[0]) && (len + num < sizeof(passwd))) {
|
||||||
|
memcpy(passwd + len, pass_buffer, num);
|
||||||
|
len += num;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_ui(d, w, v, cmap, screen);
|
draw_ui(d, w, v, cmap, width, height, screen);
|
||||||
|
|
||||||
if(!check)
|
if(!check)
|
||||||
exit(0);
|
exit(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -337,20 +338,22 @@ static const char *generate_hash(void){
|
||||||
const char *hash;
|
const char *hash;
|
||||||
struct passwd *pw;
|
struct passwd *pw;
|
||||||
|
|
||||||
if(!(pw = getpwuid(getuid())))
|
if( !(pw = getpwuid(getuid())) )
|
||||||
catch_fire("Cannot get password info\n", 2);
|
catch_fire("Cannot get password info\n", 2);
|
||||||
|
|
||||||
hash = pw->pw_passwd;
|
hash = pw->pw_passwd;
|
||||||
|
|
||||||
if(!strcmp(hash, "x")){
|
if (!strcmp(hash, "x")) {
|
||||||
struct spwd *sp;
|
struct spwd *sp;
|
||||||
if(!(sp = getspnam(pw->pw_name)))
|
if (!(sp = getspnam(pw->pw_name)))
|
||||||
catch_fire("cannot retrieve shadow entry. ", 69);
|
catch_fire("cannot retrieve shadow entry. "
|
||||||
|
"Make sure to suid or sgid slock.\n", 69);
|
||||||
hash = sp->sp_pwdp;
|
hash = sp->sp_pwdp;
|
||||||
}
|
}
|
||||||
|
if (!strcmp(hash, "*")) {
|
||||||
if(!strcmp(hash, "*"))
|
catch_fire("slock: getpwuid: cannot retrieve shadow entry. "
|
||||||
catch_fire("slock: getpwuid: cannot retrieve shadow entry. ", 98);
|
"Make sure to suid or sgid slock.\n", 98);
|
||||||
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue