From 050e200061d2b5002251c85a83c55bb7e1864a39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 3 Sep 2010 13:41:04 +0300 Subject: auth-ip: implement logout Implement logout function and some minor fixes. --- authdb.c | 5 +++++ authdb.h | 1 + squark-auth-ip.c | 29 ++++++++++++++++++++++++----- squark-filter.c | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/authdb.c b/authdb.c index 77620a3..997e45c 100644 --- a/authdb.c +++ b/authdb.c @@ -224,6 +224,11 @@ void authdb_commit_login(void *token, struct authdb_entry *e, time_t now) authdb_set(token, e); } +void authdb_commit_logout(void *token) +{ + memset(token, 0, sizeof(struct authdb_entry)); +} + void authdb_commit_override(void *token, struct authdb_entry *e, time_t now) { struct authdb_entry *mme = token; diff --git a/authdb.h b/authdb.h index d8bec04..1e50726 100644 --- a/authdb.h +++ b/authdb.h @@ -46,6 +46,7 @@ void authdb_clear_entry(struct authdb_entry *entry); int authdb_set(void *token, struct authdb_entry *entry); int authdb_check_login(void *token, struct authdb_entry *e, blob_t username, time_t now); void authdb_commit_login(void *token, struct authdb_entry *e, time_t now); +void authdb_commit_logout(void *token); void authdb_commit_override(void *token, struct authdb_entry *entry, time_t now); #endif diff --git a/squark-auth-ip.c b/squark-auth-ip.c index dff4f8d..6993e85 100644 --- a/squark-auth-ip.c +++ b/squark-auth-ip.c @@ -17,9 +17,10 @@ #include "blob.h" #include "authdb.h" -#define DO_LOGIN -1 -#define DO_OVERRIDE -2 -#define DO_PRINT -3 +#define DO_LOGIN -1 +#define DO_OVERRIDE -2 +#define DO_PRINT -3 +#define DO_LOGOUT -4 static int running = 1; static struct authdb adb; @@ -106,7 +107,7 @@ int main(int argc, char **argv) sockaddr_any ipaddr = { .any.sa_family = AF_UNSPEC }; blob_t ip = BLOB_NULL, username = BLOB_NULL; - while ((opt = getopt(argc, argv, "i:u:olp")) != -1) { + while ((opt = getopt(argc, argv, "i:u:olpL")) != -1) { switch (opt) { case 'i': ip = BLOB_STRLEN(optarg); @@ -128,6 +129,9 @@ int main(int argc, char **argv) case 'p': running = DO_PRINT; break; + case 'L': + running = DO_LOGOUT; + break; } } @@ -168,13 +172,28 @@ int main(int argc, char **argv) fprintf(stdout, "IP-address: %s\n" "Username: %s\n" + "MAC-address: %02x:%02x:%02x:%02x:%02x:%02x\n" + "Soft block mask: %016llx\n" + "Hard block mask: %016llx\n" "Login time: %s" "Override time: %s", ip.ptr, - username.ptr, + entry.p.login_name, + entry.p.mac_address[0], + entry.p.mac_address[1], + entry.p.mac_address[2], + entry.p.mac_address[3], + entry.p.mac_address[4], + entry.p.mac_address[5], + entry.p.block_categories, + entry.p.hard_block_categories, entry.u.login_time ? ctime_r(&entry.u.login_time, buf1) : "\n", entry.u.override_time ? ctime_r(&entry.u.override_time, buf2) : "\n"); break; + case DO_LOGOUT: + if (authdb_check_login(token, &entry, username, now)) + authdb_commit_logout(token); + break; } } else { while (running) diff --git a/squark-filter.c b/squark-filter.c index 236dad4..78728de 100644 --- a/squark-filter.c +++ b/squark-filter.c @@ -421,8 +421,8 @@ static void read_input(struct sqdb *db) if (!auth_ok) { send_redirect(redirect_login_page, id, url, BLOB_STR("auth"), username); } else if (((1ULL << category) & entry.p.block_categories) && - (entry.u.override_time < now || - entry.u.override_time + FILTER_OVERRIDE_TIMEOUT > now || + (now < entry.u.override_time || + now > entry.u.override_time + FILTER_OVERRIDE_TIMEOUT || ((1ULL << category) & entry.p.hard_block_categories))) { send_redirect(redirect_banned_page, id, url, get_category_name(db, category), username); } else -- cgit v1.2.3