summaryrefslogtreecommitdiffstats
path: root/src
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
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')
-rw-r--r--src/Makefile8
-rw-r--r--src/squark-auth-ip.c23
-rw-r--r--src/squark-auth-snmp.c25
-rw-r--r--src/squark-filter.c20
4 files changed, 61 insertions, 15 deletions
diff --git a/src/Makefile b/src/Makefile
index 5863414..eb24877 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2,14 +2,16 @@ progs-y += squark-filter squark-auth-snmp squark-auth-ip
shlibs-y += squarkdb.so
scripts-y += sqdb-build.lua
-common-objs += filterdb.o authdb.o blob.o addr.o
+common-objs += filterdb.o authdb.o blob.o addr.o config.o
squark-filter-objs += squark-filter.o $(common-objs)
squark-auth-snmp-objs += squark-auth-snmp.o $(common-objs)
squark-auth-ip-objs += squark-auth-ip.o $(common-objs)
squarkdb.so-objs += lua-squarkdb.o filterdb.o blob.o
-CFLAGS += -DSQUARK_VERSION=\"$(FULL_VERSION)\"
+CFLAGS_config.o += -DSQUARK_VERSION=\"$(FULL_VERSION)\" \
+ -DCONFDIR=\"$(CONFDIR)\" \
+ -DLIBDIR=\"$(LIBDIR)\"
LIBS += -lrt
CFLAGS_lua-squarkdb.o += $(shell pkg-config --cflags lua5.1)
@@ -22,4 +24,4 @@ install:
$(INSTALL) $(addprefix $(obj)/,$(progs-y) $(scripts-y)) $(DESTDIR)$(BINDIR)
$(INSTALLDIR) $(DESTDIR)$(LUALIBDIR)
- $(INSTALL) $(addprefix $(obj)/,$(shlibs-y)) $(DESTDIR)$(LUALIBDIR) \ No newline at end of file
+ $(INSTALL) $(addprefix $(obj)/,$(shlibs-y)) $(DESTDIR)$(LUALIBDIR)
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;
}
diff --git a/src/squark-auth-snmp.c b/src/squark-auth-snmp.c
index aa45c73..40ef6b5 100644
--- a/src/squark-auth-snmp.c
+++ b/src/squark-auth-snmp.c
@@ -26,6 +26,7 @@
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
+#include "config.h"
#include "blob.h"
#include "addr.h"
#include "authdb.h"
@@ -1063,13 +1064,16 @@ int main(int argc, char **argv)
struct timeval timeout;
sockaddr_any addr;
fd_set fdset;
- int opt, fds, block, i;
+ int opt, fds, block, i, rc = 1;
setenv("MIBS", "", 1);
init_snmp("squark-auth");
- while ((opt = getopt(argc, argv, "c:r:i:R:v:f:T:K")) != -1) {
+ while ((opt = getopt(argc, argv, "Vc:r:i:R:v:f:T:K")) != -1) {
switch (opt) {
+ case 'V':
+ fprintf(stderr, "squark-auth-snmp %s\n", squark_version);
+ return 0;
case 'c':
snmp_community = optarg;
break;
@@ -1104,8 +1108,15 @@ int main(int argc, char **argv)
return 1;
}
- 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 (l2_root == NULL)
l2_root = l3_root;
@@ -1145,8 +1156,12 @@ int main(int argc, char **argv)
} else
snmp_timeout();
}
+ rc = 0;
+
authdb_close(&adb);
+err_adb:
sqdb_close(&db);
+err_sqdb:
- return 0;
+ return rc;
}
diff --git a/src/squark-filter.c b/src/squark-filter.c
index 14515cf..567201a 100644
--- a/src/squark-filter.c
+++ b/src/squark-filter.c
@@ -18,6 +18,7 @@
#include <cmph.h>
+#include "config.h"
#include "blob.h"
#include "addr.h"
#include "filterdb.h"
@@ -422,12 +423,25 @@ static void read_input(struct sqdb *db)
int main(int argc, char **argv)
{
- sqdb_open(&db, "/var/lib/squark/squark.db");
- authdb_open(&adb, &adbc, &db);
+ int rc = 1;
+
+ 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;
+ }
while (running)
read_input(&db);
+ rc = 0;
- sqdb_close(&db);
authdb_close(&adb);
+err_adb:
+ sqdb_close(&db);
+err_sqdb:
+ return rc;
}