From cb2db2f1c759c60849b66dabf8ee03c9cdfb2dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Sun, 7 Nov 2010 01:37:06 +0200 Subject: all: check error for sqdb_open and adb_open so we don't crash on startup if essential files are missing. fixes #454 --- src/squark-auth-ip.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src/squark-auth-ip.c') 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 #include +#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; } -- cgit v1.2.3