summaryrefslogtreecommitdiff
path: root/meta-openembedded/meta-oe/recipes-graphics/lxdm/lxdm/0007-greeter.c-support-to-update-expired-password.patch
blob: 84a9faebb860cff57bf683d4c5b63260139f2629 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
From bae6a2b3a2232abd16a8d8558dda542d4970f1bb Mon Sep 17 00:00:00 2001
From: Kai Kang <kai.kang@windriver.com>
Date: Tue, 12 Jan 2021 09:23:05 +0800
Subject: [PATCH 7/8] greeter.c: support to update expired password

Update greeter to work with ui to handle expired password. It checks
whether password is expired after input user and password. If expired,
force user to update password immediately. It allows 3 times to try. If
exceeds, reset to input user.

Upstream-Status: Submitted [https://sourceforge.net/p/lxdm/code/merge-requests/1/]

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 src/greeter.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 81 insertions(+), 2 deletions(-)

diff --git a/src/greeter.c b/src/greeter.c
index f100c72..804fca0 100644
--- a/src/greeter.c
+++ b/src/greeter.c
@@ -77,6 +77,8 @@ static GtkWidget *lang_menu;
 
 static char* user = NULL;
 static char* pass = NULL;
+static char* new_pass = NULL;
+static gboolean pass_expired = FALSE;
 
 static char* ui_file = NULL;
 static char *ui_nobody = NULL;
@@ -167,10 +169,19 @@ static void switch_to_input_passwd(void)
 		else
 			gtk_widget_hide(user_list);
 	}
-	gtk_label_set_text( GTK_LABEL(prompt), _("Password:") );
+	if (pass_expired) {
+		if (!new_pass) {
+			gtk_label_set_text(GTK_LABEL(prompt), _("New password:"));
+		} else {
+			gtk_label_set_text(GTK_LABEL(prompt), _("Retype new password:"));
+		}
+	} else {
+		gtk_label_set_text( GTK_LABEL(prompt), _("Password:") );
+	}
 	gtk_entry_set_text(GTK_ENTRY(login_entry), "");
 	gtk_entry_set_visibility(GTK_ENTRY(login_entry), FALSE);
 	gtk_widget_show(login_entry);
+	gtk_widget_show(prompt);
 	gtk_widget_grab_focus(login_entry);
 }
 
@@ -189,6 +200,8 @@ static void try_login_user(const char *user)
 
 static void on_entry_activate(GtkEntry* entry)
 {
+	static int count = 0;
+
 	char* tmp;
 	if( !user )
 	{
@@ -217,6 +230,46 @@ static void on_entry_activate(GtkEntry* entry)
 	}
 	else
 	{
+		if (pass_expired) {
+			if (!new_pass) {
+				new_pass = g_strdup(gtk_entry_get_text(entry));
+				switch_to_input_passwd();
+			} else {
+				tmp = g_strdup(gtk_entry_get_text(entry));
+				if (strcmp(new_pass, tmp)) {
+					g_free(new_pass);
+					new_pass = NULL;
+					// if new passwords not match, retry for 3 times at most
+					if (++count < 3) {
+						switch_to_input_passwd();
+					} else {
+						count = 0;
+						pass_expired = FALSE;
+						switch_to_input_user();
+					}
+				} else if (!strcmp(pass, g_base64_encode((guchar*)new_pass, strlen(new_pass) + 1))) {
+					// if new password is same as old one
+					g_free(new_pass);
+					new_pass = NULL;
+					if (++count < 3) {
+						switch_to_input_passwd();
+					} else {
+						count = 0;
+						pass_expired = FALSE;
+						switch_to_input_user();
+					}
+				} else {
+					char *session_exec=get_session_exec();
+					char *session_lang=get_session_lang();
+
+					printf("update-new-password user=%s newpass=%s session=%s lang=%s\n",
+						user, new_pass, session_exec, session_lang);
+				}
+			}
+
+			return ;
+		}
+
 		char *session_exec=get_session_exec();
 		char *session_lang=get_session_lang();
 		
@@ -227,6 +280,7 @@ static void on_entry_activate(GtkEntry* entry)
 		printf("login user=%s pass=%s session=%s lang=%s\n",
 			user, pass, session_exec, session_lang);
 
+#if 0
 		/* password check failed */
 		g_free(user);
 		user = NULL;
@@ -241,6 +295,7 @@ static void on_entry_activate(GtkEntry* entry)
 		gtk_label_set_text( GTK_LABEL(prompt), _("User:") );
 		gtk_entry_set_text(GTK_ENTRY(entry), "");
 		gtk_entry_set_visibility(GTK_ENTRY(entry), TRUE);
+#endif
 	}
 }
 
@@ -1091,8 +1146,12 @@ static void on_screen_size_changed(GdkScreen *screen,GtkWidget *win)
 
 static gint login_entry_on_key_press (GtkWidget *widget,GdkEventKey *event)
 {
-	if(event->keyval == GDK_Escape)
+	if(event->keyval == GDK_Escape) {
+		g_free(new_pass);
+		new_pass = NULL;
+		pass_expired = FALSE;
 		switch_to_input_user();
+	}
 	return FALSE;
 }		     
 
@@ -1285,8 +1344,10 @@ static void create_win()
 
 static gboolean on_lxdm_command(GIOChannel *source, GIOCondition condition, gpointer data)
 {
+
 	GIOStatus ret;
 	char *str;
+	static int count = 0;
 
 	if( !(G_IO_IN & condition) )
 		return FALSE;
@@ -1300,10 +1361,28 @@ static gboolean on_lxdm_command(GIOChannel *source, GIOCondition condition, gpoi
 	{
 		switch_to_input_user();
 	}
+	else if (!strncmp(str, "password-expire", 15))
+	{
+		pass_expired = TRUE;
+		switch_to_input_passwd();
+	}
 	else if( !strncmp(str, "password", 8))
 	{
 		switch_to_input_passwd();
 	}
+	else if (!strncmp(str, "invalid-new-password", 20))
+	{
+		g_free(new_pass);
+		new_pass = NULL;
+
+		if (count++ < 3) {
+			switch_to_input_passwd();
+		} else {
+			count = 0;
+			pass_expired = FALSE;
+			switch_to_input_user();
+		}
+	}
 	g_free(str);
 	return TRUE;
 }
-- 
2.25.1