diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-09-03 13:41:04 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-09-03 13:41:04 +0300 |
commit | 050e200061d2b5002251c85a83c55bb7e1864a39 (patch) | |
tree | b17b56e60d176bd349e4f419cc25bbfffd1fcc1b | |
parent | 5bc7fd8f1e41365677eb6787cb7d2a6dea62ee0c (diff) | |
download | squark-050e200061d2b5002251c85a83c55bb7e1864a39.tar.bz2 squark-050e200061d2b5002251c85a83c55bb7e1864a39.tar.xz |
auth-ip: implement logout
Implement logout function and some minor fixes.
-rw-r--r-- | authdb.c | 5 | ||||
-rw-r--r-- | authdb.h | 1 | ||||
-rw-r--r-- | squark-auth-ip.c | 29 | ||||
-rw-r--r-- | squark-filter.c | 4 |
4 files changed, 32 insertions, 7 deletions
@@ -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; @@ -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) : "<none>\n", entry.u.override_time ? ctime_r(&entry.u.override_time, buf2) : "<none>\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 |