diff options
Diffstat (limited to 'authdb.c')
-rw-r--r-- | authdb.c | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -159,9 +159,9 @@ void *authdb_get(struct authdb *adb, sockaddr_any *addr, struct authdb_entry *en for (i = 0; i < 3; i++) { memcpy(entry, &me->entries[e], sizeof(struct authdb_entry)); - if (entry->u.checksum == 0 && entry->u.login_time == 0) + if (entry->checksum == 0 && entry->p.login_time == 0) return &me->entries[e]; - if (entry->u.checksum == authdb_entry_checksum(entry)) + if (entry->checksum == authdb_entry_checksum(entry)) return &me->entries[e]; sched_yield(); } @@ -174,13 +174,13 @@ void *authdb_get(struct authdb *adb, sockaddr_any *addr, struct authdb_entry *en int authdb_set(void *token, struct authdb_entry *entry) { struct authdb_entry *mme = token; - uint32_t checksum = entry->u.checksum; + uint32_t checksum = entry->checksum; - entry->u.checksum = authdb_entry_checksum(entry); - if (mme->u.checksum != checksum) + entry->checksum = authdb_entry_checksum(entry); + if (mme->checksum != checksum) return 0; - mme->u.checksum = entry->u.checksum; + mme->checksum = ~0; memcpy(mme, entry, sizeof(*entry)); return 1; @@ -196,30 +196,33 @@ int authdb_check_login(void *token, struct authdb_entry *e, blob_t username, tim return 0; /* and dates */ - if (now > e->u.login_time + AUTHDB_LOGOFF_PERIOD) + if (now > e->last_activity_time + AUTHDB_LOGOFF_PERIOD) return 0; /* and that no one clobbered the entry */ - if (mme->u.checksum != e->u.checksum) + if (mme->checksum != e->checksum) return 0; /* refresh last activity */ - mme->u.login_time = now; + mme->last_activity_time = now; return 1; } void authdb_clear_entry(struct authdb_entry *entry) { - memset(&entry->p, 0, sizeof(entry->p)); - entry->u.login_time = 0; - entry->u.override_time = 0; + uint32_t checksum = entry->checksum; + + memset(entry, 0, sizeof(*entry)); + entry->checksum = checksum; } void authdb_commit_login(void *token, struct authdb_entry *e, time_t now) { /* fixme read stuff from config files */ - e->u.login_time = now; + e->p.login_time = now; + e->last_activity_time = now; + e->override_time = 0; authdb_set(token, e); } @@ -233,5 +236,5 @@ void authdb_commit_override(void *token, struct authdb_entry *e, time_t now) { struct authdb_entry *mme = token; - mme->u.override_time = now; + mme->override_time = now; } |