summaryrefslogtreecommitdiffstats
path: root/mbbsd/passwd.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-30 18:08:49 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2009-08-30 18:08:49 +0800
commit5f589c904a3be5b6eaa5abd57052b481d6a24c18 (patch)
treeb58ee25144de9400bc84f164bbb1530ce44a3bee /mbbsd/passwd.c
parent19e36427e3fdfebc319fd7e0a92054ea9db85fd1 (diff)
downloadpttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar.gz
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar.bz2
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar.lz
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar.xz
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.tar.zst
pttbbs-5f589c904a3be5b6eaa5abd57052b481d6a24c18.zip
* fix numlogindays
git-svn-id: http://opensvn.csie.org/pttbbs/branches/pttbbs.pwcu@4799 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/passwd.c')
-rw-r--r--mbbsd/passwd.c34
1 files changed, 27 insertions, 7 deletions
diff --git a/mbbsd/passwd.c b/mbbsd/passwd.c
index 05363661..83fb45a5 100644
--- a/mbbsd/passwd.c
+++ b/mbbsd/passwd.c
@@ -428,21 +428,41 @@ pwcuToggleUserFlag2 (unsigned int mask)
// which we should update/calculate every variables to log.
int pwcuLoginSave ()
{
- PWCU_START(); // XXX no need to reload for speed up?
+ // XXX because LoginSave was called very long after
+ // login_start_time, so we must reload passwd again
+ // here to prevent race condition.
+ // If you want to remove this reload, make sure
+ // pwcuLoginSave is called AFTER login_start_time
+ // was decided.
+ int regdays = 0, prev_regdays = 0;
+ int reftime = login_start_time;
+ PWCU_START();
// new host from 'fromhost'
+ strlcpy( u.lasthost, fromhost, sizeof( u.lasthost));
strlcpy(cuser.lasthost, fromhost, sizeof(cuser.lasthost));
- // calculate numlogins (only increase one per each key)
- if (((login_start_time - cuser.firstlogin) % DAY_SECONDS) !=
- ((cuser.lastlogin - cuser.firstlogin) % DAY_SECONDS) )
- cuser.numlogins++;
+ // this must be valid.
+ assert(login_start_time > 0);
+
+ // invalid session?
+ if (reftime < u.lastlogin)
+ reftime = u.lastlogin;
+
+ regdays = ( reftime - u.firstlogin) / DAY_SECONDS;
+ prev_regdays = (u.lastlogin - u.firstlogin) / DAY_SECONDS;
+ // assert(regdays >= prev_regdays);
+
+ // calculate numlogindays (only increase one per each key)
+ if (regdays > prev_regdays)
+ ++u.numlogindays;
+ cuser.numlogindays = u.numlogindays;
// update last login time
- cuser.lastlogin = login_start_time;
+ cuser.lastlogin = u.lastlogin = reftime;
if (!PERM_HIDE(currutmp))
- cuser.lastseen = login_start_time;
+ cuser.lastseen = u.lastseen = reftime;
PWCU_END();
}