diff options
Diffstat (limited to 'authdb.c')
-rw-r--r-- | authdb.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -9,8 +9,11 @@ #include "addr.h" #include "blob.h" +#define ALIGN(s,a) (((s) + a - 1) & ~(a - 1)) + #define AUTHDB_IP_PER_ME 256 #define AUTHDB_LOGOFF_PERIOD (15*60) /* 15 mins */ +#define AUTHDB_SHM_SIZE ALIGN(sizeof(struct authdb_entry[AUTHDB_IP_PER_ME]), 4096) static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) { @@ -32,13 +35,12 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) if (fd < 0) return NULL; - if (create && - ftruncate(fd, sizeof(struct authdb_entry[AUTHDB_IP_PER_ME])) < 0) { + if (create && ftruncate(fd, AUTHDB_SHM_SIZE) < 0) { close(fd); return NULL; } - base = mmap(NULL, sizeof(struct authdb_entry[AUTHDB_IP_PER_ME]), + base = mmap(NULL, AUTHDB_SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); close(fd); @@ -47,7 +49,7 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) me = malloc(sizeof(*me)); if (me == NULL) { - munmap(base, sizeof(struct authdb_entry[AUTHDB_IP_PER_ME])); + munmap(base, AUTHDB_SHM_SIZE); return NULL; } @@ -60,7 +62,7 @@ static struct authdb_map_entry *authdb_me_open(sockaddr_any *addr, int create) static void authdb_me_free(struct authdb_map_entry *me) { - munmap(me->entries, sizeof(struct authdb_entry[AUTHDB_IP_PER_ME])); + munmap(me->entries, AUTHDB_SHM_SIZE); free(me); } @@ -130,7 +132,7 @@ static uint32_t authdb_entry_checksum(struct authdb_entry *entry) void *authdb_get(struct authdb *adb, sockaddr_any *addr, struct authdb_entry *entry, int create) { struct authdb_map_entry *me; - int hash, e, i; + unsigned int hash, e, i; sockaddr_any baseaddr; blob_t b; @@ -156,7 +158,7 @@ void *authdb_get(struct authdb *adb, sockaddr_any *addr, struct authdb_entry *en } for (i = 0; i < 3; i++) { - memcpy(&me->entries[e], entry, sizeof(struct authdb_entry)); + memcpy(entry, &me->entries[e], sizeof(struct authdb_entry)); if (entry->u.checksum == 0 && entry->u.login_time == 0) return &me->entries[e]; if (entry->u.checksum == authdb_entry_checksum(entry)) @@ -221,3 +223,10 @@ void authdb_commit_login(void *token, struct authdb_entry *e, time_t now) authdb_set(token, e); } + +void authdb_commit_override(void *token, struct authdb_entry *e, time_t now) +{ + struct authdb_entry *mme = token; + + mme->u.override_time = now; +} |