From 07e3d4cc011b131619e227a29174f19abb3a20e8 Mon Sep 17 00:00:00 2001 From: Aaron Ball Date: Mon, 17 Aug 2015 20:08:58 -0600 Subject: Added sanity check for bios clock errors When bios clock resets to 1979, terminus reads that, determines the threshold has not been exceeded (because it's a negative number since lastlogin obviously ahead of 1979), and writes the new lastlogin time, which is in 1979. If ntp then updates the clock, the user hasn't logged in in over 35 years, likely exceeding their set threshold. This puts in a sanity check to ensure the difference between lastlogin and now is a positive number. If the difference exceeds -1 day, terminus exits since the system clock is evidently unreliable. --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index fa89688..372e011 100644 --- a/src/main.c +++ b/src/main.c @@ -209,6 +209,15 @@ int main(int argc, char* argv[]) { if((now - lastlogin) > threshold) { printf("You're dead!\n"); exec_cmd(cmd); + } else if((lastlogin - now) > -86400) { + // Abort if last login is too far in the future. + // This should account for when + printf( + "Error: Last login appears to be over one day in the future.\n" + "This likely means something has gone wrong with the system clock.\n" + "Unable to determine current time. Aborting terminus check.\n" + ); + return 2; } else { if(write_lastlogin(lastlogin_path) == 1) { printf("Failure writing lastlogin\n"); -- cgit v1.2.3