From 3cf835af6d85a8364123116199b24a83d63aee40 Mon Sep 17 00:00:00 2001 From: brapru Date: Sat, 29 May 2021 11:19:05 -0400 Subject: [PATCH] LibCore: Do not write disabled spwd values in generate_shadow_file When LibC/shadow.cpp parses shadow entries in getspent, it sets the spwd member value to disabled (-1) if the value is empty. When Core::Account::sync calls getspent to generate a new shadow file, it would recieve the -1 values and write them in the shadow file. This would cause the /etc/shadow file to be cluttered with disabled values after any password change. This patch checks if the spwd member value is disabled, and prints the appropriate value to the shadow file. --- Userland/Libraries/LibCore/Account.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibCore/Account.cpp b/Userland/Libraries/LibCore/Account.cpp index a0e72f2de4..9151176fca 100644 --- a/Userland/Libraries/LibCore/Account.cpp +++ b/Userland/Libraries/LibCore/Account.cpp @@ -224,18 +224,24 @@ String Account::generate_shadow_file() const if (p->sp_namp == m_username) { builder.appendff("{}:{}:{}:{}:{}:{}:{}:{}:{}\n", m_username, m_password_hash, - p->sp_lstchg, p->sp_min, - p->sp_max, p->sp_warn, - p->sp_inact, p->sp_expire, - p->sp_flag); + (p->sp_lstchg == -1) ? "" : String::formatted("{}", p->sp_lstchg), + (p->sp_min == -1) ? "" : String::formatted("{}", p->sp_min), + (p->sp_max == -1) ? "" : String::formatted("{}", p->sp_max), + (p->sp_warn == -1) ? "" : String::formatted("{}", p->sp_warn), + (p->sp_inact == -1) ? "" : String::formatted("{}", p->sp_inact), + (p->sp_expire == -1) ? "" : String::formatted("{}", p->sp_expire), + (p->sp_flag == 0) ? "" : String::formatted("{}", p->sp_flag)); } else { builder.appendff("{}:{}:{}:{}:{}:{}:{}:{}:{}\n", p->sp_namp, p->sp_pwdp, - p->sp_lstchg, p->sp_min, - p->sp_max, p->sp_warn, - p->sp_inact, p->sp_expire, - p->sp_flag); + (p->sp_lstchg == -1) ? "" : String::formatted("{}", p->sp_lstchg), + (p->sp_min == -1) ? "" : String::formatted("{}", p->sp_min), + (p->sp_max == -1) ? "" : String::formatted("{}", p->sp_max), + (p->sp_warn == -1) ? "" : String::formatted("{}", p->sp_warn), + (p->sp_inact == -1) ? "" : String::formatted("{}", p->sp_inact), + (p->sp_expire == -1) ? "" : String::formatted("{}", p->sp_expire), + (p->sp_flag == 0) ? "" : String::formatted("{}", p->sp_flag)); } } endspent();