Merge lp:~uoms-gregt/lightdm-gtk-greeter/trim-username into lp:lightdm-gtk-greeter

Proposed by Greg Trounson on 2019-02-10
Status: Needs review
Proposed branch: lp:~uoms-gregt/lightdm-gtk-greeter/trim-username
Merge into: lp:lightdm-gtk-greeter
Diff against target: 55 lines (+10/-5)
1 file modified
src/lightdm-gtk-greeter.c (+10/-5)
To merge this branch: bzr merge lp:~uoms-gregt/lightdm-gtk-greeter/trim-username
Reviewer Review Type Date Requested Status
LightDM Gtk+ Greeter Development Team 2019-02-10 Pending
Review via email: mp+362953@code.launchpad.net

Commit message

Ignore whitespace before and after username when authenticating.

Description of the change

Our use case:
Users press the space bar to either power up the computer or bring the monitor out
of sleep. If the computer is already powered on then that keypress propagates to the username
field in lightdm-gtk-greeter, inserting a <space> before they type their username, resulting in a failed login. With proportional fonts this is almost impossible to see at a glance.

Given that whitespace can never be part of a valid username (cf IEEE 1003.1-2001), this patch trims the beginning and end of the username string before passing it to the authentication code. <Space> characters still appear in the username field, but have no effect.

To test:
At a lightdm login prompt, type:
<space>username
or:
username<space>
then enter your password.

Pre-patch:
The login will fail.
Post-patch:
The login will succeed.

To post a comment you must log in.

Unmerged revisions

477. By Greg Trounson <email address hidden> on 2019-02-10

Ignore whitespace before and after username when authenticating

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/lightdm-gtk-greeter.c'
2--- src/lightdm-gtk-greeter.c 2018-03-15 00:29:41 +0000
3+++ src/lightdm-gtk-greeter.c 2019-02-10 20:58:40 +0000
4@@ -1999,13 +1999,17 @@
5 password_prompted = FALSE;
6 prompt_active = FALSE;
7
8+ gchar* trimmed_username;
9+ trimmed_username = g_strdup (username);
10+ g_strstrip (trimmed_username);
11+
12 if (pending_questions)
13 {
14 g_slist_free_full (pending_questions, (GDestroyNotify) pam_message_finalize);
15 pending_questions = NULL;
16 }
17
18- config_set_string (STATE_SECTION_GREETER, STATE_KEY_LAST_USER, username);
19+ config_set_string (STATE_SECTION_GREETER, STATE_KEY_LAST_USER, trimmed_username);
20
21 if (g_strcmp0 (username, "*other") == 0)
22 {
23@@ -2031,7 +2035,7 @@
24 }
25 }
26 }
27- else if (g_strcmp0 (username, "*guest") == 0)
28+ else if (g_strcmp0 (trimmed_username, "*guest") == 0)
29 {
30 #ifdef HAVE_LIBLIGHTDMGOBJECT_1_19_2
31 lightdm_greeter_authenticate_as_guest (greeter, NULL);
32@@ -2043,7 +2047,7 @@
33 {
34 LightDMUser *user;
35
36- user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username);
37+ user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), trimmed_username);
38 if (user)
39 {
40 if (!current_session)
41@@ -2057,11 +2061,12 @@
42 set_language (NULL);
43 }
44 #ifdef HAVE_LIBLIGHTDMGOBJECT_1_19_2
45- lightdm_greeter_authenticate (greeter, username, NULL);
46+ lightdm_greeter_authenticate (greeter, trimmed_username, NULL);
47 #else
48- lightdm_greeter_authenticate (greeter, username);
49+ lightdm_greeter_authenticate (greeter, trimmed_username);
50 #endif
51 }
52+ g_free (trimmed_username);
53 }
54
55 static void

Subscribers

People subscribed via source and target branches

to all changes: