summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-06-14 11:18:06 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-06-14 11:18:06 +0300
commita1277ab45a9d2bab9ca28baf05f978bf8066d928 (patch)
treecdd341e59b4e9ef9e82ccafd2bc1058ea2be8671
parenta0ed0e6bc7809e88ee1272fa9516dd7e3c7e8d2d (diff)
downloadsquark-a1277ab45a9d2bab9ca28baf05f978bf8066d928.tar.bz2
squark-a1277ab45a9d2bab9ca28baf05f978bf8066d928.tar.xz
filter: support filter-only and track-only modes
-rw-r--r--src/squark-filter.c70
1 files changed, 61 insertions, 9 deletions
diff --git a/src/squark-filter.c b/src/squark-filter.c
index 22c8800..db8fb38 100644
--- a/src/squark-filter.c
+++ b/src/squark-filter.c
@@ -26,11 +26,17 @@
#define FILTER_OVERRIDE_TIMEOUT (15*60)
+#define MODE_NOAUTH 0
+#define MODE_TRACK 1
+#define MODE_CAPTIVE 2
+
static struct sqdb db;
static struct authdb adb;
static struct authdb_config adbc;
static int running = 1;
+static int mode = MODE_CAPTIVE;
+
static const blob_t dash = BLOB_STR_INIT("-");
static const blob_t space = BLOB_STR_INIT(" ");
static const blob_t slash = BLOB_STR_INIT("/");
@@ -401,12 +407,22 @@ static void read_input(struct sqdb *db)
else
category = 0;
- token = authdb_get(&adb, &addr, &entry, 1);
- if (authdb_check_login(token, &entry, username, now, &adbc)) {
+ if (mode == MODE_NOAUTH) {
auth_ok = 1;
- username = BLOB_STRLEN(entry.p.login_name);
} else {
- auth_ok = 0;
+ token = authdb_get(&adb, &addr, &entry, 1);
+ if (authdb_check_login(token, &entry, username, now, &adbc)) {
+ auth_ok = 1;
+ username = BLOB_STRLEN(entry.p.login_name);
+ } else if (mode == MODE_TRACK) {
+ auth_ok = 1;
+ authdb_clear_entry(&entry);
+ memcpy(entry.p.login_name, username.ptr, username.len);
+ authdb_commit_login(token, &entry, now, &adbc);
+ } else {
+ /* mode == MODE_CAPTIVE, and not authenticated */
+ auth_ok = 0;
+ }
}
if (!auth_ok) {
@@ -429,25 +445,61 @@ static void read_input(struct sqdb *db)
} while (b.len);
}
+static int usage(const char *progname)
+{
+ fprintf(stderr,
+ "Usage: %s [-m {captive|track|nauth}]\n"
+ "\n"
+ "Program arguments:\n"
+ " -m Select authentication mode:\n"
+ " captive captive portal authentication enforced\n"
+ " track squid authentication is tracked if available\n"
+ " noauth authentication infromation is ignored (filter only)\n",
+ progname);
+ return 1;
+}
+
int main(int argc, char **argv)
{
- int rc = 1;
+ int rc = 1, opt;
+
+ while ((opt = getopt(argc, argv, "hm:")) != -1) {
+ switch (opt) {
+ case 'm':
+ if (!strcmp(optarg, "captive"))
+ mode = MODE_CAPTIVE;
+ else if (!strcmp(optarg, "track"))
+ mode = MODE_TRACK;
+ else if (!strcmp(optarg, "noauth"))
+ mode = MODE_NOAUTH;
+ else
+ return usage(argv[0]);
+ break;
+ case 'h':
+ default:
+ return usage(argv[0]);
+ }
+ }
if (sqdb_open(&db, squark_dbname) < 0) {
fprintf(stderr, "%s: failed to open squarkdb\n",
squark_dbname);
goto err_sqdb;
}
- if (authdb_open(&adb, &adbc, &db) < 0) {
- fprintf(stderr, "Failed to initialize authdb\n");
- goto err_adb;
+
+ if (mode != MODE_NOAUTH) {
+ if (authdb_open(&adb, &adbc, &db) < 0) {
+ fprintf(stderr, "Failed to initialize authdb\n");
+ goto err_adb;
+ }
}
while (running)
read_input(&db);
rc = 0;
- authdb_close(&adb);
+ if (mode != MODE_NOAUTH)
+ authdb_close(&adb);
err_adb:
sqdb_close(&db);
err_sqdb: