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.
This commit is contained in:
brapru 2021-05-29 11:19:05 -04:00 committed by Linus Groh
parent 92339b7fe5
commit 3cf835af6d
Notes: sideshowbarker 2024-07-18 17:12:24 +09:00

View file

@ -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();