Aestethic code improvements
This commit is contained in:
parent
7639469ea2
commit
b6b0441889
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
loqy
|
loqy
|
||||||
|
.gitignore
|
||||||
|
|
71
main.c
71
main.c
|
@ -15,13 +15,15 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/xf86vmode.h>
|
#include <X11/extensions/xf86vmode.h>
|
||||||
|
|
||||||
|
#define PASS_LEN 1024
|
||||||
|
#define PASS_BOX_LEN 20
|
||||||
|
#define FONT_SIZE 12
|
||||||
|
|
||||||
|
|
||||||
/* user and group to drop privileges to */
|
/* user and group to drop privileges to */
|
||||||
static const char *user = "overlord";
|
static const char *user = "overlord";
|
||||||
static const char *group = "wheel";
|
static const char *group = "wheel";
|
||||||
static const char *message = "Password";
|
static const char *message = "Password";
|
||||||
#define PASS_LEN 1024
|
|
||||||
#define PASS_BOX_LEN 20
|
|
||||||
#define FONT_SIZE 12
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct{unsigned long flags;
|
typedef struct{unsigned long flags;
|
||||||
|
@ -38,13 +40,12 @@ typedef struct { unsigned long flags;
|
||||||
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, int, 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*, Window w, Visual *v, Colormap cmap, int width, int height, int screen, 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);
|
||||||
|
void window_attr(Display*, Window, int, int, int);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -91,11 +92,13 @@ int main(void) {
|
||||||
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, width, height);
|
window_attr(d, w, s, width, height);
|
||||||
// DRAW THE RECTANGLES AND STRINGS
|
// DRAW THE RECTANGLES AND STRINGS
|
||||||
|
@ -120,10 +123,22 @@ int main(void) {
|
||||||
// CHECK THE DAMNED PASSWORD
|
// CHECK THE DAMNED PASSWORD
|
||||||
get_passwd(d, w, visual, cmap, width, height, s, hash);
|
get_passwd(d, w, visual, cmap, width, height, s, hash);
|
||||||
|
|
||||||
|
|
||||||
XCloseDisplay(d);
|
XCloseDisplay(d);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void anullate(char *str, int size){
|
||||||
|
memset(str, 0, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void catch_fire(char *string, int error){
|
void catch_fire(char *string, int error){
|
||||||
fprintf(stderr, string);
|
fprintf(stderr, string);
|
||||||
exit(error);
|
exit(error);
|
||||||
|
@ -135,8 +150,6 @@ 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);
|
||||||
|
@ -145,9 +158,8 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int
|
||||||
|
|
||||||
|
|
||||||
// FONT COLORS
|
// FONT COLORS
|
||||||
XftColor xft_black;
|
XftColor xft_black, xft_white;
|
||||||
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);
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,11 +184,11 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int
|
||||||
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;
|
||||||
|
@ -187,8 +199,6 @@ void draw_ui(Display *d, Window w, Visual *visual, Colormap cmap, int width, int
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,7 +214,7 @@ void window_attr (Display *d, Window w, int s, int width, int height){
|
||||||
video_mode = modes[0];
|
video_mode = modes[0];
|
||||||
|
|
||||||
|
|
||||||
// COCKS FOR FULLSCREEN QOQS
|
// DISABLE DECORATIONS
|
||||||
Hints hints;
|
Hints hints;
|
||||||
hints.flags = 2;
|
hints.flags = 2;
|
||||||
hints.decorations = 0;
|
hints.decorations = 0;
|
||||||
|
@ -213,8 +223,6 @@ void window_attr (Display *d, Window w, int s, int width, int height){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
XSelectInput(d, w, ExposureMask | KeyPressMask);
|
||||||
XMapWindow(d, w);
|
XMapWindow(d, w);
|
||||||
|
|
||||||
|
@ -224,6 +232,7 @@ void window_attr (Display *d, Window w, int s, int width, int height){
|
||||||
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);
|
||||||
|
|
||||||
|
@ -234,15 +243,6 @@ void window_attr (Display *d, Window w, int s, int width, int height){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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){
|
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;
|
||||||
|
@ -257,12 +257,12 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int h
|
||||||
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)
|
if(ksym == XK_KP_Enter)
|
||||||
ksym = XK_Return;
|
ksym = XK_Return;
|
||||||
|
|
||||||
|
@ -270,6 +270,7 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int h
|
||||||
ksym = (ksym - XK_KP_0) + XK_0;
|
ksym = (ksym - XK_KP_0) + XK_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (IsFunctionKey(ksym) ||
|
if (IsFunctionKey(ksym) ||
|
||||||
IsKeypadKey(ksym) ||
|
IsKeypadKey(ksym) ||
|
||||||
IsMiscFunctionKey(ksym) ||
|
IsMiscFunctionKey(ksym) ||
|
||||||
|
@ -277,12 +278,12 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int h
|
||||||
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);
|
||||||
|
@ -292,7 +293,6 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int h
|
||||||
|
|
||||||
|
|
||||||
if(check){
|
if(check){
|
||||||
|
|
||||||
XBell(d, 100);
|
XBell(d, 100);
|
||||||
failure = 1;
|
failure = 1;
|
||||||
}
|
}
|
||||||
|
@ -326,7 +326,6 @@ void get_passwd(Display *d, Window w, Visual *v, Colormap cmap, int width, int h
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,20 +339,18 @@ static const char *generate_hash(void){
|
||||||
|
|
||||||
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. "
|
catch_fire("cannot retrieve shadow entry. ", 69);
|
||||||
"Make sure to suid or sgid slock.\n", 69);
|
|
||||||
hash = sp->sp_pwdp;
|
hash = sp->sp_pwdp;
|
||||||
}
|
}
|
||||||
if (!strcmp(hash, "*")) {
|
|
||||||
catch_fire("slock: getpwuid: cannot retrieve shadow entry. "
|
if(!strcmp(hash, "*"))
|
||||||
"Make sure to suid or sgid slock.\n", 98);
|
catch_fire("slock: getpwuid: cannot retrieve shadow entry. ", 98);
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue