summaryrefslogtreecommitdiffstats
path: root/authdb.h
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-08-27 17:05:18 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-08-27 17:05:18 +0300
commitb8944ab71ccdc9951c6b74ef8ed8686d0329f99c (patch)
treea44327faefdfb99bf61d1249c044bfef66419267 /authdb.h
parent29331f1c5e940499f282aea8155b89fae69f3fb8 (diff)
downloadsquark-b8944ab71ccdc9951c6b74ef8ed8686d0329f99c.tar.bz2
squark-b8944ab71ccdc9951c6b74ef8ed8686d0329f99c.tar.xz
authdb: implement basics
Implement a shared memory based authentication cache. It's a simple local cache indexed by IP-address, and keeps track of that IP's auth info such as username, allowed categories and timeouts. This provides basis for captive portal, per-user definable category restrictions and implementation of soft blocks (block which can be overridden by user by clicking a button on the blocked page).
Diffstat (limited to 'authdb.h')
-rw-r--r--authdb.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/authdb.h b/authdb.h
new file mode 100644
index 0000000..5a3f3c4
--- /dev/null
+++ b/authdb.h
@@ -0,0 +1,50 @@
+#ifndef AUTHDB_H
+#define AUTHDB_H
+
+#include <stddef.h>
+#include <stdint.h>
+#include "blob.h"
+#include "addr.h"
+
+#define AUTHDB_IP_HASH_SIZE 64
+
+struct authdb_map_entry;
+
+struct authdb {
+ struct authdb_map_entry *hash_bucket[AUTHDB_IP_HASH_SIZE];
+};
+
+struct authdb_entry {
+ struct {
+ char login_name[44];
+ char mac_address[6];
+ uint16_t switch_port;
+ sockaddr_any switch_ip;
+ uint64_t block_categories;
+ uint64_t hard_block_categories;
+ } p;
+
+ struct {
+ uint32_t login_time;
+ uint32_t override_time;
+ uint32_t checksum;
+ } u;
+};
+
+struct authdb_map_entry {
+ struct authdb_map_entry *next;
+ sockaddr_any baseaddr;
+ struct authdb_entry * entries;
+};
+
+int authdb_open(struct authdb *adb);
+void authdb_close(struct authdb *adb);
+
+void *authdb_get(struct authdb *adb, sockaddr_any *addr, struct authdb_entry *entry, int create);
+
+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);
+
+#endif