From 54b2ed18ca52fa682ade2fe84e1b0d19d1b78cc4 Mon Sep 17 00:00:00 2001
From: Kai Kang <kai.kang@windriver.com>
Date: Mon, 11 Jan 2021 16:48:26 +0800
Subject: [PATCH 5/8] ui.c: handle password-expire and update-new-password

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

Signed-off-by: Kai Kang <kai.kang@windriver.com>
---
 src/ui.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/ui.c b/src/ui.c
index f233589..3ddb484 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -161,6 +161,9 @@ static gboolean on_greeter_input(GIOChannel *source, GIOCondition condition, gpo
 				ui_drop();
 				lxdm_do_login(pw, session, lang,NULL);
 			}
+			else if (AUTH_PASSWD_EXPIRE == ret) {
+				xwrite(greeter_pipe[0], "password-expire\n", 16);
+			}
 			else
 			{
 				if(pass!=NULL)
@@ -205,6 +208,23 @@ static gboolean on_greeter_input(GIOChannel *source, GIOCondition condition, gpo
 		g_free(session);
 		g_free(lang);
 	}
+	else if (!strncmp(str, "update-new-password", 19)) {
+		xwrite(greeter_pipe[0], "update-new-password\n", 20);
+		char *user = greeter_param(str, "user");
+		char *pass = greeter_param(str, "newpass");
+		char *session = greeter_param(str, "session");
+		char *lang = greeter_param(str, "lang");
+
+		int ret = lxdm_change_passwd(user, pass);
+		if (ret) {
+			xwrite(greeter_pipe[0], "invalid-new-password\n", 21);
+		} else {
+			struct passwd *pw;
+			ret = lxdm_auth_user(AUTH_TYPE_NORMAL, user, pass, &pw);
+			ui_drop();
+			lxdm_do_login(pw, session, lang, NULL);
+		}
+	}
 	g_free(str);
 	return TRUE;
 }
-- 
2.25.1

