Date: Wed, 6 Jan 2010 20:04:36 +0000 (UTC) From: Ed Schouten <ed@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r201662 - user/ed/utmpx/lib/libc/gen Message-ID: <201001062004.o06K4aob025384@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ed Date: Wed Jan 6 20:04:36 2010 New Revision: 201662 URL: http://svn.freebsd.org/changeset/base/201662 Log: Add some checks to time stamps: - Prevent login sessions from ever getting a negative duration. - Don't update lastlogin when the timestamp is lower than the old value. Modified: user/ed/utmpx/lib/libc/gen/pututxline.c Modified: user/ed/utmpx/lib/libc/gen/pututxline.c ============================================================================== --- user/ed/utmpx/lib/libc/gen/pututxline.c Wed Jan 6 19:57:38 2010 (r201661) +++ user/ed/utmpx/lib/libc/gen/pututxline.c Wed Jan 6 20:04:36 2010 (r201662) @@ -136,7 +136,7 @@ found: } static int -utx_active_remove(const struct futx *fu) +utx_active_remove(struct futx *fu) { int fd; struct futx fe; @@ -158,6 +158,15 @@ utx_active_remove(const struct futx *fu) case LOGIN_PROCESS: if (strncmp(fu->fu_id, fe.fu_id, sizeof fe.fu_id) != 0) continue; + + /* + * Prevent login sessions from having a negative + * timespan. + */ + if (fu->fu_tv < fe.fu_tv) + fu->fu_tv = fe.fu_tv; + + /* Terminate session. */ lseek(fd, -sizeof fe, SEEK_CUR); _write(fd, fu, sizeof *fu); lockf(fd, F_ULOCK, 0); @@ -190,12 +199,19 @@ utx_lastlogin_add(const struct futx *fu) return; } while (_read(fd, &fe, sizeof fe) == sizeof fe) { - if (strncmp(fu->fu_user, fe.fu_user, sizeof fe.fu_user) == 0) { - lseek(fd, -sizeof fe, SEEK_CUR); - break; - } + if (strncmp(fu->fu_user, fe.fu_user, sizeof fe.fu_user) != 0) + continue; + + /* Prevent lowering of the time value. */ + if (fu->fu_tv <= fe.fu_tv) + goto done; + + /* Found a previous lastlogin entry for this * user. */ + lseek(fd, -sizeof fe, SEEK_CUR); + break; } _write(fd, fu, sizeof *fu); +done: lockf(fd, F_ULOCK, 0); _close(fd); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001062004.o06K4aob025384>