summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Dowad <alexinbeijing@gmail.com>2014-04-04 14:49:06 +0200
committerTimo Teräs <timo.teras@iki.fi>2014-04-25 10:13:27 +0300
commit184b62e95f19a8eb754d9cc443c332c1b640097c (patch)
tree773e88d4c47c7e95ab68b592542baab54cec386d
parent7efc2ebeda4414bf3c633a6cf86b49c033973f52 (diff)
downloadsquark-184b62e95f19a8eb754d9cc443c332c1b640097c.tar.bz2
squark-184b62e95f19a8eb754d9cc443c332c1b640097c.tar.xz
squark-filter: don't segfault if there is an error in the auth DB
[tt] renamed .htm to .html
-rw-r--r--src/squark-filter.c49
-rw-r--r--www/internal-error.html20
2 files changed, 47 insertions, 22 deletions
diff --git a/src/squark-filter.c b/src/squark-filter.c
index 50b96de..1955a59 100644
--- a/src/squark-filter.c
+++ b/src/squark-filter.c
@@ -416,30 +416,35 @@ static void read_input(struct sqdb *db)
category = 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 ((!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);
- authdb_commit_login(token, &entry, now, &adbc);
+ if (token == NULL) {
+ /* internal error */
+ send_redirect(BLOB_STR("internal-error.html"), id, url, BLOB_STR("internal_error"), username);
} else {
- auth_ok = 0;
- }
+ if (authdb_check_login(token, &entry, username, now, &adbc)) {
+ auth_ok = 1;
+ username = BLOB_STRLEN(entry.p.login_name);
+ } 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);
+ authdb_commit_login(token, &entry, now, &adbc);
+ } else {
+ auth_ok = 0;
+ }
- if (!auth_ok) {
- send_redirect(BLOB_STR("login.cgi"), id, url, BLOB_STR("auth"), username);
- } else if ((1ULL << category) & entry.p.hard_block_categories) {
- send_redirect(BLOB_STR("blocked.cgi"), id, url, get_category_name(db, category), username);
- } else if (((1ULL << category) & entry.p.block_categories) &&
- (now < entry.override_time ||
- now > entry.override_time + FILTER_OVERRIDE_TIMEOUT)) {
- send_redirect(BLOB_STR("warning.cgi"), id, url, get_category_name(db, category), username);
- } else
- send_ok(id, get_category_name(db, category),
- !!((1ULL << category) & entry.p.block_categories));
+ if (!auth_ok) {
+ send_redirect(BLOB_STR("login.cgi"), id, url, BLOB_STR("auth"), username);
+ } else if ((1ULL << category) & entry.p.hard_block_categories) {
+ send_redirect(BLOB_STR("blocked.cgi"), id, url, get_category_name(db, category), username);
+ } else if (((1ULL << category) & entry.p.block_categories) &&
+ (now < entry.override_time ||
+ now > entry.override_time + FILTER_OVERRIDE_TIMEOUT)) {
+ send_redirect(BLOB_STR("warning.cgi"), id, url, get_category_name(db, category), username);
+ } else
+ send_ok(id, get_category_name(db, category),
+ !!((1ULL << category) & entry.p.block_categories));
+ }
}
if (b.len) {
diff --git a/www/internal-error.html b/www/internal-error.html
new file mode 100644
index 0000000..193b978
--- /dev/null
+++ b/www/internal-error.html
@@ -0,0 +1,20 @@
+Content-Type: text/html;charset=UTF-8
+Pragma: no-cache
+Cache-Control: no-cache
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <title>Internal Error</title>
+ <link rel="stylesheet" type="text/css" href="/static/style.css" />
+ </head>
+ <body>
+ <div><img id="warning" src="/static/warning.png" alt="Warning sign" /></div>
+ <div id="outer_container">
+ <div id="inner_container">
+ <h1>Sorry!</h1>
+ <p>An error occurred inside the web filter. Please report this to your network administrator. If you are the administrator, check the system logs on your web proxy.</p>
+ </div>
+ </div>
+ </body>
+</html> \ No newline at end of file