summaryrefslogtreecommitdiffstats
path: root/src/squark-auth-ip.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-11-07 01:37:06 +0200
committerTimo Teräs <timo.teras@iki.fi>2010-11-07 01:37:06 +0200
commitcb2db2f1c759c60849b66dabf8ee03c9cdfb2dd5 (patch)
tree870455fc986e81816bd3631f4674b6dd49c30506 /src/squark-auth-ip.c
parent660b77270e599fed9a8a6bc94a0e2d44b8f282dd (diff)
downloadsquark-cb2db2f1c759c60849b66dabf8ee03c9cdfb2dd5.tar.bz2
squark-cb2db2f1c759c60849b66dabf8ee03c9cdfb2dd5.tar.xz
all: check error for sqdb_open and adb_open
so we don't crash on startup if essential files are missing. fixes #454
Diffstat (limited to 'src/squark-auth-ip.c')
-rw-r--r--src/squark-auth-ip.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/squark-auth-ip.c b/src/squark-auth-ip.c
index 3cdea0b..08adca9 100644
--- a/src/squark-auth-ip.c
+++ b/src/squark-auth-ip.c
@@ -14,6 +14,7 @@
#include <stdio.h>
#include <unistd.h>
+#include "config.h"
#include "blob.h"
#include "authdb.h"
#include "filterdb.h"
@@ -113,12 +114,15 @@ static void read_input(void)
int main(int argc, char **argv)
{
- int opt;
+ int opt, rc = 1;
sockaddr_any ipaddr = { .any.sa_family = AF_UNSPEC };
blob_t ip = BLOB_NULL, username = BLOB_NULL;
- while ((opt = getopt(argc, argv, "i:u:olpL")) != -1) {
+ while ((opt = getopt(argc, argv, "Vi:u:olpL")) != -1) {
switch (opt) {
+ case 'V':
+ fprintf(stderr, "squark-auth-ip %s\n", squark_version);
+ return 0;
case 'i':
ip = BLOB_STRLEN(optarg);
if (!addr_parse(ip, &ipaddr)) {
@@ -146,8 +150,15 @@ int main(int argc, char **argv)
}
now = time(NULL);
- sqdb_open(&db, "/var/lib/squark/squark.db");
- authdb_open(&adb, &adbc, &db);
+ 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 (running < 0) {
struct authdb_entry entry;
@@ -212,7 +223,11 @@ int main(int argc, char **argv)
while (running)
read_input();
}
+ rc = 0;
authdb_close(&adb);
+err_adb:
sqdb_close(&db);
+err_sqdb:
+ return rc;
}