summaryrefslogtreecommitdiffstats
path: root/src/squark-auth-ip.c
diff options
context:
space:
mode:
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;
}