summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-09-01 15:13:24 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-09-01 15:14:27 +0300
commiteafaf02a07ea8436d195805bba57a25dc6b9e26b (patch)
treedf3acec78429955708c6c4495eaeeddf6a999520
parent604378a88fc348718b01e5ce8a3a77cf976a7065 (diff)
downloadsquark-eafaf02a07ea8436d195805bba57a25dc6b9e26b.tar.bz2
squark-eafaf02a07ea8436d195805bba57a25dc6b9e26b.tar.xz
filter: option to allow automatic anonymous login
so no captive portal, snmp or squid authentication is required. fixes #737.
-rw-r--r--src/authdb.c13
-rw-r--r--src/authdb.h1
-rw-r--r--src/blob.c7
-rw-r--r--src/blob.h1
-rw-r--r--src/squark-filter.c13
5 files changed, 33 insertions, 2 deletions
diff --git a/src/authdb.c b/src/authdb.c
index d48c43d..8c17ed9 100644
--- a/src/authdb.c
+++ b/src/authdb.c
@@ -323,6 +323,16 @@ static inline uint64_t to_category(struct sqdb *db, blob_t c)
return 0;
}
+static int is_true(blob_t p)
+{
+ if (blob_icmp(p, BLOB_STR("yes")) == 0 ||
+ blob_icmp(p, BLOB_STR("true")) == 0 ||
+ blob_icmp(p, BLOB_STR("1")) == 0)
+ return 1;
+
+ return 0;
+}
+
int adbc_refresh(struct authdb_config *cfg, time_t now)
{
FILE *in;
@@ -349,6 +359,7 @@ int adbc_refresh(struct authdb_config *cfg, time_t now)
cfg->block_categories = 0;
cfg->hard_block_categories = 0;
cfg->logout_timeout = DEFAULT_LOGOUT_TIMEOUT;
+ cfg->require_auth = 1;
while (1) {
b = read_word(in, &lineno, BLOB_BUF(word1));
@@ -364,6 +375,8 @@ int adbc_refresh(struct authdb_config *cfg, time_t now)
cfg->block_categories |= to_category(cfg->db, p);
} else if (blob_cmp(b, BLOB_STR("logout_timeout")) == 0) {
cfg->logout_timeout = blob_pull_uint(&p, 10);
+ } else if (blob_cmp(b, BLOB_STR("require_auth")) == 0) {
+ cfg->require_auth = is_true(p);
}
}
cfg->block_categories |= cfg->hard_block_categories;
diff --git a/src/authdb.h b/src/authdb.h
index 562ed17..5c6c53d 100644
--- a/src/authdb.h
+++ b/src/authdb.h
@@ -19,6 +19,7 @@ struct authdb_config {
uint64_t hard_block_categories;
blob_t redirect_url_base;
unsigned int logout_timeout;
+ int require_auth;
};
struct authdb {
diff --git a/src/blob.c b/src/blob.c
index 0b52233..ea02ea4 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -132,6 +132,13 @@ int blob_cmp(blob_t a, blob_t b)
return memcmp(a.ptr, b.ptr, a.len);
}
+int blob_icmp(blob_t a, blob_t b)
+{
+ if (a.len != b.len)
+ return a.len - b.len;
+ return strncasecmp(a.ptr, b.ptr, a.len);
+}
+
unsigned long blob_inet_addr(blob_t b)
{
unsigned long ip = 0;
diff --git a/src/blob.h b/src/blob.h
index 76afed7..1fcaec0 100644
--- a/src/blob.h
+++ b/src/blob.h
@@ -38,6 +38,7 @@ static inline int blob_is_null(blob_t b)
char *blob_cstr_dup(blob_t b);
blob_t blob_dup(blob_t b);
int blob_cmp(blob_t a, blob_t b);
+int blob_icmp(blob_t a, blob_t b);
unsigned long blob_inet_addr(blob_t buf);
blob_t blob_pushed(blob_t buffer, blob_t left);
diff --git a/src/squark-filter.c b/src/squark-filter.c
index ac99a67..a5d4013 100644
--- a/src/squark-filter.c
+++ b/src/squark-filter.c
@@ -405,7 +405,8 @@ static void read_input(struct sqdb *db)
if (authdb_check_login(token, &entry, username, now, &adbc)) {
auth_ok = 1;
username = BLOB_STRLEN(entry.p.login_name);
- } else if (!blob_is_null(username) && blob_cmp(username, dash) != 0) {
+ } else if ((!adbc.require_auth) ||
+ (!blob_is_null(username) && blob_cmp(username, dash) != 0)) {
auth_ok = 1;
authdb_clear_entry(&entry);
memcpy(entry.p.login_name, username.ptr, username.len);
@@ -436,7 +437,15 @@ static void read_input(struct sqdb *db)
int main(int argc, char **argv)
{
- int rc = 1;
+ int rc = 1, opt;
+
+ while ((opt = getopt(argc, argv, "V")) != -1) {
+ switch (opt) {
+ case 'V':
+ fprintf(stderr, "squark-filter %s\n", squark_version);
+ return 0;
+ }
+ }
if (sqdb_open(&db, squark_dbname) < 0) {
fprintf(stderr, "%s: failed to open squarkdb\n",