summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorgy A. Shepelev <gerik@k24a.ulsu.ru>2009-12-09 12:18:50 +0300
committerAlan Coopersmith <alan.coopersmith@sun.com>2010-03-15 18:19:58 -0700
commit7437298deab265b7669043d4a470a684201f5f3c (patch)
treee5c17de4902d2b148981b8b039594e666a2fe974
parent34d120f31347697886a419411d9d4d825874f3f0 (diff)
Adding an option to show stars instead of the password itself.
The behaviour can be controlled via 'xlogin*echoPasswd' option in Xresource file. The default option value is 'false'. Signed-off-by: Georgy A. Shepelev <shepelev.georgy@googlemail.com> Tested-by: Georgy A. Shepelev <shepelev.georgy@googlemail.com> [Reformatted to match existing code style by Alan Coopersmith] Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com>
-rw-r--r--greeter/Login.c54
-rw-r--r--greeter/Login.h2
-rw-r--r--greeter/LoginP.h2
-rw-r--r--greeter/greet.c6
4 files changed, 54 insertions, 10 deletions
diff --git a/greeter/Login.c b/greeter/Login.c
index c691992..60c21e9 100644
--- a/greeter/Login.c
+++ b/greeter/Login.c
@@ -219,7 +219,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
@@ -350,12 +352,34 @@ 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);
@@ -365,7 +389,7 @@ realizeValue (LoginWidget w, int cursor, int promptNum, GC gc)
height -= (w->login.inframeswidth * 2);
width -= (w->login.inframeswidth * 2);
#ifdef XPM
- width -= (w->login.logoWidth + 2*(w->login.logoPadding));
+ width -= (w->login.logoWidth + (w->login.logoPadding * 2));
#endif
if (cursor > VALUE_SHOW_START(w, promptNum))
curoff = TEXT_WIDTH (text, text, cursor);
@@ -379,7 +403,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);
@@ -412,6 +438,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
@@ -460,9 +491,18 @@ realizeCursor (LoginWidget w, GC gc)
}
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);
+ 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;
}
diff --git a/greeter/Login.h b/greeter/Login.h
index 43e3f5d..e819672 100644
--- a/greeter/Login.h
+++ b/greeter/Login.h
@@ -100,6 +100,7 @@ from The Open Group.
# define XtNallowAccess "allowAccess"
# define XtNallowNullPasswd "allowNullPasswd"
# define XtNallowRootLogin "allowRootLogin"
+# define XtNechoPasswd "echoPasswd"
# define XtNface "face"
# define XtCFace "Face"
@@ -140,6 +141,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 59274d3..049c8b1 100644
--- a/greeter/LoginP.h
+++ b/greeter/LoginP.h
@@ -130,6 +130,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 d5ea0e6..7f235ef 100644
--- a/greeter/greet.c
+++ b/greeter/greet.c
@@ -73,7 +73,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
@@ -499,9 +499,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 { \