diff --git a/CHANGELOG b/CHANGELOG index 6afd986..3ca66cd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,12 @@ Version 1.0 +2005-05-24: + + * more consistency in the ui, updated documentation + * added -auth md5:file= + * added -auth sha1:file= + * rename -cursor font to -cursor glyph + 2005-05-23: * added -bg image:shade= diff --git a/alock.txt b/alock.txt index 625c7f4..8362620 100644 --- a/alock.txt +++ b/alock.txt @@ -1,7 +1,7 @@ ALOCK(1) ======== Mathias Gumz -v0.5, ?? May 2005 +v1.0, ?? May 2005 NAME ---- @@ -13,11 +13,11 @@ SYNOPSIS DESCRIPTION ----------- -alock locks the X server till the user enters a password at the +'alock' locks the X server till the user enters a password at the keyboard. If the authentification was successful the X server is unlocked and the user can continue to work. -alock does not provide fancy animations like 'xlock' and 'xscreensaver' +'alock' does not provide fancy animations like 'xlock' and 'xscreensaver' and never will. Its just for locking the current X session. OPTIONS @@ -30,36 +30,52 @@ OPTIONS -auth type:options :: Define the type of the authentification, depends strongly on how alock was built: - - list - Displays a list of available types - - passwd - Tries to authentificate against the users system-password. - On systems using 'shadow' alock needs the suid-flag set. - - pam - Tries to authentificate against the users system-password - using the 'pam-login'-module. - - md5:hash - alock creates a md5-hash from the entered unlockpassword - and compares it with the hash provided as option - - sha1:hash - alock creates a sha1-hash from the entered unlockpassword - and compares it with the hash provided as option - - none - Every 'password' is valid + - list - Displays a list of available types + - passwd - Tries to authentificate against the users system-password. + On systems using 'shadow' alock needs the suid-flag set. + - pam - Tries to authentificate against the users system-password + using the 'pam-login'-module. + - md5 - alock creates a md5-hash from the entered unlockpassword and compares it with the hash provided + * hash= - use as reference + * file= - use content of as reference + + - sha1 - alock creates a sha1-hash from the entered unlockpassword and compares it with the hash provided + * hash= - use as reference + * file= - use as reference -bg type:options :: Define the type of alock should handle the background: - - list - Displays a list of available types - - none - You can see everything like it is - - blank:color - Fill the background with color - - shade:shade=,color= - Dims content of the screen and - recolors it. - - image:name,center,scale,tile,color=,shade= - Use the image and puts it as - the background. + - list - Displays a list of available types + - none - You can see everything like it is + - blank - Fill the background with color + * color= - Use + - shade - Dims content of the screen and recolors it. + * shade= - Valid from 1 to 99 + * color= - Use + - image - Use the image and puts it as the background + * file= + * center + * scale + * tile + * color= - Use + * shade= - Valid from 1 to 99 -cursor type:options :: Define the look-a-like of the cursor/mouse pointer: - - list - Displays a list of available types - - theme:name,bg=,fg= - Use the given internal cursor, if name == "list" it lists - the available themes - - font:name,bg=,fg= - Use the given glyph of the "cursor"-font, if name == - "list" it lists the available glyphnames - - xcursor:file - Use the given cursorfile in xcursor-format - - none - no change to the current cursor + - list - Displays a list of available types + - theme - Use the given internal cursor + * list - Display all possible themes + * name= + * bg= - Use forground-color + * fg= - Use background-color + - glyph - Use the given glyph of the "cursor"-font + * list - Display all possible glyph-names + * name= + * bg= + * fg= + - xcursor - Use the given in xcursor-format + * file= + - none - No change to the current cursor AUTHOR ------ @@ -69,7 +85,7 @@ RESOURCES --------- Web site: http://darkshed.net -Other lockers:: +Other lockers :: - xlockmore http://www.tux.org/~bagleyd/xlockmore.html - xscreensaver http://www.jwz.org/xscreensaver/ - xtrlock ftp://ftp.debian.org/debian/dists/stable/main/source/x11/ diff --git a/src/SConscript b/src/SConscript index 4511799..5abd62f 100644 --- a/src/SConscript +++ b/src/SConscript @@ -9,7 +9,7 @@ alock_sources = [ 'alock.c', 'alock_utils.c' ] auth_sources = [ 'auth_none.c' ] bg_sources = [ 'bg_none.c', 'bg_blank.c' ] -cursor_sources = [ 'cursor_none.c', 'cursor_theme.c', 'cursor_font.c' ] +cursor_sources = [ 'cursor_none.c', 'cursor_theme.c', 'cursor_glyph.c' ] Import('alock_env') diff --git a/src/alock.c b/src/alock.c index 773d7ce..43ea77a 100644 --- a/src/alock.c +++ b/src/alock.c @@ -49,7 +49,7 @@ static struct aBackground* alock_backgrounds[] = { &alock_bg_none, &alock_bg_blank, #ifdef HAVE_IMLIB2 - &alock_bg_imlib2, + &alock_bg_image, #endif /* HAVE_IMLIB2 */ #ifdef HAVE_XRENDER &alock_bg_shade, @@ -60,7 +60,7 @@ static struct aBackground* alock_backgrounds[] = { static struct aCursor* alock_cursors[] = { &alock_cursor_none, &alock_cursor_theme, - &alock_cursor_font, + &alock_cursor_glyph, #ifdef HAVE_XCURSOR &alock_cursor_xcursor, #endif /* HAVE_XCURSOR */ diff --git a/src/alock.h b/src/alock.h index f2050de..de19e4d 100644 --- a/src/alock.h +++ b/src/alock.h @@ -67,6 +67,7 @@ struct aOpts { /*------------------------------------------------------------------*\ \*------------------------------------------------------------------*/ +void alock_string2lower(char* string); int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name, const char* fallback_name, XColor* result); int alock_check_xrender(const struct aXInfo* xinfo); @@ -84,7 +85,7 @@ int alock_shade_pixmap(const struct aXInfo* xinfo, extern struct aBackground alock_bg_none; extern struct aBackground alock_bg_blank; #ifdef HAVE_IMLIB2 -extern struct aBackground alock_bg_imlib2; +extern struct aBackground alock_bg_image; #endif /* HAVE_IMLIB2 */ #ifdef HAVE_XRENDER extern struct aBackground alock_bg_shade; @@ -106,7 +107,7 @@ extern struct aAuth alock_auth_pam; \*------------------------------------------------------------------*/ extern struct aCursor alock_cursor_none; extern struct aCursor alock_cursor_theme; -extern struct aCursor alock_cursor_font; +extern struct aCursor alock_cursor_glyph; #ifdef HAVE_XCURSOR extern struct aCursor alock_cursor_xcursor; #endif /* HAVE_XCURSOR */ diff --git a/src/alock_utils.c b/src/alock_utils.c index e0735fa..641167f 100644 --- a/src/alock_utils.c +++ b/src/alock_utils.c @@ -23,8 +23,18 @@ # include #endif /* HAVE_XRENDER */ #include +#include +#include #include "alock.h" +/*------------------------------------------------------------------*\ +\*------------------------------------------------------------------*/ +void alock_string2lower(char* string) { + static unsigned int i; + for(i = strlen(string) - 1; i; --i) + tolower(string[i]); +} + /* ---------------------------------------------------------------- *\ \* ---------------------------------------------------------------- */ int alock_alloc_color(const struct aXInfo* xinfo, const char* color_name, @@ -91,6 +101,7 @@ int alock_shade_pixmap(const struct aXInfo* xinfo, { /* fill the alpha-picture */ Pixmap alpha_pm = None; + XRenderColor alpha_color; XRenderPictureAttributes alpha_attr; diff --git a/src/auth_md5.c b/src/auth_md5.c index 6f335e3..6808875 100644 --- a/src/auth_md5.c +++ b/src/auth_md5.c @@ -23,7 +23,7 @@ about : - provide -auth md5:hash + provide -auth md5:hash=,file= \* ---------------------------------------------------------------- */ @@ -34,6 +34,7 @@ #include #include #include +#include #ifndef STAND_ALONE # include # include "alock.h" @@ -286,29 +287,81 @@ static void md5_transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LEN #ifndef STAND_ALONE -static const char* userhash = NULL; +static char* userhash = NULL; static int alock_auth_md5_init(const char* args) { - if (args) { - char* check = strstr(args, "md5:"); - if (!check || check != args) { - fprintf(stderr, "alock: error, missing arguments for [md5].\n"); - return 0; - } - if (strlen(&args[4]) != MD5_DIGEST_STRING_LENGTH - 1) { - fprintf(stderr, "alock: error, invalid md5-hash.\n"); - return 0; - } - - userhash = &args[4]; - return 1; + if (!args) { + fprintf(stderr, "alock: error, missing arguments for [md5].\n"); + return 0; } - return 0; + if (strstr(args, "md5:") == args && strlen(&args[4]) > 0) { + char* arguments = strdup(&args[4]); + char* tmp; + char* arg = NULL; + for (tmp = arguments; tmp; ) { + arg = strsep(&tmp, ","); + if (arg && !userhash) { + if (strstr(arg, "hash=") == arg && strlen(arg) > 5) { + if (strlen(&arg[5]) == MD5_DIGEST_STRING_LENGTH - 1) { + if (!userhash) + userhash = strdup(&arg[5]); + } else { + printf("alock: error, missing or incorrect hash for [md5].\n"); + free(arguments); + return 0; + } + } else if (strstr(arg, "file=") == arg && strlen(arg) > 6) { + char* tmp_hash = NULL; + FILE* hashfile = fopen(&arg[5], "r"); + if (hashfile) { + int c; + unsigned int i = 0; + tmp_hash = (char*)malloc(MD5_DIGEST_STRING_LENGTH); + memset(tmp_hash, 0, MD5_DIGEST_STRING_LENGTH); + for(i = 0, c = fgetc(hashfile); + i < MD5_DIGEST_STRING_LENGTH - 1 && c != EOF; i++, c = fgetc(hashfile)) { + tmp_hash[i] = tolower(c); + } + fclose(hashfile); + } else { + printf("alock: error, couldnt read [%s] for [md5].\n", + &arg[5]); + free(arguments); + return 0; + } + + if (!tmp_hash || strlen(tmp_hash) != MD5_DIGEST_STRING_LENGTH - 1) { + printf("alock: error, given file [%s] doesnt contain a valid hash for [md5].\n", + &arg[5]); + free(arguments); + return 0; + } + + userhash = tmp_hash; + } + } + } + free(arguments); + } else { + fprintf(stderr, "alock: error, missing arguments for [md5].\n"); + return 0; + } + + if (!userhash) { + printf("alock: error, missing hash for [md5].\n"); + return 0; + } + + alock_string2lower(userhash); + + return 1; } static int alock_auth_md5_deinit() { + if (userhash) + free(userhash); return 1; } diff --git a/src/auth_sha1.c b/src/auth_sha1.c index aa604c3..2f544f4 100644 --- a/src/auth_sha1.c +++ b/src/auth_sha1.c @@ -17,7 +17,7 @@ about : - provide -auth sha1:hash + provide -auth sha1:hash=,file= \* ---------------------------------------------------------------- */ @@ -30,6 +30,7 @@ #include #include #include +#include #ifndef STAND_ALONE # include # include "alock.h" @@ -222,29 +223,81 @@ static void sha1_final(u_int8_t digest[SHA1_DIGEST_LENGTH], sha1Context *context \* ---------------------------------------------------------------- */ #ifndef STAND_ALONE -static const char* userhash = NULL; +static char* userhash = NULL; static int alock_auth_sha1_init(const char* args) { - if (args) { - char* check = strstr(args, "sha1:"); - if (!check || check != args) { - fprintf(stderr, "alock: error, missing arguments for [sha1].\n"); - return 0; - } - if (strlen(&args[5]) != SHA1_DIGEST_STRING_LENGTH - 1) { - fprintf(stderr, "alock: error, invalid sha1-hash.\n"); - return 0; - } - - userhash = &args[5]; - return 1; + if (!args) { + fprintf(stderr, "alock: error, missing arguments for [sha1].\n"); + return 0; } - return 0; + if (strstr(args, "sha1:") == args && strlen(&args[5]) > 0) { + char* arguments = strdup(&args[5]); + char* tmp; + char* arg = NULL; + for (tmp = arguments; tmp; ) { + arg = strsep(&tmp, ","); + if (arg && !userhash) { + if (strstr(arg, "hash=") == arg && strlen(arg) > 5) { + if (strlen(&arg[5]) == SHA1_DIGEST_STRING_LENGTH - 1) { + if (!userhash) + userhash = strdup(&arg[5]); + } else { + printf("alock: error, missing or incorrect hash for [sha1].\n"); + free(arguments); + return 0; + } + } else if (strstr(arg, "file=") == arg && strlen(arg) > 6) { + char* tmp_hash = NULL; + FILE* hashfile = fopen(&arg[5], "r"); + if (hashfile) { + int c; + unsigned int i = 0; + tmp_hash = (char*)malloc(SHA1_DIGEST_STRING_LENGTH); + memset(tmp_hash, 0, SHA1_DIGEST_STRING_LENGTH); + for(i = 0, c = fgetc(hashfile); + i < SHA1_DIGEST_STRING_LENGTH - 1 && c != EOF; i++, c = fgetc(hashfile)) { + tmp_hash[i] = tolower(c); + } + fclose(hashfile); + } else { + printf("alock: error, couldnt read [%s] for [md5].\n", + &arg[5]); + free(arguments); + return 0; + } + + if (!tmp_hash || strlen(tmp_hash) != SHA1_DIGEST_STRING_LENGTH - 1) { + printf("alock: error, given file [%s] doesnt contain a valid hash for [sha1].\n", + &arg[5]); + free(arguments); + return 0; + } + + userhash = tmp_hash; + } + } + } + free(arguments); + } else { + fprintf(stderr, "alock: error, missing arguments for [sha1].\n"); + return 0; + } + + if (!userhash) { + printf("alock: error, missing hash for [sha1].\n"); + return 0; + } + + alock_string2lower(userhash); + + return 1; } static int alock_auth_sha1_deinit() { + if (userhash) + free(userhash); return 1; } diff --git a/src/bg_image.c b/src/bg_image.c index 35e9510..2317b17 100644 --- a/src/bg_image.c +++ b/src/bg_image.c @@ -41,7 +41,7 @@ static Window window = 0; static Pixmap pixmap = 0; static XColor color; -static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { +static int alock_bg_image_init(const char* args, struct aXInfo* xinfo) { XWindowAttributes xgwa; XSetWindowAttributes xswa; @@ -77,13 +77,15 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { } else { printf("alock: error, shade not in range [1, 99] for [image].\n"); free(color_name); + if (filename) + free(filename); free(arguments); return 0; } - } else { + } else if (strstr(arg, "file=") == arg && strlen(arg) > 6) { if (!filename) - filename = strdup(arg); + filename = strdup(&arg[5]); } } } @@ -235,7 +237,7 @@ static int alock_bg_imlib2_init(const char* args, struct aXInfo* xinfo) { } -static int alock_bg_imlib2_deinit(struct aXInfo* xinfo) { +static int alock_bg_image_deinit(struct aXInfo* xinfo) { if (!xinfo || !window) return 0; XDestroyWindow(xinfo->display, window); @@ -243,10 +245,10 @@ static int alock_bg_imlib2_deinit(struct aXInfo* xinfo) { return 1; } -struct aBackground alock_bg_imlib2 = { +struct aBackground alock_bg_image = { "image", - alock_bg_imlib2_init, - alock_bg_imlib2_deinit + alock_bg_image_init, + alock_bg_image_deinit }; /* ---------------------------------------------------------------- *\ diff --git a/src/bg_shade.c b/src/bg_shade.c index a6356df..8278e85 100644 --- a/src/bg_shade.c +++ b/src/bg_shade.c @@ -80,7 +80,7 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { free(color_name); return 0; } - + /* get a color from color_name */ alock_alloc_color(xinfo, color_name, "black", &color); free(color_name); @@ -97,7 +97,6 @@ static int alock_bg_shade_init(const char* args, struct aXInfo* xinfo) { Window root = xinfo->root; int scrnr = DefaultScreen(dpy); int depth = DefaultDepth(dpy, scrnr); - Visual* vis = DefaultVisual(dpy, scrnr); GC gc = DefaultGC(dpy, scrnr); { /* grab whats on the screen */ diff --git a/src/cursor_font.c b/src/cursor_glyph.c similarity index 78% rename from src/cursor_font.c rename to src/cursor_glyph.c index 75474d8..0732643 100644 --- a/src/cursor_font.c +++ b/src/cursor_glyph.c @@ -1,6 +1,6 @@ /* ---------------------------------------------------------------- *\ - file : cursor_font.c + file : cursor_glyph.c author : m. gumz copyr : copyright (c) 2005 by m. gumz @@ -125,9 +125,8 @@ static Cursor cursor = 0; static XColor color_fg; static XColor color_bg; -static int alock_cursor_font_init(const char* args, struct aXInfo* xinfo) { +static int alock_cursor_glyph_init(const char* args, struct aXInfo* xinfo) { - XColor tmp_color; char* color_bg_name = strdup("steelblue3"); char* color_fg_name = strdup("grey25"); unsigned int shape = 0; /* XC_X_cursor */ @@ -135,42 +134,38 @@ static int alock_cursor_font_init(const char* args, struct aXInfo* xinfo) { if (!xinfo || !args) return 0; - if (strstr(args, "font:") == args && strlen(&args[5]) > 0) { - char* arguments = strdup(&args[5]); + if (strstr(args, "glyph:") == args && strlen(&args[6]) > 0) { + char* arguments = strdup(&args[6]); char* tmp; char* arg = NULL; for (tmp = arguments; tmp; ) { arg = strsep(&tmp, ","); if (arg) { - const struct CursorFontName* cursor_font_name; + const struct CursorFontName* cursor_glyph_name; if (!strcmp(arg, "list")) { - for (cursor_font_name = cursor_names; cursor_font_name->name; ++cursor_font_name) { - printf("%s\n", cursor_font_name->name); + for (cursor_glyph_name = cursor_names; cursor_glyph_name->name; ++cursor_glyph_name) { + printf("%s\n", cursor_glyph_name->name); } free(color_fg_name); free(color_bg_name); free(arguments); exit(0); - } - if (strstr(arg, "fg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) { + } else if (strstr(arg, "fg=") == arg && strlen(arg) > 4) { free(color_fg_name); color_fg_name = strdup(&arg[3]); - } - else if (strstr(arg, "bg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) { + } else if (strstr(arg, "bg=") == arg && strlen(arg) > 4) { free(color_bg_name); color_bg_name = strdup(&arg[3]); - } - else { - /* TODO: accept as well -> strtol */ - for (cursor_font_name = cursor_names; cursor_font_name->name; ++cursor_font_name) { - if(!strcmp(cursor_font_name->name, arg)) { - shape = cursor_font_name->shape; + } else if (strstr(arg, "name=") == arg && strlen(arg) > 6) { + for (cursor_glyph_name = cursor_names; cursor_glyph_name->name; ++cursor_glyph_name) { + if(!strcmp(cursor_glyph_name->name, &arg[5])) { + shape = cursor_glyph_name->shape; break; } } - if (!cursor_font_name->name) { - printf("alock: error, couldnt find [%s]\n", arg); + if (!cursor_glyph_name->name) { + printf("alock: error, couldnt find [%s]\n", &arg[5]); free(color_bg_name); free(color_fg_name); free(arguments); @@ -182,10 +177,8 @@ static int alock_cursor_font_init(const char* args, struct aXInfo* xinfo) { free(arguments); } - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_bg_name, &tmp_color, &color_bg)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color_bg); - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_fg_name, &tmp_color, &color_fg)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "white", &tmp_color, &color_fg); + alock_alloc_color(xinfo, color_bg_name, "black", &color_bg); + alock_alloc_color(xinfo, color_fg_name, "white", &color_fg); free(color_fg_name); free(color_bg_name); @@ -202,7 +195,7 @@ static int alock_cursor_font_init(const char* args, struct aXInfo* xinfo) { return 1; } -static int alock_cursor_font_deinit(struct aXInfo* xinfo) { +static int alock_cursor_glyph_deinit(struct aXInfo* xinfo) { if (!xinfo || !cursor) return 0; @@ -212,10 +205,10 @@ static int alock_cursor_font_deinit(struct aXInfo* xinfo) { } -struct aCursor alock_cursor_font = { - "font", - alock_cursor_font_init, - alock_cursor_font_deinit +struct aCursor alock_cursor_glyph = { + "glyph", + alock_cursor_glyph_init, + alock_cursor_glyph_deinit }; diff --git a/src/cursor_theme.c b/src/cursor_theme.c index e776efe..81097ae 100644 --- a/src/cursor_theme.c +++ b/src/cursor_theme.c @@ -78,7 +78,6 @@ static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) { char* color_bg_name = strdup("steelblue3"); char* color_fg_name = strdup("grey25"); - XColor tmp_color; Pixmap pixmap_cursor; Pixmap pixmap_cursor_mask; const struct ThemeCursor* theme = cursors; @@ -103,18 +102,15 @@ static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) { free(color_bg_name); free(arguments); exit(0); - } - if (strstr(arg, "fg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) { + } else if (strstr(arg, "fg=") == arg && strlen(arg) > 4) { free(color_fg_name); color_fg_name = strdup(&arg[3]); - } - else if (strstr(arg, "bg=") == arg && strlen(arg) > 3 && strlen(&arg[3])) { + } else if (strstr(arg, "bg=") == arg && strlen(arg) > 4) { free(color_bg_name); color_bg_name = strdup(&arg[3]); - } - else { + } else if (strstr(arg, "name=") == arg && strlen(arg) > 6) { for (cursor_theme_name = cursors; cursor_theme_name->name; ++cursor_theme_name) { - if(!strcmp(cursor_theme_name->name, arg)) { + if(!strcmp(cursor_theme_name->name, &arg[5])) { theme = cursor_theme_name; break; } @@ -132,11 +128,9 @@ static int alock_cursor_theme_init(const char* args, struct aXInfo* xinfo) { free(arguments); } - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_bg_name, &tmp_color, &color_bg)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "black", &tmp_color, &color_bg); - if((XAllocNamedColor(xinfo->display, xinfo->colormap, color_fg_name, &tmp_color, &color_fg)) == 0) - XAllocNamedColor(xinfo->display, xinfo->colormap, "white", &tmp_color, &color_fg); - + alock_alloc_color(xinfo, color_fg_name, "white", &color_fg); + alock_alloc_color(xinfo, color_bg_name, "blank", &color_bg); + free(color_fg_name); free(color_bg_name);