Skip to content

Commit ce89bfc

Browse files
Set expiry date to 1970-01-01 to disable account
Currently, we set the expiry date to 1970-01-02 to disable account. When BMC time is 1970-01-01 (default time when RTC is not present), disabling account will not work as expected. This patch fixes this issue by setting the expiry date to 1970-01-01. Tested: Verified account will no longer be able to log in after disabling it on 1970-01-01. Change-Id: Idee0976a5844d742c09bc9ab7383b81a20fadc23 Signed-off-by: Jiaqing Zhao <[email protected]>
1 parent ce4e1aa commit ce89bfc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: user_mgr.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ void UserMgr::createUser(std::string userName,
320320
}
321321
try
322322
{
323+
// set EXPIRE_DATE to 0 to disable user, PAM takes 0 as expire on
324+
// 1970-01-01, that's an implementation-defined behavior
323325
executeCmd("/usr/sbin/useradd", userName.c_str(), "-G", groups.c_str(),
324326
"-m", "-N", "-s",
325327
(sshRequested ? "/bin/sh" : "/bin/nologin"), "-e",
326-
(enabled ? "" : "1970-01-02"));
328+
(enabled ? "" : "1970-01-01"));
327329
}
328330
catch (const InternalFailure& e)
329331
{
@@ -649,8 +651,10 @@ void UserMgr::userEnable(const std::string& userName, bool enabled)
649651
throwForUserDoesNotExist(userName);
650652
try
651653
{
654+
// set EXPIRE_DATE to 0 to disable user, PAM takes 0 as expire on
655+
// 1970-01-01, that's an implementation-defined behavior
652656
executeCmd("/usr/sbin/usermod", userName.c_str(), "-e",
653-
(enabled ? "" : "1970-01-02"));
657+
(enabled ? "" : "1970-01-01"));
654658
}
655659
catch (const InternalFailure& e)
656660
{

0 commit comments

Comments
 (0)