From 832bbfc2d3b14a6c0ddb5a896a16fe33e4379f27 Mon Sep 17 00:00:00 2001 From: Georgy A. Shepelev Date: Wed, 9 Dec 2009 12:18:50 +0300 Subject: [PATCH] [PATCH] xdm: Adding an option to show stars instead of the password itself. xdm: The behaviour can be controlled via 'xlogin*echoPasswd' option xdm: in Xresource file. The default option value is 'false'. Signed-off-by: Georgy A. Shepelev Tested-by: Georgy A. Shepelev --- greeter/Login.c | 63 ++++++++++++++++++++++++++++++++++++++++++++--------- greeter/Login.h | 2 + greeter/LoginP.h | 2 + greeter/greet.c | 6 ++-- 4 files changed, 59 insertions(+), 14 deletions(-) diff --git a/greeter/Login.c b/greeter/Login.c index fefa29d..29a8c31 100644 --- a/greeter/Login.c +++ b/greeter/Login.c @@ -224,7 +224,9 @@ static XtResource resources[] = { {XtNallowNullPasswd, XtCAllowNullPasswd, XtRBoolean, sizeof (Boolean), offset(allow_null_passwd), XtRImmediate, (XtPointer) False}, {XtNallowRootLogin, XtCAllowRootLogin, XtRBoolean, sizeof(Boolean), - offset(allow_root_login), XtRImmediate, (XtPointer) True} + offset(allow_root_login), XtRImmediate, (XtPointer) True}, + {XtNechoPasswd, XtCEchoPasswd, XtRBoolean, sizeof(Boolean), + offset(echo_passwd), XtRImmediate, (XtPointer) False} }; #undef offset @@ -355,11 +357,32 @@ static inline int max (int a, int b) { return a > b ? a : b; } static void realizeValue (LoginWidget w, int cursor, int promptNum, GC gc) { - loginPromptState state = w->login.prompts[promptNum].state; + loginPromptState state = PROMPT_STATE(w, promptNum); char *text = VALUE_TEXT(w, promptNum); int x, y, height, width, curoff; XDM_ASSERT(promptNum >= 0 && promptNum <= LAST_PROMPT); + /* replace all password characters with asterisks */ + if ((promptNum == LOGIN_PROMPT_PASSWORD) && (w->login.echo_passwd == True)) + { + Cardinal length = strlen(text); + Cardinal i = 0; + + text = XtMalloc(length + 1); + + if (text == NULL) + { + LogOutOfMem("realizeValue"); + return; + } + + while (i < length) + { + text[i++] = '*'; + } + + text[i] = 0; + } x = VALUE_X (w,promptNum); y = PROMPT_Y (w,promptNum); @@ -367,10 +390,10 @@ realizeValue (LoginWidget w, int cursor, int promptNum, GC gc) height = PROMPT_H(w); width = PROMPT_W(w) - x - 3; - height -= (w->login.inframeswidth * 2); - width -= (w->login.inframeswidth * 2); + height -= (w->login.inframeswidth << 1); + width -= (w->login.inframeswidth << 1); #ifdef XPM - width -= (w->login.logoWidth + 2*(w->login.logoPadding)); + width -= (w->login.logoWidth + (w->login.logoPadding << 1)); #endif if (cursor > VALUE_SHOW_START(w, promptNum)) curoff = TEXT_WIDTH (text, text, cursor); @@ -384,7 +407,9 @@ realizeValue (LoginWidget w, int cursor, int promptNum, GC gc) x + curoff, y - TEXT_Y_INC(w), width - curoff, height); } - } else if ((state == LOGIN_PROMPT_ECHO_ON) || (state == LOGIN_TEXT_INFO)) { + } else if ((state == LOGIN_PROMPT_ECHO_ON) || (state == LOGIN_TEXT_INFO) || + ((promptNum == LOGIN_PROMPT_PASSWORD) && (w->login.echo_passwd == True))) + { int textwidth; int offset = max(cursor, VALUE_SHOW_START(w, promptNum)); int textlen = strlen (text + offset); @@ -417,6 +442,11 @@ realizeValue (LoginWidget w, int cursor, int promptNum, GC gc) DRAW_STRING(text, x + curoff, y, text + offset, textlen); } } + /* free memory */ + if ((promptNum == LOGIN_PROMPT_PASSWORD) && (w->login.echo_passwd == True)) + { + XtFree(text); + } } static void @@ -464,11 +494,22 @@ realizeCursor (LoginWidget w, GC gc) - VALUE_SHOW_START(w, w->login.activePrompt) ); } break; - case LOGIN_PROMPT_ECHO_OFF: - /* Move cursor one pixel per character to give some feedback without - giving away the password length */ - x += PROMPT_CURSOR(w, w->login.activePrompt); - break; + + case LOGIN_PROMPT_ECHO_OFF: + if ((w->login.activePrompt == LOGIN_PROMPT_PASSWORD) && (w->login.echo_passwd == True)) + { + int len = PROMPT_CURSOR(w, w->login.activePrompt) - + VALUE_SHOW_START(w, w->login.activePrompt); + + x += len*TEXT_WIDTH(text, "*", 1); + } + else + { + /* Move cursor one pixel per character to give some feedback without + giving away the password length */ + x += PROMPT_CURSOR(w, w->login.activePrompt); + } + break; } XFillRectangle (XtDisplay (w), XtWindow (w), gc, diff --git a/greeter/Login.h b/greeter/Login.h index 7d04a1a..2e79e5e 100644 --- a/greeter/Login.h +++ b/greeter/Login.h @@ -105,6 +105,7 @@ from The Open Group. # define XtNallowAccess "allowAccess" # define XtNallowNullPasswd "allowNullPasswd" # define XtNallowRootLogin "allowRootLogin" +# define XtNechoPasswd "echoPasswd" # define XtNface "face" # define XtCFace "Face" @@ -145,6 +146,7 @@ from The Open Group. # define XtCAllowAccess "AllowAccess" # define XtCAllowNullPasswd "AllowNullPasswd" # define XtCAllowRootLogin "AllowRootLogin" +# define XtCEchoPasswd "EchoPasswd" # define XtNchangePasswdMessage "changePasswdMessage" # define XtCChangePasswdMessage "ChangePasswdMessage" diff --git a/greeter/LoginP.h b/greeter/LoginP.h index d73a9a1..37e9001 100644 --- a/greeter/LoginP.h +++ b/greeter/LoginP.h @@ -135,6 +135,8 @@ typedef struct { Boolean allow_access; /* disable access control on login */ Boolean allow_null_passwd; /* allow null password on login */ Boolean allow_root_login; /* allow root login */ + /* show password as asterisks, i.e. '**...' */ + Boolean echo_passwd; XIC xic; /* input method of input context */ loginPromptData prompts[NUM_PROMPTS]; time_t msgTimeout; diff --git a/greeter/greet.c b/greeter/greet.c index 17d21c8..2610641 100644 --- a/greeter/greet.c +++ b/greeter/greet.c @@ -78,7 +78,7 @@ from The Open Group. #include "dm.h" #include "dm_error.h" #include "greet.h" -#include "Login.h" +#include "LoginP.h" #if defined(HAVE_OPENLOG) && defined(HAVE_SYSLOG_H) # define USE_SYSLOG @@ -507,9 +507,9 @@ greet_user_rtn GreetUser( const char * login_prompt; - SetPrompt(login, 0, NULL, LOGIN_PROMPT_NOT_SHOWN, False); + SetPrompt(login, LOGIN_PROMPT_USERNAME, NULL, LOGIN_PROMPT_NOT_SHOWN, False); login_prompt = GetPrompt(login, LOGIN_PROMPT_USERNAME); - SetPrompt(login, 1, NULL, LOGIN_PROMPT_NOT_SHOWN, False); + SetPrompt(login, LOGIN_PROMPT_PASSWORD, NULL, LOGIN_PROMPT_NOT_SHOWN, False); # define RUN_AND_CHECK_PAM_ERROR(function, args) \ do { \ -- 1.6.4