Andrew Geissler | ac970dd | 2021-02-12 15:32:45 -0600 | [diff] [blame^] | 1 | From bae6a2b3a2232abd16a8d8558dda542d4970f1bb Mon Sep 17 00:00:00 2001 |
| 2 | From: Kai Kang <kai.kang@windriver.com> |
| 3 | Date: Tue, 12 Jan 2021 09:23:05 +0800 |
| 4 | Subject: [PATCH 7/8] greeter.c: support to update expired password |
| 5 | |
| 6 | Update greeter to work with ui to handle expired password. It checks |
| 7 | whether password is expired after input user and password. If expired, |
| 8 | force user to update password immediately. It allows 3 times to try. If |
| 9 | exceeds, reset to input user. |
| 10 | |
| 11 | Upstream-Status: Submitted [https://sourceforge.net/p/lxdm/code/merge-requests/1/] |
| 12 | |
| 13 | Signed-off-by: Kai Kang <kai.kang@windriver.com> |
| 14 | --- |
| 15 | src/greeter.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++-- |
| 16 | 1 file changed, 81 insertions(+), 2 deletions(-) |
| 17 | |
| 18 | diff --git a/src/greeter.c b/src/greeter.c |
| 19 | index f100c72..804fca0 100644 |
| 20 | --- a/src/greeter.c |
| 21 | +++ b/src/greeter.c |
| 22 | @@ -77,6 +77,8 @@ static GtkWidget *lang_menu; |
| 23 | |
| 24 | static char* user = NULL; |
| 25 | static char* pass = NULL; |
| 26 | +static char* new_pass = NULL; |
| 27 | +static gboolean pass_expired = FALSE; |
| 28 | |
| 29 | static char* ui_file = NULL; |
| 30 | static char *ui_nobody = NULL; |
| 31 | @@ -167,10 +169,19 @@ static void switch_to_input_passwd(void) |
| 32 | else |
| 33 | gtk_widget_hide(user_list); |
| 34 | } |
| 35 | - gtk_label_set_text( GTK_LABEL(prompt), _("Password:") ); |
| 36 | + if (pass_expired) { |
| 37 | + if (!new_pass) { |
| 38 | + gtk_label_set_text(GTK_LABEL(prompt), _("New password:")); |
| 39 | + } else { |
| 40 | + gtk_label_set_text(GTK_LABEL(prompt), _("Retype new password:")); |
| 41 | + } |
| 42 | + } else { |
| 43 | + gtk_label_set_text( GTK_LABEL(prompt), _("Password:") ); |
| 44 | + } |
| 45 | gtk_entry_set_text(GTK_ENTRY(login_entry), ""); |
| 46 | gtk_entry_set_visibility(GTK_ENTRY(login_entry), FALSE); |
| 47 | gtk_widget_show(login_entry); |
| 48 | + gtk_widget_show(prompt); |
| 49 | gtk_widget_grab_focus(login_entry); |
| 50 | } |
| 51 | |
| 52 | @@ -189,6 +200,8 @@ static void try_login_user(const char *user) |
| 53 | |
| 54 | static void on_entry_activate(GtkEntry* entry) |
| 55 | { |
| 56 | + static int count = 0; |
| 57 | + |
| 58 | char* tmp; |
| 59 | if( !user ) |
| 60 | { |
| 61 | @@ -217,6 +230,46 @@ static void on_entry_activate(GtkEntry* entry) |
| 62 | } |
| 63 | else |
| 64 | { |
| 65 | + if (pass_expired) { |
| 66 | + if (!new_pass) { |
| 67 | + new_pass = g_strdup(gtk_entry_get_text(entry)); |
| 68 | + switch_to_input_passwd(); |
| 69 | + } else { |
| 70 | + tmp = g_strdup(gtk_entry_get_text(entry)); |
| 71 | + if (strcmp(new_pass, tmp)) { |
| 72 | + g_free(new_pass); |
| 73 | + new_pass = NULL; |
| 74 | + // if new passwords not match, retry for 3 times at most |
| 75 | + if (++count < 3) { |
| 76 | + switch_to_input_passwd(); |
| 77 | + } else { |
| 78 | + count = 0; |
| 79 | + pass_expired = FALSE; |
| 80 | + switch_to_input_user(); |
| 81 | + } |
| 82 | + } else if (!strcmp(pass, g_base64_encode((guchar*)new_pass, strlen(new_pass) + 1))) { |
| 83 | + // if new password is same as old one |
| 84 | + g_free(new_pass); |
| 85 | + new_pass = NULL; |
| 86 | + if (++count < 3) { |
| 87 | + switch_to_input_passwd(); |
| 88 | + } else { |
| 89 | + count = 0; |
| 90 | + pass_expired = FALSE; |
| 91 | + switch_to_input_user(); |
| 92 | + } |
| 93 | + } else { |
| 94 | + char *session_exec=get_session_exec(); |
| 95 | + char *session_lang=get_session_lang(); |
| 96 | + |
| 97 | + printf("update-new-password user=%s newpass=%s session=%s lang=%s\n", |
| 98 | + user, new_pass, session_exec, session_lang); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + return ; |
| 103 | + } |
| 104 | + |
| 105 | char *session_exec=get_session_exec(); |
| 106 | char *session_lang=get_session_lang(); |
| 107 | |
| 108 | @@ -227,6 +280,7 @@ static void on_entry_activate(GtkEntry* entry) |
| 109 | printf("login user=%s pass=%s session=%s lang=%s\n", |
| 110 | user, pass, session_exec, session_lang); |
| 111 | |
| 112 | +#if 0 |
| 113 | /* password check failed */ |
| 114 | g_free(user); |
| 115 | user = NULL; |
| 116 | @@ -241,6 +295,7 @@ static void on_entry_activate(GtkEntry* entry) |
| 117 | gtk_label_set_text( GTK_LABEL(prompt), _("User:") ); |
| 118 | gtk_entry_set_text(GTK_ENTRY(entry), ""); |
| 119 | gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE); |
| 120 | +#endif |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | @@ -1091,8 +1146,12 @@ static void on_screen_size_changed(GdkScreen *screen,GtkWidget *win) |
| 125 | |
| 126 | static gint login_entry_on_key_press (GtkWidget *widget,GdkEventKey *event) |
| 127 | { |
| 128 | - if(event->keyval == GDK_Escape) |
| 129 | + if(event->keyval == GDK_Escape) { |
| 130 | + g_free(new_pass); |
| 131 | + new_pass = NULL; |
| 132 | + pass_expired = FALSE; |
| 133 | switch_to_input_user(); |
| 134 | + } |
| 135 | return FALSE; |
| 136 | } |
| 137 | |
| 138 | @@ -1285,8 +1344,10 @@ static void create_win() |
| 139 | |
| 140 | static gboolean on_lxdm_command(GIOChannel *source, GIOCondition condition, gpointer data) |
| 141 | { |
| 142 | + |
| 143 | GIOStatus ret; |
| 144 | char *str; |
| 145 | + static int count = 0; |
| 146 | |
| 147 | if( !(G_IO_IN & condition) ) |
| 148 | return FALSE; |
| 149 | @@ -1300,10 +1361,28 @@ static gboolean on_lxdm_command(GIOChannel *source, GIOCondition condition, gpoi |
| 150 | { |
| 151 | switch_to_input_user(); |
| 152 | } |
| 153 | + else if (!strncmp(str, "password-expire", 15)) |
| 154 | + { |
| 155 | + pass_expired = TRUE; |
| 156 | + switch_to_input_passwd(); |
| 157 | + } |
| 158 | else if( !strncmp(str, "password", 8)) |
| 159 | { |
| 160 | switch_to_input_passwd(); |
| 161 | } |
| 162 | + else if (!strncmp(str, "invalid-new-password", 20)) |
| 163 | + { |
| 164 | + g_free(new_pass); |
| 165 | + new_pass = NULL; |
| 166 | + |
| 167 | + if (count++ < 3) { |
| 168 | + switch_to_input_passwd(); |
| 169 | + } else { |
| 170 | + count = 0; |
| 171 | + pass_expired = FALSE; |
| 172 | + switch_to_input_user(); |
| 173 | + } |
| 174 | + } |
| 175 | g_free(str); |
| 176 | return TRUE; |
| 177 | } |
| 178 | -- |
| 179 | 2.25.1 |
| 180 | |